1 """browsepict - Display all "PICT" resources found"""
14 # Resource definitions
19 # Where is the picture window?
25 dummy
= Res
.GetResource('DLOG', ID_MAIN
)
28 Res
.FSpOpenResFile("PICTbrowse.rsrc", 1)
29 except Res
.Error
, arg
:
30 EasyDialogs
.Message("Cannot open PICTbrowse.rsrc: "+arg
[1])
34 class PICTbrowse(FrameWork
.Application
):
36 # First init menus, etc.
37 FrameWork
.Application
.__init
__(self
)
38 # Next create our dialog
39 self
.main_dialog
= MyDialog(self
)
41 contents
= self
.findPICTresources()
42 self
.main_dialog
.open(ID_MAIN
, contents
)
43 # Finally, go into the event loop
46 def makeusermenus(self
):
47 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
48 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
50 def quit(self
, *args
):
53 def showPICT(self
, resid
):
56 #EasyDialogs.Message('Show PICT '+`resid`)
58 def findPICTresources(self
):
59 num
= Res
.CountResources('PICT')
61 for i
in range(1, num
+1):
64 r
= Res
.GetIndResource('PICT', i
)
67 id, type, name
= r
.GetResInfo()
71 class PICTwindow(FrameWork
.Window
):
72 def open(self
, (resid
, resname
)):
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
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
90 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
91 self
.wid
.SetWindowPic(picture
)
94 class MyDialog(FrameWork
.DialogWindow
):
95 "Main dialog window for PICTbrowse"
97 def open(self
, id, contents
):
99 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
100 self
.wid
.SetDialogDefaultItem(MAIN_SHOW
)
101 self
.contents
= contents
102 self
.ctl
= self
.wid
.GetDialogItemAsControl(MAIN_LIST
)
103 h
= self
.ctl
.GetControlData_Handle(Controls
.kControlListBoxPart
,
104 Controls
.kControlListBoxListHandleTag
)
105 self
.list = List
.as_List(h
)
109 self
.list.LDelRow(0, 0)
110 self
.list.LSetDrawingMode(0)
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)
119 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
121 def getselection(self
):
125 ok
, point
= self
.list.LGetSelect(1, point
)
128 items
.append(point
[1])
129 point
= point
[0], point
[1]+1
132 values
.append(self
.contents
[i
])
135 def do_show(self
, *args
):
136 selection
= self
.getselection()
137 for resid
in selection
:
138 self
.parent
.showPICT(resid
)
143 def do_itemhit(self
, item
, event
):
144 if item
== MAIN_SHOW
: