# wxPython Image Processing Application v. 0.0.1 # Created by: Nathan Jennings # Updated: 03.18.2007 # nate@deltateck.com # www.jenningsplanet.com # Uses wxPython, Python, and eventually the Python Imaging Library # Code based from wxPython fundamentals found on the www.wxPython.org site # and the wxPython in Action text ## wxPython in Action ## By Noel Rappin and Robin Dunn ## Published: March 2006, 620 pages ## Published by Manning Publications ## ISBN: 1932394621 # Additions from code snippets found on the net. Documented as best as possible. ## I am hoping to add copiously to this as time affords to provide some basic ## image processing routines for remotely sensed imagery. ## The following is the basic shell routines, then I hope to add classes of image ## processing functions #!/usr/bin/env python2.4 ###this makes it nice for non-Windows Users import wx import images # a python script found in the same directory as the Image Processing script # needed to do the AddSimple Tool piece. # originated from the wxPython in Action scripts USE_BUFFERED_DC = 1 # flag used for the drawing of the imagery in the frame class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size = (800, 600)) #panel = wx.Panel(self) # main panel #panel.SetBackgroundColour('White') statusBar = self.CreateStatusBar() # create status bar (at the bottom) toolbar = self.CreateToolBar() # create a tool bar (at top) toolbar.AddSimpleTool(wx.NewId(), images.getNewBitmap(), "New", "Long help for 'New'") # create a simple tool toolbar.Realize() # make the tool show up menuBar = wx.MenuBar() # create a menu bar (at top) menu1 = wx.Menu() # create a new menu menuOpen = menu1.Append(wx.NewId(), "Open", "Open an Image File") menuTest = menu1.Append(wx.NewId(), "Test", "Load My Image") menuExit = menu1.Append(wx.NewId(), "Exit", "") menuBar.Append(menu1, "&File") # create a new menu item "File" menu2 = wx.Menu() # create a second menu menu2.Append(wx.NewId(), "&Copy", "Copy in status bar") menu2.Append(wx.NewId(), "C&ut", "") menu2.Append(wx.NewId(), "Paste", "") menu2.AppendSeparator() # add a separator menu2.Append(wx.NewId(), "&Options...", "Display Options") menuBar.Append(menu2, "&Edit") """Image Utilities Menu""" menu3 = wx.Menu() menu3.Append(wx.NewId(), "Subset", "") menu3.Append(wx.NewId(), "Convert", "") menuBar.Append(menu3, "Image Utilities") """Enhancement Menu""" menu4 = wx.Menu() menu4.Append(wx.NewId(), "Contrast Stretch", "") menu4.Append(wx.NewId(), "Principal Components", "") menuBar.Append(menu4, "Image Enhancement") """Help Menu""" menu5 = wx.Menu() menu5.Append(wx.NewId(), "Help", "") menuAbout = menu5.Append(wx.NewId(), "About", "") menuBar.Append(menu5, "Help") self.SetMenuBar(menuBar) # make the menu bar show up """Run Specific Events on the Buttons""" self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout) self.Bind(wx.EVT_MENU, self.OnExit, menuExit) self.Bind(wx.EVT_MENU, self.openNew, menuOpen) #self.Bind(wx.EVT_MENU, self.Test, menuTest) #self.bitmap = wx.Bitmap('c:\\gis_programming\\python\\remote_sensing\\memento.png') #self.bitmap = wx.Bitmap('c:\\pictures\\julia_thumb.jpg') #wx.EVT_PAINT(self, self.OnPaint) #self.Refresh() #self.Center() ## 03.18.2007 Update ## This should bring up an image browser or ## a dialog box to ask for an image file...possibly PIL kinds ## then actually open the file and draw it. ## Will also need to do some fit image to window and scrolling mechanisms def openNew(self,event): print "In Open New" imagefile = "c:\\remote_sensing_images\\franfurt_1mtc.jpg" self.bitmap = wx.Bitmap(imagefile) wx.EVT_PAINT(self, self.OnPaint) # Call the paint routine, then refresh the # frame to show the selected image self.Refresh() # Redraw the image in the frame, so you can see it def OnPaint(self, event): #print "In On Paint" dc = wx.PaintDC(self) #dc.DrawBitmap(self.bitmap, 60, 20) dc.Clear() ## Code below comes from Chris Barker 1/27/03 Chris.Barker@noaa.gov ## http://wiki.wxpython.org/index.cgi/DoubleBufferedDrawing ## used on 03.18.2007...Thanks for the help! if USE_BUFFERED_DC: #dc = wx.BufferedPaintDC(self, self._Buffer) dc = wx.BufferedPaintDC(self, self.bitmap) else: dc = wx.PaintDC(self) #dc.DrawBitmap(self._Buffer,0,0) dc.DrawBitmap(self.bitmap, 0, 0) # Don't do self.Refresh() here. It flickers infinitely def OnAbout(self, event): dlg = wx.MessageBox("Created by: Nathan Jennings\n" "Updated: 03.18.07\n" "v. 0.0.1\n\n" "Developed in: Python, wxPython, and Python Image Library (PIL)\n\n" "This program provides a framework for some\n" "basic image processing routines related to\n" "remotely sensed imagery.\n\n" "email me at the address below with any problems\n" "or questions.\n\n" "nate@deltateck.com", "About", wx.OK | wx.ICON_QUESTION) def OnExit (self, event): self.Destroy() print "Exited the Application" class MyApp(wx.App): def OnInit(self): frame = MyFrame(None, -1, 'Image Processing wxPython v. 0.0.1') frame.Show(True) self.SetTopWindow(frame) return True app = MyApp(0) app.MainLoop()