]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/SashWindow.py
Warning fixes and source cleaning.
[wxWidgets.git] / wxPython / demo / SashWindow.py
index aee3be673a8fbfe3ca43f3f83dd08b227cb2823b..72b6357c9cd258a16791bec856e1d2edfd961d6d 100644 (file)
@@ -4,112 +4,115 @@ import  wx
 #---------------------------------------------------------------------------
 
 class TestSashWindow(wx.Panel):
-    ID_WINDOW_TOP    = 5100
-    ID_WINDOW_LEFT1  = 5101
-    ID_WINDOW_LEFT2  = 5102
-    ID_WINDOW_BOTTOM = 5103
-
 
     def __init__(self, parent, log):
         wx.Panel.__init__(self, parent, -1)
 
         self.log = log
-
-        # will occupy the space not used by the Layout Algorithm
-        self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
-
-        self.Bind(
-            wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,
-            id=self.ID_WINDOW_TOP, id2=self.ID_WINDOW_BOTTOM, 
-            )
-
-        self.Bind(wx.EVT_SIZE, self.OnSize)
-
+        winids = []
 
         # Create some layout windows
         # A window like a toolbar
-        win = wx.SashLayoutWindow(
-            self, self.ID_WINDOW_TOP, wx.DefaultPosition, (200, 30), 
+        topwin = wx.SashLayoutWindow(
+            self, -1, wx.DefaultPosition, (200, 30), 
             wx.NO_BORDER|wx.SW_3D
             )
 
-        win.SetDefaultSize((1000, 30))
-        win.SetOrientation(wx.LAYOUT_HORIZONTAL)
-        win.SetAlignment(wx.LAYOUT_TOP)
-        win.SetBackgroundColour(wx.Colour(255, 0, 0))
-        win.SetSashVisible(wx.SASH_BOTTOM, True)
-
-        self.topWindow = win
+        topwin.SetDefaultSize((1000, 30))
+        topwin.SetOrientation(wx.LAYOUT_HORIZONTAL)
+        topwin.SetAlignment(wx.LAYOUT_TOP)
+        topwin.SetBackgroundColour(wx.Colour(255, 0, 0))
+        topwin.SetSashVisible(wx.SASH_BOTTOM, True)
 
+        self.topWindow = topwin
+        winids.append(topwin.GetId())
 
         # A window like a statusbar
-        win = wx.SashLayoutWindow(
-                self, self.ID_WINDOW_BOTTOM, wx.DefaultPosition, (200, 30), 
+        bottomwin = wx.SashLayoutWindow(
+                self, -1, wx.DefaultPosition, (200, 30), 
                 wx.NO_BORDER|wx.SW_3D
                 )
 
-        win.SetDefaultSize((1000, 30))
-        win.SetOrientation(wx.LAYOUT_HORIZONTAL)
-        win.SetAlignment(wx.LAYOUT_BOTTOM)
-        win.SetBackgroundColour(wx.Colour(0, 0, 255))
-        win.SetSashVisible(wx.SASH_TOP, True)
+        bottomwin.SetDefaultSize((1000, 30))
+        bottomwin.SetOrientation(wx.LAYOUT_HORIZONTAL)
+        bottomwin.SetAlignment(wx.LAYOUT_BOTTOM)
+        bottomwin.SetBackgroundColour(wx.Colour(0, 0, 255))
+        bottomwin.SetSashVisible(wx.SASH_TOP, True)
 
-        self.bottomWindow = win
+        self.bottomWindow = bottomwin
+        winids.append(bottomwin.GetId())
 
         # A window to the left of the client window
-        win =  wx.SashLayoutWindow(
-                self, self.ID_WINDOW_LEFT1, wx.DefaultPosition, (200, 30), 
+        leftwin1 =  wx.SashLayoutWindow(
+                self, -1, wx.DefaultPosition, (200, 30), 
                 wx.NO_BORDER|wx.SW_3D
                 )
 
-        win.SetDefaultSize((120, 1000))
-        win.SetOrientation(wx.LAYOUT_VERTICAL)
-        win.SetAlignment(wx.LAYOUT_LEFT)
-        win.SetBackgroundColour(wx.Colour(0, 255, 0))
-        win.SetSashVisible(wx.SASH_RIGHT, True)
-        win.SetExtraBorderSize(10)
+        leftwin1.SetDefaultSize((120, 1000))
+        leftwin1.SetOrientation(wx.LAYOUT_VERTICAL)
+        leftwin1.SetAlignment(wx.LAYOUT_LEFT)
+        leftwin1.SetBackgroundColour(wx.Colour(0, 255, 0))
+        leftwin1.SetSashVisible(wx.SASH_RIGHT, True)
+        leftwin1.SetExtraBorderSize(10)
         textWindow = wx.TextCtrl(
-                        win, -1, "", wx.DefaultPosition, wx.DefaultSize, 
+                        leftwin1, -1, "", wx.DefaultPosition, wx.DefaultSize, 
                         wx.TE_MULTILINE|wx.SUNKEN_BORDER
                         )
 
         textWindow.SetValue("A sub window")
 
-        self.leftWindow1 = win
+        self.leftWindow1 = leftwin1
+        winids.append(leftwin1.GetId())
 
 
         # Another window to the left of the client window
-        win = wx.SashLayoutWindow(
-                self, self.ID_WINDOW_LEFT2, wx.DefaultPosition, (200, 30), 
+        leftwin2 = wx.SashLayoutWindow(
+                self, -1, wx.DefaultPosition, (200, 30), 
                 wx.NO_BORDER|wx.SW_3D
                 )
 
-        win.SetDefaultSize((120, 1000))
-        win.SetOrientation(wx.LAYOUT_VERTICAL)
-        win.SetAlignment(wx.LAYOUT_LEFT)
-        win.SetBackgroundColour(wx.Colour(0, 255, 255))
-        win.SetSashVisible(wx.SASH_RIGHT, True)
+        leftwin2.SetDefaultSize((120, 1000))
+        leftwin2.SetOrientation(wx.LAYOUT_VERTICAL)
+        leftwin2.SetAlignment(wx.LAYOUT_LEFT)
+        leftwin2.SetBackgroundColour(wx.Colour(0, 255, 255))
+        leftwin2.SetSashVisible(wx.SASH_RIGHT, True)
+
+        self.leftWindow2 = leftwin2
+        winids.append(leftwin2.GetId())
+
+        # will occupy the space not used by the Layout Algorithm
+        self.remainingSpace = wx.Panel(self, -1, style=wx.SUNKEN_BORDER)
+
+        self.Bind(
+            wx.EVT_SASH_DRAGGED_RANGE, self.OnSashDrag,
+            id=min(winids), id2=max(winids)
+            )
 
-        self.leftWindow2 = win
+        self.Bind(wx.EVT_SIZE, self.OnSize)
 
 
     def OnSashDrag(self, event):
         if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
+            self.log.write('drag is out of range')
             return
 
-        eID = event.GetId()
+        eobj = event.GetEventObject()
 
-        if eID == self.ID_WINDOW_TOP:
+        if eobj is self.topWindow:
+            self.log.write('topwin received drag event')
             self.topWindow.SetDefaultSize((1000, event.GetDragRect().height))
 
-        elif eID == self.ID_WINDOW_LEFT1:
+        elif eobj is self.leftWindow1:
+            self.log.write('leftwin1 received drag event')
             self.leftWindow1.SetDefaultSize((event.GetDragRect().width, 1000))
 
 
-        elif eID == self.ID_WINDOW_LEFT2:
+        elif eobj is self.leftWindow2:
+            self.log.write('leftwin2 received drag event')
             self.leftWindow2.SetDefaultSize((event.GetDragRect().width, 1000))
 
-        elif eID == self.ID_WINDOW_BOTTOM:
+        elif eobj is self.bottomWindow:
+            self.log.write('bottomwin received drag event')
             self.bottomWindow.SetDefaultSize((1000, event.GetDragRect().height))
 
         wx.LayoutAlgorithm().LayoutWindow(self, self.remainingSpace)
@@ -143,4 +146,4 @@ in more detail.
 if __name__ == '__main__':
     import sys,os
     import run
-    run.main(['', os.path.basename(sys.argv[0])])
+    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])