Home > python, wxpython > Python: Copy progress bar

Python: Copy progress bar

9 Marzo 2012
    import os  
    import wx  
      
      
    class ProgressBar(wx.ProgressDialog):  
        '''''Progress Bar class'''  
        def __init__(self, *args, **kwargs):  
            super(ProgressBar, self).__init__(*args, **kwargs)  
      
      
    def progress_copy(src, dest, buffer_size=1024):  
        '''''copy source file to destination file'''  
        steps = os.stat(src).st_size / buffer_size + 1  
        source = open(src, 'rb')  
        target = open(dest, 'wb')  
        pbar = ProgressBar(title="wait...", message="Time remaining",  
                           maximum=steps, parent=None,  
                           style=wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME |  
                           wx.PD_REMAINING_TIME)  
        count = 0  
        while count <= (steps):  
            chunk = source.read(buffer_size)  
            if chunk:  
                count += 1  
                target.write(chunk)  
                pbar.Update(count)  
            else:  
                break  
      
        source.close()  
        target.close()  
        pbar.Destroy()  
        print "...copied"  
      
      
    def main():  
        '''''app starter'''  
        app = wx.PySimpleApp()  
        progress_copy(src=SOURCE_FILE, dest=DEST_FILE)  
        app.MainLoop()  
      
    if __name__ == '__main__':  
        main()
Categorie:python, wxpython Tag:
I commenti sono chiusi.