1 """browsepict - Display all "PICT" resources found"""
8 from Carbon
import Controls
9 from Carbon
import List
14 # Resource definitions
19 # Where is the picture window?
24 macresource
.need('DLOG', ID_MAIN
, "PICTbrowse.rsrc")
27 class PICTbrowse(FrameWork
.Application
):
29 # First init menus, etc.
30 FrameWork
.Application
.__init
__(self
)
31 # Next create our dialog
32 self
.main_dialog
= MyDialog(self
)
34 contents
= self
.findPICTresources()
35 self
.main_dialog
.open(ID_MAIN
, contents
)
36 # Finally, go into the event loop
39 def makeusermenus(self
):
40 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
41 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
43 def quit(self
, *args
):
46 def showPICT(self
, resid
):
49 #EasyDialogs.Message('Show PICT %r' % (resid,))
51 def findPICTresources(self
):
52 num
= Res
.CountResources('PICT')
54 for i
in range(1, num
+1):
57 r
= Res
.GetIndResource('PICT', i
)
60 id, type, name
= r
.GetResInfo()
64 class PICTwindow(FrameWork
.Window
):
65 def open(self
, (resid
, resname
)):
67 resname
= '#%r' % (resid
,)
69 picture
= Qd
.GetPicture(self
.resid
)
70 # Get rect for picture
71 print repr(picture
.data
[:16])
72 sz
, t
, l
, b
, r
= struct
.unpack('hhhhh', picture
.data
[:10])
73 print 'pict:', t
, l
, b
, r
76 if width
< 64: width
= 64
77 elif width
> 480: width
= 480
78 if height
< 64: height
= 64
79 elif height
> 320: height
= 320
80 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
81 print 'bounds:', bounds
83 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
84 self
.wid
.SetWindowPic(picture
)
87 class MyDialog(FrameWork
.DialogWindow
):
88 "Main dialog window for PICTbrowse"
90 def open(self
, id, contents
):
92 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
93 self
.dlg
.SetDialogDefaultItem(MAIN_SHOW
)
94 self
.contents
= contents
95 self
.ctl
= self
.dlg
.GetDialogItemAsControl(MAIN_LIST
)
96 h
= self
.ctl
.GetControlData_Handle(Controls
.kControlListBoxPart
,
97 Controls
.kControlListBoxListHandleTag
)
98 self
.list = List
.as_List(h
)
102 self
.list.LDelRow(0, 0)
103 self
.list.LSetDrawingMode(0)
105 self
.list.LAddRow(len(self
.contents
), 0)
106 for i
in range(len(self
.contents
)):
107 v
= repr(self
.contents
[i
][0])
108 if self
.contents
[i
][1]:
109 v
= v
+ '"' + self
.contents
[i
][1] + '"'
110 self
.list.LSetCell(v
, (0, i
))
111 self
.list.LSetDrawingMode(1)
112 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
114 def getselection(self
):
118 ok
, point
= self
.list.LGetSelect(1, point
)
121 items
.append(point
[1])
122 point
= point
[0], point
[1]+1
125 values
.append(self
.contents
[i
])
128 def do_show(self
, *args
):
129 selection
= self
.getselection()
130 for resid
in selection
:
131 self
.parent
.showPICT(resid
)
136 def do_itemhit(self
, item
, event
):
137 if item
== MAIN_SHOW
: