Guest User

show_loading

a guest
Dec 6th, 2012
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.08 KB | None | 0 0
  1. def show_loading(parent, title, message=None, maximum=100):
  2.     if not message:
  3.         message = title
  4.  
  5.     # A class for the return value.
  6.     class LoadingObject(object):
  7.         def __init__(self, dialog):
  8.             self.dialog = dialog
  9.             self.is_done = False
  10.  
  11.         def done(self):
  12.             if not self.is_done:
  13.                 self.dialog.Destroy()
  14.                 self.is_done = True
  15.  
  16.         def pulse(self, message):
  17.             self.dialog.Pulse(message)
  18.  
  19.         def progress(self, current, message=None):
  20.             if current >= maximum:
  21.                 current = current - 1
  22.  
  23.             if message is not None:
  24.                 self.dialog.Update(current, message)
  25.             else:
  26.                 self.dialog.Update(current)
  27.  
  28.     # Create the progress dialog.
  29.     dlg_style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME
  30.     dlg = wx.ProgressDialog(
  31.         title, message, parent=parent, style=dlg_style, maximum=maximum
  32.     )
  33.     dlg.Pulse()
  34.  
  35.     # Return an instance of the LoadingDialog with the progress dialog attached.
  36.     return LoadingObject(dlg)
Advertisement
Add Comment
Please, Sign In to add comment