1 """browsepict - Display all "PICT" resources found"""
8 from Carbon
import List
14 # Resource definitions
19 # Where is the picture window?
24 macresource
.need('DLOG', ID_MAIN
, "oldPICTbrowse.rsrc")
27 class PICTbrowse(FrameWork
.Application
):
29 # First init menus, etc.
30 FrameWork
.Application
.__init
__(self
)
31 # Next create our dialog
32 self
.main_dialog
= MyDialog(self
)
34 contents
= self
.findPICTresources()
35 self
.main_dialog
.open(ID_MAIN
, contents
)
36 # Finally, go into the event loop
39 def makeusermenus(self
):
40 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
41 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
43 def quit(self
, *args
):
46 def showPICT(self
, resid
):
49 #EasyDialogs.Message('Show PICT '+`resid`)
51 def findPICTresources(self
):
52 num
= Res
.CountResources('PICT')
54 for i
in range(1, num
+1):
57 r
= Res
.GetIndResource('PICT', i
)
60 id, type, name
= r
.GetResInfo()
64 class PICTwindow(FrameWork
.Window
):
65 def open(self
, (resid
, resname
)):
69 picture
= Qd
.GetPicture(self
.resid
)
70 # Get rect for picture
71 print `picture
.data
[:16]`
72 sz
, t
, l
, b
, r
= struct
.unpack('hhhhh', picture
.data
[:10])
73 print 'pict:', t
, l
, b
, r
76 if width
< 64: width
= 64
77 elif width
> 480: width
= 480
78 if height
< 64: height
= 64
79 elif height
> 320: height
= 320
80 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
81 print 'bounds:', bounds
83 self
.wid
= Win
.NewWindow(bounds
, resname
, 1, 0, -1, 1, 0)
84 self
.wid
.SetWindowPic(picture
)
87 class MyDialog(FrameWork
.DialogWindow
):
88 "Main dialog window for PICTbrowse"
90 def open(self
, id, contents
):
92 FrameWork
.DialogWindow
.open(self
, ID_MAIN
)
93 self
.dlg
.SetDialogDefaultItem(MAIN_SHOW
)
94 tp
, h
, rect
= self
.dlg
.GetDialogItem(MAIN_LIST
)
95 rect2
= rect
[0]+1, rect
[1]+1, rect
[2]-17, rect
[3]-17 # Scroll bar space
96 self
.list = List
.LNew(rect2
, (0, 0, 1, len(contents
)), (0,0), 0, self
.wid
,
98 self
.contents
= contents
102 self
.list.LDelRow(0, 0)
103 self
.list.LSetDrawingMode(0)
105 self
.list.LAddRow(len(self
.contents
), 0)
106 for i
in range(len(self
.contents
)):
107 v
= `self
.contents
[i
][0]`
108 if self
.contents
[i
][1]:
109 v
= v
+ '"' + self
.contents
[i
][1] + '"'
110 self
.list.LSetCell(v
, (0, i
))
111 self
.list.LSetDrawingMode(1)
112 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
114 def do_listhit(self
, event
):
115 (what
, message
, when
, where
, modifiers
) = event
117 where
= Qd
.GlobalToLocal(where
)
118 print 'LISTHIT', where
119 if self
.list.LClick(where
, modifiers
):
122 def getselection(self
):
126 ok
, point
= self
.list.LGetSelect(1, point
)
129 items
.append(point
[1])
130 point
= point
[0], point
[1]+1
133 values
.append(self
.contents
[i
])
136 def do_show(self
, *args
):
137 selection
= self
.getselection()
138 for resid
in selection
:
139 self
.parent
.showPICT(resid
)
141 def do_rawupdate(self
, window
, event
):
142 tp
, h
, rect
= self
.dlg
.GetDialogItem(MAIN_LIST
)
145 self
.list.LUpdate(self
.wid
.GetWindowPort().visRgn
)
147 def do_activate(self
, activate
, event
):
148 self
.list.LActivate(activate
)
153 def do_itemhit(self
, item
, event
):
154 if item
== MAIN_LIST
:
155 self
.do_listhit(event
)
156 if item
== MAIN_SHOW
: