]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/samples/doodle/doodle.py
newevent helpers
[wxWidgets.git] / wxPython / samples / doodle / doodle.py
index 4895026e744eda797deac2247e5a27d41c14d344..15e4de19a63ee77d3e80f10f049ea920486f5cdb 100644 (file)
@@ -6,11 +6,11 @@ can do simple drawings upon.
 """
 
 
 """
 
 
-from wxPython.wx import *
+import wx                  # This module uses the new wx namespace
 
 #----------------------------------------------------------------------
 
 
 #----------------------------------------------------------------------
 
-class DoodleWindow(wxWindow):
+class DoodleWindow(wx.Window):
     menuColours = { 100 : 'Black',
                     101 : 'Yellow',
                     102 : 'Red',
     menuColours = { 100 : 'Black',
                     101 : 'Yellow',
                     102 : 'Red',
@@ -32,7 +32,7 @@ class DoodleWindow(wxWindow):
 
 
     def __init__(self, parent, ID):
 
 
     def __init__(self, parent, ID):
-        wxWindow.__init__(self, parent, ID, style=wxNO_FULL_REPAINT_ON_RESIZE)
+        wx.Window.__init__(self, parent, ID, style=wx.NO_FULL_REPAINT_ON_RESIZE)
         self.SetBackgroundColour("WHITE")
         self.listeners = []
         self.thickness = 1
         self.SetBackgroundColour("WHITE")
         self.listeners = []
         self.thickness = 1
@@ -44,20 +44,20 @@ class DoodleWindow(wxWindow):
         self.InitBuffer()
 
         # hook some mouse events
         self.InitBuffer()
 
         # hook some mouse events
-        EVT_LEFT_DOWN(self, self.OnLeftDown)
-        EVT_LEFT_UP(self, self.OnLeftUp)
-        EVT_RIGHT_UP(self, self.OnRightUp)
-        EVT_MOTION(self, self.OnMotion)
+        wx.EVT_LEFT_DOWN(self, self.OnLeftDown)
+        wx.EVT_LEFT_UP(self, self.OnLeftUp)
+        wx.EVT_RIGHT_UP(self, self.OnRightUp)
+        wx.EVT_MOTION(self, self.OnMotion)
 
         # the window resize event and idle events for managing the buffer
 
         # the window resize event and idle events for managing the buffer
-        EVT_SIZE(self, self.OnSize)
-        EVT_IDLE(self, self.OnIdle)
+        wx.EVT_SIZE(self, self.OnSize)
+        wx.EVT_IDLE(self, self.OnIdle)
 
         # and the refresh event
 
         # and the refresh event
-        EVT_PAINT(self, self.OnPaint)
+        wx.EVT_PAINT(self, self.OnPaint)
 
         # When the window is destroyed, clean up resources.
 
         # When the window is destroyed, clean up resources.
-        EVT_WINDOW_DESTROY(self, self.Cleanup)
+        wx.EVT_WINDOW_DESTROY(self, self.Cleanup)
 
 
     def Cleanup(self, evt):
 
 
     def Cleanup(self, evt):
@@ -69,9 +69,9 @@ class DoodleWindow(wxWindow):
     def InitBuffer(self):
         """Initialize the bitmap used for buffering the display."""
         size = self.GetClientSize()
     def InitBuffer(self):
         """Initialize the bitmap used for buffering the display."""
         size = self.GetClientSize()
-        self.buffer = wxEmptyBitmap(size.width, size.height)
-        dc = wxBufferedDC(None, self.buffer)
-        dc.SetBackground(wxBrush(self.GetBackgroundColour()))
+        self.buffer = wx.EmptyBitmap(size.width, size.height)
+        dc = wx.BufferedDC(None, self.buffer)
+        dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
         dc.Clear()
         self.DrawLines(dc)
         self.reInitBuffer = False
         dc.Clear()
         self.DrawLines(dc)
         self.reInitBuffer = False
@@ -80,14 +80,14 @@ class DoodleWindow(wxWindow):
     def SetColour(self, colour):
         """Set a new colour and make a matching pen"""
         self.colour = colour
     def SetColour(self, colour):
         """Set a new colour and make a matching pen"""
         self.colour = colour
-        self.pen = wxPen(wxNamedColour(self.colour), self.thickness, wxSOLID)
+        self.pen = wx.Pen(self.colour, self.thickness, wx.SOLID)
         self.Notify()
 
 
     def SetThickness(self, num):
         """Set a new line thickness and make a matching pen"""
         self.thickness = num
         self.Notify()
 
 
     def SetThickness(self, num):
         """Set a new line thickness and make a matching pen"""
         self.thickness = num
-        self.pen = wxPen(wxNamedColour(self.colour), self.thickness, wxSOLID)
+        self.pen = wx.Pen(self.colour, self.thickness, wx.SOLID)
         self.Notify()
 
 
         self.Notify()
 
 
@@ -103,20 +103,20 @@ class DoodleWindow(wxWindow):
 
     def MakeMenu(self):
         """Make a menu that can be popped up later"""
 
     def MakeMenu(self):
         """Make a menu that can be popped up later"""
-        menu = wxMenu()
+        menu = wx.Menu()
         keys = self.menuColours.keys()
         keys.sort()
         for k in keys:
             text = self.menuColours[k]
         keys = self.menuColours.keys()
         keys.sort()
         for k in keys:
             text = self.menuColours[k]
-            menu.Append(k, text, kind=wxITEM_CHECK)
-        EVT_MENU_RANGE(self, 100, 200, self.OnMenuSetColour)
-        EVT_UPDATE_UI_RANGE(self, 100, 200, self.OnCheckMenuColours)
+            menu.Append(k, text, kind=wx.ITEM_CHECK)
+        wx.EVT_MENU_RANGE(self, 100, 200, self.OnMenuSetColour)
+        wx.EVT_UPDATE_UI_RANGE(self, 100, 200, self.OnCheckMenuColours)
         menu.Break()
 
         for x in range(1, self.maxThickness+1):
         menu.Break()
 
         for x in range(1, self.maxThickness+1):
-            menu.Append(x, str(x), kind=wxITEM_CHECK)
-        EVT_MENU_RANGE(self, 1, self.maxThickness, self.OnMenuSetThickness)
-        EVT_UPDATE_UI_RANGE(self, 1, self.maxThickness, self.OnCheckMenuThickness)
+            menu.Append(x, str(x), kind=wx.ITEM_CHECK)
+        wx.EVT_MENU_RANGE(self, 1, self.maxThickness, self.OnMenuSetThickness)
+        wx.EVT_UPDATE_UI_RANGE(self, 1, self.maxThickness, self.OnCheckMenuThickness)
         self.menu = menu
 
 
         self.menu = menu
 
 
@@ -126,8 +126,11 @@ class DoodleWindow(wxWindow):
         text = self.menuColours[event.GetId()]
         if text == self.colour:
             event.Check(True)
         text = self.menuColours[event.GetId()]
         if text == self.colour:
             event.Check(True)
+            event.SetText(text.upper())
         else:
             event.Check(False)
         else:
             event.Check(False)
+            event.SetText(text)
+
     def OnCheckMenuThickness(self, event):
         if event.GetId() == self.thickness:
             event.Check(True)
     def OnCheckMenuThickness(self, event):
         if event.GetId() == self.thickness:
             event.Check(True)
@@ -164,7 +167,7 @@ class DoodleWindow(wxWindow):
         current one.  Save the coordinants for redraws.
         """
         if event.Dragging() and event.LeftIsDown():
         current one.  Save the coordinants for redraws.
         """
         if event.Dragging() and event.LeftIsDown():
-            dc = wxBufferedDC(wxClientDC(self), self.buffer)
+            dc = wx.BufferedDC(wx.ClientDC(self), self.buffer)
             dc.BeginDrawing()
             dc.SetPen(self.pen)
             pos = event.GetPositionTuple()
             dc.BeginDrawing()
             dc.SetPen(self.pen)
             pos = event.GetPositionTuple()
@@ -200,10 +203,10 @@ class DoodleWindow(wxWindow):
         Called when the window is exposed.
         """
         # Create a buffered paint DC.  It will create the real
         Called when the window is exposed.
         """
         # Create a buffered paint DC.  It will create the real
-        # wxPaintDC and then blit the bitmap to it when dc is
+        # wx.PaintDC and then blit the bitmap to it when dc is
         # deleted.  Since we don't need to draw anything else
         # here that's all there is to it.
         # deleted.  Since we don't need to draw anything else
         # here that's all there is to it.
-        dc = wxBufferedPaintDC(self, self.buffer)
+        dc = wx.BufferedPaintDC(self, self.buffer)
 
 
     def DrawLines(self, dc):
 
 
     def DrawLines(self, dc):
@@ -212,7 +215,7 @@ class DoodleWindow(wxWindow):
         """
         dc.BeginDrawing()
         for colour, thickness, line in self.lines:
         """
         dc.BeginDrawing()
         for colour, thickness, line in self.lines:
-            pen = wxPen(wxNamedColour(colour), thickness, wxSOLID)
+            pen = wx.Pen(colour, thickness, wx.SOLID)
             dc.SetPen(pen)
             for coords in line:
                 apply(dc.DrawLine, coords)
             dc.SetPen(pen)
             for coords in line:
                 apply(dc.DrawLine, coords)
@@ -240,16 +243,16 @@ class DoodleWindow(wxWindow):
 
 #----------------------------------------------------------------------
 
 
 #----------------------------------------------------------------------
 
-class DoodleFrame(wxFrame):
+class DoodleFrame(wx.Frame):
     def __init__(self, parent):
     def __init__(self, parent):
-        wxFrame.__init__(self, parent, -1, "Doodle Frame", size=(800,600),
-                         style=wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
+        wx.Frame.__init__(self, parent, -1, "Doodle Frame", size=(800,600),
+                         style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
         doodle = DoodleWindow(self, -1)
 
 #----------------------------------------------------------------------
 
 if __name__ == '__main__':
         doodle = DoodleWindow(self, -1)
 
 #----------------------------------------------------------------------
 
 if __name__ == '__main__':
-    app = wxPySimpleApp()
+    app = wx.PySimpleApp()
     frame = DoodleFrame(None)
     frame.Show(True)
     app.MainLoop()
     frame = DoodleFrame(None)
     frame.Show(True)
     app.MainLoop()