1 """imgbrowse - Display pictures using img"""
7 from Carbon
import QuickDraw
9 #ifrom Carbon mport List
16 # Where is the picture window?
29 class imgbrowse(FrameWork
.Application
):
31 # First init menus, etc.
32 FrameWork
.Application
.__init
__(self
)
34 # Finally, go into the event loop
37 def makeusermenus(self
):
38 self
.filemenu
= m
= FrameWork
.Menu(self
.menubar
, "File")
39 self
.openitem
= FrameWork
.MenuItem(m
, "Open...", "O", self
.opendoc
)
40 self
.infoitem
= FrameWork
.MenuItem(m
, "Info", "I", self
.info
)
41 self
.quititem
= FrameWork
.MenuItem(m
, "Quit", "Q", self
.quit
)
43 def quit(self
, *args
):
46 def opendoc(self
, *args
):
47 pathname
= EasyDialogs
.AskFileForOpen() # Any file type
50 bar
= EasyDialogs
.ProgressBar('Reading and converting...')
52 rdr
= img
.reader(imgformat
.macrgb16
, pathname
)
53 except img
.error
, arg
:
54 EasyDialogs
.Message(repr(arg
))
56 w
, h
= rdr
.width
, rdr
.height
60 pixmap
= mac_image
.mkpixmap(w
, h
, imgformat
.macrgb16
, data
)
61 self
.showimg(w
, h
, pixmap
, data
)
63 def showimg(self
, w
, h
, pixmap
, data
):
65 win
.open(w
, h
, pixmap
, data
)
68 def info(self
, *args
):
72 class imgwindow(FrameWork
.Window
):
73 def open(self
, width
, height
, pixmap
, data
):
76 self
.pictrect
= (0, 0, width
, height
)
77 bounds
= (LEFT
, TOP
, LEFT
+width
, TOP
+height
)
79 self
.wid
= Win
.NewCWindow(bounds
, "Picture", 1, 0, -1, 1, 0)
82 def do_update(self
, *args
):
84 currect
= self
.fitrect()
85 print 'PICT:', self
.pictrect
86 print 'WIND:', currect
87 print 'ARGS:', (self
.pixmap
, self
.wid
.GetWindowPort().GetPortBitMapForCopyBits(), self
.pictrect
,
88 currect
, QuickDraw
.srcCopy
, None)
90 Qd
.CopyBits(self
.pixmap
, self
.wid
.GetWindowPort().GetPortBitMapForCopyBits(), self
.pictrect
,
91 currect
, QuickDraw
.srcCopy
, None)
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
))
111 graf
= self
.wid
.GetWindowPort()
112 bits
= graf
.GetPortBitMapForCopyBits()
113 mac_image
.dumppixmap(bits
.pixmap_data
)