mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-20 11:35:49 +00:00
* PEP-8 and some clean up in the Files tab plugin.
* Some improvements to tab switching code in the interface.
This commit is contained in:
parent
5a0bddba31
commit
3848b7c67e
2 changed files with 49 additions and 45 deletions
|
@ -32,58 +32,56 @@ def enable(core, interface):
|
|||
return TorrentFiles(path, core, interface)
|
||||
|
||||
### The Plugin ###
|
||||
import deluge
|
||||
import gtk
|
||||
|
||||
import deluge
|
||||
from TorrentFiles.tab_files import FilesTabManager
|
||||
|
||||
class TorrentFiles:
|
||||
|
||||
def __init__(self, path, core, interface):
|
||||
print "Loading TorrentFiles plugin..."
|
||||
self.manager = core
|
||||
self.parent = interface
|
||||
self.treeView = gtk.TreeView()
|
||||
self.scrolledWindow = gtk.ScrolledWindow()
|
||||
self.scrolledWindow.add(self.treeView)
|
||||
self.scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
|
||||
tree_view = gtk.TreeView()
|
||||
scrolled_window = gtk.ScrolledWindow()
|
||||
scrolled_window.add(tree_view)
|
||||
scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
self.top_widget = scrolled_window
|
||||
|
||||
self.topWidget = self.scrolledWindow
|
||||
|
||||
self.parentNotebook = self.parent.notebook
|
||||
|
||||
self.parentNotebook.append_page(self.topWidget, gtk.Label(_("Files")))
|
||||
self.treeView.show()
|
||||
self.scrolledWindow.show()
|
||||
self.tab_files = FilesTabManager(self.treeView, self.manager)
|
||||
self.parent_notebook = self.parent.notebook
|
||||
self.parent_notebook.append_page(scrolled_window,
|
||||
gtk.Label(_("Files")))
|
||||
|
||||
tree_view.show()
|
||||
scrolled_window.show()
|
||||
|
||||
self.tab_files = FilesTabManager(tree_view, core)
|
||||
self.tab_files.build_file_view()
|
||||
|
||||
def unload(self):
|
||||
self.tab_files.clear_file_store()
|
||||
numPages = self.parentNotebook.get_n_pages()
|
||||
for page in xrange(numPages):
|
||||
if self.parentNotebook.get_nth_page(page) == self.topWidget:
|
||||
self.parentNotebook.remove_page(page)
|
||||
break
|
||||
tab_page = self.parent_notebook.page_num(self.top_widget)
|
||||
self.parent_notebook.remove_page(tab_page)
|
||||
|
||||
def update(self):
|
||||
if not self.parent.update_interface:
|
||||
return
|
||||
numPages = self.parentNotebook.get_n_pages()
|
||||
for page in xrange(numPages):
|
||||
if self.parentNotebook.get_nth_page(page) == self.topWidget:
|
||||
unique_id = self.parent.get_selected_torrent()
|
||||
|
||||
if unique_id is None:
|
||||
#if no torrents added or more than one torrent selected
|
||||
self.tab_files.clear_file_store()
|
||||
self.tab_files.set_unique_id(None)
|
||||
return
|
||||
|
||||
if self.tab_files.file_unique_id != unique_id:
|
||||
self.tab_files.clear_file_store()
|
||||
self.tab_files.set_unique_id(unique_id)
|
||||
self.tab_files.prepare_file_store()
|
||||
else:
|
||||
self.tab_files.update_file_store()
|
||||
|
||||
break
|
||||
|
||||
tab_page = self.parent_notebook.page_num(self.top_widget)
|
||||
current_page = self.parent_notebook.get_current_page()
|
||||
|
||||
if tab_page == current_page:
|
||||
unique_id = self.parent.get_selected_torrent()
|
||||
|
||||
if unique_id is None:
|
||||
# If no torrents added or more than one torrent selected
|
||||
self.tab_files.clear_file_store()
|
||||
self.tab_files.set_unique_id(None)
|
||||
return
|
||||
|
||||
if self.tab_files.file_unique_id != unique_id:
|
||||
self.tab_files.clear_file_store()
|
||||
self.tab_files.set_unique_id(unique_id)
|
||||
self.tab_files.prepare_file_store()
|
||||
else:
|
||||
self.tab_files.update_file_store()
|
||||
|
|
|
@ -160,8 +160,15 @@ class DelugeGTK:
|
|||
})
|
||||
|
||||
def notebook_switch_page(self, notebook, page, page_num):
|
||||
# Force an update when user changes the notebook tab
|
||||
self.update_torrent_info_widget(page_num)
|
||||
# Force an update when user changes the notebook tab.
|
||||
# See notes in torrent_clicked() why we doing it this way. The only
|
||||
# difference here is that notebook_switch_page() is called by signal
|
||||
# 'switch-page' from GTK before notebook is switched to page_num, so
|
||||
# queue up update routines so they are called after page is actually
|
||||
# showed. See docs on 'switch-page' signal for gtk.Notebook.
|
||||
|
||||
gobject.timeout_add(10, self.update_torrent_info_widget)
|
||||
gobject.timeout_add(10, self.plugins.update_active_plugins)
|
||||
|
||||
def pause_all_clicked(self, arg=None):
|
||||
self.manager.pause_all()
|
||||
|
@ -949,14 +956,13 @@ class DelugeGTK:
|
|||
|
||||
self.tray_icon.set_tooltip(msg)
|
||||
|
||||
def update_torrent_info_widget(self, page_num=None):
|
||||
def update_torrent_info_widget(self):
|
||||
unique_id = self.get_selected_torrent()
|
||||
# If no torrents added
|
||||
if unique_id is None:
|
||||
return
|
||||
# page_num is to force update info when user just changes tab
|
||||
if page_num is None:
|
||||
page_num = self.wtree.get_widget("torrent_info").get_current_page()
|
||||
|
||||
page_num = self.wtree.get_widget("torrent_info").get_current_page()
|
||||
|
||||
if page_num == 0: # Details
|
||||
self.tab_details.update(unique_id)
|
||||
|
|
Loading…
Add table
Reference in a new issue