1 """browsepict - Display all "PICT" resources found"""
13 # Resource definitions
18 # Where is the picture window?
28 dummy
= Res
.GetResource('DLOG', ID_MAIN
)
31 Res
.OpenResFile("PICTbrowse.rsrc")
32 except Res
.Error
, arg
:
33 EasyDialogs
.Message("Cannot open PICTbrowse.rsrc: "+arg
[1])
37 class PICTbrowse(FrameWork
.Application
):
39 # First init menus, etc.
40 FrameWork
.Application
.__init
__(self
)
41 # Next create our dialog
42 self
.main_dialog
= MyDialog(self
)
44 contents
= self
.findPICTresources()
45 self
.main_dialog
.open(ID_MAIN
, contents
)
46 # Finally, go into the event loop
49 def makeusermenus(self
):
50 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
51 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
53 def quit(self
, *args
):
56 def showPICT(self
, resid
):
59 #EasyDialogs.Message('Show PICT '+`resid`)
61 def findPICTresources(self
):
62 num
= Res
.CountResources('PICT')
64 for i
in range(1, num
+1):
67 r
= Res
.GetIndResource('PICT', i
)
70 id, type, name
= r
.GetResInfo()
74 class PICTwindow(FrameWork
.Window
):
75 def open(self
, (resid
, resname
)):
79 self
.picture
= Qd
.GetPicture(self
.resid
)
80 # Get rect for picture
81 sz
, t
, l
, b
, r
= struct
.unpack('hhhhh', self
.picture
.data
[:10])
82 self
.pictrect
= (l
, t
, r
, b
)
85 if width
< MINWIDTH
: width
= MINWIDTH
86 elif width
> MAXWIDTH
: width
= MAXWIDTH
87 if height
< MINHEIGHT
: height
= MINHEIGHT
88 elif height
> MAXHEIGHT
: height
= MAXHEIGHT
89 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
91 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
94 def do_update(self
, *args
):
95 currect
= self
.fitrect()
96 Qd
.DrawPicture(self
.picture
, currect
)
99 """Return self.pictrect scaled to fit in window"""
100 graf
= self
.wid
.GetWindowPort()
101 screenrect
= graf
.portRect
102 picwidth
= self
.pictrect
[2] - self
.pictrect
[0]
103 picheight
= self
.pictrect
[3] - self
.pictrect
[1]
104 if picwidth
> screenrect
[2] - screenrect
[0]:
105 factor
= float(picwidth
) / float(screenrect
[2]-screenrect
[0])
106 picwidth
= picwidth
/ factor
107 picheight
= picheight
/ factor
108 if picheight
> screenrect
[3] - screenrect
[1]:
109 factor
= float(picheight
) / float(screenrect
[3]-screenrect
[1])
110 picwidth
= picwidth
/ factor
111 picheight
= picheight
/ factor
112 return (screenrect
[0], screenrect
[1], screenrect
[0]+int(picwidth
),
113 screenrect
[1]+int(picheight
))
115 class MyDialog(FrameWork
.DialogWindow
):
116 "Main dialog window for PICTbrowse"
118 def open(self
, id, contents
):
120 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
121 self
.wid
.SetDialogDefaultItem(MAIN_SHOW
)
122 tp
, h
, rect
= self
.wid
.GetDialogItem(MAIN_LIST
)
123 rect2
= rect
[0]+1, rect
[1]+1, rect
[2]-17, rect
[3]-17 # Scroll bar space
124 self
.list = List
.LNew(rect2
, (0, 0, 1, len(contents
)), (0,0), 0, self
.wid
,
126 self
.contents
= contents
130 self
.list.LDelRow(0, 0)
131 self
.list.LSetDrawingMode(0)
133 self
.list.LAddRow(len(self
.contents
), 0)
134 for i
in range(len(self
.contents
)):
135 v
= `self
.contents
[i
][0]`
136 if self
.contents
[i
][1]:
137 v
= v
+ '"' + self
.contents
[i
][1] + '"'
138 self
.list.LSetCell(v
, (0, i
))
139 self
.list.LSetDrawingMode(1)
140 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
142 def do_listhit(self
, event
):
143 (what
, message
, when
, where
, modifiers
) = event
145 where
= Qd
.GlobalToLocal(where
)
146 print 'LISTHIT', where
147 if self
.list.LClick(where
, modifiers
):
150 def getselection(self
):
154 ok
, point
= self
.list.LGetSelect(1, point
)
157 items
.append(point
[1])
158 point
= point
[0], point
[1]+1
161 values
.append(self
.contents
[i
])
164 def do_show(self
, *args
):
165 selection
= self
.getselection()
166 for resid
in selection
:
167 self
.parent
.showPICT(resid
)
169 def do_rawupdate(self
, window
, event
):
170 tp
, h
, rect
= self
.wid
.GetDialogItem(MAIN_LIST
)
173 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
175 def do_activate(self
, activate
, event
):
176 self
.list.LActivate(activate
)
181 def do_itemhit(self
, item
, event
):
182 if item
== MAIN_LIST
:
183 self
.do_listhit(event
)
184 if item
== MAIN_SHOW
: