# Created by Leo from: C:\Python23\Tom\leo\imageview.leo # @path c:\python23\lib # << CameraS declarations >> import wx #from wx.Python.lib.evtmgr import EM.eventManager import wx.lib.evtmgr as EM import Image import ImageChops #import ImageStat import ImageEnhance import sys, time, math, string, os import urllib2 import StringIO #for py2exe #import ArgImagePlugin,BmpImagePlugin,BufrStubImagePlugin,CurImagePlugin,DcxImagePlugin,EpsImagePlugin,FitsStubImagePlugin,FliImagePlugin,FpxImagePlugin,GbrImagePlugin,GifImagePlugin,GribStubImagePlugin,Hdf5StubImagePlugin,IcoImagePlugin,ImImagePlugin,ImtImagePlugin,IptcImagePlugin,JpegImagePlugin,McIdasImagePlugin,MicImagePlugin,MpegImagePlugin,MspImagePlugin,PalmImagePlugin,PcdImagePlugin,PcxImagePlugin,PdfImagePlugin,PixarImagePlugin,PngImagePlugin,PpmImagePlugin,PsdImagePlugin,SgiImagePlugin,SunImagePlugin,TgaImagePlugin,TiffImagePlugin,WmfImagePlugin,XbmImagePlugin,XpmImagePlugin,XVThumbImagePlugin # -- end -- << CameraS declarations >> # <> (1 of 23) def WXToPIL(image, mode = 'RGBA'): "convert a wx.Image to a PIL RGBA image" imageData = image.GetData() size = (image.GetWidth(), image.GetHeight()) imagePIL = Image.fromstring('RGB', size, imageData) if mode != 'RGB': imagePIL = imagePIL.convert(mode) return imagePIL # <> (2 of 23) def DCToPIL(DC,coords): "convert a wx.DC to a PIL RGB image" bmp = wx.EmptyBitmap(coords[2], coords[3]) mdc = wx.MemoryDC() mdc.SelectObject(bmp) mdc.Clear() mdc.Blit( wx.Point(0,0), wx.Size(coords[2], coords[3]), DC, wx.Point(coords[0], coords[1])) wx.SafeYield() del mdc pyimg = wx.ImageFromBitmap(bmp) dcimg = WXToPIL(pyimg) return dcimg # <> (3 of 23) def PILToWX(image): "convert a PIL image to a wx.Image" if (image.mode == 'RGBA'): bk = Image.new("RGB", image.size, (255, 250, 255)) image = Image.composite(image, bk, image) if (image.mode != 'RGB'): image = image.convert('RGB') imageData = image.tostring('raw', 'RGB') imageWx = wx.EmptyImage(image.size[0], image.size[1]) imageWx.SetData(imageData) imageWx.SetMaskColour(255, 250, 255) return imageWx # <> (4 of 23) def PILToPy(image): ret = "import Image\n" ret += "\n" ret += "mode = %s\n" % repr(image.mode) ret += "size = %s\n" % repr(image.size) ret += "data = %s\n" % repr(image.tostring()) ret += "img = Image.fromstring(mode, size, data)\n" return ret # <> (5 of 23) ## # A standard ImageView tool for panning around the image. class PanTool: # << class PanTool methods >> (1 of 4) def __init__(self, image_view): self.__image_view = image_view hand_tool_mode = 'RGBA' hand_tool_size = (16, 16) self.isrgb = 0 hand_tool_data = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\xd4\x00\x00\x00\xbb\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xd4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' hand_tool_img = Image.fromstring(hand_tool_mode, hand_tool_size, hand_tool_data) self.multi = 1 img = hand_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) self.active = 0 id = image_view.get_tool_id(self) self.__id = id self.__dragging = 0 self.__last_pos = (0, 0) image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Pan") #image_view.get_toolbar().AddCheckTool(id, bmp, shortHelp="Pan") image_view.get_toolbar().AddSeparator() #image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Pan") # << class PanTool methods >> (2 of 4) ## # Called by the ImageView when the tool is activated. def activate(self, ids): wind = self.__image_view.get_image_window() #print 'pan activate' cursor = wx.StockCursor(wx.CURSOR_HAND) wind.SetCursor(cursor) self.active = 1 # win.Connect(-1, -1, wx.EVT_LEFT_DOWN, self.on_mouse) # win.Connect(-1, -1, EVT_LEFT_UP, self.on_mouse) # win.Connect(-1, -1, EVT_MOTION, self.on_mouse) # EM.eventManager.Register(self.on_mouse, EVT_MOUSE_EVENTS, win=wind, id=ids) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_DOWN, wind) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_UP, wind) EM.eventManager.Register(self.on_mouse, wx.EVT_MOTION, wind) # << class PanTool methods >> (3 of 4) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): win = self.__image_view.get_image_window() #print 'pan deactivate' win.SetCursor(wx.STANDARD_CURSOR) self.active = 0 EM.eventManager.DeregisterListener(self.on_mouse) win.Refresh(1) # << class PanTool methods >> (4 of 4) def on_mouse(self, evt): pos = (evt.m_x, evt.m_y) win = self.__image_view.get_image_window() if evt.GetEventType() == wx.wxEVT_MOTION: if not self.__dragging: return diff = (pos[0] - self.__last_pos[0], pos[1] - self.__last_pos[1]) self.__last_pos = pos origin = self.__image_view.get_origin() self.__image_view.set_origin((origin[0] - diff[0], origin[1] - diff[1])) elif evt.GetEventType() == wx.wxEVT_LEFT_DOWN: #win.CaptureMouse() self.__last_pos = pos self.__dragging = 1 elif evt.GetEventType() == wx.wxEVT_LEFT_UP: #win.ReleaseMouse() self.__dragging = 0 # -- end -- << class PanTool methods >> # <> (6 of 23) ## # A standard ImageView tool for zooming in and out of the image. class ZoomTool: # << class ZoomTool methods >> (1 of 6) def __init__(self, image_view): self.__image_view = image_view zoom_tool_mode = 'RGBA' zoom_tool_size = (16, 16) self.isrgb = 0 zoom_tool_data = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' zoom_tool_img = Image.fromstring(zoom_tool_mode, zoom_tool_size, zoom_tool_data) self.active = 0 img = zoom_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) self.multi = 1 id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Zoom") image_view.get_toolbar().AddSeparator() #print 'Im zoomed' # << class ZoomTool methods >> (2 of 6) ## # Called by the ImageView when the tool is activated. def activate(self, id): win = self.__image_view.get_image_window() self.active = 1 #print 'Im zoom active' #print win cursor = wx.StockCursor(wx.CURSOR_MAGNIFIER) win.SetCursor(cursor) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_UP, win) EM.eventManager.Register(self.on_mouse, wx.EVT_RIGHT_UP, win) # << class ZoomTool methods >> (3 of 6) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): win = self.__image_view.get_image_window() #print 'im zoom deactive' self.active = 0 win.SetCursor(wx.STANDARD_CURSOR) EM.eventManager.DeregisterListener(self.on_mouse) # << class ZoomTool methods >> (4 of 6) def on_mouse(self, evt): #print 'zoom on mouse' #print evt.GetEventType() if evt.GetEventType() == 10022: #print 'left up' if evt.ControlDown() or evt.ShiftDown(): self.zoom_out() else: self.zoom_in() elif evt.GetEventType() == 10026: #print 'right up' self.zoom_out() # << class ZoomTool methods >> (5 of 6) def zoom_in(self): zoom = self.__image_view.get_zoom() #print 'setting' if zoom >= 1.0: self.__image_view.set_zoom(zoom + 1.0) else: self.__image_view.set_zoom(1.0 / (1.0 / zoom - 1.0)) # << class ZoomTool methods >> (6 of 6) def zoom_out(self): zoom = self.__image_view.get_zoom() if zoom > 1.0: self.__image_view.set_zoom(zoom - 1.0) else: self.__image_view.set_zoom(1.0 / (1.0 / zoom + 1.0)) # -- end -- << class ZoomTool methods >> # <> (7 of 23) ## # A standard ImageView tool for zooming in and out of the image. class ContTool: # << class ContTool methods >> (1 of 6) def __init__(self, image_view): self.__image_view = image_view self.multi = 0 self.active = 0 self.isrgb = 0 cont_tool_data = '\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd1\xd1\xd1\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd1\xd1\xd1\xb3\xb3\xb3\x8d\x8d\x8d\xd2\xd2\xd2\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd1\xd1\xd1\xd2\xd2\xd2\xd0\xd0\x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\xc2\x88\x88\x88\xc0\xc0\xc0\xd1\xd1\xd1\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0' sharp_tool_mode = 'RGB' sharp_tool_size = (16, 16) sharp_tool_img = Image.fromstring(sharp_tool_mode, sharp_tool_size, cont_tool_data) img = sharp_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Contrast") # << class ContTool methods >> (2 of 6) ## # Called by the ImageView when the tool is activated. def activate(self, id): win = self.__image_view.get_image_window() self.active = 1 #cursor = wx.StockCursor(wx.CURSOR_PAINT_BRUSH) #win.SetCursor(cursor) # win.Connect(-1, -1, EVT_LEFT_UP, self.on_mouse) # win.Connect(-1, -1, wx.EVT_RIGHT_UP, self.on_mouse) #EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_DOWN, win) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_UP, win) EM.eventManager.Register(self.on_mouse, wx.EVT_RIGHT_UP, win) # << class ContTool methods >> (3 of 6) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): #win = self.__image_view.get_image_window() #win.SetCursor(wx.STANDARD_CURSOR) EM.eventManager.DeregisterListener(self.on_mouse) self.active = 0 #win.Disconnect(-1, -1, EVT_LEFT_UP) #win.Disconnect(-1, -1, wx.EVT_RIGHT_UP) # << class ContTool methods >> (4 of 6) def on_mouse(self, evt): if evt.GetEventType() == wx.wxEVT_LEFT_UP: if evt.ControlDown() or evt.ShiftDown(): self.cont_out() else: self.cont_in() elif evt.GetEventType() == wx.wxEVT_RIGHT_UP: self.cont_out() # << class ContTool methods >> (5 of 6) def cont_in(self): contrast = self.__image_view.get_contrast() if contrast > 19.9: contrast = 20.0 self.__image_view.set_contrast(contrast) else: contrast = contrast + .1 self.__image_view.set_contrast(contrast) #print contrast # << class ContTool methods >> (6 of 6) def cont_out(self): contrast = self.__image_view.get_contrast() if contrast < -19.9: contrast = -20.0 self.__image_view.set_contrast(contrast) else: contrast = contrast - .1 self.__image_view.set_contrast(contrast) #print contrast # -- end -- << class ContTool methods >> # <> (8 of 23) ## # A standard ImageView tool for zooming in and out of the image. class BrightTool: # << class BrightTool methods >> (1 of 6) def __init__(self, image_view): self.__image_view = image_view self.multi = 0 self.active = 0 self.isrgb = 0 inspect_tool_data ='\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xd0\xd0\xd3\xc7N<=?@CDFGGJ@\x96\xd1\xd3\xc38[l{\x88\x97\xa7\xb6\xc5\xd4\xe6\x8cU\xc5\xd3\xc3> (2 of 6) ## # Called by the ImageView when the tool is activated. def activate(self, id): win = self.__image_view.get_image_window() self.active = 1 #cursor = wx.StockCursor(wx.CURSOR_SPRAYCAN) #win.SetCursor(cursor) # win.Connect(-1, -1, EVT_LEFT_UP, self.on_mouse) # win.Connect(-1, -1, wx.EVT_RIGHT_UP, self.on_mouse) #EM.eventManager.Register(self.on_mouse, EVT_LEFT_DOWN, win) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_UP, win) EM.eventManager.Register(self.on_mouse, wx.EVT_RIGHT_UP, win) # << class BrightTool methods >> (3 of 6) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): #win = self.__image_view.get_image_window() #win.SetCursor(wx.STANDARD_CURSOR) EM.eventManager.DeregisterListener(self.on_mouse) self.active = 0 #win.Disconnect(-1, -1, EVT_LEFT_UP) #win.Disconnect(-1, -1, wx.EVT_RIGHT_UP) # << class BrightTool methods >> (4 of 6) def on_mouse(self, evt): if evt.GetEventType() == wx.wxEVT_LEFT_UP: if evt.ControlDown() or evt.ShiftDown(): self.bright_out() else: self.bright_in() elif evt.GetEventType() == wx.wxEVT_RIGHT_UP: self.bright_out() # << class BrightTool methods >> (5 of 6) def bright_in(self): bright = self.__image_view.get_bright() if bright > 19.9: bright = 20.0 self.__image_view.set_bright(bright) else: bright = bright + .1 self.__image_view.set_bright(bright) #print bright # << class BrightTool methods >> (6 of 6) def bright_out(self): bright = self.__image_view.get_bright() if bright < -19.9: bright = -20.0 self.__image_view.set_bright(bright) else: bright = bright - .1 self.__image_view.set_bright(bright) #print bright # -- end -- << class BrightTool methods >> # <> (9 of 23) ## # A standard ImageView tool for zooming in and out of the image. class ColorTool: # << class ColorTool methods >> (1 of 6) def __init__(self, image_view): self.__image_view = image_view self.multi = 0 self.active = 0 self.isrgb = 0 color_tool_data =""" '\xbf\xbf\xbf\xca\xca\xca\xcd\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xce\xcd\xce\xce\xce\xce\xce\xcd\xce\xce\xcd\xcd\xcd\xcc\xcc\xcc\xc7\xc7\xc7zxxSEEHEFEEGFEGGEGIEGIEGMEGJEFOEGLEFQEG\x8a\x89\x89\xcc\xcc\xcc\xc5\xca\xcaeKK\xc1\x00\x00-\x00\x08\x00\x00!\x11\x00\x15\x1c\x00\x1c;\x00\x1b4\x00\x15l\x00 H\x00\x11\x90\x04\x1fi\x00\x11\xae\x00\x1aMHI\xba\xba\xba\xc7\xca\xca]NNo\x00\x00\x1b\x00\x07\x00\x00\x15\x0c\x00\x0e\x12\x00\x12#\x00\x11 \x00\x0e?\x00\x15+\x00\x0cT\x05\x14>\x02\x0cd\x02\x11>;;\xb1\xb2\xb2\xc6\xc9\xcadSN\xa2\x1f\x00(\x13\t\x00 \x1f\x12\x15\x15\x1b\x1c\x1b4\x1b\x1a0\x17\x16m%$G\x15\x15\x84""P\x0e\x0ey\x11\x10?<<\xb1\xb2\xb2\xc6\xc9\xcaaRN\x90\x19\x00$\x10\x08\x00\x1b\x1c\x10\x12\x12\x18\x17\x18.\x16\x17*\x13\x14`\x1f ?\x12\x12v\x1d\x1eH\x0c\x0cm\x0e\x0e><<\xb1\xb2\xb2\xc6\xc9\xca_UN\x7f1\x00\x1f\x1e\x07\x001\x18\x0e!\x10\x14+\x15/1\x17)(\x14N6\x193 \x0f`2\x18:\x18\nY"\x0b><<\xb1\xb2\xb2\xc5\xc8\xcafXN\xb3D\x00,)\x0b\x00D"\x14-\x17\x1d;\x1dBC!:7\x1cmJ$H+\x15\x87D!R"\x0f}.\x10?=<\xb1\xb2\xb2\xc7\xc8\xca[VN`;\x00\x18"\x06\x009\x13\n%\x0c\x0f/\x10(<\x14#2\x10CB\x16,\'\rR=\x142\x1f\x08L-\n><;\xb2\xb2\xb2\xc4\xc6\xcai`N\xcb\x7f\x003J\r\x00z)\x16O\x1a!d"U\x82+Km$\x8e\x8e0^T\x1c\xaf\x83,jD\x13\xa2a\x15A><\xb1\xb2\xb2\xc8\xc8\xcaYVNO:\x00\x13#\x04\x00:\x0f\x08\'\n\r2\r!;\x11\x1d1\x0e8D\x12%(\x0bEA\x11*"\x07@1\x08==;\xb2\xb2\xb2\xc4\xc5\xcajeN\xd4\xa9\x005f\x0e\x00\xab+\x19s\x1c$\x93$\\\xaa/Q\x8f\'\x9a\xc74ew\x1e\xbd\xc00sf\x14\xb0\x93\x18A@<\xb1\xb1\xb2\xc8\xc8\xcaYWNOC\x00\x13(\x04\x00C\x0f\x06-\n\t:\r"?\x11\x1e5\x0e9J\x13%,\x0bFG\x11*%\x07A6\x08==;\xb2\xb2\xb2\xc4\xc4\xcaiiN\xcb\xc9\x003u\r\x00\xc3)\x00\x83\x1b\x00\xa8#X\xa3-N\x89%\x94\xbf2ar\x1d\xb6\xb8.oa\x14\xa9\x8d\x17A@<\xb1\xb1\xb2\xc7\xc7\xca^^R_^\x04\x1a7\t\x03Z\x16\x03=\x0f\x03N\x13*L\x17&@\x14EX\x19/6\x10TU\x184/\x0cNB\x0e@?>\xb2\xb2\xb2\xc7\xc7\xc7\x8f\x8f\x91==I739:/8:39:18518638208549008459028^^^\xb6\xb6\xb6'""" sharp_tool_mode = 'RGB' sharp_tool_size = (16, 16) sharp_tool_img = Image.fromstring(sharp_tool_mode, sharp_tool_size, color_tool_data) img = sharp_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Color") # << class ColorTool methods >> (2 of 6) ## # Called by the ImageView when the tool is activated. def activate(self, id): win = self.__image_view.get_image_window() self.active = 1 #cursor = wx.StockCursor(wx.CURSOR_PENCIL) #win.SetCursor(cursor) #win.Connect(-1, -1, EVT_LEFT_UP, self.on_mouse) #win.Connect(-1, -1, wx.EVT_RIGHT_UP, self.on_mouse) #EM.eventManager.Register(self.on_mouse, EVT_LEFT_DOWN, win) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_UP, win) EM.eventManager.Register(self.on_mouse, wx.EVT_RIGHT_UP, win) # << class ColorTool methods >> (3 of 6) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): #win = self.__image_view.get_image_window() #win.SetCursor(wx.STANDARD_CURSOR) EM.eventManager.DeregisterListener(self.on_mouse) self.active = 0 #win.Disconnect(-1, -1, EVT_LEFT_UP) #win.Disconnect(-1, -1, wx.EVT_RIGHT_UP) # << class ColorTool methods >> (4 of 6) def on_mouse(self, evt): if evt.GetEventType() == wx.wxEVT_LEFT_UP: if evt.ControlDown() or evt.ShiftDown(): self.color_out() else: self.color_in() elif evt.GetEventType() == wx.wxEVT_RIGHT_UP: self.color_out() # << class ColorTool methods >> (5 of 6) def color_in(self): color = self.__image_view.get_color() if color > 19.9: color = 20.0 self.__image_view.set_color(color) else: color = color + .1 self.__image_view.set_color(color) #print color # << class ColorTool methods >> (6 of 6) def color_out(self): color = self.__image_view.get_color() if color < -19.9: color = -20.0 self.__image_view.set_color(color) else: color = color - .1 self.__image_view.set_color(color) #print color # -- end -- << class ColorTool methods >> # <> (10 of 23) ## # A standard ImageView tool for zooming in and out of the image. class SharpTool: # << class SharpTool methods >> (1 of 6) def __init__(self, image_view): self.__image_view = image_view self.multi = 0 self.active = 0 self.isrgb = 0 inspect_tool_data = '\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd1\xd1\xd1\xcf\xcf\xcf\xd1\xd1\xd1\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd3\xd3\xd3\x9d\x9d\x9d:::\x9d\x9d\x9d\xd4\xd4\xd4\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd2\xd2\xd2\x9c\x9c\x9c\x19\x19\x19\x00\x00\x00\x19\x19\x19\x9d\x9d\x9d\xd2\xd2\xd2\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd1\xd1\xd1\xd4\xd4\xd4\xd5\xd5\xd5\xd6\xd6\xd6\xac\xac\xacmmm\x04\x04\x04lll\xac\xac\xac\xd6\xd6\xd6\xd5\xd5\xd5\xd2\xd2\xd2\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xc8\xc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\xa9\xa9\xa9}}}XXX\xca\xca\xca\xd1\xd1\xd1\xd0\xd0\xd0\xd1\xd1\xd1\xaf\xaf\xafYYY\xcc\xcc\xcc\xb3\xb3\xb3\x9d\x9d\x9d\x9f\x9f\x9f\x99\x99\x99\xa3\xa3\xa3\xa5\xa5\xa5\xc6\xc6\xc6\x87\x87\x87WWW\xca\xca\xca\xd1\xd1\xd1\xd0\xd0\xd0\xd1\xd1\xd1\xbc\xbc\xbcCCC???>>>:::888666888<<<@@@666fff\xc9\xc9\xc9\xd1\xd1\xd1\xce\xce\xce\xce\xce\xce\xcf\xcf\xcf\xc0\xc0\xc0\xab\xab\xab\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xac\xaf\xaf\xaf\xca\xca\xca\xce\xce\xce\xb4\xb4\xb4\xaf\xaf\xaf\xad\xad\xad\xaf\xaf\xaf\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xb1\xae\xae\xae\xad\xad\xad' sharp_tool_mode = 'RGB' sharp_tool_size = (16, 16) sharp_tool_img = Image.fromstring(sharp_tool_mode, sharp_tool_size, inspect_tool_data) img = sharp_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Sharpness") # << class SharpTool methods >> (2 of 6) ## # Called by the ImageView when the tool is activated. def activate(self, id): win = self.__image_view.get_image_window() #cursor = wx.StockCursor(wx.CURSOR_BULLSEYE) #win.SetCursor(cursor) #win.Connect(-1, -1, EVT_LEFT_UP, self.on_mouse) #win.Connect(-1, -1, wx.EVT_RIGHT_UP, self.on_mouse) self.active = 1 #EM.eventManager.Register(self.on_mouse, EVT_LEFT_DOWN, win) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_UP, win) EM.eventManager.Register(self.on_mouse, wx.EVT_RIGHT_UP, win) # << class SharpTool methods >> (3 of 6) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): #win = self.__image_view.get_image_window() #win.SetCursor(wx.STANDARD_CURSOR) EM.eventManager.DeregisterListener(self.on_mouse) self.active = 0 #win.Disconnect(-1, -1, EVT_LEFT_UP) #win.Disconnect(-1, -1, wx.EVT_RIGHT_UP) # << class SharpTool methods >> (4 of 6) def on_mouse(self, evt): if evt.GetEventType() == wx.wxEVT_LEFT_UP: if evt.ControlDown() or evt.ShiftDown(): self.sharp_out() else: self.sharp_in() elif evt.GetEventType() == wx.wxEVT_RIGHT_UP: self.sharp_out() # << class SharpTool methods >> (5 of 6) def sharp_in(self): sharpness = self.__image_view.get_sharp() if sharpness > 19.9: sharpness = 20.0 self.__image_view.set_sharp(sharpness) else: sharpness = sharpness + .1 self.__image_view.set_sharp(sharpness) #print sharpness # << class SharpTool methods >> (6 of 6) def sharp_out(self): sharpness = self.__image_view.get_sharp() if sharpness < -19.9: sharpness = -20.0 self.__image_view.set_sharp(sharpness) else: sharpness = sharpness - .1 self.__image_view.set_sharp(sharpness) #print sharpness # -- end -- << class SharpTool methods >> # <> (11 of 23) ## # A standard ImageView tool for zooming in and out of the image. class BlueTool: # << class BlueTool methods >> (1 of 3) def __init__(self, image_view): self.__image_view = image_view self.multi = 0 self.active = 0 self.isrgb = 1 zoom_tool_mode = 'RGB' zoom_tool_size = (16, 16) zoom_tool_data = '\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\x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fe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\x00\xcb\xfe\x00\xcb\xfe\x00\xcb\xfe\x00\xcb\xfe\x00\xcb\xfe\x00\xcb\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe' zoom_tool_img = Image.fromstring(zoom_tool_mode, zoom_tool_size, zoom_tool_data) img = zoom_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 0, shortHelpString = "Blue") image_view.get_toolbar().AddSeparator() # << class BlueTool methods >> (2 of 3) ## # Called by the ImageView when the tool is activated. def activate(self, id): self.__image_view.set_rgb(3) self.active = 1 # << class BlueTool methods >> (3 of 3) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): self.__image_view.set_rgb(0) self.active = 0 # -- end -- << class BlueTool methods >> # <> (12 of 23) ## # A standard ImageView tool for zooming in and out of the image. class GreenTool: # << class GreenTool methods >> (1 of 3) def __init__(self, image_view): self.__image_view = image_view self.multi = 0 self.active = 0 self.isrgb = 1 zoom_tool_mode = 'RGB' zoom_tool_size = (16, 16) zoom_tool_data = '\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe2\xfe\x002\xfe\x002\xfe\x002\xfe\x002\xfe\x00\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe2\xfe\x002\xfe\x00\xfe\xfe\xfe\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e\xfe\xfe\xfe\xfe' zoom_tool_img = Image.fromstring(zoom_tool_mode, zoom_tool_size, zoom_tool_data) img = zoom_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 0, shortHelpString = "Green") # << class GreenTool methods >> (2 of 3) ## # Called by the ImageView when the tool is activated. def activate(self, id): self.__image_view.set_rgb(2) self.active = 1 # << class GreenTool methods >> (3 of 3) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): self.__image_view.set_rgb(0) self.active = 0 # -- end -- << class GreenTool methods >> # <> (13 of 23) ## # A standard ImageView tool for zooming in and out of the image. class RedTool: # << class RedTool methods >> (1 of 3) def __init__(self, image_view): self.__image_view = image_view self.multi = 0 self.active = 0 self.isrgb = 1 zoom_tool_mode = 'RGB' zoom_tool_size = (16, 16) zoom_tool_data = '\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe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\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe\xfe' zoom_tool_img = Image.fromstring(zoom_tool_mode, zoom_tool_size, zoom_tool_data) img = zoom_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) image_view.get_toolbar().AddSeparator() id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 0, shortHelpString = "Red") # << class RedTool methods >> (2 of 3) ## # Called by the ImageView when the tool is activated. def activate(self, id): self.__image_view.set_rgb(1) self.active = 1 # << class RedTool methods >> (3 of 3) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): self.__image_view.set_rgb(0) self.active = 0 # -- end -- << class RedTool methods >> # <> (14 of 23) ## # A standard ImageView tool for zooming in and out of the image. class RestoreTool: # << class RestoreTool methods >> (1 of 3) def __init__(self, image_view): self.__image_view = image_view self.multi = 1 self.active = 0 self.isrgb = 0 inspect_tool_data ='\xcf\xd0\xd1\xcf\xd1\xcf\xd1\xd2\xd0\xcd\xcf\xd1\xcf\xd1\xd0\xcf\xd0\xcf\xd1\xd1\xd1\xd0\xd1\xc8\xaa\xaa\xcf\xd0\xcf\xd1\xd0\xcf\xd0\xcf\xd0\xd1\xd2\xca\xb4\x8fw\x97\xd2\xd1\xd1\xd1\xd0\xd0\xcf\xd0\xd1\xcd\xb8\x93znp\x8e\xbd\xc8\xd1\xd1\xcf\xd0\xcf\xcf\xbf\x9azqpopru\x8e\xb9\xcf\xd0\xd0\xcf\xcd\xa0soqonoopn\x80\xb9\xd1\xd0\xcf\xcd\xbe\x9f~pnpqz\x81oo\x8d\xca\xd0\xcf\xd0\xd1\xcd\xbb\x9c}or\x95\xbc\x87oy\xb7\xd0\xcf\xcf\xd1\xd1\xd0\xcb\xb9\x9a\x84\xa4\xcf\xabpu\xac\xd2\xcf\xcf\xd0\xd1\xd0\xd1\xd1\xcb\xc0\xc9\xd2\xb1st\xaf\xd2\xcf\xd0\xd1\xd0\xd0\xd0\xcf\xd0\xcf\xce\xc9\x94q}\xbf\xd1\xcf\xd0\xd1\xd0\xd0\xd1\xc0\x92\x8a\x8b\x86to\x99\xcf\xcf\xcf\xcf\xd0\xd0\xd0\xd0\xaavutrr\x87\xc2\xd1\xcf\xcf\xcf\xd0\xd0\xd1\xd0\xa8vuuz\x95\xbe\xd1\xcf\xd0\xcf\xd0\xd0\xd0\xd0\xd0\xc5\xba\xba\xba\xc0\xca\xd1\xd1\xd0\xd0\xd1\xcf\xd0\xd1\xcf\xd1\xd0\xd0\xd2\xd1\xd1\xd1\xd1\xd0\xd0\xd0' sharp_tool_mode = 'P' sharp_tool_size = (16, 16) sharp_tool_img = Image.fromstring(sharp_tool_mode, sharp_tool_size, inspect_tool_data) img = sharp_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddSeparator() image_view.get_toolbar().AddSimpleTool(id, bmp, 'Restore all Enhancement Tools', "Restore") image_view.get_toolbar().AddSeparator() # << class RestoreTool methods >> (2 of 3) ## # Called by the ImageView when the tool is activated. def activate(self, id): self.__image_view.set_sharp(1.0) self.__image_view.set_bright(1.0) self.__image_view.set_color(1.0) self.__image_view.set_contrast(1.0) self.__image_view.set_zoom(1.0) self.__image_view.set_rgb(0) self.deactivate(id) # << class RestoreTool methods >> (3 of 3) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): self.active = 0 # -- end -- << class RestoreTool methods >> # <> (15 of 23) ## # A standard ImageView tool for zooming in and out of the image. class SaveTool: # << class SaveTool methods >> (1 of 3) def __init__(self, image_view): self.__image_view = image_view zoom_tool_mode = 'P' zoom_tool_size = (16, 16) zoom_tool_data ='\xd0\xd0\xcd\xd0\xd0\xd0\xcb\xcc\xd0\xcd\xd0\xd0\xcd\xd0\xd0\xd0\xcd\xcd\xd0\xd0\xd0\xd0\xbb\xb6\xd0\xcc\xd0\xd0\xd0\xd0\xcd\xd0\xd0\xcd\xd0\xd0\xd0\xc5\xae\xb9\xde\xd0\xc9\xcc\xcd\xd0\xd0\xd0\xd0\xcd\xd0\xd0\xcd\xbf\xa7\xcd\xc3\xb2\xae\xa1\xab\xca\xd0\xd0\xd0\xd0\xd0\xd0\xc5\xb2\xab\xd3\xb6\xa6\x8coz\x9f\xb8\xcd\xd0\xd0\xd0\xd0\xbc\xa7\xa6\xb2\xb5\x9by^\x80\x80\x83\xc6\xd0\xcd\xd0\xca\xb5\xa5\xa1\xa6\x93y{o\x88u\x86\xc9\xd0\xcd\xd0\xc0\xa7\xa4\x9f\xbf\xc3\xa4\x85\x88\x85o\xa4\xcd\xd0\xcd\xcd\xae\xa4\xa1\xa0\xa5\xb4\x93\x83\x86zw\xc2\xcd\xd0\xcd\xb0\x9c\x9b\x9b\x93\x8f\x88\x86\x86\x85o\x97\xcd\xcd\xd0\xcd\xac\x82\x83\x8e\x8d\x8a\x88\x86\x85zr\xb2\xd0\xd0\xd0\xcd\xd0\xbb\x94\x81\x81\x83\x83\x82\x81p\x86\xc2\xd0\xd0\xd0\xcd\xd0\xd0\xcd\xb8\x9b\x85{\x81|k\x9e\xcc\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd1\xcb\xc0\xa1\x83pt\xbb\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xcd\xd0\xcd\xbb\x99\xa5\xca\xd0\xcd\xd0\xd0\xcd\xd0\xd0\xd0\xd0\xcd\xd0\xd0\xd1\xd0\xcb\xd0\xcd\xd0\xd0' zoom_tool_img = Image.fromstring(zoom_tool_mode, zoom_tool_size, zoom_tool_data) self.active = 0 self.multi = 0 self.isrgb = 0 img = zoom_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Save") # << class SaveTool methods >> (2 of 3) ## # Called by the ImageView when the tool is activated. def activate(self, id): filename = '' wildcard = "Jpeg (*.jpg)|*.jpg|Giff (*.gif)|*.gif|Bitmap (*.bmp)|*.bmp|All files (*.*)|*.*" #save dialog and get file from self.__image_view.get_image() img = self.__image_view.get_image() dlg = wx.FileDialog(self.__image_view, "Choose a file", "", "", wildcard, wx.SAVE) if dlg.ShowModal() == wx.ID_OK: filename = str(dlg.GetPath()) img.save(filename) dlg.Destroy() self.deactivate(id) # << class SaveTool methods >> (3 of 3) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): self.__image_view.get_toolbar().ToggleTool(id, 0) self.active = 0 # -- end -- << class SaveTool methods >> # <> (16 of 23) ## # A standard ImageView tool for zooming in and out of the image. class LoadTool: # << class LoadTool methods >> (1 of 3) def __init__(self, image_view): self.__image_view = image_view zoom_tool_mode = 'P' zoom_tool_size = (16, 16) zoom_tool_data ='\xd0\xd0\xcd\xd0\xd0\xbf\xbb\xcc\xd0\xcd\xd0\xd0\xcd\xd0\xd0\xd0\xcd\xd0\xd0\xd0\xcb\xb1\xac\x9c\xcc\xd0\xcd\xd0\xd0\xd0\xcd\xd0\xd0\xd0\xd0\xd0\xbf\xca\xc7\xa1\xaa\xc7\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xcd\xd0\xc5\xc2\xde\xe2\xd4\xbc\xaa\xb9\xc5\xc9\xd0\xd0\xd0\xd0\xcd\xcd\xb9\xd4\xe1\xe2\xe2\xdb\xc9\xb6\xc2\xbc\xbf\xcd\xd0\xd0\xcd\xc2\xc2\xe1\xe0\xe2\xe1\xe4\xde\xd1\xca\xc7\xaf\xb1\xcc\xd0\xcb\xb9\xcd\xe0\xe1\xe4\xe1\xe2\xe1\xe0\xd6\xc2\xc3\xab\xa5\xd0\xc2\xc3\xd3\xdc\xe1\xe1\xe1\xe4\xe2\xe0\xe4\xdb\xb9{\x88\xd1\xc2\xbc\xd0\xd6\xde\xe1\xe2\xe1\xe2\xe0\xe4\xdc\x9e[\xa5\xd1\xc7\x9b\xa8\xcc\xd6\xdd\xe1\xe2\xe1\xe0\xe4\xc3s|\xc9\xd0\xcd\xc7\x9f\x93\xbc\xd6\xda\xdc\xdc\xde\xda\xa1[\xaf\xd0\xd0\xcd\xd1\xd0\xb2\x93\xa1\xc9\xd6\xd4\xde\xc3s\x80\xca\xd0\xd0\xcd\xd0\xd0\xcd\xc6\xa1\x90\xb1\xcd\xcd\x97c\xb2\xcd\xd0\xd0\xcd\xd0\xd0\xd0\xd0\xd0\xbb\x96\x99\x99Z\x8f\xcc\xd0\xcd\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xd0\xcb\xabz|\xbf\xd0\xd0\xd0\xd0\xcd\xd0\xd0\xd0\xd0\xcd\xd0\xd0\xd0\xc2\xbf\xcd\xd0\xd0\xd0' zoom_tool_img = Image.fromstring(zoom_tool_mode, zoom_tool_size, zoom_tool_data) self.multi = 0 self.isrgb = 0 self.active = 0 img = zoom_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Load") # << class LoadTool methods >> (2 of 3) ## # Called by the ImageView when the tool is activated. def activate(self, id): filename = '' wildcard = "Jpeg (*.jpg)|*.jpg|Giff (*.gif)|*.gif|Bitmap (*.bmp)|*.bmp|All files (*.*)|*.*" #save dialog and get file from self.__image_view.get_image() img = self.__image_view.get_image() dlg = wx.FileDialog(self.__image_view, "Choose a file", "", "", wildcard, wx.OPEN) if dlg.ShowModal() == wx.ID_OK: filename = str(dlg.GetPath()) #print filename #fil = file(filename) #filtxt = fil.read() #img = Image.fromstring('RGB', (width, height), buffer, 'raw', 'BGR', 0, -1) img = Image.open(filename) self.__image_view.set_image(img) dlg.Destroy() self.deactivate(id) # << class LoadTool methods >> (3 of 3) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): self.__image_view.get_toolbar().ToggleTool(id, 0) self.active = 0 # -- end -- << class LoadTool methods >> # <> (17 of 23) ## # A standard ImageView tool for zooming in and out of the image. class URLTool: # << class URLTool methods >> (1 of 3) def __init__(self, image_view): self.multi = 0 self.isrgb = 0 self.active = 0 self.__image_view = image_view zoom_tool_mode = 'P' zoom_tool_size = (16, 16) zoom_tool_data ='\xd1\xd1\xd0\xd1\xd1\xd0\xd1\xd0\xd1\xd0\xd1\xd1\xd0\xd1\xd1\xd0\xd1\xd1\xd0\xd1\xd1\xd1\xd1\xd1\xd1\xd1\xd1\xd0\xd1\xd0\xd1\xd0\xd1\xd1\xce\xca\xc9\xc8\xc9\xc7\xc8\xc8\xc8\xcc\xd1\xd0\xd2\xd1\xd1\xd2\xc4\x91\x84\x89\x8a\x8a\x89\x87}\x9b\xc7\xd1\xd1\xd1\xd1\xd3\xbf\x9b\xae\x9a\xbb\xbf\x95\xb3\x96\x9a\x98\xc1\xd1\xd1\xd1\xd3\xbf\xa0\xa7q\xb3\xbbg\xaf\x9e\xbc\xa4\x98\xc5\xd2\xd1\xd3\xbf\xa0\xa7o\xb2\xbaf\xaf\x92\x8f\x8ew\xaf\xd2\xd1\xd3\xbf\xa0\xa7o\xb2\xbaf\xb7\xc1\xb5\xab~\xac\xd2\xd1\xd3\xbf\xa0\xa7o\xb2\xbae\xb8\xd5\xd5\xc7\x88\xab\xd2\xd1\xd3\xbf\xa0\xa7p\xb1\xbaf\xb9\xd5\xd6\xc8\x89\xab\xd2\xd1\xd3\xbf\x9e\xb7\x85\x89\x8b\x7f\xc7\xd5\xd6\xc8\x88\xab\xd2\xd1\xd3\xc1\x93\xa9\xa6\x94\x94\xa3\xb4\xb4\xb6\xaa~\xac\xd2\xd1\xd2\xca\x9axywyxyyyx|\xb3\xd2\xd1\xd1\xd1\xcb\xc1\xbe\xbf\xbf\xbf\xbf\xc0\xbe\xc0\xc0\xc9\xd0\xd1\xd1\xd0\xd1\xd1\xd0\xd0\xcf\xcf\xd2\xd0\xcf\xd0\xd0\xd0\xd1\xd1\xd1\xd1\xd2\xd0\xd1\xd1\xd0\xd0\xd1\xd0\xd1\xd0\xd1\xd0\xd1' zoom_tool_img = Image.fromstring(zoom_tool_mode, zoom_tool_size, zoom_tool_data) img = zoom_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) self.__id = id image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "URL") # << class URLTool methods >> (2 of 3) ## # Called by the ImageView when the tool is activated. def activate(self, id): dlg = wx.TextEntryDialog(self.__image_view, 'Enter Image URL','', '') dlg.SetValue('') if dlg.ShowModal() == wx.ID_OK: #print str(dlg.GetValue()) tom = urllib2.urlopen(str(dlg.GetValue())) tomstr = tom.read() typofimage = os.path.splitext(str(dlg.GetValue()))[1] #print typofimage img = WXToPIL(wx.ImageFromStream(StringIO.StringIO(tomstr)),'RGB') self.__image_view.set_image(img) dlg.Destroy() self.deactivate(id) # << class URLTool methods >> (3 of 3) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): self.__image_view.get_toolbar().ToggleTool(id, 0) self.active = 0 # -- end -- << class URLTool methods >> # <> (18 of 23) ## # A standard ImageView tool for panning around the image. class BoxTool: # << class BoxTool methods >> (1 of 5) def __init__(self, image_view): self.__image_view = image_view mode = 'RGB' size = (16, 16) data = '\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x0c\\x0c\\x0c\\x0c\\x0c\\x0c\\x02\\x02\\x02\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x15\\x15\\x15\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x00\\x00\\x00\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x02\\x02\\x02\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x02\\x02\\x02\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\x07\\x07\\x07\\x0c\\x0c\\x0c\\x02\\x02\\x02\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x0c\\x0c\\x0c\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff' img = Image.fromstring(mode, size, data) self.isrgb = 0 img = PILToWX(img) bmp = wx.BitmapFromImage(img) self.active = 0 self.multi = 1 self.coords = (0,0,1,1)# the box coordinates (probably redundant) self.x, self.y = 0,0 # the mouse position self.recstartx, self.recstarty = 0,0 # the rectangle start position id = image_view.get_tool_id(self) self.__id = id self.inspect = True self.pencolor = wx.NamedColour('RED') self.boxthick = 1 self.__last_pos = (0, 0) image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Box") image_view.get_toolbar().AddSeparator() # << class BoxTool methods >> (2 of 5) ## # Called by the ImageView when the tool is activated. def activate(self, id): win = self.__image_view.get_image_window() self.active = 1 cursor = wx.StockCursor(wx.CURSOR_CROSS) win.SetCursor(cursor) pyimg = self.__image_view.get_image() if pyimg: self.bmp = wx.BitmapFromImage(PILToWX(pyimg)) #win.Connect(-1, -1, wx.EVT_LEFT_DOWN, self.on_mouse) #win.Connect(-1, -1, wx.EVT_LEFT_UP, self.on_mouse) #win.Connect(-1, -1, wx.EVT_MOTION, self.on_mouse) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_DOWN, win) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_UP, win) EM.eventManager.Register(self.on_mouse, wx.EVT_MOTION, win) #EM.eventManager.Register(self.OnPaint, wx.EVT_PAINT,win ) # << class BoxTool methods >> (3 of 5) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): win = self.__image_view.get_image_window() self.active = 0 win.SetCursor(wx.STANDARD_CURSOR) EM.eventManager.DeregisterListener(self.on_mouse) #EM.eventManager.DeregisterListener(self.OnPaint) # << class BoxTool methods >> (4 of 5) def OnPaint(self, event):# when the window is moved or uncovered win = self.__image_view.get_image_window() dc = wx.PaintDC(win) win.PrepareDC(dc)# link with class # make a device context, paint because it is in the OnPaint method pyimg = self.__image_view.get_image() #dc = wx.PaintDC(self.__image_win) cache = self.__image_view.get_cache() if not pyimg: return (cw, ch) = win.GetClientSize() bmp = wx.EmptyBitmap(cw, ch) mdc = wx.MemoryDC() mdc.SelectObject(bmp) mdc.SetBackground(wx.Brush(wx.Colour(128, 128, 128))) mdc.Clear() w = int(pyimg.size[0] * self.__image_view.get_zoom()) h = int(pyimg.size[1] * self.__image_view.get_zoom()) origin = self.__image_view.get_origin() if w + 64 < cw: origin[0] = 0 if h + 64 < ch: origin[1] = 0 self.__image_view.set_origin(origin) (x, y) = self.__image_view.image_to_window((0, 0)) mdc.DrawLinePoint(wx.Point(x - 1, y - 1), wx.Point(x + w, y - 1)) mdc.DrawLinePoint(wx.Point(x + w, y - 1), wx.Point(x + w, y + h)) mdc.DrawLinePoint(wx.Point(x + w, y + h),wx.Point( x - 1, y + h)) mdc.DrawLinePoint(wx.Point(x - 1, y + h),wx.Point( x - 1, y - 1)) if self.__image_view.get_zoom() == 1.0: img_bmp = cache.get_tile((0, 0), pyimg.size, 1.0) mdc.DrawBitmapPoint(img_bmp, wx.Point(x, y)) else: ul = self.__image_view.window_to_image((0, 0)) ul = map(int, map(math.floor, ul)) br = self.__image_view.window_to_image((cw - 1, ch - 1)) br = map(int, map(math.ceil, br)) if ul[0] < 0: ul[0] = 0 if ul[1] < 0: ul[1] = 0 if br[0] >= pyimg.size[0]: br[0] = pyimg.size[0] if br[1] >= pyimg.size[1]: br[1] = pyimg.size[1] tile_size = int(256 / self.__image_view.get_zoom()) if tile_size < 1: tile_size = 1 y = ul[1] / tile_size * tile_size while y < br[1]: x = ul[0] / tile_size * tile_size while x < br[0]: img_bmp = cache.get_tile((x, y), (tile_size, tile_size), self.__image_view.get_zoom()) pt = self.__image_view.image_to_window((x, y)) pt = map(int, pt) mdc.DrawBitmapPoint(img_bmp, wx.Point(pt[0], pt[1])) x += tile_size y += tile_size del mdc #dc.DrawBitmapPoint(bmp, wx.Point(0, 0), 0) dc.BeginDrawing()# draw to the DC dc.DrawBitmapPoint(bmp,wx.Point( 0, 0), 0)# draw the GIF from the DEM Package dc.SetBrush(wx.TRANSPARENT_BRUSH)# make sure the square is not filled dc.SetPen(wx.Pen(wx.NamedColour('RED'), 1))# set the box outline to red 1pixel dc.DrawRectanglePointSize(wx.Point(self.coords[0],self.coords[1]),(self.coords[2],self.coords[3])) #apply(dc.DrawRectanglePointSize, self.coords)# draw the box dc.EndDrawing()# move the drawing to the window self.__image_view.set_scrollbars() # << class BoxTool methods >> (5 of 5) def on_mouse(self,event):# the whole point of this class #self.x, self.y = event.m_x, event.m_y self.x, self.y = event.GetX(),event.GetY() #pos = (self.x, self.y) #pos = (event.m_x, event.m_y) win = self.__image_view.get_image_window() if event.LeftDown():# mouse down # get the mouse position self.recstartx, self.recstarty = self.x, self.y # set the start of the rectangle mouse position #win.CaptureMouse()# Capture all mouse events in class #self.__last_pos = pos elif event.Dragging(): dc = wx.ClientDC(win) win.PrepareDC(dc)# link with class pyimg = self.__image_view.get_image() #cache = self.__image_view.get_cache() if not pyimg: return (cw, ch) = win.GetClientSize() #bmp = wx.EmptyBitmap(cw, ch) #mdc = wx.MemoryDC() #mdc.SelectObject(bmp) #mdc.SetBackground(wx.Brush(wx.Colour(128, 128, 128))) #mdc.Clear() w = int(pyimg.size[0] * self.__image_view.get_zoom()) h = int(pyimg.size[1] * self.__image_view.get_zoom()) origin = self.__image_view.get_origin() if w + 64 < cw: origin[0] = 0 if h + 64 < ch: origin[1] = 0 self.__image_view.set_origin(origin) #(x, y) = self.__image_view.image_to_window((0, 0)) #print 'x y ',x,y #mdc.DrawLinePoint(wx.Point(x - 1, y - 1), wx.Point(x + w, y - 1)) #mdc.DrawLinePoint(wx.Point(x + w, y - 1), wx.Point(x + w, y + h)) #mdc.DrawLinePoint(wx.Point(x + w, y + h),wx.Point( x - 1, y + h)) #mdc.DrawLinePoint(wx.Point(x - 1, y + h),wx.Point( x - 1, y - 1)) #if self.__image_view.get_zoom() == 1.0: # img_bmp = cache.get_tile((0, 0), pyimg.size, 1.0) # mdc.DrawBitmapPoint(img_bmp, wx.Point(x, y)) #else: # ul = self.__image_view.window_to_image((0, 0)) # ul = map(int, map(math.floor, ul)) # br = self.__image_view.window_to_image((cw - 1, ch - 1)) # br = map(int, map(math.ceil, br)) # if ul[0] < 0: # ul[0] = 0 # if ul[1] < 0: # ul[1] = 0 # if br[0] >= pyimg.size[0]: # br[0] = pyimg.size[0] # if br[1] >= pyimg.size[1]: # br[1] = pyimg.size[1] # tile_size = int(256 / self.__image_view.get_zoom()) # if tile_size < 1: # tile_size = 1 # y = ul[1] / tile_size * tile_size # while y < br[1]: # x = ul[0] / tile_size * tile_size # while x < br[0]: # img_bmp = cache.get_tile((x, y), (tile_size, tile_size), self.__image_view.get_zoom()) # pt = self.__image_view.image_to_window((x, y)) # pt = map(int, pt) # mdc.DrawBitmapPoint(img_bmp, wx.Point(pt[0], pt[1])) # x += tile_size # y += tile_size #del mdc #dc.DrawBitmapPoint(bmp, wx.Point(0, 0), 0) #win.Refresh(0) dc.BeginDrawing()# draw to the DC #dc.DrawBitmapPoint(bmp,wx.Point( 0, 0), 0)# draw the GIF from the DEM Package dc.SetBrush(wx.TRANSPARENT_BRUSH)# make sure the square is not filled dc.SetPen(wx.Pen(self.pencolor, self.boxthick))# set the box outline to red 1pixel self.coords = (self.recstartx, self.recstarty) + ((self.x - self.recstartx), (self.y - self.recstarty)) # put the box in a tuple for the drawing function dc.DrawRectanglePointSize(wx.Point(self.coords[0],self.coords[1]),(self.coords[2],self.coords[3])) #apply(dc.DrawRectanglePointSize, self.coords)# draw the box dc.EndDrawing()# move the drawing to the window self.__image_view.set_scrollbars() elif event.LeftUp(): dc = wx.ClientDC(win) win.PrepareDC(dc)# link with class dc.BeginDrawing()# draw to the DC #dc.DrawBitmapPoint(bmp,wx.Point( 0, 0), 0)# draw the GIF from the DEM Package dc.SetBrush(wx.TRANSPARENT_BRUSH)# make sure the square is not filled dc.SetPen(wx.Pen(self.pencolor, self.boxthick))# set the box outline to red 1pixel self.coords = (self.recstartx, self.recstarty) + ((self.x - self.recstartx), (self.y - self.recstarty)) # put the box in a tuple for the drawing function dc.DrawRectanglePointSize(wx.Point(self.coords[0],self.coords[1]),(self.coords[2],self.coords[3])) #apply(dc.DrawRectanglePointSize, self.coords)# draw the box # move the drawing to the window# let go of mouse button dc.EndDrawing() if self.inspect: self.clipwin = BoxWindow() bmp = wx.EmptyBitmap(abs(self.coords[2]), abs(self.coords[3])) mdc = wx.MemoryDC() mdc.SelectObject(bmp) mdc.Clear() mdc.Blit( wx.Point(0,0), wx.Size(abs(self.coords[2]), abs(self.coords[3])), dc, wx.Point(self.coords[0], self.coords[1])) wx.SafeYield() del mdc pyimg = wx.ImageFromBitmap(bmp) dcimg = WXToPIL(pyimg) self.clipwin.iv.set_image(dcimg) self.clipwin.Show() # -- end -- << class BoxTool methods >> # <> (19 of 23) class InspectWindow (wx.Frame): # << class InspectWindow methods >> (1 of 3) def __init__(self, image_view): wx.Frame.__init__(self, None, -1, "Color inspector", style = wx.FRAME_TOOL_WINDOW | wx.DEFAULT_FRAME_STYLE) display_size = wx.DisplaySize() self.SetBackgroundColour(wx.Colour(0,0,155)) self.color_view = wx.Window(self, -1, style = wx.SUNKEN_BORDER) self.color_view.SetClientSize((80, 80)) m = (96 - self.color_view.GetSize()[0]) / 2 self.color_view.SetPosition((m, m)) self.color_view.SetBackgroundColour(wx.Colour(0, 0, 0)) base = (m, m + self.color_view.GetSize()[1] + m) across = self.color_view.GetSize()[0] self.red_text = wx.StaticText(self, -1, "-", (base[0], base[1]), size = (across / 3, 24), style = wx.ALIGN_CENTRE | wx.ST_NO_AUTORESIZE) self.grn_text = wx.StaticText(self, -1, "-", (base[0] + across / 3, base[1]), size = (across / 3, 24), style = wx.ALIGN_CENTRE | wx.ST_NO_AUTORESIZE) self.blu_text = wx.StaticText(self, -1, "-", (base[0] + 2 * across / 3, base[1]), size = (across / 3, 24), style = wx.ALIGN_CENTRE | wx.ST_NO_AUTORESIZE) self.SetClientSize((96, base[1] + 16 + m)) size = self.GetSize() self.SetPosition((display_size[0] - size[0] - 32, display_size[1] - size[1] - 32)) wx.EVT_PAINT(self.color_view, self.on_paint) self.image_view = image_view self.pos = (0, 0) # << class InspectWindow methods >> (2 of 3) def set_position(self, pos): self.pos = (int(pos[0]), int(pos[1])) img = self.image_view.get_image() try: if img == None: raise IndexError rgb = img.getpixel(self.pos) self.red_text.SetLabel(str(rgb[0])) self.grn_text.SetLabel(str(rgb[1])) self.blu_text.SetLabel(str(rgb[2])) except IndexError: self.red_text.SetLabel("-") self.grn_text.SetLabel("-") self.blu_text.SetLabel("-") self.color_view.Refresh(0) # << class InspectWindow methods >> (3 of 3) def on_paint(self, evt): dc = wx.PaintDC(self.color_view) img = self.image_view.get_image() if img == None: return for y in range(-2, 3): for x in range(-2, 3): try: rgb = img.getpixel((self.pos[0] + x, self.pos[1] + y)) except IndexError: rgb = (0, 0, 0) if x == 0 and y == 0: dc.SetPen(wx.BLACK_PEN) else: dc.SetPen(wx.TRANSPARENT_PEN) dc.SetBrush(wx.Brush(wx.Colour(rgb[0], rgb[1], rgb[2]))) dc.DrawRectanglePointSize(wx.Point((x + 2) * 16, (y + 2) * 16), (16, 16)) # -- end -- << class InspectWindow methods >> # <> (20 of 23) class BoxWindow (wx.Frame): # << class BoxWindow methods >> def __init__(self): wx.Frame.__init__(self, None, -1, "Box inspector",wx.DefaultPosition,wx.Size(100,100),style = wx.DEFAULT_FRAME_STYLE) self.iv = ImageView(self, -1, tools = [PanTool, ZoomTool, SharpTool, ColorTool, BrightTool, ContTool, RestoreTool, SaveTool], image = None, pos = wx.DefaultPosition, size = wx.Size(100,100), style=wx.DEFAULT_FRAME_STYLE, name='ImageView') sizer = wx.BoxSizer(wx.HORIZONTAL) sizer.Add(self.iv, 1, wx.EXPAND) self.SetSizer(sizer) self.SetAutoLayout(1) sizer.Fit(self) # -- end -- << class BoxWindow methods >> # <> (21 of 23) ## # A standard ImageView tool for inspecting colors in the image. class InspectTool: # << class InspectTool methods >> (1 of 4) def __init__(self, image_view): self.__image_view = image_view inspect_tool_mode = 'RGBA' inspect_tool_size = (16, 16) self.isrgb = 0 inspect_tool_data = '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' inspect_tool_img = Image.fromstring(inspect_tool_mode, inspect_tool_size, inspect_tool_data) self.active = 0 img = inspect_tool_img img = PILToWX(img) bmp = wx.BitmapFromImage(img) id = image_view.get_tool_id(self) image_view.get_toolbar().AddTool(id, bmp, isToggle = 1, shortHelpString = "Inspect") image_view.get_toolbar().AddSeparator() self.multi = 0 self.__id = id self.__dragging = 0 self.__win = None # << class InspectTool methods >> (2 of 4) ## # Called by the ImageView when the tool is activated. def activate(self, id): win = self.__image_view.get_image_window() cursor = wx.StockCursor(wx.CURSOR_CROSS) win.SetCursor(cursor) self.active = 1 #win.Connect(-1, -1, EVT_LEFT_DOWN, self.on_mouse) #win.Connect(-1, -1, EVT_LEFT_UP, self.on_mouse) #win.Connect(-1, -1, EVT_MOTION, self.on_mouse) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_DOWN, win) EM.eventManager.Register(self.on_mouse, wx.EVT_LEFT_UP, win) EM.eventManager.Register(self.on_mouse, wx.EVT_MOTION, win) # << class InspectTool methods >> (3 of 4) ## # Called by the ImageView when the tool is deactivated. def deactivate(self, id): win = self.__image_view.get_image_window() win.SetCursor(wx.STANDARD_CURSOR) EM.eventManager.DeregisterListener(self.on_mouse) self.active = 0 #win.Disconnect(-1, -1, EVT_LEFT_DOWN) #win.Disconnect(-1, -1, EVT_LEFT_UP) #win.Disconnect(-1, -1, EVT_MOTION) # << class InspectTool methods >> (4 of 4) def on_mouse(self, evt): pos = (evt.m_x, evt.m_y) win = self.__image_view.get_image_window() if evt.GetEventType() == wx.wxEVT_MOTION: if not self.__dragging: return if self.__image_view.get_image() != None: self.__win.set_position(self.__image_view.window_to_image(pos)) elif evt.GetEventType() == wx.wxEVT_LEFT_DOWN: #win.CaptureMouse() self.__win = InspectWindow(self.__image_view) self.__win.Show() self.__dragging = 1 elif evt.GetEventType() == wx.wxEVT_LEFT_UP: #win.ReleaseMouse() if self.__win: self.__win.Close() self.__win = None self.__dragging = 0 # -- end -- << class InspectTool methods >> # <> (22 of 23) class TileCache: # << class TileCache methods >> (1 of 3) def __init__(self, image, megapixel_limit = 1.0): self.image = image self.limit = int(megapixel_limit * 1024 * 1024) self.used = 0 self.cache = [] # << class TileCache methods >> (2 of 3) def get_tile(self, pos, size, zoom): key = (pos, size, zoom) for (k, v) in self.cache: if key == k: self.cache.remove((k, v)) self.cache.append((k, v)) return v self.make_space(size[0] * size[1]) end = [pos[0] + size[0], pos[1] + size[1]] if end[0] > self.image.size[0]: end[0] = self.image.size[0] if end[1] > self.image.size[1]: end[1] = self.image.size[1] img = self.image.crop((pos[0], pos[1], end[0], end[1])) img = img.resize((int(img.size[0] * zoom), int(img.size[1] * zoom))) img = PILToWX(img) img_bmp = wx.BitmapFromImage(img) self.used += size[0] * size[1] self.cache.append((key, img_bmp)) return img_bmp # << class TileCache methods >> (3 of 3) def make_space(self, size): while self.used + size > self.limit and self.cache: self.used -= self.cache[0][0][1][0] * self.cache[0][0][1][1] self.cache.remove(self.cache[0]) # -- end -- << class TileCache methods >> # <> (23 of 23) ## # A wx.Python window used for viewing an image with pan, zoom and inspect # tools built in. # # Note that if you are writing your own tools to use with the ImageView window, you must provide an # __init__ method which takes a reference to the ImageView window, an activate # method which is called when the tool is activated and is passed the tool button id, and a deactivate # method which is called when the tool is deactivated and is also passed the tool button id. # #

# tools is a list of tools used for constructing the toolbar and image is the initial # image to be viewed. image can be a PIL image or a wx.Python Image. class ImageView(wx.Window): # << class ImageView methods >> (1 of 33) def __init__(self, parent, id, tools = [ PanTool, ZoomTool, BoxTool, InspectTool , SharpTool , ColorTool , BrightTool , ContTool , RestoreTool , RedTool , GreenTool , BlueTool, LoadTool, SaveTool, URLTool], image = None, pos=(-1, -1), size=(-1, -1), style=0, name='ImageView'): wx.Window.__init__(self, parent, id, pos = pos, size = size, style = style, name = name) self.__rgb = 0 self.__image = None self.__cache = None self.__tools = tools self.__tool_id = 10 self.__tool_ids = {} self.__active_tool = None self.__origin = [0, 0] self.__zoom = 1.0 self.__sharp = 1.0 self.__color = 1.0 self.__bright = 1.0 self.__contrast = 1.0 self.__image_win = wx.Window(self, -1, style = wx.SUNKEN_BORDER) #EM.eventManager.Register(self.on_mouse, EVT_LEFT_DOWN, self.__image_win) #EM.eventManager.Register(self.on_mouse, EVT_LEFT_UP, self.__image_win) #EM.eventManager.Register(self.on_mouse, EVT_MOTION, self.__image_win) #self.toolid = wx.NewId() self.__toolbar = wx.ToolBar(self, -1) #EM.eventManager.Register(self.__on_tool, EVT_TOOL, self.__toolbar) self.set_image(image) for tool in self.__tools: tool(self) if 10 in self.__tool_ids: self.__set_tool(10) #self.Bind(wx.EVT_TOOL, self.__on_tool, id=self.__toolbar.GetId()) #self.Bind(wx.EVT_TOOL_RCLICKED, self.__on_tool, id=self.__toolbar.GetId()) #EM.eventManager.Register(self.__on_tool, wx.EVT_TOOL, self.__toolbar) #EM.eventManager.Register(self.__on_tool, wx.EVT_TOOL, win=self.__toolbar,id=self.toolid) self.__toolbar.Realize() self.__set_constraints() #EVT_SIZE(self, self.__on_size) wx.EVT_TOOL(self.__toolbar, -1, self.__on_tool) #EVT_PAINT(self.__image_win, self.__on_paint) #EVT_SCROLLWIN(self.__image_win, self.__on_scroll) EM.eventManager.Register(self.__on_size, wx.EVT_SIZE, self) EM.eventManager.Register(self.__on_paint, wx.EVT_PAINT,self.__image_win ) EM.eventManager.Register(self.__on_scroll, wx.EVT_SCROLLWIN_TOP, self.__image_win ) EM.eventManager.Register(self.__on_scroll, wx.EVT_SCROLLWIN_BOTTOM, self.__image_win ) EM.eventManager.Register(self.__on_scroll, wx.EVT_SCROLLWIN_LINEUP, self.__image_win ) EM.eventManager.Register(self.__on_scroll, wx.EVT_SCROLLWIN_LINEDOWN, self.__image_win ) EM.eventManager.Register(self.__on_scroll, wx.EVT_SCROLLWIN_PAGEUP, self.__image_win ) EM.eventManager.Register(self.__on_scroll, wx.EVT_SCROLLWIN_PAGEDOWN, self.__image_win ) EM.eventManager.Register(self.__on_scroll, wx.EVT_SCROLLWIN_THUMBTRACK, self.__image_win ) EM.eventManager.Register(self.__on_scroll, wx.EVT_SCROLLWIN_THUMBRELEASE, self.__image_win ) self.__image_win.SetBackgroundColour(wx.Colour(128, 128, 128)) # << class ImageView methods >> (2 of 33) ## # Sets the image being viewed. def set_image(self, image): #if isinstance(image, wx.Image): # image = WXToPIL(image) if image != None: self.__image = image.convert('RGB') else: self.__image = image if self.__rgb > 0: colors = self.__image.split() self.__image = colors[self.__rgb - 1] #print 'RGB!!!!!!' if self.__sharp <> 1.0: sharper = ImageEnhance.Sharpness(self.__image) self.__image = sharper.enhance(self.__sharp) if self.__color <> 1.0: sharper = ImageEnhance.Color(self.__image) self.__image = sharper.enhance(self.__color) if self.__bright <> 1.0: sharper = ImageEnhance.Brightness(self.__image) self.__image = sharper.enhance(self.__bright) if self.__contrast <> 1.0: sharper = ImageEnhance.Contrast(self.__image) self.__image = sharper.enhance(self.__contrast) self.__cache = TileCache(self.__image) self.__image_win.Refresh(0) # << class ImageView methods >> (3 of 33) ## # Returns the viewed image. def get_image(self): return self.__image # << class ImageView methods >> (4 of 33) ## # Returns the viewed image. def on_mouse(self,evt): pass # << class ImageView methods >> (5 of 33) ## # Returns the wx.Python window displaying the image. This is used by custom tool implementations to # add event handlers or change the cursor when the tool is active. def get_image_window(self): return self.__image_win#self.__image_view.get_image_window() # << class ImageView methods >> (6 of 33) ## # Returns the toolbar window. This is used by custom tool implementations to add tool buttons to the # toolbar. def get_toolbar(self): return self.__toolbar # << class ImageView methods >> (7 of 33) ## # Returns the toolbar window. This is used by custom tool implementations to add tool buttons to the # toolbar. def get_self(self): return self # << class ImageView methods >> (8 of 33) ## # Returns a unique tool id for use in the toolbar. This is used by custom tool implementations when they # add tools to the toolbar to ensure that their tool ids don't conflict with those used by other tools. # The custom tool is responsible for adding the tool to the toolbar, but it doesn't need to set up any # event handlers because the ImageView window will call the activate and deactivate # methods of the tool automatically when a tool with the id returned is activated. def get_tool_id(self, tool): self.__tool_id += 1 self.__tool_ids[self.__tool_id] = tool return self.__tool_id # << class ImageView methods >> (9 of 33) def __set_tool(self, id): if not self.__tool_ids[id].multi: for toolkey in self.__tool_ids.keys(): if self.__tool_ids[toolkey].multi and self.__tool_ids[toolkey].active: self.__tool_ids[toolkey].deactivate(toolkey) # deactivate multi self.__toolbar.ToggleTool(toolkey, 0) elif self.__tool_ids[toolkey].isrgb and self.__tool_ids[id].isrgb: if toolkey <> id: self.__tool_ids[toolkey].deactivate(toolkey) # deactivate multi self.__toolbar.ToggleTool(toolkey, 0) if not self.__tool_ids[id].active: self.__tool_ids[id].activate(id) elif self.__tool_ids[id].active: self.__tool_ids[id].deactivate(id) else: for toolkey in self.__tool_ids.keys(): if self.__tool_ids[toolkey].active and not self.__tool_ids[toolkey].isrgb: self.__tool_ids[toolkey].deactivate(toolkey) # deactivate everything self.__toolbar.ToggleTool(toolkey, 0) self.__tool_ids[id].activate(id) # for toolkey in self.__tool_ids.keys(): # print 'self.__tool_ids[toolkey].active:',self.__tool_ids[toolkey].active,' toolkey ',toolkey,' self.__toolbar.GetToolState(toolkey): ',self.__toolbar.GetToolState(toolkey) # if self.__toolbar.GetToolState(toolkey): # #self.__toolbar.ToggleTool(toolkey, 1) # if not self.__tool_ids[toolkey].active: # self.__tool_ids[toolkey].activate(toolkey) # else: # #self.__toolbar.ToggleTool(toolkey, 0) # if self.__tool_ids[toolkey].active: # self.__tool_ids[toolkey].deactivate(toolkey) # if self.__active_tool: # if self.__tool_ids[self.__active_tool].multi: # self.__toolbar.ToggleTool(self.__active_tool, 0) # if self.__active_tool in self.__tool_ids: # self.__tool_ids[self.__active_tool].deactivate(id) # elif self.__toolbar.GetToolState(id): # self.__toolbar.ToggleTool(self.__active_tool, 0) # self.__tool_ids[self.__active_tool].deactivate(id) # else: # self.__toolbar.ToggleTool(id, 1) # if id in self.__tool_ids: # self.__tool_ids[id].activate(id) # self.__active_tool = id # else: # self.__toolbar.ToggleTool(id, 1) # if id in self.__tool_ids: # self.__tool_ids[id].activate(id) self.__active_tool = id # << class ImageView methods >> (10 of 33) ## # Sets the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image and # the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def set_zoom(self, zoom): self.__origin = [self.__origin[0] * zoom / self.__zoom, self.__origin[1] * zoom / self.__zoom] #print 'set zoom' self.__zoom = zoom self.__set_scrollbars() self.__get_scrollbars() self.__image_win.Refresh(0) # << class ImageView methods >> (11 of 33) ## # Returns the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image # and the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def get_zoom(self): return self.__zoom # << class ImageView methods >> (12 of 33) ## # Returns the cache def get_cache(self): return self.__cache # << class ImageView methods >> (13 of 33) ## # Returns the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image # and the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def get_sharp(self): return self.__sharp # << class ImageView methods >> (14 of 33) ## # Returns the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image # and the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def get_color(self): return self.__color # << class ImageView methods >> (15 of 33) ## # Returns the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image # and the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def get_bright(self): return self.__bright # << class ImageView methods >> (16 of 33) ## # Returns the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image # and the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def get_contrast(self): return self.__contrast # << class ImageView methods >> (17 of 33) ## # Sets the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image and # the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def set_sharp(self, sharp): self.__sharp = sharp old_image = self.__image self.set_image(self.__image) self.__image = old_image # << class ImageView methods >> (18 of 33) ## # Sets the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image and # the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def set_rgb(self, rgb): self.__rgb = rgb old_image = self.__image self.set_image(self.__image) self.__image = old_image # << class ImageView methods >> (19 of 33) ## # Sets the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image and # the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def set_color(self, color): self.__color = color old_image = self.__image self.set_image(self.__image) self.__image = old_image # << class ImageView methods >> (20 of 33) ## # Sets the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image and # the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def set_bright(self, bright): self.__bright = bright old_image = self.__image self.set_image(self.__image) self.__image = old_image # << class ImageView methods >> (21 of 33) ## # Sets the zoom factor of the image being viewed. 1.0 is a one-for-one pixel correspondence between the image and # the screen, 2.0 is zoomed in by a factor of two and 1.0 / 2.0 is zoomed out by a factor of two. def set_contrast(self, contrast): self.__contrast = contrast old_image = self.__image self.set_image(self.__image) self.__image = old_image # << class ImageView methods >> (22 of 33) ## # Sets the on-screen origin of the image being viewed. (0, 0) causes the image to be centered in the image view # window. The origin is applied after the zoom factor. def set_origin(self, origin): self.__origin = list(origin) self.__set_scrollbars() self.__get_scrollbars() self.__image_win.Refresh(0) # << class ImageView methods >> (23 of 33) ## # Returns the on-screen origin of the image being viewed. (0, 0) causes the image to be centered in the image view # window. The origin is applied after the zoom factor. def get_origin(self): return [] + self.__origin # << class ImageView methods >> (24 of 33) def __set_constraints(self): l = wx.LayoutConstraints() l.left.Absolute(0) l.top.Absolute(0) l.height.AsIs() l.width.SameAs(self, wx.Width) self.__toolbar.SetConstraints(l) l = wx.LayoutConstraints() l.left.Absolute(0) l.top.Below(self.__toolbar) l.bottom.SameAs(self, wx.Height) l.width.SameAs(self, wx.Width) self.__image_win.SetConstraints(l) self.Layout() # << class ImageView methods >> (25 of 33) def __on_tool(self, evt): #print 'tool ',evt.GetId(),' ',self.__toolbar.GetToolState(evt.GetId()) self.__set_tool(evt.GetId()) # << class ImageView methods >> (26 of 33) def __on_scroll(self, evt): if evt.GetOrientation() == wx.HORIZONTAL: dim = 0 else: dim = 1 pos = self.__image_win.GetScrollPos(evt.GetOrientation()) self.__image_win.SetScrollPos(evt.GetOrientation(), evt.GetPosition()) if evt.GetEventType() == wx.EVT_SCROLLWIN_TOP: self.__image_win.SetScrollPos(evt.GetOrientation(), 0) if evt.GetEventType() == wx.EVT_SCROLLWIN_BOTTOM: self.__image_win.SetScrollPos(evt.GetOrientation(), evt.GetScrollRange(evt.GetOrientation())) if evt.GetEventType() == wx.EVT_SCROLLWIN_LINEUP: self.__image_win.SetScrollPos(evt.GetOrientation(), pos - 96) if evt.GetEventType() == wx.EVT_SCROLLWIN_LINEDOWN: self.__image_win.SetScrollPos(evt.GetOrientation(), pos + 96) if evt.GetEventType() == wx.EVT_SCROLLWIN_PAGEUP: self.__image_win.SetScrollPos(evt.GetOrientation(), pos - self.GetClientSize()[1]) if evt.GetEventType() == wx.EVT_SCROLLWIN_PAGEDOWN: self.__image_win.SetScrollPos(evt.GetOrientation(), pos + self.GetClientSize()[1]) cw = self.__image_win.GetClientSize()[dim] w = self.__image.size[dim] * self.__zoom self.__origin[dim] = self.__image_win.GetScrollPos(evt.GetOrientation()) - 32 - w / 2 + cw / 2 self.__image_win.Refresh(0) # << class ImageView methods >> (27 of 33) ## # Translates a tuple of image coordinates from pixel coordinates in the image window to # pixel coordinates in the image itself. def window_to_image(self, pos): (x, y) = pos (cw, ch) = self.__image_win.GetClientSize() if not self.__image: raise ValueError w = self.__image.size[0] * self.__zoom h = self.__image.size[1] * self.__zoom return (((x - cw / 2) + (w / 2 + self.__origin[0])) / self.__zoom, ((y - ch / 2) + (h / 2 + self.__origin[1])) / self.__zoom) # << class ImageView methods >> (28 of 33) ## # Translates a tuple of image coordinates from pixel coordinates in the image to # pixel coordinates in the image window. def image_to_window(self, pos): (x, y) = pos (cw, ch) = self.__image_win.GetClientSize() if not self.__image: raise ValueError w = self.__image.size[0] * self.__zoom h = self.__image.size[1] * self.__zoom return (x * self.__zoom - (w / 2 + self.__origin[0]) + cw / 2, y * self.__zoom - (h / 2 + self.__origin[1]) + ch / 2) # << class ImageView methods >> (29 of 33) def __on_size(self, evt): self.Layout() self.__set_scrollbars() self.__get_scrollbars() self.__image_win.Refresh(0) # << class ImageView methods >> (30 of 33) def __on_paint(self, evt): dc = wx.PaintDC(self.__image_win) if not self.__image: return (cw, ch) = self.__image_win.GetClientSize() bmp = wx.EmptyBitmap(cw, ch) mdc = wx.MemoryDC() mdc.SelectObject(bmp) mdc.SetBackground(wx.Brush(wx.Colour(128, 128, 128))) mdc.Clear() w = int(self.__image.size[0] * self.__zoom) h = int(self.__image.size[1] * self.__zoom) if w + 64 < cw: self.__origin[0] = 0 if h + 64 < ch: self.__origin[1] = 0 (x, y) = self.image_to_window((0, 0)) mdc.DrawLinePoint(wx.Point(x - 1, y - 1), wx.Point(x + w, y - 1)) mdc.DrawLinePoint(wx.Point(x + w, y - 1), wx.Point(x + w, y + h)) mdc.DrawLinePoint(wx.Point(x + w, y + h),wx.Point( x - 1, y + h)) mdc.DrawLinePoint(wx.Point(x - 1, y + h),wx.Point( x - 1, y - 1)) if self.__zoom == 1.0: img_bmp = self.__cache.get_tile((0, 0), self.__image.size, 1.0) mdc.DrawBitmapPoint(img_bmp, wx.Point(x, y)) else: ul = self.window_to_image((0, 0)) ul = map(int, map(math.floor, ul)) br = self.window_to_image((cw - 1, ch - 1)) br = map(int, map(math.ceil, br)) if ul[0] < 0: ul[0] = 0 if ul[1] < 0: ul[1] = 0 if br[0] >= self.__image.size[0]: br[0] = self.__image.size[0] if br[1] >= self.__image.size[1]: br[1] = self.__image.size[1] tile_size = int(256 / self.__zoom) if tile_size < 1: tile_size = 1 y = ul[1] / tile_size * tile_size while y < br[1]: x = ul[0] / tile_size * tile_size while x < br[0]: img_bmp = self.__cache.get_tile((x, y), (tile_size, tile_size), self.__zoom) pt = self.image_to_window((x, y)) pt = map(int, pt) mdc.DrawBitmapPoint(img_bmp, wx.Point(pt[0], pt[1])) x += tile_size y += tile_size del mdc dc.DrawBitmapPoint(bmp, wx.Point(0, 0), 0) self.__set_scrollbars() # << class ImageView methods >> (31 of 33) def __set_scrollbars(self): (cw, ch) = self.__image_win.GetClientSize() if not self.__image: return w = self.__image.size[0] * self.__zoom h = self.__image.size[1] * self.__zoom self.__image_win.SetScrollbar(wx.HORIZONTAL, w / 2 - cw / 2 + self.__origin[0] + 32, cw, w + 64) self.__image_win.SetScrollbar(wx.VERTICAL, h / 2 - ch / 2 + self.__origin[1] + 32, ch, h + 64) # << class ImageView methods >> (32 of 33) def set_scrollbars(self): self.__set_scrollbars() self.__get_scrollbars() # << class ImageView methods >> (33 of 33) def __get_scrollbars(self): (cw, ch) = self.__image_win.GetClientSize() if not self.__image: return w = self.__image.size[0] * self.__zoom h = self.__image.size[1] * self.__zoom self.__origin[0] = self.__image_win.GetScrollPos(wx.HORIZONTAL) - 32 - w / 2 + cw / 2 self.__origin[1] = self.__image_win.GetScrollPos(wx.VERTICAL) - 32 - h / 2 + ch / 2 # -- end -- << class ImageView methods >> # -- end -- <>