[Python-checkins] python/dist/src/Mac/Demo/imgbrowse imgbrowse.py, 1.8, 1.9 mac_image.py, 1.4, 1.5

tim_one at users.sourceforge.net tim_one at users.sourceforge.net
Sun Jul 18 07:58:38 CEST 2004


Update of /cvsroot/python/python/dist/src/Mac/Demo/imgbrowse
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29056/Demo/imgbrowse

Modified Files:
	imgbrowse.py mac_image.py 
Log Message:
Whitespace normalization, via reindent.py.


Index: imgbrowse.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Demo/imgbrowse/imgbrowse.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** imgbrowse.py	12 Feb 2004 17:35:12 -0000	1.8
--- imgbrowse.py	18 Jul 2004 05:58:05 -0000	1.9
***************
*** 26,117 ****
  
  def main():
! 	print 'hello world'
! 	imgbrowse()
  
  class imgbrowse(FrameWork.Application):
! 	def __init__(self):
! 		# First init menus, etc.
! 		FrameWork.Application.__init__(self)
! 		self.lastwin = None
! 		# Finally, go into the event loop
! 		self.mainloop()
! 		
! 	def makeusermenus(self):
! 		self.filemenu = m = FrameWork.Menu(self.menubar, "File")
! 		self.openitem = FrameWork.MenuItem(m, "Open...", "O", self.opendoc)
! 		self.infoitem = FrameWork.MenuItem(m, "Info", "I", self.info)
! 		self.quititem = FrameWork.MenuItem(m, "Quit", "Q", self.quit)
! 	
! 	def quit(self, *args):
! 		self._quit()
! 		
! 	def opendoc(self, *args):
! 		pathname = EasyDialogs.AskFileForOpen() # Any file type
! 		if not pathname:
! 			return
! 		bar = EasyDialogs.ProgressBar('Reading and converting...')
! 		try:
! 			rdr = img.reader(imgformat.macrgb16, pathname)
! 		except img.error, arg:
! 			EasyDialogs.Message(repr(arg))
! 			return
! 		w, h = rdr.width, rdr.height
! 		bar.set(10)
! 		data = rdr.read()
! 		del bar
! 		pixmap = mac_image.mkpixmap(w, h, imgformat.macrgb16, data)
! 		self.showimg(w, h, pixmap, data)
! 			
! 	def showimg(self, w, h, pixmap, data):
! 		win = imgwindow(self)
! 		win.open(w, h, pixmap, data)
! 		self.lastwin = win
  
- 	def info(self, *args):
- 		if self.lastwin:
- 			self.lastwin.info()		
- 		
  class imgwindow(FrameWork.Window):
! 	def open(self, width, height, pixmap, data):
! 		self.pixmap = pixmap
! 		self.data = data
! 		self.pictrect = (0, 0, width, height)
! 		bounds = (LEFT, TOP, LEFT+width, TOP+height)
! 		
! 		self.wid = Win.NewCWindow(bounds, "Picture", 1, 0, -1, 1, 0)
! 		self.do_postopen()
! 		
! 	def do_update(self, *args):
! 		pass
! 		currect = self.fitrect()
! 		print 'PICT:', self.pictrect
! 		print 'WIND:', currect
! 		print 'ARGS:', (self.pixmap, self.wid.GetWindowPort().GetPortBitMapForCopyBits(), self.pictrect,
! 				currect, QuickDraw.srcCopy, None)
! 		self.info()
! 		Qd.CopyBits(self.pixmap, self.wid.GetWindowPort().GetPortBitMapForCopyBits(), self.pictrect,
! 				currect, QuickDraw.srcCopy, None)
! 		
! 	def fitrect(self):
! 		"""Return self.pictrect scaled to fit in window"""
! 		graf = self.wid.GetWindowPort()
! 		screenrect = graf.GetPortBounds()
! 		picwidth = self.pictrect[2] - self.pictrect[0]
! 		picheight = self.pictrect[3] - self.pictrect[1]
! 		if picwidth > screenrect[2] - screenrect[0]:
! 			factor = float(picwidth) / float(screenrect[2]-screenrect[0])
! 			picwidth = picwidth / factor
! 			picheight = picheight / factor
! 		if picheight > screenrect[3] - screenrect[1]:
! 			factor = float(picheight) / float(screenrect[3]-screenrect[1])
! 			picwidth = picwidth / factor
! 			picheight = picheight / factor
! 		return (screenrect[0], screenrect[1], screenrect[0]+int(picwidth),
! 				screenrect[1]+int(picheight))
! 				
! 	def info(self):
! 		graf = self.wid.GetWindowPort()
! 		bits = graf.GetPortBitMapForCopyBits()
! 		mac_image.dumppixmap(bits.pixmap_data)
  
  main()
--- 26,117 ----
  
  def main():
!     print 'hello world'
!     imgbrowse()
  
  class imgbrowse(FrameWork.Application):
!     def __init__(self):
!         # First init menus, etc.
!         FrameWork.Application.__init__(self)
!         self.lastwin = None
!         # Finally, go into the event loop
!         self.mainloop()
! 
!     def makeusermenus(self):
!         self.filemenu = m = FrameWork.Menu(self.menubar, "File")
!         self.openitem = FrameWork.MenuItem(m, "Open...", "O", self.opendoc)
!         self.infoitem = FrameWork.MenuItem(m, "Info", "I", self.info)
!         self.quititem = FrameWork.MenuItem(m, "Quit", "Q", self.quit)
! 
!     def quit(self, *args):
!         self._quit()
! 
!     def opendoc(self, *args):
!         pathname = EasyDialogs.AskFileForOpen() # Any file type
!         if not pathname:
!             return
!         bar = EasyDialogs.ProgressBar('Reading and converting...')
!         try:
!             rdr = img.reader(imgformat.macrgb16, pathname)
!         except img.error, arg:
!             EasyDialogs.Message(repr(arg))
!             return
!         w, h = rdr.width, rdr.height
!         bar.set(10)
!         data = rdr.read()
!         del bar
!         pixmap = mac_image.mkpixmap(w, h, imgformat.macrgb16, data)
!         self.showimg(w, h, pixmap, data)
! 
!     def showimg(self, w, h, pixmap, data):
!         win = imgwindow(self)
!         win.open(w, h, pixmap, data)
!         self.lastwin = win
! 
!     def info(self, *args):
!         if self.lastwin:
!             self.lastwin.info()
  
  class imgwindow(FrameWork.Window):
!     def open(self, width, height, pixmap, data):
!         self.pixmap = pixmap
!         self.data = data
!         self.pictrect = (0, 0, width, height)
!         bounds = (LEFT, TOP, LEFT+width, TOP+height)
! 
!         self.wid = Win.NewCWindow(bounds, "Picture", 1, 0, -1, 1, 0)
!         self.do_postopen()
! 
!     def do_update(self, *args):
!         pass
!         currect = self.fitrect()
!         print 'PICT:', self.pictrect
!         print 'WIND:', currect
!         print 'ARGS:', (self.pixmap, self.wid.GetWindowPort().GetPortBitMapForCopyBits(), self.pictrect,
!                         currect, QuickDraw.srcCopy, None)
!         self.info()
!         Qd.CopyBits(self.pixmap, self.wid.GetWindowPort().GetPortBitMapForCopyBits(), self.pictrect,
!                         currect, QuickDraw.srcCopy, None)
! 
!     def fitrect(self):
!         """Return self.pictrect scaled to fit in window"""
!         graf = self.wid.GetWindowPort()
!         screenrect = graf.GetPortBounds()
!         picwidth = self.pictrect[2] - self.pictrect[0]
!         picheight = self.pictrect[3] - self.pictrect[1]
!         if picwidth > screenrect[2] - screenrect[0]:
!             factor = float(picwidth) / float(screenrect[2]-screenrect[0])
!             picwidth = picwidth / factor
!             picheight = picheight / factor
!         if picheight > screenrect[3] - screenrect[1]:
!             factor = float(picheight) / float(screenrect[3]-screenrect[1])
!             picwidth = picwidth / factor
!             picheight = picheight / factor
!         return (screenrect[0], screenrect[1], screenrect[0]+int(picwidth),
!                         screenrect[1]+int(picheight))
! 
!     def info(self):
!         graf = self.wid.GetWindowPort()
!         bits = graf.GetPortBitMapForCopyBits()
!         mac_image.dumppixmap(bits.pixmap_data)
  
  main()

Index: mac_image.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Demo/imgbrowse/mac_image.py,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** mac_image.py	25 Aug 2001 12:06:15 -0000	1.4
--- mac_image.py	18 Jul 2004 05:58:05 -0000	1.5
***************
*** 7,56 ****
  
  _fmt_to_mac = {
! 	imgformat.macrgb16 : (16, 16, 3, 5),
  }
  
  def mkpixmap(w, h, fmt, data):
! 	"""kludge a pixmap together"""
! 	fmtinfo = _fmt_to_mac[fmt]
! 	
! 	rv = struct.pack("lHhhhhhhlllhhhhlll",
! 		id(data)+MacOS.string_id_to_buffer, # HACK HACK!!
! 		w*2 + 0x8000,
! 		0, 0, h, w,
! 		0,
! 		0, 0, # XXXX?
! 		72<<16, 72<<16,
! 		fmtinfo[0], fmtinfo[1],
! 		fmtinfo[2], fmtinfo[3],
! 		0, 0, 0)
! ##	print 'Our pixmap, size %d:'%len(rv)
! ##	dumppixmap(rv)
! 	return Qd.RawBitMap(rv)
  
  def dumppixmap(data):
! 	baseAddr, \
! 		rowBytes, \
! 		t, l, b, r, \
! 		pmVersion, \
! 		packType, packSize, \
! 		hRes, vRes, \
! 		pixelType, pixelSize, \
! 		cmpCount, cmpSize, \
! 		planeBytes, pmTable, pmReserved \
! 			= struct.unpack("lhhhhhhhlllhhhhlll", data)
! 	print 'Base:       0x%x'%baseAddr
! 	print 'rowBytes:   %d (0x%x)'%(rowBytes&0x3fff, rowBytes)
! 	print 'rect:       %d, %d, %d, %d'%(t, l, b, r)
! 	print 'pmVersion:  0x%x'%pmVersion
! 	print 'packing:    %d %d'%(packType, packSize)
! 	print 'resolution: %f x %f'%(float(hRes)/0x10000, float(vRes)/0x10000)
! 	print 'pixeltype:  %d, size %d'%(pixelType, pixelSize)
! 	print 'components: %d, size %d'%(cmpCount, cmpSize)
! 	print 'planeBytes: %d (0x%x)'%(planeBytes, planeBytes)
! 	print 'pmTable:    0x%x'%pmTable
! 	print 'pmReserved: 0x%x'%pmReserved
! 	for i in range(0, len(data), 16):
! 		for j in range(16):
! 			if i + j < len(data):
! 				print '%02.2x'%ord(data[i+j]),
! 		print
--- 7,56 ----
  
  _fmt_to_mac = {
!         imgformat.macrgb16 : (16, 16, 3, 5),
  }
  
  def mkpixmap(w, h, fmt, data):
!     """kludge a pixmap together"""
!     fmtinfo = _fmt_to_mac[fmt]
! 
!     rv = struct.pack("lHhhhhhhlllhhhhlll",
!             id(data)+MacOS.string_id_to_buffer, # HACK HACK!!
!             w*2 + 0x8000,
!             0, 0, h, w,
!             0,
!             0, 0, # XXXX?
!             72<<16, 72<<16,
!             fmtinfo[0], fmtinfo[1],
!             fmtinfo[2], fmtinfo[3],
!             0, 0, 0)
! ##      print 'Our pixmap, size %d:'%len(rv)
! ##      dumppixmap(rv)
!     return Qd.RawBitMap(rv)
  
  def dumppixmap(data):
!     baseAddr, \
!             rowBytes, \
!             t, l, b, r, \
!             pmVersion, \
!             packType, packSize, \
!             hRes, vRes, \
!             pixelType, pixelSize, \
!             cmpCount, cmpSize, \
!             planeBytes, pmTable, pmReserved \
!                     = struct.unpack("lhhhhhhhlllhhhhlll", data)
!     print 'Base:       0x%x'%baseAddr
!     print 'rowBytes:   %d (0x%x)'%(rowBytes&0x3fff, rowBytes)
!     print 'rect:       %d, %d, %d, %d'%(t, l, b, r)
!     print 'pmVersion:  0x%x'%pmVersion
!     print 'packing:    %d %d'%(packType, packSize)
!     print 'resolution: %f x %f'%(float(hRes)/0x10000, float(vRes)/0x10000)
!     print 'pixeltype:  %d, size %d'%(pixelType, pixelSize)
!     print 'components: %d, size %d'%(cmpCount, cmpSize)
!     print 'planeBytes: %d (0x%x)'%(planeBytes, planeBytes)
!     print 'pmTable:    0x%x'%pmTable
!     print 'pmReserved: 0x%x'%pmReserved
!     for i in range(0, len(data), 16):
!         for j in range(16):
!             if i + j < len(data):
!                 print '%02.2x'%ord(data[i+j]),
!         print



More information about the Python-checkins mailing list