1 """browsepict - Display all "PICT" resources found"""
8 from Carbon
import Controls
9 from Carbon
import List
15 # Resource definitions
20 # Where is the picture window?
25 macresource
.need('DLOG', ID_MAIN
, "PICTbrowse.rsrc")
28 class PICTbrowse(FrameWork
.Application
):
30 # First init menus, etc.
31 FrameWork
.Application
.__init
__(self
)
32 # Next create our dialog
33 self
.main_dialog
= MyDialog(self
)
35 contents
= self
.findPICTresources()
36 self
.main_dialog
.open(ID_MAIN
, contents
)
37 # Finally, go into the event loop
40 def makeusermenus(self
):
41 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
42 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
44 def quit(self
, *args
):
47 def showPICT(self
, resid
):
50 #EasyDialogs.Message('Show PICT '+`resid`)
52 def findPICTresources(self
):
53 num
= Res
.CountResources('PICT')
55 for i
in range(1, num
+1):
58 r
= Res
.GetIndResource('PICT', i
)
61 id, type, name
= r
.GetResInfo()
65 class PICTwindow(FrameWork
.Window
):
66 def open(self
, (resid
, resname
)):
70 picture
= Qd
.GetPicture(self
.resid
)
71 # Get rect for picture
72 print `picture
.data
[:16]`
73 sz
, t
, l
, b
, r
= struct
.unpack('hhhhh', picture
.data
[:10])
74 print 'pict:', t
, l
, b
, r
77 if width
< 64: width
= 64
78 elif width
> 480: width
= 480
79 if height
< 64: height
= 64
80 elif height
> 320: height
= 320
81 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
82 print 'bounds:', bounds
84 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
85 self
.wid
.SetWindowPic(picture
)
88 class MyDialog(FrameWork
.DialogWindow
):
89 "Main dialog window for PICTbrowse"
91 def open(self
, id, contents
):
93 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
94 self
.dlg
.SetDialogDefaultItem(MAIN_SHOW
)
95 self
.contents
= contents
96 self
.ctl
= self
.dlg
.GetDialogItemAsControl(MAIN_LIST
)
97 h
= self
.ctl
.GetControlData_Handle(Controls
.kControlListBoxPart
,
98 Controls
.kControlListBoxListHandleTag
)
99 self
.list = List
.as_List(h
)
103 self
.list.LDelRow(0, 0)
104 self
.list.LSetDrawingMode(0)
106 self
.list.LAddRow(len(self
.contents
), 0)
107 for i
in range(len(self
.contents
)):
108 v
= `self
.contents
[i
][0]`
109 if self
.contents
[i
][1]:
110 v
= v
+ '"' + self
.contents
[i
][1] + '"'
111 self
.list.LSetCell(v
, (0, i
))
112 self
.list.LSetDrawingMode(1)
113 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
115 def getselection(self
):
119 ok
, point
= self
.list.LGetSelect(1, point
)
122 items
.append(point
[1])
123 point
= point
[0], point
[1]+1
126 values
.append(self
.contents
[i
])
129 def do_show(self
, *args
):
130 selection
= self
.getselection()
131 for resid
in selection
:
132 self
.parent
.showPICT(resid
)
137 def do_itemhit(self
, item
, event
):
138 if item
== MAIN_SHOW
: