def update_torrent_health(self, seeders, leechers): # Check if details widget is still showing the same entry and the entry still exists in the table try: data_item = self.index.model().data_items[self.index.row()] except IndexError: return if self.torrent_info["infohash"] != data_item[u'infohash']: return data_item[u'num_seeders'] = seeders data_item[u'num_leechers'] = leechers data_item[u'last_tracker_check'] = time.time() data_item[u'health'] = get_health(data_item[u'num_seeders'], data_item[u'num_leechers'], data_item[u'last_tracker_check']) if u'health' in self.index.model().column_position: index = self.index.model().index( self.index.row(), self.index.model().column_position[u'health']) self.index.model().dataChanged.emit(index, index, []) # Update the health label of the detail widget self.update_health_label(data_item[u'num_seeders'], data_item[u'num_leechers'], data_item[u'last_tracker_check'])
def paint(self, painter, rect, index, hover=False): data_item = index.model().data_items[index.row()] if 'health' not in data_item or data_item['health'] == "updated": data_item['health'] = get_health(data_item['num_seeders'], data_item['num_leechers'], data_item['last_tracker_check']) health = data_item['health'] # ---------------- # |b---b| | # |b|i|b| 0S 0L | # |b---b| | # ---------------- r = rect painter.save() # Indicator ellipse rectangle y = r.top() + (r.height() - self.indicator_side) / 2 x = r.left() + self.indicator_border w = self.indicator_side h = self.indicator_side indicator_rect = QRect(x, y, w, h) # Paint indicator painter.setBrush(QBrush(self.health_colors[health])) painter.setPen( QPen(self.health_colors[health], 0, Qt.SolidLine, Qt.RoundCap)) painter.drawEllipse(indicator_rect) x = indicator_rect.left() + indicator_rect.width( ) + 2 * self.indicator_border y = r.top() w = r.width() - indicator_rect.width() - 2 * self.indicator_border h = r.height() text_box = QRect(x, y, w, h) # Paint status text, if necessary if health in (HEALTH_CHECKING, HEALTH_UNCHECKED, HEALTH_ERROR): txt = health else: seeders = int(data_item['num_seeders']) leechers = int(data_item['num_leechers']) txt = 'S' + str(seeders) + ' L' + str(leechers) color = TRIBLER_PALETTE.light().color() if hover else TRIBLER_NEUTRAL draw_text(painter, text_box, txt, color=color) painter.restore()
def update_health_label(self, seeders, leechers, last_tracker_check): try: health = get_health(seeders, leechers, last_tracker_check) if health == HEALTH_UNCHECKED: self.torrent_detail_health_label.setText("Unknown health") elif health == HEALTH_GOOD: self.torrent_detail_health_label.setText( "Good health (S%d L%d)" % (seeders, leechers)) elif health == HEALTH_MOOT: self.torrent_detail_health_label.setText( "Unknown health (found peers)") else: self.torrent_detail_health_label.setText("No peers found") except RuntimeError: self._logger.error( "The underlying GUI widget has already been removed.")
def update_torrent_health(self, infohash, seeders, leechers): # Check if details widget is still showing the same entry and the entry still exists in the table row = self.model.item_uid_map.get(infohash) if row is None: return data_item = self.model.data_items[row] data_item['num_seeders'] = seeders data_item['num_leechers'] = leechers data_item['last_tracker_check'] = time.time() data_item['health'] = get_health( data_item['num_seeders'], data_item['num_leechers'], data_item['last_tracker_check'] ) if 'health' in self.model.column_position: index = self.model.index(row, self.model.column_position['health']) self.model.dataChanged.emit(index, index, [])