PageRenderTime 42ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 1ms

/wxPython-src-2.8.12.0/wxPython/demo/Throbber.py

#
Python | 247 lines | 176 code | 62 blank | 9 comment | 7 complexity | d555877a895cbdfe6b0cd03c28b320b4 MD5 | raw file
Possible License(s): BSD-2-Clause, GPL-2.0, LGPL-2.0, LGPL-3.0, AGPL-3.0, CC-BY-SA-3.0, BSD-3-Clause
  1. import wx
  2. import wx.lib.throbber as throb
  3. import throbImages
  4. from wx.lib.throbber import __doc__ as docString
  5. #----------------------------------------------------------------------
  6. class TestPanel(wx.Panel):
  7. def __init__(self, parent, log):
  8. wx.Panel.__init__(self, parent, -1)
  9. self.log = log
  10. # create the throbbers
  11. self.throbbers = {
  12. 'plain': { 'throbber': None,
  13. 'text': "Plain throbber." },
  14. 'reverse': { 'throbber': None,
  15. 'text': "This throbber runs in reverse and faster." },
  16. 'autoreverse': { 'throbber': None,
  17. 'text': "This throbber switches direction." },
  18. 'label': { 'throbber': None,
  19. 'text': "With a label." },
  20. 'overlay': { 'throbber': None,
  21. 'text': "With an overlayed image." },
  22. 'overlay+text': { 'throbber': None,
  23. 'text': "With a label and an overlayed image." },
  24. }
  25. images = [throbImages.catalog[i].GetBitmap()
  26. for i in throbImages.index
  27. if i not in ['eclouds', 'logo']]
  28. self.throbbers['plain']['throbber'] = \
  29. throb.Throbber(self, -1, images, size=(36, 36),frameDelay = 0.1)
  30. self.throbbers['reverse']['throbber'] = \
  31. throb.Throbber(self, -1, images, frameDelay = 0.07)
  32. self.throbbers['reverse']['throbber'].Reverse()
  33. self.throbbers['autoreverse']['throbber'] = \
  34. throb.Throbber(self, -1, images, frameDelay = 0.1, reverse = True)
  35. self.throbbers['autoreverse']['throbber'].sequence.append(0)
  36. self.throbbers['label']['throbber'] = \
  37. throb.Throbber(self, -1, images, frameDelay = 0.1, label = 'Label')
  38. self.throbbers['label']['throbber'].SetFont(wx.Font(
  39. pointSize = 10, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
  40. ))
  41. self.throbbers['overlay']['throbber'] = \
  42. throb.Throbber(
  43. self, -1, images, frameDelay = 0.1,
  44. overlay = throbImages.catalog['logo'].GetBitmap()
  45. )
  46. self.throbbers['overlay+text']['throbber'] = \
  47. throb.Throbber(
  48. self, -1, images, frameDelay = 0.1,
  49. overlay = throbImages.catalog['logo'].GetBitmap(), label = "Python!"
  50. )
  51. self.throbbers['overlay+text']['throbber'].SetFont(wx.Font(
  52. pointSize = 8, family = wx.DEFAULT, style = wx.NORMAL, weight = wx.BOLD
  53. ))
  54. self.customThrobber = \
  55. throb.Throbber(self, -1, images, size=(36, 36),
  56. frameDelay = 0.1,
  57. rest = 4,
  58. sequence = [ 1, 5, 2, 7, 3, 6, 4, 4, 4, 4, 7, 2, 2, 0 ]
  59. )
  60. box = wx.BoxSizer(wx.VERTICAL)
  61. sizer = wx.GridBagSizer()
  62. box.Add(sizer, 1, wx.EXPAND|wx.ALL, 5)
  63. sizer.AddGrowableCol(1)
  64. row = 2
  65. # use a list so we can keep our order
  66. for t in ['plain', 'reverse', 'autoreverse', 'label', 'overlay', 'overlay+text']:
  67. sizer.Add(
  68. self.throbbers[t]['throbber'], (row, 0), (1, 1),
  69. flag = wx.ALIGN_CENTER|wx.ALL, border=2
  70. )
  71. sizer.Add(
  72. wx.StaticText(self, -1, self.throbbers[t]['text']),
  73. (row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
  74. )
  75. row += 1
  76. # Add custom throbber to sizer.
  77. row += 2
  78. sizer.Add(
  79. self.customThrobber, (row, 0), (1, 1),
  80. flag = wx.ALIGN_CENTER|wx.ALL, border=2
  81. )
  82. sizer.Add(
  83. wx.StaticText(self, -1, 'with custom & manual sequences'),
  84. (row, 1), flag = wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_LEFT
  85. )
  86. # start and stop buttons
  87. startButton = wx.Button(self, -1, "Start")
  88. self.Bind(wx.EVT_BUTTON, self.OnStartAnimation, startButton)
  89. stopButton = wx.Button(self, -1, "Stop")
  90. self.Bind(wx.EVT_BUTTON, self.OnStopAnimation, stopButton)
  91. buttonBox = wx.BoxSizer(wx.HORIZONTAL)
  92. buttonBox.AddMany([
  93. (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  94. (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  95. ])
  96. sizer.Add(
  97. buttonBox, (len(self.throbbers) + 2, 0), (1, 3), flag = wx.ALIGN_CENTER
  98. )
  99. # Buttoms for the custom throbber.
  100. nextButton = wx.Button(self, -1, "Next")
  101. self.Bind(wx.EVT_BUTTON, self.OnNext, nextButton)
  102. prevButton = wx.Button(self, -1, "Previous")
  103. self.Bind(wx.EVT_BUTTON, self.OnPrevious, prevButton)
  104. incButton = wx.Button(self, -1, "Increment")
  105. self.Bind(wx.EVT_BUTTON, self.OnIncrement, incButton)
  106. decButton = wx.Button(self, -1, "Decrement")
  107. self.Bind(wx.EVT_BUTTON, self.OnDecrement, decButton)
  108. revButton = wx.Button(self, -1, "Reverse")
  109. self.Bind(wx.EVT_BUTTON, self.OnReverse, revButton)
  110. restButton = wx.Button(self, -1, "Rest")
  111. self.Bind(wx.EVT_BUTTON, self.OnRest, restButton)
  112. startButton = wx.Button(self, -1, "Start")
  113. self.Bind(wx.EVT_BUTTON, self.OnStart, startButton)
  114. stopButton = wx.Button(self, -1, "Stop")
  115. self.Bind(wx.EVT_BUTTON, self.OnStop, stopButton)
  116. customBox1 = wx.BoxSizer(wx.HORIZONTAL)
  117. customBox1.AddMany([
  118. (nextButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  119. (prevButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  120. (incButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  121. (decButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  122. (revButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  123. ])
  124. customBox2 = wx.BoxSizer(wx.HORIZONTAL)
  125. customBox2.AddMany([
  126. (restButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  127. (startButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  128. (stopButton, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.ALL, 5),
  129. ])
  130. sizer.Add( customBox1, (len(self.throbbers) + 5, 0), (1, 3), flag = wx.ALIGN_CENTER )
  131. sizer.Add( customBox2, (len(self.throbbers) + 6, 0), (1, 3), flag = wx.ALIGN_CENTER )
  132. # Layout.
  133. self.SetSizer(box)
  134. self.SetAutoLayout(True)
  135. self.Layout()
  136. sizer.SetSizeHints(self)
  137. sizer.Fit(self)
  138. for t in self.throbbers.keys():
  139. self.throbbers[t]['throbber'].Start()
  140. self.Bind(wx.EVT_WINDOW_DESTROY, self.OnDestroy)
  141. def OnDestroy(self, event):
  142. self.log.write("got destroy event")
  143. event.Skip()
  144. def OnStartAnimation(self, event):
  145. for t in self.throbbers.keys():
  146. self.throbbers[t]['throbber'].Start()
  147. def OnStopAnimation(self, event):
  148. for t in self.throbbers.keys():
  149. self.throbbers[t]['throbber'].Rest()
  150. def OnNext(self, event):
  151. self.customThrobber.Next()
  152. def OnPrevious(self, event):
  153. self.customThrobber.Previous()
  154. def OnIncrement(self, event):
  155. self.customThrobber.Increment()
  156. def OnDecrement(self, event):
  157. self.customThrobber.Decrement()
  158. def OnReverse(self, event):
  159. self.customThrobber.Reverse()
  160. def OnRest(self, event):
  161. self.customThrobber.Rest()
  162. def OnStart(self, event):
  163. self.customThrobber.Start()
  164. def OnStop(self, event):
  165. self.customThrobber.Stop()
  166. def ShutdownDemo(self):
  167. for t in self.throbbers.keys():
  168. self.throbbers[t]['throbber'].Rest()
  169. #----------------------------------------------------------------------
  170. def runTest(frame, nb, log):
  171. win = TestPanel(nb, log)
  172. return win
  173. #----------------------------------------------------------------------
  174. overview = """<html><body>
  175. <h4><center>Throbber</center></h4>
  176. <p>%s</p>
  177. </body></html>
  178. """ % docString
  179. if __name__ == '__main__':
  180. import sys,os
  181. import run
  182. run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])