]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/ImageEditor.py
   1 #---------------------------------------------------------------------------- 
   3 # Purpose:      Image Editor for pydocview 
   8 # Copyright:    (c) 2004-2005 ActiveGrid, Inc. 
  10 # License:      wxWindows License 
  11 #---------------------------------------------------------------------------- 
  18 class ImageDocument(wx
.lib
.docview
.Document
): 
  22 class ImageView(wx
.lib
.docview
.View
): 
  25     #---------------------------------------------------------------------------- 
  27     #---------------------------------------------------------------------------- 
  30         wx
.lib
.docview
.View
.__init
__(self
) 
  34     def OnCreate(self
, doc
, flags
): 
  35         if len(doc
.GetFilename()) == 0: 
  36             wx
.MessageBox(_("Cannot create a new image file.\n%s has no paint capability.") % wx
.GetApp().GetAppName(), 
  38                                 wx
.OK | wx
.ICON_EXCLAMATION
) 
  42             self
._bitmap 
= wx
.Image(doc
.GetFilename()).ConvertToBitmap() 
  44             wx
.MessageBox(_("Error loading '%s'. %s") % (doc
.GetPrintableName(), sys
.exc_value
), 
  46                                 wx
.OK | wx
.ICON_EXCLAMATION
) 
  49         frame 
= wx
.GetApp().CreateDocumentFrame(self
, doc
, flags
) 
  50         panel 
= wx
.Panel(frame
, -1)             
  51         self
._ctrl 
= wx
.StaticBitmap(panel
, -1, self
._bitmap
, (0,0), (self
._bitmap
.GetWidth(), self
._bitmap
.GetHeight())) 
  52         wx
.EVT_LEFT_DOWN(self
._ctrl
, self
.OnFocus
) 
  53         wx
.EVT_LEFT_DCLICK(self
._ctrl
, self
.OnFocus
) 
  54         wx
.EVT_RIGHT_DOWN(self
._ctrl
, self
.OnFocus
) 
  55         wx
.EVT_RIGHT_DCLICK(self
._ctrl
, self
.OnFocus
) 
  56         wx
.EVT_MIDDLE_DOWN(self
._ctrl
, self
.OnFocus
) 
  57         wx
.EVT_MIDDLE_DCLICK(self
._ctrl
, self
.OnFocus
) 
  58         panel
.SetClientSize(self
._bitmap
.GetSize()) 
  59         frame
.SetClientSize(panel
.GetSize()) 
  64     def OnFocus(self
, event
): 
  69     def OnClose(self
, deleteWindow 
= True): 
  70         statusC 
= wx
.GetApp().CloseChildDocuments(self
.GetDocument()) 
  71         statusP 
= wx
.lib
.docview
.View
.OnClose(self
, deleteWindow 
= deleteWindow
) 
  72         if not (statusC 
and statusP
): 
  76             self
.GetFrame().Destroy() 
  81         """ for Print Preview and Print """ 
  83         dc
.DrawBitmap(self
._bitmap
, 10, 10, True) 
  87 #---------------------------------------------------------------------------- 
  88 # Icon Bitmaps - generated by encode_bitmaps.py 
  89 #---------------------------------------------------------------------------- 
  90 from wx 
import ImageFromStream
, BitmapFromImage
 
  96 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
  97 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
  98 \x00\x017IDAT8\x8dcddbfh\x9f\xb3\xf3?\x03\x0e\xf0\xfc\xc5[\x0c\xb1\xfb\x0f\ 
  99 \x9f10000l\x9e]\xc2\xc8\x02\x13,Ot\xc6e\x06V\xe0\x9f1\x81\x81\x81\x81\x81\ 
 100 \x81\x05Y\xf0\xdc\x0b\x88C\x1e|\xfc\xc2\xf0\xe3\xf7\x01\x86{\x1fO20000(\xf1\ 
 101 \x9b3p\xb0:\xc0\xd5\x05\xa9\xf3\xc2\xd9L\xe8&\xa3kf```8\xfah-\xc3\xb57\x9d\ 
 102 \x0c?~\x1f\xc0p\t\x86\x01\xe8\x9aa\xe0\xf9\xc7\'X\xc5Q\x0c\x90\xe1c\xc4P\xf4\ 
 103 \xfc\xe3\x13\x14\xb6\x02?\x0f~\x17(\xf1\x9bc\xd5\xcc\xc0\xc0\xc0 \xc9/\x03g_\ 
 104 \xbbx\ta\x00,\xaa\xc4\xb8\x18\x18\x8c%\xd5\xb0j\x86\x19n$\xc1\x88"\xc6\x82\ 
 105 \xaeH]X\x9d!T#\x96\xe1\xec\xf3[\x0cG\x1f\xade````\xb0\x96\x0bf0\x96TcP\x17V\ 
 106 \xc70\x14\xc3\x00\x98!\xea\xc2\xea\x0c\xb7\x1a\x1a\x19\x18\x18\x18\x18\xa2\ 
 107 \xd6,\xc0\xa6\x0c\xe1\x05J\x00\x0b\x03\x03"iz,\xd3A\x91|l\xf2\x8a\x81\x81\ 
 108 \x81\x81au\x87\x18\x8a\xf8\xd5\x8aW\xc4\xb9@VN\x0c\x9f4v\x03\x94\x05LH2\x04%\ 
 109 \x10wD]!h#N\x03`\xb9\x0b\x06`\t\x85\x10\x00\x00\xe4\x0ecz\x94h\xf0\x8e\x00\ 
 110 \x00\x00\x00IEND\xaeB`\x82'  
 113 def getImageBitmap(): 
 114     return BitmapFromImage(getImageImage()) 
 117     stream 
= cStringIO
.StringIO(getImageData()) 
 118     return ImageFromStream(stream
) 
 121     return wx
.IconFromBitmap(getImageBitmap())