1 """browsepict - Display all "ICON" resources found"""
15 # Resource definitions
20 # Where is the picture window?
30 dummy
= Res
.GetResource('DLOG', ID_MAIN
)
33 Res
.FSpOpenResFile("PICTbrowse.rsrc", 1)
34 except Res
.Error
, arg
:
35 EasyDialogs
.Message("Cannot open PICTbrowse.rsrc: "+arg
[1])
39 class ICONbrowse(FrameWork
.Application
):
41 # First init menus, etc.
42 FrameWork
.Application
.__init
__(self
)
43 # Next create our dialog
44 self
.main_dialog
= MyDialog(self
)
46 contents
= self
.findICONresources()
47 self
.main_dialog
.open(ID_MAIN
, contents
)
48 # Finally, go into the event loop
51 def makeusermenus(self
):
52 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
53 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
55 def quit(self
, *args
):
58 def showICON(self
, resid
):
61 #EasyDialogs.Message('Show ICON '+`resid`)
63 def findICONresources(self
):
64 num
= Res
.CountResources('ICON')
66 for i
in range(1, num
+1):
69 r
= Res
.GetIndResource('ICON', i
)
72 id, type, name
= r
.GetResInfo()
76 class ICONwindow(FrameWork
.Window
):
77 def open(self
, (resid
, resname
)):
81 self
.picture
= Icn
.GetIcon(self
.resid
)
82 l
, t
, r
, b
= 0, 0, 32, 32
83 self
.pictrect
= (l
, t
, r
, b
)
86 if width
< MINWIDTH
: width
= MINWIDTH
87 elif width
> MAXWIDTH
: width
= MAXWIDTH
88 if height
< MINHEIGHT
: height
= MINHEIGHT
89 elif height
> MAXHEIGHT
: height
= MAXHEIGHT
90 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
92 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
95 def do_update(self
, *args
):
96 currect
= self
.fitrect()
97 Icn
.PlotIcon(currect
, self
.picture
)
100 """Return self.pictrect scaled to fit in window"""
101 graf
= self
.wid
.GetWindowPort()
102 screenrect
= graf
.portRect
103 picwidth
= self
.pictrect
[2] - self
.pictrect
[0]
104 picheight
= self
.pictrect
[3] - self
.pictrect
[1]
105 if picwidth
> screenrect
[2] - screenrect
[0]:
106 factor
= float(picwidth
) / float(screenrect
[2]-screenrect
[0])
107 picwidth
= picwidth
/ factor
108 picheight
= picheight
/ factor
109 if picheight
> screenrect
[3] - screenrect
[1]:
110 factor
= float(picheight
) / float(screenrect
[3]-screenrect
[1])
111 picwidth
= picwidth
/ factor
112 picheight
= picheight
/ factor
113 return (screenrect
[0], screenrect
[1], screenrect
[0]+int(picwidth
),
114 screenrect
[1]+int(picheight
))
116 class MyDialog(FrameWork
.DialogWindow
):
117 "Main dialog window for ICONbrowse"
119 def open(self
, id, contents
):
121 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
122 self
.wid
.SetDialogDefaultItem(MAIN_SHOW
)
123 self
.contents
= contents
124 self
.ctl
= self
.wid
.GetDialogItemAsControl(MAIN_LIST
)
125 h
= self
.ctl
.GetControlData_Handle(Controls
.kControlListBoxPart
,
126 Controls
.kControlListBoxListHandleTag
)
127 self
.list = List
.as_List(h
)
131 self
.list.LDelRow(0, 0)
132 self
.list.LSetDrawingMode(0)
134 self
.list.LAddRow(len(self
.contents
), 0)
135 for i
in range(len(self
.contents
)):
136 v
= `self
.contents
[i
][0]`
137 if self
.contents
[i
][1]:
138 v
= v
+ '"' + self
.contents
[i
][1] + '"'
139 self
.list.LSetCell(v
, (0, i
))
140 self
.list.LSetDrawingMode(1)
141 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
143 def getselection(self
):
147 ok
, point
= self
.list.LGetSelect(1, point
)
150 items
.append(point
[1])
151 point
= point
[0], point
[1]+1
154 values
.append(self
.contents
[i
])
157 def do_show(self
, *args
):
158 selection
= self
.getselection()
159 for resid
in selection
:
160 self
.parent
.showICON(resid
)
165 def do_itemhit(self
, item
, event
):
166 if item
== MAIN_SHOW
: