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?
28 macresource
.need('DLOG', ID_MAIN
, "PICTbrowse.rsrc")
31 class PICTbrowse(FrameWork
.Application
):
33 # First init menus, etc.
34 FrameWork
.Application
.__init
__(self
)
35 # Next create our dialog
36 self
.main_dialog
= MyDialog(self
)
38 contents
= self
.findPICTresources()
39 self
.main_dialog
.open(ID_MAIN
, contents
)
40 # Finally, go into the event loop
43 def makeusermenus(self
):
44 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
45 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
47 def quit(self
, *args
):
50 def showPICT(self
, resid
):
53 #EasyDialogs.Message('Show PICT %r' % (resid,))
55 def findPICTresources(self
):
56 num
= Res
.CountResources('PICT')
58 for i
in range(1, num
+1):
61 r
= Res
.GetIndResource('PICT', i
)
64 id, type, name
= r
.GetResInfo()
68 class PICTwindow(FrameWork
.Window
):
69 def open(self
, (resid
, resname
)):
71 resname
= '#%r' % (resid
,)
73 self
.picture
= Qd
.GetPicture(self
.resid
)
74 # Get rect for picture
75 sz
, t
, l
, b
, r
= struct
.unpack('hhhhh', self
.picture
.data
[:10])
76 self
.pictrect
= (l
, t
, r
, b
)
79 if width
< MINWIDTH
: width
= MINWIDTH
80 elif width
> MAXWIDTH
: width
= MAXWIDTH
81 if height
< MINHEIGHT
: height
= MINHEIGHT
82 elif height
> MAXHEIGHT
: height
= MAXHEIGHT
83 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
85 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
88 def do_update(self
, *args
):
89 currect
= self
.fitrect()
90 Qd
.DrawPicture(self
.picture
, currect
)
93 """Return self.pictrect scaled to fit in window"""
94 graf
= self
.dlg
.GetWindowPort()
95 screenrect
= graf
.GetPortBounds()
96 picwidth
= self
.pictrect
[2] - self
.pictrect
[0]
97 picheight
= self
.pictrect
[3] - self
.pictrect
[1]
98 if picwidth
> screenrect
[2] - screenrect
[0]:
99 factor
= float(picwidth
) / float(screenrect
[2]-screenrect
[0])
100 picwidth
= picwidth
/ factor
101 picheight
= picheight
/ factor
102 if picheight
> screenrect
[3] - screenrect
[1]:
103 factor
= float(picheight
) / float(screenrect
[3]-screenrect
[1])
104 picwidth
= picwidth
/ factor
105 picheight
= picheight
/ factor
106 return (screenrect
[0], screenrect
[1], screenrect
[0]+int(picwidth
),
107 screenrect
[1]+int(picheight
))
109 class MyDialog(FrameWork
.DialogWindow
):
110 "Main dialog window for PICTbrowse"
112 def open(self
, id, contents
):
114 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
115 self
.dlg
.SetDialogDefaultItem(MAIN_SHOW
)
116 self
.contents
= contents
117 self
.ctl
= self
.dlg
.GetDialogItemAsControl(MAIN_LIST
)
118 h
= self
.ctl
.GetControlData_Handle(Controls
.kControlListBoxPart
,
119 Controls
.kControlListBoxListHandleTag
)
120 self
.list = List
.as_List(h
)
124 self
.list.LDelRow(0, 0)
125 self
.list.LSetDrawingMode(0)
127 self
.list.LAddRow(len(self
.contents
), 0)
128 for i
in range(len(self
.contents
)):
129 v
= repr(self
.contents
[i
][0])
130 if self
.contents
[i
][1]:
131 v
= v
+ '"' + self
.contents
[i
][1] + '"'
132 self
.list.LSetCell(v
, (0, i
))
133 self
.list.LSetDrawingMode(1)
134 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
136 def getselection(self
):
140 ok
, point
= self
.list.LGetSelect(1, point
)
143 items
.append(point
[1])
144 point
= point
[0], point
[1]+1
147 values
.append(self
.contents
[i
])
150 def do_show(self
, *args
):
151 selection
= self
.getselection()
152 for resid
in selection
:
153 self
.parent
.showPICT(resid
)
158 def do_itemhit(self
, item
, event
):
159 if item
== MAIN_SHOW
: