forked from esitarski/CrossMgr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFtpUploadProgress.py
53 lines (44 loc) · 1.54 KB
/
FtpUploadProgress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import wx
import os
import datetime
import Utils
class FtpUploadProgress( wx.Dialog ):
def __init__( self, parent, id=wx.ID_ANY, fileTotal=0, bytesTotal=0 ):
super().__init__( parent, id, title=_('Ftp Update Progress'), style=wx.CAPTION )
self.fileTotal = fileTotal
self.bytesCur = 0
self.bytesTotal = bytesTotal
self.startTime = datetime.datetime.now()
self.message = wx.StaticText( self, label='{}:\n\n{}/{}: '.format(
_('Ftp Update Progress'),
1, self.fileTotal,
)
)
self.bytesGauge = wx.Gauge( self, range=bytesTotal, size=(600,24) )
border = 16
ms = wx.BoxSizer( wx.VERTICAL )
ms.Add( self.message, flag=wx.TOP|wx.LEFT|wx.RIGHT, border=border )
ms.Add( self.bytesGauge, flag=wx.ALL, border=border )
self.SetSizerAndFit( ms )
def update( self, bytestr, fname, i ):
eta = ''
tCur = (datetime.datetime.now() - self.startTime).total_seconds()
self.bytesCur += len(bytestr)
if self.bytesTotal:
tEnd = tCur * float(self.bytesTotal) / float(self.bytesCur)
eta = '{}, {} {}'.format(Utils.formatTime(
max(0.0, tEnd - tCur + 1.0)),
max(0.0, self.bytesTotal - self.bytesCur) // 1024, _('KB to go'),
)
self.bytesGauge.SetValue( self.bytesCur )
self.message.SetLabel( '{}: {}\n\n{} {} {} {}: {}'.format(
_('Ftp Update Progress'), eta,
_('Uploading'), i+1, _('of'), self.fileTotal,
os.path.basename(fname),
)
)
if __name__ == '__main__':
app = wx.App(False)
ftpUploadProgress = FtpUploadProgress( None, fileTotal=6, bytesTotal=500000 )
ftpUploadProgress.Show()
app.MainLoop()