1 """browsepict - Display all "cicn" resources found"""
8 from Carbon
import Controls
9 from Carbon
import List
10 from Carbon
import Icn
14 # Resource definitions
19 # Where is the picture window?
28 macresource
.need('DLOG', ID_MAIN
, "PICTbrowse.rsrc")
31 class CIconbrowse(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
.findcicnresources()
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 showCIcon(self
, resid
):
53 #EasyDialogs.Message('Show cicn %r' % (resid,))
55 def findcicnresources(self
):
56 num
= Res
.CountResources('cicn')
58 for i
in range(1, num
+1):
61 r
= Res
.GetIndResource('cicn', i
)
64 id, type, name
= r
.GetResInfo()
68 class CIconwindow(FrameWork
.Window
):
69 def open(self
, (resid
, resname
)):
71 resname
= '#%r' % (resid
,)
73 self
.picture
= Icn
.GetCIcon(self
.resid
)
74 l
, t
, r
, b
= 0, 0, 32, 32
75 self
.pictrect
= (l
, t
, r
, b
)
78 if width
< MINWIDTH
: width
= MINWIDTH
79 elif width
> MAXWIDTH
: width
= MAXWIDTH
80 if height
< MINHEIGHT
: height
= MINHEIGHT
81 elif height
> MAXHEIGHT
: height
= MAXHEIGHT
82 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
84 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
87 def do_update(self
, *args
):
88 currect
= self
.fitrect()
89 Icn
.PlotCIcon(currect
, self
.picture
)
92 """Return self.pictrect scaled to fit in window"""
93 graf
= self
.wid
.GetWindowPort()
94 screenrect
= graf
.GetPortBounds()
95 picwidth
= self
.pictrect
[2] - self
.pictrect
[0]
96 picheight
= self
.pictrect
[3] - self
.pictrect
[1]
97 if picwidth
> screenrect
[2] - screenrect
[0]:
98 factor
= float(picwidth
) / float(screenrect
[2]-screenrect
[0])
99 picwidth
= picwidth
/ factor
100 picheight
= picheight
/ factor
101 if picheight
> screenrect
[3] - screenrect
[1]:
102 factor
= float(picheight
) / float(screenrect
[3]-screenrect
[1])
103 picwidth
= picwidth
/ factor
104 picheight
= picheight
/ factor
105 return (screenrect
[0], screenrect
[1], screenrect
[0]+int(picwidth
),
106 screenrect
[1]+int(picheight
))
108 class MyDialog(FrameWork
.DialogWindow
):
109 "Main dialog window for cicnbrowse"
111 def open(self
, id, contents
):
113 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
114 self
.dlg
.SetDialogDefaultItem(MAIN_SHOW
)
115 self
.contents
= contents
116 self
.ctl
= self
.dlg
.GetDialogItemAsControl(MAIN_LIST
)
117 h
= self
.ctl
.GetControlData_Handle(Controls
.kControlListBoxPart
,
118 Controls
.kControlListBoxListHandleTag
)
119 self
.list = List
.as_List(h
)
123 self
.list.LDelRow(0, 0)
124 self
.list.LSetDrawingMode(0)
126 self
.list.LAddRow(len(self
.contents
), 0)
127 for i
in range(len(self
.contents
)):
128 v
= repr(self
.contents
[i
][0])
129 if self
.contents
[i
][1]:
130 v
= v
+ '"' + self
.contents
[i
][1] + '"'
131 self
.list.LSetCell(v
, (0, i
))
132 self
.list.LSetDrawingMode(1)
133 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
135 def getselection(self
):
139 ok
, point
= self
.list.LGetSelect(1, point
)
142 items
.append(point
[1])
143 point
= point
[0], point
[1]+1
146 values
.append(self
.contents
[i
])
149 def do_show(self
, *args
):
150 selection
= self
.getselection()
151 for resid
in selection
:
152 self
.parent
.showCIcon(resid
)
157 def do_itemhit(self
, item
, event
):
158 if item
== MAIN_SHOW
: