touchups for torrentpieces - micah

This commit is contained in:
Marcos Pinto 2007-07-31 21:54:11 +00:00
parent b6ee1d0e37
commit 5aec3526cf
2 changed files with 11 additions and 12 deletions

View File

@ -54,9 +54,7 @@ class TorrentPieces:
print "Loading TorrentPieces plugin..." print "Loading TorrentPieces plugin..."
self.manager = core self.manager = core
self.parent = interface self.parent = interface
self.table = gtk.Table()
self.viewport = gtk.Viewport() self.viewport = gtk.Viewport()
self.viewport.add(self.table)
self.scrolledWindow = gtk.ScrolledWindow() self.scrolledWindow = gtk.ScrolledWindow()
self.scrolledWindow.add(self.viewport) self.scrolledWindow.add(self.viewport)
self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
@ -68,13 +66,13 @@ class TorrentPieces:
self.parentNotebook.append_page(self.topWidget, gtk.Label(_("Pieces"))) self.parentNotebook.append_page(self.topWidget, gtk.Label(_("Pieces")))
self.viewport.show() self.viewport.show()
self.scrolledWindow.show() self.scrolledWindow.show()
self.table.show() self.tab_pieces = PiecesManager(self.viewport, self.manager)
self.tab_pieces = PiecesManager(self.table, self.manager)
def unload(self): def unload(self):
self.manager.disconnect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.tab_pieces.handle_event) self.manager.disconnect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.tab_pieces.handle_event)
self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_pieces.handle_event) self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_pieces.handle_event)
self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_pieces.handle_event) self.manager.disconnect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_pieces.handle_event)
self.tab_pieces.clear_pieces_store()
numPages = self.parentNotebook.get_n_pages() numPages = self.parentNotebook.get_n_pages()
for page in xrange(numPages): for page in xrange(numPages):
if self.parentNotebook.get_nth_page(page) == self.topWidget: if self.parentNotebook.get_nth_page(page) == self.topWidget:

View File

@ -3,8 +3,9 @@ import gtk
import math import math
class PiecesManager(object): class PiecesManager(object):
def __init__(self, table, manager): def __init__(self, viewport, manager):
self.table = table self.viewport = viewport
self.table = None
self.manager = manager self.manager = manager
self.progress = [] self.progress = []
self.tooltips = [] self.tooltips = []
@ -23,11 +24,9 @@ class PiecesManager(object):
def clear_pieces_store(self): def clear_pieces_store(self):
self.unique_id = -1 self.unique_id = -1
self.rows = 0 self.rows = 0
for widget in self.eventboxes: if not self.table is None:
widget.destroy() self.table.destroy()
for widget in self.progress: self.table = None
widget.hide()
widget.destroy()
self.peer_speed = [] self.peer_speed = []
self.eventboxes = [] self.eventboxes = []
self.progress = [] self.progress = []
@ -35,6 +34,8 @@ class PiecesManager(object):
self.tooltips = [] self.tooltips = []
def prepare_pieces_store(self): def prepare_pieces_store(self):
self.table = gtk.Table()
self.viewport.add(self.table)
state = self.manager.get_torrent_state(self.unique_id) state = self.manager.get_torrent_state(self.unique_id)
num_pieces = state["num_pieces"] num_pieces = state["num_pieces"]
self.rows = int(math.ceil(num_pieces/self.columns)) self.rows = int(math.ceil(num_pieces/self.columns))
@ -57,7 +58,6 @@ class PiecesManager(object):
self.tooltips[index].set_tip(self.eventboxes[index], _("Piece finished")) self.tooltips[index].set_tip(self.eventboxes[index], _("Piece finished"))
else: else:
self.tooltips[index].set_tip(self.eventboxes[index], _("Piece not started")) self.tooltips[index].set_tip(self.eventboxes[index], _("Piece not started"))
self.eventboxes[index].show_all()
all_piece_info = self.manager.get_all_piece_info(self.unique_id) all_piece_info = self.manager.get_all_piece_info(self.unique_id)
for piece_index in all_piece_info: for piece_index in all_piece_info:
temp_piece_info = {'blocks_total':piece_index['blocks_total'], \ temp_piece_info = {'blocks_total':piece_index['blocks_total'], \
@ -69,6 +69,7 @@ class PiecesManager(object):
if self.progress[index].get_fraction() == 0: if self.progress[index].get_fraction() == 0:
self.progress[index].set_fraction(0.5) self.progress[index].set_fraction(0.5)
self.tooltips[index].set_tip(self.eventboxes[index], info_string) self.tooltips[index].set_tip(self.eventboxes[index], info_string)
self.table.show_all()
def handle_event(self, event): def handle_event(self, event):
if event['event_type'] is self.manager.constants['EVENT_PIECE_FINISHED']: if event['event_type'] is self.manager.constants['EVENT_PIECE_FINISHED']: