summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Huuhko <kai.huuhko@gmail.com>2016-09-20 11:51:07 +0300
committerKai Huuhko <kai.huuhko@gmail.com>2016-09-20 14:24:18 +0300
commite20d6c3788ef2361914517cddccd2cc7dffd9de6 (patch)
tree92b301456520e3596e7ddadf83898dda7de9d638
parent50e60e6311d1295e58df37d6c0708277a6d2a0fc (diff)
Fix tooltips for torrents without metadata
-rw-r--r--epour/gui/Widgets.py44
-rw-r--r--epour/gui/__init__.py15
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):
170 (0, 255, 0, 255) 170 (0, 255, 0, 255)
171 ) 171 )
172 172
173 def __init__(self, parent, pieces, num_complete_pieces=0, *args, **kwargs): 173 def __init__(self, parent, pieces, num_completed_pieces=0, *args, **kwargs):
174 174
175 self.num_complete_pieces = num_complete_pieces 175 self.num_completed_pieces = num_completed_pieces
176 self.pieces = pieces
176 177
177 self._blocks = None
178 self._block_size = None
179 self.rects = [] 178 self.rects = []
180 179
181 super(self.__class__, self).__init__(parent, *args, **kwargs) 180 super(self.__class__, self).__init__(parent, *args, **kwargs)
182 181
183 self.pieces = pieces
184 self.num_total_pieces = len(pieces)
185
186 self.pack_rects() 182 self.pack_rects()
187 183
188 def block_size_get(self): 184 @property
189 if self._block_size is not None: 185 def num_total_pieces(self):
190 return self._block_size 186 return len(self.pieces)
191 187
188 @property
189 def block_size(self):
192 width, height = self.size 190 width, height = self.size
193 num_pieces = self.num_total_pieces 191 num_pieces = self.num_total_pieces
194 grid_size = width * height 192 grid_size = width * height
195 block_size = \ 193 block_size = \
196 num_pieces//grid_size + bool(num_pieces % grid_size) 194 num_pieces//grid_size + bool(num_pieces % grid_size)
197 195
198 self._block_size = block_size
199 return block_size 196 return block_size
200 197
201 block_size = property(block_size_get) 198 @property
202 199 def blocks(self):
203 def blocks_get(self):
204 if self._blocks is not None:
205 return self._blocks
206
207 blocks = [] 200 blocks = []
208 201
202 if self.block_size == 0:
203 raise ValueError("Block size 0")
204
209 for block in chunker(self.pieces, self.block_size): 205 for block in chunker(self.pieces, self.block_size):
210 if all(block): 206 if all(block):
211 blocks.append(2) 207 blocks.append(2)
@@ -214,12 +210,11 @@ class BlockGraph(Grid):
214 else: 210 else:
215 blocks.append(0) 211 blocks.append(0)
216 212
217 self._blocks = blocks
218 return blocks 213 return blocks
219 214
220 blocks = property(blocks_get)
221
222 def pack_rects(self): 215 def pack_rects(self):
216 if self.num_total_pieces == 0:
217 return
223 blocks = self.blocks 218 blocks = self.blocks
224 width, height = self.size 219 width, height = self.size
225 len_blocks = len(blocks) 220 len_blocks = len(blocks)
@@ -244,10 +239,15 @@ class BlockGraph(Grid):
244 rect.show() 239 rect.show()
245 p += 1 240 p += 1
246 241
247 def update(self, pieces): 242 def update(self, pieces, num_pieces):
243 self.pieces = pieces
244 if pieces and not self.rects:
245 self.pack_rects()
246 elif self.num_completed_pieces == num_pieces:
247 return
248 self.num_completed_pieces = num_pieces
248 width, height = self.size 249 width, height = self.size
249 old_blocks = self.blocks 250 old_blocks = self.blocks
250 self.pieces = pieces
251 self._blocks = None 251 self._blocks = None
252 new_blocks = self.blocks 252 new_blocks = self.blocks
253 row = 0 253 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):
260 if info_hash not in self.torrentitems: 260 if info_hash not in self.torrentitems:
261 return 261 return
262 262
263 self.torrentitems[info_hash].fields_update( 263 item = self.torrentitems[info_hash]
264
265 item.fields_update(
264 "*", ELM_GENLIST_ITEM_FIELD_TEXT 266 "*", ELM_GENLIST_ITEM_FIELD_TEXT
265 ) 267 )
266 self.torrentitems[info_hash].fields_update( 268 item.fields_update(
267 "elm.swallow.progress", ELM_GENLIST_ITEM_FIELD_CONTENT 269 "elm.swallow.progress", ELM_GENLIST_ITEM_FIELD_CONTENT
268 ) 270 )
269 271
@@ -714,9 +716,6 @@ class TorrentTooltip(Table):
714 flags = lt.status_flags_t.query_pieces 716 flags = lt.status_flags_t.query_pieces
715 status = handle.status(flags) 717 status = handle.status(flags)
716 718
717 # if not s.has_metadata:
718 # return
719
720 Table.__init__(self, parent, size_hint_weight=EXPAND_BOTH) 719 Table.__init__(self, parent, size_hint_weight=EXPAND_BOTH)
721 720
722 value_labels = [] 721 value_labels = []
@@ -777,9 +776,7 @@ class TorrentTooltip(Table):
777 v = conv(v) 776 v = conv(v)
778 l.text = str(v) 777 l.text = str(v)
779 778
780 num_pieces = s.num_pieces 779 if s.has_metadata:
781 if g.num_complete_pieces != num_pieces: 780 g.update(s.pieces, s.num_pieces)
782 g.update(s.pieces)
783 g.num_complete_pieces = num_pieces
784 781
785 return True 782 return True