ProgressBar riutilizzabile alleggerita
9 Settembre 2011
in riferimento alla vecchia versione, ho snellito il codice, sempre utilizzando un ProgressDialog:
''' ProgressDialog sample for progress bar generating. wx.ProgressDialog(title, message, maximum, parent, style) style type: wx.PD_APP_MODAL - the progress dialog will block all user events wx.PD_AUTO_HIDE - The progress dialog will automatically hide itself when it reaches its maximum value. wx.PD_CAN_ABORT - Puts a Cancel button on box for stop the process. wx.PD_ELAPSED_TIME - Displays the elapsed time wx.PD_ESTIMATED_TIME - Displays an estimate of the total time to complete the process. wx.PD_REMAINING_TIME - Displays the amount of time remaining in a process, estimated time - elapsed time. ''' import wx class ProgressBar(wx.ProgressDialog): '''Progress Bar class''' def __init__(self, *args, **kwargs): self.count = 0 wx.ProgressDialog.__init__(self, *args, **kwargs) self.pmax = kwargs['maximum'] def update_bar(self): '''update the progress bar''' while self.count < self.pmax: self.count += 1 wx.MilliSleep(1) self.Update(self.count) def main(): '''app starter''' app = wx.PySimpleApp() app.MainLoop() max_item = 50 # range or total numer of lines in a file or.... pbar = ProgressBar(title = "progress...", message = "Time remaining", maximum = max_item, parent = None, style = wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_REMAINING_TIME) pbar.update_bar() pbar.Destroy() if __name__ == "__main__": main()
max_item è ovviamente il parametro che indica la lunghezza massima della progress bar. Se per esempio stessimo parsando un file di testo, max_item sarebbe il numero di righe del file…
Commenti recenti