]> git.saurik.com Git - wxWidgets.git/blame - wxPython/samples/ide/activegrid/tool/ImageEditor.py
Copy about.htm
[wxWidgets.git] / wxPython / samples / ide / activegrid / tool / ImageEditor.py
CommitLineData
1f780e48
RD
1#----------------------------------------------------------------------------
2# Name: ImageEditor.py
3# Purpose: Image Editor for pydocview
4#
5# Author: Morgan Hua
6#
7# Created: 12/24/04
8# Copyright: (c) 2004-2005 ActiveGrid, Inc.
9# CVS-ID: $Id$
10# License: wxWindows License
11#----------------------------------------------------------------------------
12import wx
13import wx.lib.docview
14_ = wx.GetTranslation
15
16
17class ImageDocument(wx.lib.docview.Document):
18 pass
19
20
21class ImageView(wx.lib.docview.View):
22
23
24 #----------------------------------------------------------------------------
25 # Overridden methods
26 #----------------------------------------------------------------------------
27
28 def __init__(self):
29 wx.lib.docview.View.__init__(self)
30 self._ctrl = None
31
32
33 def OnCreate(self, doc, flags):
34 if len(doc.GetFilename()) == 0:
35 wx.MessageBox(_("Cannot create a new image file.\n%s has no paint capability.") % wx.GetApp().GetAppName(),
36 _("New Image File"),
37 wx.OK | wx.ICON_EXCLAMATION)
38 return False
39
40 frame = wx.GetApp().CreateDocumentFrame(self, doc, flags)
41 panel = wx.Panel(frame, -1)
42 bitmap = wx.Image(doc.GetFilename()).ConvertToBitmap()
43 self._ctrl = wx.StaticBitmap(panel, -1, bitmap, (0,0), (bitmap.GetWidth(), bitmap.GetHeight()))
44 panel.SetClientSize(bitmap.GetSize())
45 frame.SetClientSize(panel.GetSize())
46 self.Activate()
47 return True
48
49
50 def OnClose(self, deleteWindow = True):
51 statusC = wx.GetApp().CloseChildDocuments(self.GetDocument())
52 statusP = wx.lib.docview.View.OnClose(self, deleteWindow = deleteWindow)
53 if not (statusC and statusP):
54 return False
55 self.Activate(False)
56 if deleteWindow:
57 self.GetFrame().Destroy()
58 return True
59
60
61#----------------------------------------------------------------------------
62# Icon Bitmaps - generated by encode_bitmaps.py
63#----------------------------------------------------------------------------
64from wx import ImageFromStream, BitmapFromImage
65from wx import EmptyIcon
66import cStringIO
67
68
69def getImageData():
70 return \
71'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x0f\x00\x00\x00\x0e\x08\x06\
72\x00\x00\x00\xf0\x8aF\xef\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
73\x00\x00\x97IDAT(\x91\x9d\x93Q\n\xc4 \x0cD\'\xda\xd3\xa9\xe9ac\xdb\x8bx\xa0\
74\xf4C"\xd6mAw@\x0c1/\t\x03\x123+\x16\x95s\x06\x00l\x00p\x9c\x17\xad\xc0\xe4<\
75R\x0c\xeaf\x81\x14\x83\xa6\x18\x1e[N\xc1)\x06\x15\x01Dj\xbc\x04\x7fi\x9b):\
76\xce\x8b\xf6\xbdN\xec\xfd\x99\x82G\xc8\xf4\xba\xf6\x9b9o\xfa\x81\xab9\x02\
77\x11i\xe6|6cf%\xe7A\xce\x83\x99\xd5\xc4\xccZJ\xd11\xd7\xd76\xd8\x8aJ)\xed\
78\xb6c\x8d,~\xc0\xe3\xe3L\xdc\xe0~\xcaJ\x03\xfa\xe7c\x98n\x01\x88\xc6k\xb1\
79\x83\x04\x87\x00\x00\x00\x00IEND\xaeB`\x82'
80
81
82def getImageBitmap():
83 return BitmapFromImage(getImageImage())
84
85def getImageImage():
86 stream = cStringIO.StringIO(getImageData())
87 return ImageFromStream(stream)
88
89def getImageIcon():
90 icon = EmptyIcon()
91 icon.CopyFromBitmap(getImageBitmap())
92 return icon
93