]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/ImageEditor.py
Merged modifications from the 2.6 branch
[wxWidgets.git] / wxPython / samples / ide / activegrid / tool / ImageEditor.py
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 #----------------------------------------------------------------------------
12 import wx
13 import wx.lib.docview
14 import sys
15 _ = wx.GetTranslation
16
17
18 class ImageDocument(wx.lib.docview.Document):
19 pass
20
21
22 class ImageView(wx.lib.docview.View):
23
24
25 #----------------------------------------------------------------------------
26 # Overridden methods
27 #----------------------------------------------------------------------------
28
29 def __init__(self):
30 wx.lib.docview.View.__init__(self)
31 self._ctrl = None
32
33
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(),
37 _("New Image File"),
38 wx.OK | wx.ICON_EXCLAMATION)
39 return False
40
41 try:
42 self._bitmap = wx.Image(doc.GetFilename()).ConvertToBitmap()
43 except:
44 wx.MessageBox(_("Error loading '%s'. %s") % (doc.GetPrintableName(), sys.exc_value),
45 _("Open Image File"),
46 wx.OK | wx.ICON_EXCLAMATION)
47 return False
48
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())
60 self.Activate()
61 return True
62
63
64 def OnFocus(self, event):
65 self._ctrl.SetFocus()
66 event.Skip()
67
68
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):
73 return False
74 self.Activate(False)
75 if deleteWindow:
76 self.GetFrame().Destroy()
77 return True
78
79
80 def OnDraw(self, dc):
81 """ for Print Preview and Print """
82 dc.BeginDrawing()
83 dc.DrawBitmap(self._bitmap, 10, 10, True)
84 dc.EndDrawing()
85
86
87 #----------------------------------------------------------------------------
88 # Icon Bitmaps - generated by encode_bitmaps.py
89 #----------------------------------------------------------------------------
90 from wx import ImageFromStream, BitmapFromImage
91 import cStringIO
92
93
94 def getImageData():
95 return \
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'
111
112
113 def getImageBitmap():
114 return BitmapFromImage(getImageImage())
115
116 def getImageImage():
117 stream = cStringIO.StringIO(getImageData())
118 return ImageFromStream(stream)
119
120 def getImageIcon():
121 return wx.IconFromBitmap(getImageBitmap())
122