improve pieces performance - micah

This commit is contained in:
Marcos Pinto 2007-08-04 07:41:27 +00:00
parent c0beb51d37
commit 09558b82e4
2 changed files with 54 additions and 18 deletions

View File

@ -58,19 +58,15 @@ class TorrentPieces:
print "Loading TorrentPieces plugin..." print "Loading TorrentPieces plugin..."
self.manager = core self.manager = core
self.parent = interface self.parent = interface
self.viewport = gtk.Viewport() scrolledWindow = gtk.ScrolledWindow()
self.scrolledWindow = gtk.ScrolledWindow() scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.scrolledWindow.add(self.viewport) self.topWidget = scrolledWindow
self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.topWidget = self.scrolledWindow
self.parentNotebook = self.parent.notebook self.parentNotebook = self.parent.notebook
self.parentNotebook.append_page(self.topWidget, gtk.Label(_("Pieces"))) self.parentNotebook.append_page(self.topWidget, gtk.Label(_("Pieces")))
self.viewport.show() self.topWidget.show_all()
self.scrolledWindow.show() self.tab_pieces = PiecesManager(self.manager)
self.tab_pieces = PiecesManager(self.viewport, 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)
@ -92,12 +88,45 @@ class TorrentPieces:
return return
if unique_id != self.tab_pieces.unique_id or unique_id in update_files_removed.keys(): if unique_id != self.tab_pieces.unique_id or unique_id in update_files_removed.keys():
#if different torrent was selected or file priorities were changed. #if different torrent was selected or file priorities were changed.
self.tab_pieces.clear_pieces_store()
numPages = self.parentNotebook.get_n_pages()
for page in xrange(numPages):
if self.parentNotebook.get_nth_page(page) == self.topWidget:
break
switch_page = False
if self.parentNotebook.get_current_page() == page:
switch_page = True
self.parentNotebook.remove_page(page)
viewport = gtk.Viewport()
scrolledWindow = gtk.ScrolledWindow()
scrolledWindow.add(viewport)
scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
label = gtk.Label(_("""
This is a temporary page used while the pieces tab gets built.
When operations are complete this will automatically become the
pieces tab.
"""))
label.set_alignment(0,0)
viewport.add(label)
self.parentNotebook.insert_page(scrolledWindow,gtk.Label(_("Pieces")),page)
scrolledWindow.show_all()
if switch_page:
self.parentNotebook.set_current_page(page)
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() self.tab_pieces.clear_pieces_store()
self.tab_pieces.set_unique_id(unique_id) self.tab_pieces.set_unique_id(unique_id)
self.tab_pieces.prepare_pieces_store() self.topWidget = self.tab_pieces.prepare_pieces_store()
switch_page = False
if self.parentNotebook.get_current_page() == page:
switch_page = True
self.parentNotebook.remove_page(page)
self.parentNotebook = self.parent.notebook
self.parentNotebook.insert_page(self.topWidget, gtk.Label(_("Pieces")), page)
self.topWidget.show_all()
if switch_page:
self.parentNotebook.set_current_page(page)
self.manager.connect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.tab_pieces.handle_event) self.manager.connect_event(self.manager.constants['EVENT_PIECE_FINISHED'], self.tab_pieces.handle_event)
self.manager.connect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_pieces.handle_event) self.manager.connect_event(self.manager.constants['EVENT_BLOCK_FINISHED'], self.tab_pieces.handle_event)
self.manager.connect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_pieces.handle_event) self.manager.connect_event(self.manager.constants['EVENT_BLOCK_DOWNLOADING'], self.tab_pieces.handle_event)

View File

@ -2,8 +2,7 @@ import gtk
import math import math
class PiecesManager(object): class PiecesManager(object):
def __init__(self, viewport, manager): def __init__(self, manager):
self.viewport = viewport
self.vbox = None self.vbox = None
self.manager = manager self.manager = manager
self.progress = [] self.progress = []
@ -32,9 +31,6 @@ 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
if not self.vbox is None:
self.vbox.destroy()
self.vbox = None
self.peer_speed = [] self.peer_speed = []
self.eventboxes = [] self.eventboxes = []
self.progress = [] self.progress = []
@ -45,14 +41,22 @@ class PiecesManager(object):
self.all_files = None self.all_files = None
self.file_priorities = None self.file_priorities = None
self.index = 0 self.index = 0
self.num_files = 0
self.prev_file_index = -1 self.prev_file_index = -1
self.file_index = 0 self.file_index = 0
self.next_file_index = 1 self.next_file_index = 1
self.num_files = 0 if not self.vbox is None:
self.vbox.destroy()
self.vbox = None
def prepare_pieces_store(self): def prepare_pieces_store(self):
gtk.main_iteration_do(False)
viewport = gtk.Viewport()
scrolledWindow = gtk.ScrolledWindow()
scrolledWindow.add(viewport)
scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.vbox = gtk.VBox() self.vbox = gtk.VBox()
self.viewport.add(self.vbox) viewport.add(self.vbox)
self.all_files = self.manager.get_torrent_file_info(self.unique_id) self.all_files = self.manager.get_torrent_file_info(self.unique_id)
self.file_priorities = self.manager.get_priorities(self.unique_id) self.file_priorities = self.manager.get_priorities(self.unique_id)
state = self.manager.get_torrent_state(self.unique_id) state = self.manager.get_torrent_state(self.unique_id)
@ -74,9 +78,10 @@ class PiecesManager(object):
self.prev_file_index += 1 self.prev_file_index += 1
self.get_current_pieces_info() self.get_current_pieces_info()
self.vbox.show_all() return scrolledWindow
def build_file_pieces(self): def build_file_pieces(self):
gtk.main_iteration_do(False)
label = gtk.Label() label = gtk.Label()
label.set_alignment(0,0) label.set_alignment(0,0)
label.set_text(self.all_files[self.file_index]['path']) label.set_text(self.all_files[self.file_index]['path'])
@ -130,6 +135,7 @@ class PiecesManager(object):
temp_range = self.last_indexes[self.file_index]-self.first_indexes[self.file_index] temp_range = self.last_indexes[self.file_index]-self.first_indexes[self.file_index]
#last piece handled outside of loop, skip it from range #last piece handled outside of loop, skip it from range
for index in xrange(temp_range): for index in xrange(temp_range):
gtk.main_iteration_do(False)
main_index = diff+self.first_indexes[self.file_index]+index main_index = diff+self.first_indexes[self.file_index]+index
if temp_prev_priority > 0: if temp_prev_priority > 0:
#normal behavior #normal behavior
@ -163,6 +169,7 @@ class PiecesManager(object):
self.index = index+1 self.index = index+1
def build_last_file_piece(self, table, main_index, only_one_piece): def build_last_file_piece(self, table, main_index, only_one_piece):
gtk.main_iteration_do(False)
if only_one_piece: if only_one_piece:
#if piece is shared with a skipped file #if piece is shared with a skipped file
self.share_skipped_piece(main_index) self.share_skipped_piece(main_index)