Commits

Gabriele Lanaro  committed 9b7973c

proceeding with papercuts on transfer dialog

  • Participants
  • Parent commits 3510987

Comments (0)

Files changed (2)

 * Short Term
 ** Papercuts (Third iterate)
-*** TODO Trasfer file dialog is ugly [1/6]
+*** TODO Trasfer file dialog is ugly [3/6]
 
     - [X] bad speed representation
-    - [ ] bad size
-    - [ ] status not always updated
+    - [X] status not always updated
+    - [X] bad size identifier in the menu
     - [ ] ETA not displayed
     - [ ] No icon
-    - [ ] Menu hasn't any functionality
+    - [ ] Menu hasn't any functionality, should remove it
 
 *** TODO Design icon 22x22, refine 16x16
-*** TODO Statusbar not updating when finished
-
+*** TODO Statusbar not updating when transfer is finished    
 
 ** Windows Packaging
 ** Release

File filesnake/gui/transfers.py

             if item.completed == 100:
                 self.objectlist.remove(item)
 
+def prettify_byte_size(size):
+    '''Makes a nice representation of sizes:
+    - 10 b
+    - 10.2 Kb
+    - 56.1 Mb
+    - 3.6 Gb
+    '''
+    if size < 1024:
+        return "{0} b".format(size)
+    elif 1024 <= size <  1048576:
+        return "{0:.1f} Kb".format(size/1024.0)
+    elif 1048576 <= size < 1073741824:
+        return "{0:.1f} Mb".format(size/1048576.0)  
+    elif size >= 1073741824:
+        return "{0:.1f} Gb".format(size/1073741824.0)  
+
+
+
 
 class TransferMonitor(GObject):
     '''
     def __init__(self, filename, size):
         super(TransferMonitor, self).__init__()
         self.filename = filename
-        self.size = size  # Total size of the transfer
-        self.progress = 0 # bytes transferred
+        self.size = size        # Total size of the transfer
+        self.progress = 0       # bytes transferred
         self.status = "waiting" # status of the transfer
-        self.speed = 0 # Speed in byte/sec
-        self.ETA = 0   # Estimate of the time
+        self.speed = 0          # Speed in byte/sec
+        self.ETA = 0            # Estimate of the time
         self.complete = 0
         self._count = 0
+
+    @property
+    def size(self):
+        return prettify_byte_size(self._size)
     
+    @size.setter
+    def size(self, value):
+        self._size = value
+
     @property
     def speed(self):
         value = self._speed
-        if value < 1024:
-            return "{0} b/s".format(value)
-        elif value > 1024 and value <  1048576:
-            return "{0:.1f} Kb/s".format(value/1024.0)
-        elif value > 1048576:
-            return "{0:.1f} Mb/s".format(value/1048576.0)  
+        return prettify_byte_size(value)+"/s"
     
     @speed.setter
     def speed(self, value):
 
 
     def update_speed(self):
+        '''This function keep tracks of the time between two
+        "producing" calls, letting displaying the speed
+        '''
+        
         if not hasattr(self, "_old_progress"):
             self._old_progress = self.progress
+
         prog =  self.progress - self._old_progress 
         self._old_progress = self.progress
         
         
 
     def time_interval(self):
+        '''
+        Keeps a time interval between two calls
+        '''
+        
         if not hasattr(self,"_prec"):
             self._prec=time.time()
             
         cur = time.time()
         
-        # Avoid zero division error
+                                # Avoid zero division error
         ret = cur - self._prec
         self._prec=cur
         return ret
         '''
         Called when the source is producing data
         '''
+        self.status = "receiving"
+        
         chunk = len(data)
-        # Checking
-        if self.progress + chunk > self.size:
+        # self._size is the size in byte
+        if self.progress + chunk > self._size:
             raise ValueError("Producing more data that the declared one")
         
         self.progress += chunk        
-        self.complete = self.progress*100/self.size 
+        self.complete = self.progress*100/self._size 
 
         self._count+=1
         if self._count%100 == 0:
         The source has finished to do its stuff
         '''
         self.emit("changed")
-        self.status = "finish"
+        self.status = "finished"
 
 
 def test():
     a = TransfersDialog()
     a.show()
-
+    
     for i in range(3):
         mon = a.add_transfer("galois", "filename%d"%i, 1024)
         refresh_gui()
         mon.producing("hello")
         refresh_gui()
 
+
 def test_monitor():
     tm = TransferMonitor("hello.pdf", 1400)