blob: 04d321c057f6b62429245276c42e2b37c3a58c55 [file] [log] [blame]
Jack Jansen07043b41995-11-14 11:32:06 +00001"""browsepict - Display all "PICT" resources found"""
2
3import FrameWork
4import EasyDialogs
5import Res
6import Qd
7import Win
Jack Jansen3b23ed91999-12-23 14:45:02 +00008import Controls
Jack Jansen07043b41995-11-14 11:32:06 +00009import List
10import sys
11import struct
12
13#
14# Resource definitions
15ID_MAIN=512
16MAIN_LIST=1
17MAIN_SHOW=2
18
19# Where is the picture window?
20LEFT=200
21TOP=64
22
23def main():
24 try:
25 dummy = Res.GetResource('DLOG', ID_MAIN)
26 except Res.Error:
27 try:
Jack Jansen8eff33b2000-06-20 22:01:04 +000028 Res.FSpOpenResFile("PICTbrowse.rsrc", 1)
Jack Jansen07043b41995-11-14 11:32:06 +000029 except Res.Error, arg:
30 EasyDialogs.Message("Cannot open PICTbrowse.rsrc: "+arg[1])
31 sys.exit(1)
32 PICTbrowse()
33
34class PICTbrowse(FrameWork.Application):
35 def __init__(self):
36 # First init menus, etc.
37 FrameWork.Application.__init__(self)
38 # Next create our dialog
39 self.main_dialog = MyDialog(self)
40 # Now open the dialog
41 contents = self.findPICTresources()
42 self.main_dialog.open(ID_MAIN, contents)
43 # Finally, go into the event loop
44 self.mainloop()
45
46 def makeusermenus(self):
47 self.filemenu = m = FrameWork.Menu(self.menubar, "File")
48 self.quititem = FrameWork.MenuItem(m, "Quit", "Q", self.quit)
49
50 def quit(self, *args):
Jack Jansenef5cd051996-09-17 12:39:12 +000051 self._quit()
Jack Jansen07043b41995-11-14 11:32:06 +000052
53 def showPICT(self, resid):
54 w = PICTwindow(self)
55 w.open(resid)
56 #EasyDialogs.Message('Show PICT '+`resid`)
57
58 def findPICTresources(self):
59 num = Res.CountResources('PICT')
60 rv = []
61 for i in range(1, num+1):
62 Res.SetResLoad(0)
63 try:
64 r = Res.GetIndResource('PICT', i)
65 finally:
66 Res.SetResLoad(1)
67 id, type, name = r.GetResInfo()
Jack Jansen34d11f02000-03-07 23:40:13 +000068 rv.append((id, name))
Jack Jansen07043b41995-11-14 11:32:06 +000069 return rv
70
71class PICTwindow(FrameWork.Window):
72 def open(self, (resid, resname)):
73 if not resname:
74 resname = '#'+`resid`
75 self.resid = resid
76 picture = Qd.GetPicture(self.resid)
77 # Get rect for picture
78 print `picture.data[:16]`
79 sz, t, l, b, r = struct.unpack('hhhhh', picture.data[:10])
80 print 'pict:', t, l, b, r
81 width = r-l
82 height = b-t
83 if width < 64: width = 64
84 elif width > 480: width = 480
85 if height < 64: height = 64
86 elif height > 320: height = 320
87 bounds = (LEFT, TOP, LEFT+width, TOP+height)
88 print 'bounds:', bounds
89
90 self.wid = Win.NewWindow(bounds, resname, 1, 0, -1, 1, 0)
91 self.wid.SetWindowPic(picture)
92 self.do_postopen()
93
94class MyDialog(FrameWork.DialogWindow):
95 "Main dialog window for PICTbrowse"
96
97 def open(self, id, contents):
98 self.id = id
99 FrameWork.DialogWindow.open(self, ID_MAIN)
100 self.wid.SetDialogDefaultItem(MAIN_SHOW)
Jack Jansen07043b41995-11-14 11:32:06 +0000101 self.contents = contents
Jack Jansen3b23ed91999-12-23 14:45:02 +0000102 self.ctl = self.wid.GetDialogItemAsControl(MAIN_LIST)
Jack Jansene7bfc912001-01-09 22:22:58 +0000103 h = self.ctl.GetControlData_Handle(Controls.kControlListBoxPart,
Jack Jansen3b23ed91999-12-23 14:45:02 +0000104 Controls.kControlListBoxListHandleTag)
105 self.list = List.as_List(h)
Jack Jansen07043b41995-11-14 11:32:06 +0000106 self.setlist()
107
108 def setlist(self):
109 self.list.LDelRow(0, 0)
110 self.list.LSetDrawingMode(0)
111 if self.contents:
112 self.list.LAddRow(len(self.contents), 0)
113 for i in range(len(self.contents)):
114 v = `self.contents[i][0]`
115 if self.contents[i][1]:
116 v = v + '"' + self.contents[i][1] + '"'
117 self.list.LSetCell(v, (0, i))
118 self.list.LSetDrawingMode(1)
Jack Jansen84949671996-04-10 14:53:29 +0000119 self.list.LUpdate(self.wid.GetWindowPort().visRgn)
Jack Jansen07043b41995-11-14 11:32:06 +0000120
Jack Jansen07043b41995-11-14 11:32:06 +0000121 def getselection(self):
122 items = []
123 point = (0,0)
124 while 1:
125 ok, point = self.list.LGetSelect(1, point)
126 if not ok:
127 break
128 items.append(point[1])
129 point = point[0], point[1]+1
130 values = []
131 for i in items:
132 values.append(self.contents[i])
133 return values
134
135 def do_show(self, *args):
136 selection = self.getselection()
137 for resid in selection:
138 self.parent.showPICT(resid)
139
Jack Jansen07043b41995-11-14 11:32:06 +0000140 def do_close(self):
141 self.close()
142
143 def do_itemhit(self, item, event):
Jack Jansen07043b41995-11-14 11:32:06 +0000144 if item == MAIN_SHOW:
145 self.do_show()
146
147main()