Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP migrate to GTK3 and assorted deprecated functions #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 39 additions & 33 deletions oletoy/App.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@

import sys,struct,os
import re
import tree, gtk
import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk

import tree

import ole,mf,svm,cdr,clp,cpl
import rx2,fh,fh12,mdb,cpt,cdw,pkzip,wld,vsd,yep
import abr,rtf,otxml,chdraw,vfb,fbx,nki,pngot
import drw
import qxp
#import qxp
import iwa
import lrf
import palm
Expand Down Expand Up @@ -73,9 +79,9 @@ def fload(self,buf="",parent=None,package=None):
f = open(self.fname,"rb")
buf = f.read()

if buf[0:7] == "\0\0IIXPR" or buf[0:7] == "\0\0MMXPR":
self.type = qxp.open(self, buf, parent)
return 0
# if buf[0:7] == "\0\0IIXPR" or buf[0:7] == "\0\0MMXPR":
# self.type = qxp.open(self, buf, parent)
# return 0

if buf[:8] == "\x89PNG\x0d\x0a\x1a\x0a":
self.type = pngot.open(self, buf, parent)
Expand Down Expand Up @@ -244,7 +250,7 @@ def fload(self,buf="",parent=None,package=None):
plist.open(buf,self,parent)
return 0

fh_off = buf.find('FreeHand')
fh_off = buf.find(b'FreeHand')
if buf[0:3] == 'AGD':
agd_off = 0
agd_ver = ord(buf[agd_off+3])
Expand All @@ -271,7 +277,7 @@ def fload(self,buf="",parent=None,package=None):
fh12.fh_open(buf, self, parent, 0)
return 0
if buf[0:2] == "FH":
fh_off = buf.find('FHDocHeader')
fh_off = buf.find(b'FHDocHeader')
if fh_off != -1:
try:
self.type = "FH"
Expand Down Expand Up @@ -299,7 +305,7 @@ def fload(self,buf="",parent=None,package=None):
bmi.open(buf, self, parent)
return 0

size = (ord(buf[1]) | (ord(buf[2]) << 8)) + 4
size = (buf[1] | (buf[2] << 8)) + 4
if buf[0] == '\0' and (size == len(buf) or (size < len(buf) and buf[4:7] == "\x80\x80\x04")):
self.type = 'IWA'
if not self.subtype:
Expand All @@ -317,7 +323,7 @@ def fload(self,buf="",parent=None,package=None):
c602.parse_chart(buf, self, parent)
return 0

if re.match('@[A-Z]{2} .*?\\r\\n', buf) and buf[-1] == '\x1a':
if re.match('@[A-Z]{2} .*?\\r\\n', str(buf)) and buf[-1] == '\x1a':
self.type = 'T602'
print('Probably T602 file')
t602.parse(buf, self, parent)
Expand All @@ -329,21 +335,21 @@ def fload(self,buf="",parent=None,package=None):
quattro_wq.wq_open(self, buf, parent)
return 0

# QuarkXPress 1.x data fork
if buf[0:4] == '\x00\x1c\x00\x1c' or buf[0:4] == '\x00\x20\x00\x20':
try:
qxp.open_v1(self,buf,parent)
self.type = 'QXP5'
return 0
except:
print ("Failed after attempt to parse as QXP1...")
if buf[0:4] == '\x00\x26\x00\x26':
try:
qxp.open_v2(self,buf,parent)
self.type = 'QXP5'
return 0
except:
print ("Failed after attempt to parse as QXP2...")
# # QuarkXPress 1.x data fork
# if buf[0:4] == '\x00\x1c\x00\x1c' or buf[0:4] == '\x00\x20\x00\x20':
# try:
# qxp.open_v1(self,buf,parent)
# self.type = 'QXP5'
# return 0
# except:
# print ("Failed after attempt to parse as QXP1...")
# if buf[0:4] == '\x00\x26\x00\x26':
# try:
# qxp.open_v2(self,buf,parent)
# self.type = 'QXP5'
# return 0
# except:
# print ("Failed after attempt to parse as QXP2...")

if parent == None:
parent = add_pgiter(self, "File", "file","unknown",buf)
Expand All @@ -363,31 +369,31 @@ def fload(self,buf="",parent=None,package=None):
return 0

def show_search(self,carg):
view = gtk.TreeView(self.search)
view = Gtk.TreeView(self.search)
view.set_reorderable(True)
view.set_enable_tree_lines(True)
cell1 = gtk.CellRendererText()
cell1 = Gtk.CellRendererText()
cell1.set_property('family-set',True)
cell1.set_property('font','monospace 10')
cell2 = gtk.CellRendererText()
cell2 = Gtk.CellRendererText()
cell2.set_property('family-set',True)
cell2.set_property('font','monospace 10')
column1 = gtk.TreeViewColumn('Type', cell1, text=0)
column2 = gtk.TreeViewColumn('Value', cell2, text=2)
column3 = gtk.TreeViewColumn('#', cell2, text=3)
column1 = Gtk.TreeViewColumn('Type', cell1, text=0)
column2 = Gtk.TreeViewColumn('Value', cell2, text=2)
column3 = Gtk.TreeViewColumn('#', cell2, text=3)
view.append_column(column3)
view.append_column(column1)
view.append_column(column2)
view.show()
view.connect("row-activated", self.on_search_row_activated)
scrolled = gtk.ScrolledWindow()
scrolled = Gtk.ScrolledWindow()
scrolled.add(view)
scrolled.set_size_request(400,400)
scrolled.show()
searchwin = gtk.Window(gtk.WINDOW_TOPLEVEL)
searchwin = Gtk.Window(Gtk.WindowType.TOPLEVEL)
searchwin.set_resizable(True)
searchwin.set_border_width(0)
scrolled.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,Gtk.PolicyType.AUTOMATIC)
searchwin.add(scrolled)
searchwin.set_title("Search: %s"%carg)
searchwin.show_all()
Expand Down
5 changes: 4 additions & 1 deletion oletoy/abr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
# USA
#

import sys,struct,gtk
import sys,struct
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from utils import *

def p_patt(page,buf,offset,name,parent):
Expand Down
2 changes: 1 addition & 1 deletion oletoy/c602.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def add_text(hd, size, data, off, name='Text'):
(length, off) = rdata(data, off, '<B')
add_iter(hd, '%s length' % name, length, off - 1, 1, '<B')
(text, off) = rdata(data, off, '%ds' % length)
add_iter(hd, name, unicode(text, 'cp852'), off - length, length, '%ds' % length)
add_iter(hd, name, str(text, 'cp852'), off - length, length, '%ds' % length)
return off

def add_range(hd, size, data, off):
Expand Down
44 changes: 23 additions & 21 deletions oletoy/cdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
# USA
#

import sys,struct,gtk,zlib
import gobject
import sys,struct,zlib
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GObject, Gdk
import icc,cmx
from utils import *
import traceback
Expand Down Expand Up @@ -710,23 +712,23 @@ def bmpf (hd,size,data):
bmp = struct.unpack("<I",data[0x18:0x1c])[0]
bmpoff = struct.pack("<I",len(data)+10-bmp)
img = 'BM'+struct.pack("<I",len(data)+8)+'\x00\x00\x00\x00'+bmpoff+data[4:]
pixbufloader = gtk.gdk.PixbufLoader()
pixbufloader = Gdk.PixbufLoader()
pixbufloader.write(img)
pixbufloader.close()
pixbuf = pixbufloader.get_pixbuf()
imgw=pixbuf.get_width()
imgh=pixbuf.get_height()
da = gtk.DrawingArea()
scrolled = gtk.ScrolledWindow()
scrolled.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
da = Gtk.DrawingArea()
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,Gtk.PolicyType.AUTOMATIC)
scrolled.add_with_viewport(da)
da.set_size_request(imgh,imgw)
hd.da = scrolled
# hd.hbox0.pack_start(hd.da)
hd.hdscrolled.add2(hd.da)
hd.dispscale = 1
da.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK)
da.connect('expose_event', hd.disp_expose,pixbuf)
da.set_events(Gdk.BUTTON_PRESS_MASK | Gdk.BUTTON_RELEASE_MASK | Gdk.POINTER_MOTION_MASK)
da.connect('draw', hd.disp_expose,pixbuf)
da.connect("button_press_event",hd.disp_on_button_press,pixbuf)
ctx = hd.da.window.cairo_create()
ctx.set_source_pixbuf(pixbuf,0,0)
Expand Down Expand Up @@ -793,23 +795,23 @@ def bmp (hd,size,data):
else:
img += data[0x7a:palsize*3] + data[bmpoff:]

