1 """browsepict - Display all "ICON" resources found"""
8 from Carbon
import Controls
9 from Carbon
import List
12 from Carbon
import Icn
16 # Resource definitions
21 # Where is the picture window?
30 macresource
.need('DLOG', ID_MAIN
, "PICTbrowse.rsrc")
33 class ICONbrowse(FrameWork
.Application
):
35 # First init menus, etc.
36 FrameWork
.Application
.__init
__(self
)
37 # Next create our dialog
38 self
.main_dialog
= MyDialog(self
)
40 contents
= self
.findICONresources()
41 self
.main_dialog
.open(ID_MAIN
, contents
)
42 # Finally, go into the event loop
45 def makeusermenus(self
):
46 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
47 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
49 def quit(self
, *args
):
52 def showICON(self
, resid
):
55 #EasyDialogs.Message('Show ICON '+`resid`)
57 def findICONresources(self
):
58 num
= Res
.CountResources('ICON')
60 for i
in range(1, num
+1):
63 r
= Res
.GetIndResource('ICON', i
)
66 id, type, name
= r
.GetResInfo()
70 class ICONwindow(FrameWork
.Window
):
71 def open(self
, (resid
, resname
)):
75 self
.picture
= Icn
.GetIcon(self
.resid
)
76 l
, t
, r
, b
= 0, 0, 32, 32
77 self
.pictrect
= (l
, t
, r
, b
)
80 if width
< MINWIDTH
: width
= MINWIDTH
81 elif width
> MAXWIDTH
: width
= MAXWIDTH
82 if height
< MINHEIGHT
: height
= MINHEIGHT
83 elif height
> MAXHEIGHT
: height
= MAXHEIGHT
84 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
86 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
89 def do_update(self
, *args
):
90 currect
= self
.fitrect()
91 Icn
.PlotIcon(currect
, self
.picture
)
94 """Return self.pictrect scaled to fit in window"""
95 graf
= self
.wid
.GetWindowPort()
96 screenrect
= graf
.GetPortBounds()
97 picwidth
= self
.pictrect
[2] - self
.pictrect
[0]
98 picheight
= self
.pictrect
[3] - self
.pictrect
[1]
99 if picwidth
> screenrect
[2] - screenrect
[0]:
100 factor
= float(picwidth
) / float(screenrect
[2]-screenrect
[0])
101 picwidth
= picwidth
/ factor
102 picheight
= picheight
/ factor
103 if picheight
> screenrect
[3] - screenrect
[1]:
104 factor
= float(picheight
) / float(screenrect
[3]-screenrect
[1])
105 picwidth
= picwidth
/ factor
106 picheight
= picheight
/ factor
107 return (screenrect
[0], screenrect
[1], screenrect
[0]+int(picwidth
),
108 screenrect
[1]+int(picheight
))
110 class MyDialog(FrameWork
.DialogWindow
):
111 "Main dialog window for ICONbrowse"
113 def open(self
, id, contents
):
115 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
116 self
.dlg
.SetDialogDefaultItem(MAIN_SHOW
)
117 self
.contents
= contents
118 self
.ctl
= self
.dlg
.GetDialogItemAsControl(MAIN_LIST
)
119 h
= self
.ctl
.GetControlData_Handle(Controls
.kControlListBoxPart
,
120 Controls
.kControlListBoxListHandleTag
)
121 self
.list = List
.as_List(h
)
125 self
.list.LDelRow(0, 0)
126 self
.list.LSetDrawingMode(0)
128 self
.list.LAddRow(len(self
.contents
), 0)
129 for i
in range(len(self
.contents
)):
130 v
= `self
.contents
[i
][0]`
131 if self
.contents
[i
][1]:
132 v
= v
+ '"' + self
.contents
[i
][1] + '"'
133 self
.list.LSetCell(v
, (0, i
))
134 self
.list.LSetDrawingMode(1)
135 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
137 def getselection(self
):
141 ok
, point
= self
.list.LGetSelect(1, point
)
144 items
.append(point
[1])
145 point
= point
[0], point
[1]+1
148 values
.append(self
.contents
[i
])
151 def do_show(self
, *args
):
152 selection
= self
.getselection()
153 for resid
in selection
:
154 self
.parent
.showICON(resid
)
159 def do_itemhit(self
, item
, event
):
160 if item
== MAIN_SHOW
: