1 """imgbrowse - Display pictures using img"""
19 # Where is the picture window?
32 class imgbrowse(FrameWork
.Application
):
34 # First init menus, etc.
35 FrameWork
.Application
.__init
__(self
)
37 # Finally, go into the event loop
40 def makeusermenus(self
):
41 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
42 self
.openitem
= FrameWork
.MenuItem(m
, "Open...", "O", self
.opendoc
)
43 self
.infoitem
= FrameWork
.MenuItem(m
, "Info", "I", self
.info
)
44 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
46 def quit(self
, *args
):
49 def opendoc(self
, *args
):
50 fss
, ok
= macfs
.StandardGetFile() # Any file type
53 bar
= EasyDialogs
.ProgressBar('Reading and converting...')
54 pathname
= fss
.as_pathname()
56 rdr
= img
.reader(imgformat
.macrgb16
, pathname
)
57 except img
.error
, arg
:
58 EasyDialogs
.Message(`arg`
)
60 w
, h
= rdr
.width
, rdr
.height
64 pixmap
= mac_image
.mkpixmap(w
, h
, imgformat
.macrgb16
, data
)
65 self
.showimg(w
, h
, pixmap
, data
)
67 def showimg(self
, w
, h
, pixmap
, data
):
69 win
.open(w
, h
, pixmap
, data
)
72 def info(self
, *args
):
76 class imgwindow(FrameWork
.Window
):
77 def open(self
, width
, height
, pixmap
, data
):
80 self
.pictrect
= (0, 0, width
, height
)
81 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
83 self
.wid
= Win
.NewCWindow(bounds
, "Picture", 1, 0, -1, 1, 0)
86 def do_update(self
, *args
):
88 currect
= self
.fitrect()
89 print 'PICT:', self
.pictrect
90 print 'WIND:', currect
91 print 'ARGS:', (self
.pixmap
, self
.wid
.GetWindowPort().portBits
, self
.pictrect
,
92 currect
, QuickDraw
.srcCopy
, None)
94 Qd
.CopyBits(self
.pixmap
, self
.wid
.GetWindowPort().portBits
, self
.pictrect
,
95 currect
, QuickDraw
.srcCopy
, None)
98 """Return self.pictrect scaled to fit in window"""
99 graf
= self
.wid
.GetWindowPort()
100 screenrect
= graf
.portRect
101 picwidth
= self
.pictrect
[2] - self
.pictrect
[0]
102 picheight
= self
.pictrect
[3] - self
.pictrect
[1]
103 if picwidth
> screenrect
[2] - screenrect
[0]:
104 factor
= float(picwidth
) / float(screenrect
[2]-screenrect
[0])
105 picwidth
= picwidth
/ factor
106 picheight
= picheight
/ factor
107 if picheight
> screenrect
[3] - screenrect
[1]:
108 factor
= float(picheight
) / float(screenrect
[3]-screenrect
[1])
109 picwidth
= picwidth
/ factor
110 picheight
= picheight
/ factor
111 return (screenrect
[0], screenrect
[1], screenrect
[0]+int(picwidth
),
112 screenrect
[1]+int(picheight
))
115 graf
= self
.wid
.GetWindowPort()
117 mac_image
.dumppixmap(bits
.pixmap_data
)