Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 07043b4

Browse files
committed
Browse all PICT resources in the resource chain. Uses SetWindowPic for
display.
1 parent 330f576 commit 07043b4

2 files changed

Lines changed: 176 additions & 0 deletions

File tree

Mac/Demo/PICTbrowse/PICTbrowse.py

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
"""browsepict - Display all "PICT" resources found"""
2+
3+
import FrameWork
4+
import EasyDialogs
5+
import Res
6+
import Qd
7+
import Win
8+
import List
9+
import sys
10+
import struct
11+
12+
#
13+
# Resource definitions
14+
ID_MAIN=512
15+
MAIN_LIST=1
16+
MAIN_SHOW=2
17+
18+
# Where is the picture window?
19+
LEFT=200
20+
TOP=64
21+
22+
def main():
23+
try:
24+
dummy = Res.GetResource('DLOG', ID_MAIN)
25+
except Res.Error:
26+
try:
27+
Res.OpenResFile("PICTbrowse.rsrc")
28+
except Res.Error, arg:
29+
EasyDialogs.Message("Cannot open PICTbrowse.rsrc: "+arg[1])
30+
sys.exit(1)
31+
PICTbrowse()
32+
33+
class PICTbrowse(FrameWork.Application):
34+
def __init__(self):
35+
# First init menus, etc.
36+
FrameWork.Application.__init__(self)
37+
# Next create our dialog
38+
self.main_dialog = MyDialog(self)
39+
# Now open the dialog
40+
contents = self.findPICTresources()
41+
self.main_dialog.open(ID_MAIN, contents)
42+
# Finally, go into the event loop
43+
self.mainloop()
44+
45+
def makeusermenus(self):
46+
self.filemenu = m = FrameWork.Menu(self.menubar, "File")
47+
self.quititem = FrameWork.MenuItem(m, "Quit", "Q", self.quit)
48+
49+
def quit(self, *args):
50+
raise self
51+
52+
def showPICT(self, resid):
53+
w = PICTwindow(self)
54+
w.open(resid)
55+
#EasyDialogs.Message('Show PICT '+`resid`)
56+
57+
def findPICTresources(self):
58+
num = Res.CountResources('PICT')
59+
rv = []
60+
for i in range(1, num+1):
61+
Res.SetResLoad(0)
62+
try:
63+
r = Res.GetIndResource('PICT', i)
64+
finally:
65+
Res.SetResLoad(1)
66+
id, type, name = r.GetResInfo()
67+
rv.append(id, name)
68+
return rv
69+
70+
class PICTwindow(FrameWork.Window):
71+
def open(self, (resid, resname)):
72+
if not resname:
73+
resname = '#'+`resid`
74+
self.resid = resid
75+
picture = Qd.GetPicture(self.resid)
76+
# Get rect for picture
77+
print `picture.data[:16]`
78+
sz, t, l, b, r = struct.unpack('hhhhh', picture.data[:10])
79+
print 'pict:', t, l, b, r
80+
width = r-l
81+
height = b-t
82+
if width < 64: width = 64
83+
elif width > 480: width = 480
84+
if height < 64: height = 64
85+
elif height > 320: height = 320
86+
bounds = (LEFT, TOP, LEFT+width, TOP+height)
87+
print 'bounds:', bounds
88+
89+
self.wid = Win.NewWindow(bounds, resname, 1, 0, -1, 1, 0)
90+
self.wid.SetWindowPic(picture)
91+
self.do_postopen()
92+
93+
class MyDialog(FrameWork.DialogWindow):
94+
"Main dialog window for PICTbrowse"
95+
96+
def open(self, id, contents):
97+
self.id = id
98+
FrameWork.DialogWindow.open(self, ID_MAIN)
99+
self.wid.SetDialogDefaultItem(MAIN_SHOW)
100+
tp, h, rect = self.wid.GetDialogItem(MAIN_LIST)
101+
rect2 = rect[0]+1, rect[1]+1, rect[2]-17, rect[3]-17 # Scroll bar space
102+
self.list = List.LNew(rect2, (0, 0, 1, len(contents)), (0,0), 0, self.wid,
103+
0, 1, 1, 1)
104+
self.contents = contents
105+
self.setlist()
106+
107+
def setlist(self):
108+
self.list.LDelRow(0, 0)
109+
self.list.LSetDrawingMode(0)
110+
if self.contents:
111+
self.list.LAddRow(len(self.contents), 0)
112+
for i in range(len(self.contents)):
113+
v = `self.contents[i][0]`
114+
if self.contents[i][1]:
115+
v = v + '"' + self.contents[i][1] + '"'
116+
self.list.LSetCell(v, (0, i))
117+
self.list.LSetDrawingMode(1)
118+
self.list.LUpdate()
119+
120+
def do_listhit(self, event):
121+
(what, message, when, where, modifiers) = event
122+
Qd.SetPort(self.wid)
123+
where = Qd.GlobalToLocal(where)
124+
print 'LISTHIT', where
125+
if self.list.LClick(where, modifiers):
126+
self.do_show()
127+
128+
def getselection(self):
129+
items = []
130+
point = (0,0)
131+
while 1:
132+
ok, point = self.list.LGetSelect(1, point)
133+
if not ok:
134+
break
135+
items.append(point[1])
136+
point = point[0], point[1]+1
137+
values = []
138+
for i in items:
139+
values.append(self.contents[i])
140+
return values
141+
142+
def do_show(self, *args):
143+
selection = self.getselection()
144+
for resid in selection:
145+
self.parent.showPICT(resid)
146+
147+
def do_rawupdate(self, window, event):
148+
tp, h, rect = self.wid.GetDialogItem(MAIN_LIST)
149+
Qd.SetPort(self.wid)
150+
Qd.FrameRect(rect)
151+
self.list.LUpdate()
152+
153+
def do_activate(self, activate, event):
154+
self.list.LActivate(activate)
155+
156+
def do_close(self):
157+
self.close()
158+
159+
def do_itemhit(self, item, event):
160+
if item == MAIN_LIST:
161+
self.do_listhit(event)
162+
if item == MAIN_SHOW:
163+
self.do_show()
164+
165+
main()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(This file may be decompressed with BinHex 4.0)
2+
3+
:$e"*3e4LFQphFf8ZFR0bB`"bFh*M8P0&4!%!N!F"P%(e!*!%!3!!!!%r!!!!2`!!
4+
!&A4J4r`!2Vr!!$kr`!!qYJ!!2VB!!$kf!!!qYJ!!2VrS!p35808BR*[Gh0P,R*c
5+
FQ-#!!!!FR0bBe*6483"!*!&FR0bBe*6483"!*!%J!#3%Uc0"jX!N!B"P2m!!2Vr
6+
!!$kf!!!qYJ!!2VB!!$kf!!!q[qJ!2Vr)2!!q[m!!2Vr!!$kf"8!!2VB!!$kf!!!
7+
%rVB!!$krb!+)!XJ$!'J!#!'X4!8q!$kr`!!qYJ!!2VB!!$kf!!!qYJ!!2VB!!$k
8+
r`!!q[m!!2Vrq!$kra!Q!!$krm!!q[m`q!$kr`#3""8!3!!3!43!a3!!!3!"!*!&
9+
!J#3"5)!!3#3"38!#J#M!+`!N!Hd!$`!b!"f"!46D'ph!!!"!!!!!6m!!!!r!!!!
10+
93$`,136H!!!!"`!4J!"4%a24`!!!"*%594-!!!!(J)!N!X#!2rr!!!!'3#3"!j#
11+
FQphFf9b)(GTEQ4[Gcf!:

0 commit comments

Comments
 (0)