luckylz
Active Member
- Joined
- Apr 8, 2015
- Messages
- 414
- Reaction score
- 107
- Country
- China
Hi @Andy_S , as I said last week, I'd like to share my code for you. In order to thanks for your wonderful program C&C !
first of all, I modified the function of display of the [Usage] of the first page, which to calculate the file size by "KB", "MB", ...
after many times of app hanging for the tricky Python thread call, and the incorrect tabify ident setting...
I made a standard alone function called [FileSizeName], the code as following:
why I seperate this, because I think [FileSizeName] can be shared to the FileManager, when showing the photo/video file size. And also later display the download speed.
you use this function or not, on your own program consideration.
first of all, I modified the function of display of the [Usage] of the first page, which to calculate the file size by "KB", "MB", ...
after many times of app hanging for the tricky Python thread call, and the incorrect tabify ident setting...
I made a standard alone function called [FileSizeName], the code as following:
Code:
#option: 0-Starts From "B", 1-Starts From "KB"
def FileSizeName(self, fileSizeBytes, option):
fileName = ""
while 1:
if fileSizeBytes > 1024:
fileSizeBytes = fileSizeBytes/float(1024)
option += 1
else:
break
pres = ["B", "KB", "MB", "GB", "TB"]
fileName = "%.1f%s" %(fileSizeBytes, pres[option])
return fileName
def UpdateUsage(self):
tosend = '{"msg_id":5,"token":%s,"type":"total"}' %self.token
totalspace = self.Comm(tosend)["param"]
tosend = '{"msg_id":5,"token":%s,"type":"free"}' %self.token
freespace = float(self.Comm(tosend)["param"])
usedspace = totalspace-freespace
#totalpre = 0
#usedpre = 0
#while 1:
# if usedspace > 1024:
# usedspace = usedspace/float(1024)
# usedpre += 1
# else:
# break
#while 1:
# if totalspace > 1024:
# totalspace = totalspace/float(1024)
# totalpre += 1
# else:
# break
#pres = ["kB", "MB", "GB", "TB"]
#usage = "Used %.1f%s of %.1f%s" %(usedspace, pres[usedpre], totalspace, pres[totalpre])
usage = "Used %s of %s" %(self.FileSizeName(usedspace, 1), self.FileSizeName(totalspace, 1))
self.usage.config(text=usage) #display usage message in statusbar
self.usage.update_idletasks()
why I seperate this, because I think [FileSizeName] can be shared to the FileManager, when showing the photo/video file size. And also later display the download speed.
you use this function or not, on your own program consideration.