1 """browsepict - Display all "PICT" resources found"""
13 # Resource definitions
18 # Where is the picture window?
24 dummy
= Res
.GetResource('DLOG', ID_MAIN
)
27 Res
.OpenResFile("PICTbrowse.rsrc")
28 except Res
.Error
, arg
:
29 EasyDialogs
.Message("Cannot open PICTbrowse.rsrc: "+arg
[1])
33 class PICTbrowse(FrameWork
.Application
):
35 # First init menus, etc.
36 FrameWork
.Application
.__init
__(self
)
37 # Next create our dialog
38 self
.main_dialog
= MyDialog(self
)
40 contents
= self
.findPICTresources()
41 self
.main_dialog
.open(ID_MAIN
, contents
)
42 # Finally, go into the event loop
45 def makeusermenus(self
):
46 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
47 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
49 def quit(self
, *args
):
52 def showPICT(self
, resid
):
55 #EasyDialogs.Message('Show PICT '+`resid`)
57 def findPICTresources(self
):
58 num
= Res
.CountResources('PICT')
60 for i
in range(1, num
+1):
63 r
= Res
.GetIndResource('PICT', i
)
66 id, type, name
= r
.GetResInfo()
70 class PICTwindow(FrameWork
.Window
):
71 def open(self
, (resid
, resname
)):
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
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
89 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
90 self
.wid
.SetWindowPic(picture
)
93 class MyDialog(FrameWork
.DialogWindow
):
94 "Main dialog window for PICTbrowse"
96 def open(self
, id, contents
):
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
,
104 self
.contents
= contents
108 self
.list.LDelRow(0, 0)
109 self
.list.LSetDrawingMode(0)
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(self
.wid
.GetWindowPort().visRgn
)
120 def do_listhit(self
, event
):
121 (what
, message
, when
, where
, modifiers
) = event
123 where
= Qd
.GlobalToLocal(where
)
124 print 'LISTHIT', where
125 if self
.list.LClick(where
, modifiers
):
128 def getselection(self
):
132 ok
, point
= self
.list.LGetSelect(1, point
)
135 items
.append(point
[1])
136 point
= point
[0], point
[1]+1
139 values
.append(self
.contents
[i
])
142 def do_show(self
, *args
):
143 selection
= self
.getselection()
144 for resid
in selection
:
145 self
.parent
.showPICT(resid
)
147 def do_rawupdate(self
, window
, event
):
148 tp
, h
, rect
= self
.wid
.GetDialogItem(MAIN_LIST
)
151 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
153 def do_activate(self
, activate
, event
):
154 self
.list.LActivate(activate
)
159 def do_itemhit(self
, item
, event
):
160 if item
== MAIN_LIST
:
161 self
.do_listhit(event
)
162 if item
== MAIN_SHOW
: