kuuko pushed a commit to branch master.

http://git.enlightenment.org/apps/epour.git/commit/?id=e20d6c3788ef2361914517cddccd2cc7dffd9de6

commit e20d6c3788ef2361914517cddccd2cc7dffd9de6
Author: Kai Huuhko <kai.huu...@gmail.com>
Date:   Tue Sep 20 11:51:07 2016 +0300

    Fix tooltips for torrents without metadata
---
 epour/gui/Widgets.py  | 44 ++++++++++++++++++++++----------------------
 epour/gui/__init__.py | 15 ++++++---------
 2 files changed, 28 insertions(+), 31 deletions(-)

diff --git a/epour/gui/Widgets.py b/epour/gui/Widgets.py
index 9e1dab9..5c96ebe 100644
--- a/epour/gui/Widgets.py
+++ b/epour/gui/Widgets.py
@@ -170,42 +170,38 @@ class BlockGraph(Grid):
         (0, 255, 0, 255)
     )
 
-    def __init__(self, parent, pieces, num_complete_pieces=0, *args, **kwargs):
+    def __init__(self, parent, pieces, num_completed_pieces=0, *args, 
**kwargs):
 
-        self.num_complete_pieces = num_complete_pieces
+        self.num_completed_pieces = num_completed_pieces
+        self.pieces = pieces
 
-        self._blocks = None
-        self._block_size = None
         self.rects = []
 
         super(self.__class__, self).__init__(parent, *args, **kwargs)
 
-        self.pieces = pieces
-        self.num_total_pieces = len(pieces)
-
         self.pack_rects()
 
-    def block_size_get(self):
-        if self._block_size is not None:
-            return self._block_size
+    @property
+    def num_total_pieces(self):
+        return len(self.pieces)
 
+    @property
+    def block_size(self):
         width, height = self.size
         num_pieces = self.num_total_pieces
         grid_size = width * height
         block_size = \
             num_pieces//grid_size + bool(num_pieces % grid_size)
 
-        self._block_size = block_size
         return block_size
 
-    block_size = property(block_size_get)
-
-    def blocks_get(self):
-        if self._blocks is not None:
-            return self._blocks
-
+    @property
+    def blocks(self):
         blocks = []
 
+        if self.block_size == 0:
+            raise ValueError("Block size 0")
+
         for block in chunker(self.pieces, self.block_size):
             if all(block):
                 blocks.append(2)
@@ -214,12 +210,11 @@ class BlockGraph(Grid):
             else:
                 blocks.append(0)
 
-        self._blocks = blocks
         return blocks
 
-    blocks = property(blocks_get)
-
     def pack_rects(self):
+        if self.num_total_pieces == 0:
+            return
         blocks = self.blocks
         width, height = self.size
         len_blocks = len(blocks)
@@ -244,10 +239,15 @@ class BlockGraph(Grid):
                 rect.show()
                 p += 1
 
-    def update(self, pieces):
+    def update(self, pieces, num_pieces):
+        self.pieces = pieces
+        if pieces and not self.rects:
+            self.pack_rects()
+        elif self.num_completed_pieces == num_pieces:
+            return
+        self.num_completed_pieces = num_pieces
         width, height = self.size
         old_blocks = self.blocks
-        self.pieces = pieces
         self._blocks = None
         new_blocks = self.blocks
         row = 0
diff --git a/epour/gui/__init__.py b/epour/gui/__init__.py
index e14532c..a060bbf 100644
--- a/epour/gui/__init__.py
+++ b/epour/gui/__init__.py
@@ -260,10 +260,12 @@ class MainInterface(object):
                 if info_hash not in self.torrentitems:
                     return
 
-                self.torrentitems[info_hash].fields_update(
+                item = self.torrentitems[info_hash]
+
+                item.fields_update(
                     "*", ELM_GENLIST_ITEM_FIELD_TEXT
                 )
-                self.torrentitems[info_hash].fields_update(
+                item.fields_update(
                     "elm.swallow.progress", ELM_GENLIST_ITEM_FIELD_CONTENT
                 )
 
@@ -714,9 +716,6 @@ class TorrentTooltip(Table):
         flags = lt.status_flags_t.query_pieces
         status = handle.status(flags)
 
-        # if not s.has_metadata:
-        #     return
-
         Table.__init__(self, parent, size_hint_weight=EXPAND_BOTH)
 
         value_labels = []
@@ -777,9 +776,7 @@ class TorrentTooltip(Table):
                     v = conv(v)
             l.text = str(v)
 
-        num_pieces = s.num_pieces
-        if g.num_complete_pieces != num_pieces:
-            g.update(s.pieces)
-            g.num_complete_pieces = num_pieces
+        if s.has_metadata:
+            g.update(s.pieces, s.num_pieces)
 
         return True

-- 


Reply via email to