]> git.saurik.com Git - wxWidgets.git/blame - wxPython/samples/ide/activegrid/tool/ImageEditor.py
Docview and IDE patch from Morag Hua with fix for bug #1217890
[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)
26ee3a06
RD
42 self._bitmap = wx.Image(doc.GetFilename()).ConvertToBitmap()
43 self._ctrl = wx.StaticBitmap(panel, -1, self._bitmap, (0,0), (self._bitmap.GetWidth(), self._bitmap.GetHeight()))
b792147d
RD
44 wx.EVT_LEFT_DOWN(self._ctrl, self.OnFocus)
45 wx.EVT_LEFT_DCLICK(self._ctrl, self.OnFocus)
46 wx.EVT_RIGHT_DOWN(self._ctrl, self.OnFocus)
47 wx.EVT_RIGHT_DCLICK(self._ctrl, self.OnFocus)
48 wx.EVT_MIDDLE_DOWN(self._ctrl, self.OnFocus)
49 wx.EVT_MIDDLE_DCLICK(self._ctrl, self.OnFocus)
26ee3a06 50 panel.SetClientSize(self._bitmap.GetSize())
1f780e48
RD
51 frame.SetClientSize(panel.GetSize())
52 self.Activate()
53 return True
54
55
b792147d
RD
56 def OnFocus(self, event):
57 self._ctrl.SetFocus()
58 event.Skip()
59
60
1f780e48
RD
61 def OnClose(self, deleteWindow = True):
62 statusC = wx.GetApp().CloseChildDocuments(self.GetDocument())
63 statusP = wx.lib.docview.View.OnClose(self, deleteWindow = deleteWindow)
64 if not (statusC and statusP):
65 return False
66 self.Activate(False)
67 if deleteWindow:
68 self.GetFrame().Destroy()
69 return True
70
71
26ee3a06
RD
72 def OnDraw(self, dc):
73 """ for Print Preview and Print """
74 dc.BeginDrawing()
75 dc.DrawBitmap(self._bitmap, 10, 10, True)
76 dc.EndDrawing()
77
78
1f780e48
RD
79#----------------------------------------------------------------------------
80# Icon Bitmaps - generated by encode_bitmaps.py
81#----------------------------------------------------------------------------
82from wx import ImageFromStream, BitmapFromImage
1f780e48
RD
83import cStringIO
84
85
86def getImageData():
87 return \
bbf7159c
RD
88'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x02\
89\x00\x00\x00\x90\x91h6\x00\x00\x00\x03sBIT\x08\x08\x08\xdb\xe1O\xe0\x00\x00\
90\x00\x9aIDAT(\x91\x95\x92\xc1\r\xc50\x08C\xdd\xaa\xeb\xc12\xec\x90\x9b\x97!\
91\x0b\xb0\x03\x19\xe8\x1fR\xa9U\xf2\xd5\xb4>DH\xf8\t\x13\xb1E\x04\xbe\xe8\x00\
92@\xf2\x8d\xb5\xd6z\x02\x00\xccl\t\x98\x19\xc9}\xe9#y\x8f\xb0\x00H\xba\xc3\
93\xfd\x8a\xbd\x9e0\xe8xn\x9b\x99*q[r\x01`\xfa\x8f?\x91\x86-\x07\x8d\x00Iww\
94\xf7\xce\xcc\xf0>\xbb\x01\xa8j)e\x80G\xa0\xb7[k\x00J)\xfdU\xd5\xd6Z\x87O_D\
95\x88\x88\x88dff>\x17"r\x02y\xd33\xb3E\xc4\xcb\xe3\xeb\xda\xbe\x9e\xf7\x0f\
96\xa0B\x86\xd5X\x16\xcc\xea\x00\x00\x00\x00IEND\xaeB`\x82'
1f780e48
RD
97
98
99def getImageBitmap():
100 return BitmapFromImage(getImageImage())
101
102def getImageImage():
103 stream = cStringIO.StringIO(getImageData())
104 return ImageFromStream(stream)
105
106def getImageIcon():
bbf7159c 107 return wx.IconFromBitmap(getImageBitmap())
1f780e48 108