]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/Throbber.py
workaround sizing bug on Mac
[wxWidgets.git] / wxPython / demo / Throbber.py
index 10294340643b3ced5a1ce1b7872a198ff87cea21..45fa4a3638a2e7dd0479b87b45a876e728886cff 100644 (file)
@@ -1,13 +1,5 @@
-#
-# Throbber.py - Cliff Wells <clifford.wells@attbi.com>
-#
-# 11/23/2003 - Jeff Grimmett (grimmtooth@softhome.net)
-#
-# o Updated for wx namespace
-# 
 
 import  wx
 
 import  wx
-import  wx.lib.rcsizer  as  rcs
 import  wx.lib.throbber as  throb
 
 import throbImages # this was created using a modified version of img2py
 import  wx.lib.throbber as  throb
 
 import throbImages # this was created using a modified version of img2py
@@ -77,47 +69,52 @@ class TestPanel(wx.Panel):
             pointSize = 8, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
             ))
 
             pointSize = 8, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
             ))
 
-        # this throbber is created using a single, composite image
-        self.otherThrobber = throb.Throbber(
-            self, -1, throbImages.catalog['eclouds'].getBitmap(), frameDelay = 0.15, 
-            frames = 12, frameWidth = 48, label = "Stop"
-            )
-
-
-        self.otherThrobber.Bind(wx.EVT_LEFT_DOWN, self.OnClickThrobber)
-
+        self.customThrobber = \
+            throb.Throbber(self, -1, images, size=(36, 36),
+                           frameDelay = 0.1,
+                           rest = 4,
+                           sequence = [ 1, 5, 2, 7, 3, 6, 4, 4, 4, 4, 7, 2, 2, 0 ]
+                           )
+                                                
         box = wx.BoxSizer(wx.VERTICAL)
         box = wx.BoxSizer(wx.VERTICAL)
-        sizer = rcs.RowColSizer()
+        sizer = wx.GridBagSizer()
         box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
         sizer.AddGrowableCol(1)
 
         box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
         sizer.AddGrowableCol(1)
 
-        sizer.Add(
-            self.otherThrobber, row = 0, col = 2, rowspan = 4, 
-            flag = wx.ALIGN_CENTER_VERTICAL
-            )
-
         row = 2
 
         # use a list so we can keep our order
         for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
             sizer.Add(
         row = 2
 
         # use a list so we can keep our order
         for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
             sizer.Add(
-                self.throbbers[t]['throbber'], row = row, col = 0
+                self.throbbers[t]['throbber'], (row, 0), (1, 1)
                 flag = wx.ALIGN_CENTER|wx.ALL, border=2
                 )
 
             sizer.Add(
                 wx.StaticText(self, -1, self.throbbers[t]['text']), 
                 flag = wx.ALIGN_CENTER|wx.ALL, border=2
                 )
 
             sizer.Add(
                 wx.StaticText(self, -1, self.throbbers[t]['text']), 
-                row = row, col = 1, flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
+                (row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
                 )
 
             row += 1
 
                 )
 
             row += 1
 
+        # Add custom throbber to sizer.
+        row += 2
+        sizer.Add(
+            self.customThrobber, (row, 0), (1, 1), 
+            flag = wx.ALIGN_CENTER|wx.ALL, border=2
+            )
+
+        sizer.Add(
+            wx.StaticText(self, -1, 'with custom & manual sequences'), 
+            (row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
+            )
+
         # start and stop buttons
         startButton = wx.Button(self, -1, "Start")
         # start and stop buttons
         startButton = wx.Button(self, -1, "Start")
-        self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, id=startButton.GetId())
+        self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, startButton)
 
         stopButton = wx.Button(self, -1, "Stop")
 
         stopButton = wx.Button(self, -1, "Stop")
-        self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, id=stopButton.GetId())
+        self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, stopButton)
 
         buttonBox = wx.BoxSizer(wx.HORIZONTAL)
         buttonBox.AddMany([
 
         buttonBox = wx.BoxSizer(wx.HORIZONTAL)
         buttonBox.AddMany([
@@ -125,13 +122,55 @@ class TestPanel(wx.Panel):
             (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
             ])
 
             (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
             ])
 
-        sizer.Add(buttonBox,
-                  row = len(self.throbbers) + 3,
-                  col = 0,
-                  colspan = 3,
-                  flag = wx.ALIGN_CENTER
-                  )
+        sizer.Add(
+            buttonBox, (len(self.throbbers) + 2, 0), (1, 3), flag = wx.ALIGN_CENTER
+            )
+
+        # Buttoms for the custom throbber.
+        nextButton = wx.Button(self, -1, "Next")
+        self.Bind(wx.EVT_BUTTON, self.OnNext, nextButton)
+
+        prevButton = wx.Button(self, -1, "Previous")
+        self.Bind(wx.EVT_BUTTON, self.OnPrevious, prevButton)
+
+        incButton = wx.Button(self, -1, "Increment")
+        self.Bind(wx.EVT_BUTTON, self.OnIncrement, incButton)
+
+        decButton = wx.Button(self, -1, "Decrement")
+        self.Bind(wx.EVT_BUTTON, self.OnDecrement, decButton)
+
+        revButton = wx.Button(self, -1, "Reverse")
+        self.Bind(wx.EVT_BUTTON, self.OnReverse, revButton)
+
+        restButton = wx.Button(self, -1, "Rest")
+        self.Bind(wx.EVT_BUTTON, self.OnRest, restButton)
+
+        startButton = wx.Button(self, -1, "Start")
+        self.Bind(wx.EVT_BUTTON, self.OnStart, startButton)
+
+        stopButton = wx.Button(self, -1, "Stop")
+        self.Bind(wx.EVT_BUTTON, self.OnStop, stopButton)
+
+        customBox1 = wx.BoxSizer(wx.HORIZONTAL)
+        customBox1.AddMany([
+            (nextButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+            (prevButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+            (incButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+            (decButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+            (revButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+            ])
+
+        customBox2 = wx.BoxSizer(wx.HORIZONTAL)
+        customBox2.AddMany([
+            (restButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+            (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+            (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
+            ])
+
+        sizer.Add( customBox1, (len(self.throbbers) + 5, 0), (1, 3), flag = wx.ALIGN_CENTER )
+        sizer.Add( customBox2, (len(self.throbbers) + 6, 0), (1, 3), flag = wx.ALIGN_CENTER )
 
 
+        # Layout.
         self.SetSizer(box)
         self.SetAutoLayout(True)
         self.Layout()
         self.SetSizer(box)
         self.SetAutoLayout(True)
         self.Layout()
@@ -141,9 +180,6 @@ class TestPanel(wx.Panel):
         for t in self.throbbers.keys():
             self.throbbers[t]['throbber'].Start()
 
         for t in self.throbbers.keys():
             self.throbbers[t]['throbber'].Start()
 
-        self.otherThrobber.Start()
-        self.otherThrobber.Reverse()
-
         self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
 
     def OnDestroy(self, event):
         self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
 
     def OnDestroy(self, event):
@@ -158,16 +194,31 @@ class TestPanel(wx.Panel):
         for t in self.throbbers.keys():
             self.throbbers[t]['throbber'].Rest()
 
         for t in self.throbbers.keys():
             self.throbbers[t]['throbber'].Rest()
 
-    def OnClickThrobber(self, event):
-        if self.otherThrobber.Running():
-            self.otherThrobber.Rest()
-            self.otherThrobber.SetLabel("Start")
-        else:
-            self.otherThrobber.Start()
-            self.otherThrobber.SetLabel("Stop")
+    def OnNext(self, event):
+        self.customThrobber.Next()
+
+    def OnPrevious(self, event):
+        self.customThrobber.Previous()
+
+    def OnIncrement(self, event):
+        self.customThrobber.Increment()
+
+    def OnDecrement(self, event):
+        self.customThrobber.Decrement()
+
+    def OnReverse(self, event):
+        self.customThrobber.Reverse()
+
+    def OnRest(self, event):
+        self.customThrobber.Rest()
+
+    def OnStart(self, event):
+        self.customThrobber.Start()
+
+    def OnStop(self, event):
+        self.customThrobber.Stop()
 
     def ShutdownDemo(self):
 
     def ShutdownDemo(self):
-        self.otherThrobber.Rest()
         for t in self.throbbers.keys():
             self.throbbers[t]['throbber'].Rest()
 
         for t in self.throbbers.keys():
             self.throbbers[t]['throbber'].Rest()
 
@@ -175,13 +226,8 @@ class TestPanel(wx.Panel):
 #----------------------------------------------------------------------
 
 def runTest(frame, nb, log):
 #----------------------------------------------------------------------
 
 def runTest(frame, nb, log):
-    if wx.Platform == "__WXMAC__":
-        wx.MessageBox("This demo currently fails on the Mac.",
-                     "Sorry")
-        return
-    else:
-        win = TestPanel(nb, log)
-        return win
+    win = TestPanel(nb, log)
+    return win
 
 #----------------------------------------------------------------------
 
 
 #----------------------------------------------------------------------
 
@@ -198,4 +244,4 @@ overview = """<html><body>
 if __name__ == '__main__':
     import sys,os
     import run
 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:])