pixbufloader = gtk.gdk.PixbufLoader()
pixbufloader = Gdk.PixbufLoader()
pixbufloader.write(img)
pixbufloader.close()
hd.dispscale = 1
pixbuf = pixbufloader.get_pixbuf()
imgw=pixbuf.get_width()
imgh=pixbuf.get_height()
da = gtk.DrawingArea()
scrolled = gtk.ScrolledWindow()
scrolled.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
da = Gtk.DrawingArea()
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,Gtk.PolicyType.AUTOMATIC)
scrolled.add_with_viewport(da)
da.set_size_request(imgh,imgw)
hd.da = scrolled
# hd.hbox0.pack_start(hd.da)
hd.hdscrolled.add2(hd.da)
da.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK)
da.connect('expose_event', hd.disp_expose,pixbuf)
da.set_events(Gdk.BUTTON_PRESS_MASK | Gdk.BUTTON_RELEASE_MASK | Gdk.POINTER_MOTION_MASK)
da.connect('draw', hd.disp_expose,pixbuf)
da.connect("button_press_event",hd.disp_on_button_press,pixbuf)
ctx = hd.da.window.cairo_create()
ctx.set_source_pixbuf(pixbuf,0,0)
Expand Down Expand Up @@ -1637,23 +1639,23 @@ def disp (hd,size,data,page):
bmp = struct.unpack("<I",data[0x18:0x1c])[0]
bmpoff = struct.pack("<I",len(data)+10-bmp)
img = 'BM'+struct.pack("<I",len(data)+8)+'\x00\x00\x00\x00'+bmpoff+data[4:]
pixbufloader = gtk.gdk.PixbufLoader()
pixbufloader = Gdk.PixbufLoader()
pixbufloader.write(img)
pixbufloader.close()
hd.dispscale = 1
pixbuf = pixbufloader.get_pixbuf()
imgw=pixbuf.get_width()
imgh=pixbuf.get_height()
da = gtk.DrawingArea()
scrolled = gtk.ScrolledWindow()
scrolled.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
da = Gtk.DrawingArea()
scrolled = Gtk.ScrolledWindow()
scrolled.set_policy(Gtk.PolicyType.AUTOMATIC,Gtk.PolicyType.AUTOMATIC)
scrolled.add_with_viewport(da)
da.set_size_request(imgh,imgw)
hd.da = scrolled
# hd.hbox0.pack_start(hd.da)
hd.hdscrolled.add2(hd.da)
da.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.POINTER_MOTION_MASK)
da.connect('expose_event', hd.disp_expose,pixbuf)
da.set_events(Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.POINTER_MOTION_MASK)
da.connect('draw', hd.disp_expose,pixbuf)
da.connect("button_press_event",hd.disp_on_button_press,pixbuf)
hd.da.show_all()

Expand Down Expand Up @@ -2377,7 +2379,7 @@ def save (page,fname):

def cdr_open (buf,page,parent,fmttype="cdr"):
# Path, Name, ID
page.dictmod = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
page.dictmod = Gtk.TreeStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING)
chunk = record()
chunk.load (buf,page,parent,0,(),fmttype)

Expand Down
6 changes: 4 additions & 2 deletions oletoy/cdw.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#

import sys,struct
import gtk
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import tree
import hexdump
from utils import *
Expand Down Expand Up @@ -43,7 +45,7 @@ def parse_lastrec (page, data,parent):
off += tlen+16+shift
elif tflag == 2:
tlen = struct.unpack("<I",data[off+0xe+shift:off+0x12+shift])[0]
tdata = unicode(data[off+0x12+shift:off+0x12+tlen*2+shift],"utf-16")
tdata = str(data[off+0x12+shift:off+0x12+tlen*2+shift],"utf-16")
off += tlen*2+18+shift
else:
tdata = "%04x"%(struct.unpack("<H",data[off+0xe+shift:off+0x10+shift])[0])
Expand Down
5 changes: 4 additions & 1 deletion oletoy/clp.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
# USA
#

import sys,struct,gtk
import sys,struct
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from utils import *

def open (buf,page,parent):
Expand Down
4 changes: 3 additions & 1 deletion oletoy/cmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#

import sys,struct
import gtk
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from utils import *


Expand Down
5 changes: 4 additions & 1 deletion oletoy/cpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@

# Corel palettes

import sys,struct,gtk
import sys,struct
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from utils import *

def open(buf,page,parent):
Expand Down
5 changes: 4 additions & 1 deletion oletoy/cpt.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
# USA
#

import sys,struct,gtk
import sys,struct
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
from utils import *

def name_cnvrt(name):
Expand Down
Loading