remove default-sidebar, make plug-in-able

This commit is contained in:
Martijn Voncken 2008-07-28 18:22:44 +00:00
commit 7cd83f8d05
4 changed files with 114 additions and 160 deletions

View file

@ -55,12 +55,12 @@ class LabelSideBar(component.Component):
component.Component.__init__(self, "LabelSideBar", interval=2000) component.Component.__init__(self, "LabelSideBar", interval=2000)
self.window = component.get("MainWindow") self.window = component.get("MainWindow")
glade = self.window.main_glade glade = self.window.main_glade
self.label_view = glade.get_widget("label_view")
self.hpaned = glade.get_widget("hpaned") self.hpaned = glade.get_widget("hpaned")
self.scrolled = glade.get_widget("scrolledwindow_sidebar") self.scrolled = glade.get_widget("scrolledwindow_sidebar")
self.is_visible = True self.is_visible = True
self.filters = {} self.filters = {}
self.first_expand = True self.first_expand = True
self.label_view = gtk.TreeView()
# Create the liststore # Create the liststore
#cat,value,count , pixmap , visible #cat,value,count , pixmap , visible
@ -76,11 +76,6 @@ class LabelSideBar(component.Component):
self.filters[("state", "All")] = self.treestore.append(self.cat_nodes["state"], self.filters[("state", "All")] = self.treestore.append(self.cat_nodes["state"],
["state", "All", 0, gtk.gdk.pixbuf_new_from_file(deluge.common.get_pixmap("dht16.png")), True]) ["state", "All", 0, gtk.gdk.pixbuf_new_from_file(deluge.common.get_pixmap("dht16.png")), True])
#remove all old columns:
for c in self.label_view.get_columns():
self.label_view.remove_column(c)
# Create the column # Create the column
column = gtk.TreeViewColumn(_("Filters")) column = gtk.TreeViewColumn(_("Filters"))
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
@ -104,8 +99,8 @@ class LabelSideBar(component.Component):
self.on_selection_changed) self.on_selection_changed)
# Select the 'All' label on init # Select the 'All' label on init
self.label_view.get_selection().select_iter( #self.label_view.get_selection().select_iter(
self.treestore.get_iter_first()) # self.treestore.get_iter_first())
self.create_model_filter() self.create_model_filter()
#init..... #init.....
@ -113,15 +108,16 @@ class LabelSideBar(component.Component):
self.label_view.expand_all() self.label_view.expand_all()
self.hpaned.set_position(170) self.hpaned.set_position(170)
def load(self): def load(self):
self.label_view.set_model(self.model_filter) sidebar = component.get("SideBar")
sidebar.add_tab(self.label_view, "filters", _("Filters"))
def unload(self): def unload(self):
#hacks! log.debug("unload..")
self.label_view.set_headers_visible(True) sidebar = component.get("SideBar")
old_sidebar = component.get("SideBar") sidebar.remove_tab("filters")
del old_sidebar log.debug("unload-end")
new_sidebar = deluge.ui.gtkui.sidebar.SideBar()
def create_model_filter(self): def create_model_filter(self):
@ -153,8 +149,6 @@ class LabelSideBar(component.Component):
self.filters[(cat, value)] = row self.filters[(cat, value)] = row
self.treestore.set_value(row, 4, True) self.treestore.set_value(row, 4, True)
def render_cell_data(self, column, cell, model, row, data): def render_cell_data(self, column, cell, model, row, data):
"cell renderer" "cell renderer"
cat = model.get_value(row, 0) cat = model.get_value(row, 0)
@ -169,9 +163,12 @@ class LabelSideBar(component.Component):
if cat == "cat": if cat == "cat":
txt = value txt = value
col = gtk.gdk.color_parse('#EEEEEE') col = gtk.gdk.color_parse('#EEEEEE')
cell.set_property("ypad",1)
else: else:
txt = "%s (%s)" % (value, count) txt = "%s (%s)" % (value, count)
col = gtk.gdk.color_parse('white') col = gtk.gdk.color_parse('white')
cell.set_property("ypad",1)
cell.set_property('text', txt) cell.set_property('text', txt)
cell.set_property("cell-background-gdk",col) cell.set_property("cell-background-gdk",col)
self.renderpix.set_property("cell-background-gdk",col) self.renderpix.set_property("cell-background-gdk",col)
@ -195,6 +192,9 @@ class LabelSideBar(component.Component):
def on_selection_changed(self, selection): def on_selection_changed(self, selection):
try: try:
(model, row) = self.label_view.get_selection().get_selected() (model, row) = self.label_view.get_selection().get_selected()
if not row:
log.debug("nothing selected")
return
cat = model.get_value(row, 0) cat = model.get_value(row, 0)
value = model.get_value(row, 1) value = model.get_value(row, 1)

View file

@ -147,13 +147,12 @@
</widget> </widget>
</child> </child>
<child> <child>
<widget class="GtkCheckMenuItem" id="menuitem_labels"> <widget class="GtkCheckMenuItem" id="menuitem_sidebar">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">_Labels</property> <property name="label" translatable="yes">_Sidebar</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="active">True</property> <property name="active">True</property>
<signal name="toggled" handler="on_menuitem_labels_toggled"/> <signal name="toggled" handler="on_menuitem_sidebar_toggled"/>
</widget> </widget>
</child> </child>
<child> <child>
@ -440,28 +439,13 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<child> <child>
<widget class="GtkScrolledWindow" id="scrolledwindow_sidebar"> <widget class="GtkNotebook" id="sidebar_notebook">
<property name="width_request">110</property>
<property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="scrollable">True</property>
<property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
<property name="shadow_type">GTK_SHADOW_OUT</property>
<child>
<widget class="GtkTreeView" id="label_view">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="enable_search">False</property>
<property name="fixed_height_mode">True</property>
<property name="show_expanders">False</property>
</widget>
</child>
</widget> </widget>
<packing> <packing>
<property name="resize">False</property> <property name="resize">False</property>
<property name="shrink">False</property> <property name="shrink">True</property>
</packing> </packing>
</child> </child>
<child> <child>

View file

@ -2,19 +2,19 @@
# menubar.py # menubar.py
# #
# Copyright (C) 2007, 2008 Andrew Resch ('andar') <andrewresch@gmail.com> # Copyright (C) 2007, 2008 Andrew Resch ('andar') <andrewresch@gmail.com>
# #
# Deluge is free software. # Deluge is free software.
# #
# You may redistribute it and/or modify it under the terms of the # You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software # GNU General Public License, as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) # Foundation; either version 2 of the License, or (at your option)
# any later version. # any later version.
# #
# deluge is distributed in the hope that it will be useful, # deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details. # See the GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with deluge. If not, write to: # along with deluge. If not, write to:
# The Free Software Foundation, Inc., # The Free Software Foundation, Inc.,
@ -50,19 +50,19 @@ class MenuBar(component.Component):
component.Component.__init__(self, "MenuBar") component.Component.__init__(self, "MenuBar")
self.window = component.get("MainWindow") self.window = component.get("MainWindow")
self.config = ConfigManager("gtkui.conf") self.config = ConfigManager("gtkui.conf")
# Get the torrent menu from the glade file # Get the torrent menu from the glade file
self.torrentmenu_glade = gtk.glade.XML( self.torrentmenu_glade = gtk.glade.XML(
pkg_resources.resource_filename("deluge.ui.gtkui", pkg_resources.resource_filename("deluge.ui.gtkui",
"glade/torrent_menu.glade")) "glade/torrent_menu.glade"))
# Attach remove torrent menu # Attach remove torrent menu
self.torrentmenu_glade.get_widget("menuitem_remove").set_submenu( self.torrentmenu_glade.get_widget("menuitem_remove").set_submenu(
self.torrentmenu_glade.get_widget("remove_torrent_menu")) self.torrentmenu_glade.get_widget("remove_torrent_menu"))
self.torrentmenu_glade.get_widget("menuitem_queue").set_submenu( self.torrentmenu_glade.get_widget("menuitem_queue").set_submenu(
self.torrentmenu_glade.get_widget("queue_torrent_menu")) self.torrentmenu_glade.get_widget("queue_torrent_menu"))
# Attach options torrent menu # Attach options torrent menu
self.torrentmenu_glade.get_widget("menuitem_options").set_submenu( self.torrentmenu_glade.get_widget("menuitem_options").set_submenu(
self.torrentmenu_glade.get_widget("options_torrent_menu")) self.torrentmenu_glade.get_widget("options_torrent_menu"))
@ -70,7 +70,7 @@ class MenuBar(component.Component):
common.get_pixmap("downloading16.png")) common.get_pixmap("downloading16.png"))
self.torrentmenu_glade.get_widget("upload-limit-image").set_from_file( self.torrentmenu_glade.get_widget("upload-limit-image").set_from_file(
common.get_pixmap("seeding16.png")) common.get_pixmap("seeding16.png"))
for menuitem in ("menuitem_down_speed", "menuitem_up_speed", for menuitem in ("menuitem_down_speed", "menuitem_up_speed",
"menuitem_max_connections", "menuitem_upload_slots"): "menuitem_max_connections", "menuitem_upload_slots"):
submenu = gtk.Menu() submenu = gtk.Menu()
@ -84,7 +84,7 @@ class MenuBar(component.Component):
submenu.append(item) submenu.append(item)
submenu.show_all() submenu.show_all()
self.torrentmenu_glade.get_widget(menuitem).set_submenu(submenu) self.torrentmenu_glade.get_widget(menuitem).set_submenu(submenu)
submenu = gtk.Menu() submenu = gtk.Menu()
item = gtk.MenuItem(_("On")) item = gtk.MenuItem(_("On"))
item.connect("activate", self.on_menuitem_set_automanaged_on) item.connect("activate", self.on_menuitem_set_automanaged_on)
@ -94,17 +94,17 @@ class MenuBar(component.Component):
submenu.append(item) submenu.append(item)
submenu.show_all() submenu.show_all()
self.torrentmenu_glade.get_widget("menuitem_auto_managed").set_submenu(submenu) self.torrentmenu_glade.get_widget("menuitem_auto_managed").set_submenu(submenu)
self.torrentmenu = self.torrentmenu_glade.get_widget("torrent_menu") self.torrentmenu = self.torrentmenu_glade.get_widget("torrent_menu")
self.menu_torrent = self.window.main_glade.get_widget("menu_torrent") self.menu_torrent = self.window.main_glade.get_widget("menu_torrent")
# Attach the torrent_menu to the Torrent file menu # Attach the torrent_menu to the Torrent file menu
self.menu_torrent.set_submenu(self.torrentmenu) self.menu_torrent.set_submenu(self.torrentmenu)
# Make sure the view menuitems are showing the correct active state # Make sure the view menuitems are showing the correct active state
self.window.main_glade.get_widget("menuitem_toolbar").set_active( self.window.main_glade.get_widget("menuitem_toolbar").set_active(
self.config["show_toolbar"]) self.config["show_toolbar"])
self.window.main_glade.get_widget("menuitem_labels").set_active( self.window.main_glade.get_widget("menuitem_sidebar").set_active(
self.config["show_sidebar"]) self.config["show_sidebar"])
self.window.main_glade.get_widget("menuitem_statusbar").set_active( self.window.main_glade.get_widget("menuitem_statusbar").set_active(
self.config["show_statusbar"]) self.config["show_statusbar"])
@ -125,12 +125,12 @@ class MenuBar(component.Component):
self.on_menuitem_preferences_activate, self.on_menuitem_preferences_activate,
"on_menuitem_connectionmanager_activate": \ "on_menuitem_connectionmanager_activate": \
self.on_menuitem_connectionmanager_activate, self.on_menuitem_connectionmanager_activate,
## View Menu ## View Menu
"on_menuitem_toolbar_toggled": self.on_menuitem_toolbar_toggled, "on_menuitem_toolbar_toggled": self.on_menuitem_toolbar_toggled,
"on_menuitem_labels_toggled": self.on_menuitem_labels_toggled, "on_menuitem_sidebar_toggled": self.on_menuitem_sidebar_toggled,
"on_menuitem_statusbar_toggled": self.on_menuitem_statusbar_toggled, "on_menuitem_statusbar_toggled": self.on_menuitem_statusbar_toggled,
## Help Menu ## Help Menu
"on_menuitem_homepage_activate": self.on_menuitem_homepage_activate, "on_menuitem_homepage_activate": self.on_menuitem_homepage_activate,
"on_menuitem_faq_activate": self.on_menuitem_faq_activate, "on_menuitem_faq_activate": self.on_menuitem_faq_activate,
@ -138,7 +138,7 @@ class MenuBar(component.Component):
self.on_menuitem_community_activate, self.on_menuitem_community_activate,
"on_menuitem_about_activate": self.on_menuitem_about_activate "on_menuitem_about_activate": self.on_menuitem_about_activate
}) })
self.torrentmenu_glade.signal_autoconnect({ self.torrentmenu_glade.signal_autoconnect({
## Torrent Menu ## Torrent Menu
"on_menuitem_pause_activate": self.on_menuitem_pause_activate, "on_menuitem_pause_activate": self.on_menuitem_pause_activate,
@ -163,24 +163,24 @@ class MenuBar(component.Component):
"on_menuitem_queue_up_activate": self.on_menuitem_queue_up_activate, "on_menuitem_queue_up_activate": self.on_menuitem_queue_up_activate,
"on_menuitem_queue_down_activate": self.on_menuitem_queue_down_activate, "on_menuitem_queue_down_activate": self.on_menuitem_queue_down_activate,
"on_menuitem_queue_bottom_activate": self.on_menuitem_queue_bottom_activate, "on_menuitem_queue_bottom_activate": self.on_menuitem_queue_bottom_activate,
}) })
self.change_sensitivity = [ self.change_sensitivity = [
"menuitem_addtorrent" "menuitem_addtorrent"
] ]
if self.config["classic_mode"]: if self.config["classic_mode"]:
# We need to remove the 'quit and shutdown daemon' menu item # We need to remove the 'quit and shutdown daemon' menu item
self.window.main_glade.get_widget("menuitem_quitdaemon").hide() self.window.main_glade.get_widget("menuitem_quitdaemon").hide()
self.window.main_glade.get_widget("separatormenuitem").hide() self.window.main_glade.get_widget("separatormenuitem").hide()
self.window.main_glade.get_widget("menuitem_connectionmanager").hide() self.window.main_glade.get_widget("menuitem_connectionmanager").hide()
def start(self): def start(self):
for widget in self.change_sensitivity: for widget in self.change_sensitivity:
self.window.main_glade.get_widget(widget).set_sensitive(True) self.window.main_glade.get_widget(widget).set_sensitive(True)
# Hide the Open Folder menuitem and separator if not connected to a # Hide the Open Folder menuitem and separator if not connected to a
# localhost. # localhost.
non_remote_items = [ non_remote_items = [
"menuitem_open_folder", "menuitem_open_folder",
@ -193,14 +193,14 @@ class MenuBar(component.Component):
else: else:
for widget in non_remote_items: for widget in non_remote_items:
self.torrentmenu_glade.get_widget(widget).set_no_show_all(False) self.torrentmenu_glade.get_widget(widget).set_no_show_all(False)
# Show the Torrent menu because we're connected to a host # Show the Torrent menu because we're connected to a host
self.menu_torrent.show() self.menu_torrent.show()
if not self.config["classic_mode"]: if not self.config["classic_mode"]:
self.window.main_glade.get_widget("separatormenuitem").show() self.window.main_glade.get_widget("separatormenuitem").show()
self.window.main_glade.get_widget("menuitem_quitdaemon").show() self.window.main_glade.get_widget("menuitem_quitdaemon").show()
def stop(self): def stop(self):
for widget in self.change_sensitivity: for widget in self.change_sensitivity:
self.window.main_glade.get_widget(widget).set_sensitive(False) self.window.main_glade.get_widget(widget).set_sensitive(False)
@ -227,9 +227,9 @@ class MenuBar(component.Component):
self.torrentmenu.append(sep) self.torrentmenu.append(sep)
sep.show() sep.show()
return sep return sep
### Callbacks ### ### Callbacks ###
## File Menu ## ## File Menu ##
def on_menuitem_addtorrent_activate(self, data=None): def on_menuitem_addtorrent_activate(self, data=None):
log.debug("on_menuitem_addtorrent_activate") log.debug("on_menuitem_addtorrent_activate")
@ -239,13 +239,13 @@ class MenuBar(component.Component):
log.debug("on_menuitem_createtorrent_activate") log.debug("on_menuitem_createtorrent_activate")
from createtorrentdialog import CreateTorrentDialog from createtorrentdialog import CreateTorrentDialog
CreateTorrentDialog().show() CreateTorrentDialog().show()
def on_menuitem_quitdaemon_activate(self, data=None): def on_menuitem_quitdaemon_activate(self, data=None):
log.debug("on_menuitem_quitdaemon_activate") log.debug("on_menuitem_quitdaemon_activate")
# Tell the core to shutdown # Tell the core to shutdown
client.shutdown() client.shutdown()
self.window.quit() self.window.quit()
def on_menuitem_quit_activate(self, data=None): def on_menuitem_quit_activate(self, data=None):
log.debug("on_menuitem_quit_activate") log.debug("on_menuitem_quit_activate")
if self.config["classic_mode"]: if self.config["classic_mode"]:
@ -254,7 +254,7 @@ class MenuBar(component.Component):
except deluge.error.NoCoreError: except deluge.error.NoCoreError:
pass pass
self.window.quit() self.window.quit()
## Edit Menu ## ## Edit Menu ##
def on_menuitem_preferences_activate(self, data=None): def on_menuitem_preferences_activate(self, data=None):
log.debug("on_menuitem_preferences_activate") log.debug("on_menuitem_preferences_activate")
@ -263,31 +263,31 @@ class MenuBar(component.Component):
def on_menuitem_connectionmanager_activate(self, data=None): def on_menuitem_connectionmanager_activate(self, data=None):
log.debug("on_menuitem_connectionmanager_activate") log.debug("on_menuitem_connectionmanager_activate")
component.get("ConnectionManager").show() component.get("ConnectionManager").show()
## Torrent Menu ## ## Torrent Menu ##
def on_menuitem_pause_activate(self, data=None): def on_menuitem_pause_activate(self, data=None):
log.debug("on_menuitem_pause_activate") log.debug("on_menuitem_pause_activate")
client.pause_torrent( client.pause_torrent(
component.get("TorrentView").get_selected_torrents()) component.get("TorrentView").get_selected_torrents())
def on_menuitem_resume_activate(self, data=None): def on_menuitem_resume_activate(self, data=None):
log.debug("on_menuitem_resume_activate") log.debug("on_menuitem_resume_activate")
client.resume_torrent( client.resume_torrent(
component.get("TorrentView").get_selected_torrents()) component.get("TorrentView").get_selected_torrents())
def on_menuitem_updatetracker_activate(self, data=None): def on_menuitem_updatetracker_activate(self, data=None):
log.debug("on_menuitem_updatetracker_activate") log.debug("on_menuitem_updatetracker_activate")
client.force_reannounce( client.force_reannounce(
component.get("TorrentView").get_selected_torrents()) component.get("TorrentView").get_selected_torrents())
def on_menuitem_edittrackers_activate(self, data=None): def on_menuitem_edittrackers_activate(self, data=None):
log.debug("on_menuitem_edittrackers_activate") log.debug("on_menuitem_edittrackers_activate")
from edittrackersdialog import EditTrackersDialog from edittrackersdialog import EditTrackersDialog
dialog = EditTrackersDialog( dialog = EditTrackersDialog(
component.get("TorrentView").get_selected_torrent(), component.get("TorrentView").get_selected_torrent(),
component.get("MainWindow").window) component.get("MainWindow").window)
dialog.run() dialog.run()
def on_menuitem_remove_session_activate(self, data=None): def on_menuitem_remove_session_activate(self, data=None):
log.debug("on_menuitem_remove_session_activate") log.debug("on_menuitem_remove_session_activate")
from removetorrentdialog import RemoveTorrentDialog from removetorrentdialog import RemoveTorrentDialog
@ -307,7 +307,7 @@ class MenuBar(component.Component):
RemoveTorrentDialog( RemoveTorrentDialog(
component.get("TorrentView").get_selected_torrents(), component.get("TorrentView").get_selected_torrents(),
remove_data=True).run() remove_data=True).run()
def on_menuitem_remove_both_activate(self, data=None): def on_menuitem_remove_both_activate(self, data=None):
log.debug("on_menuitem_remove_both_activate") log.debug("on_menuitem_remove_both_activate")
from removetorrentdialog import RemoveTorrentDialog from removetorrentdialog import RemoveTorrentDialog
@ -320,7 +320,7 @@ class MenuBar(component.Component):
log.debug("on_menuitem_recheck_activate") log.debug("on_menuitem_recheck_activate")
client.force_recheck( client.force_recheck(
component.get("TorrentView").get_selected_torrents()) component.get("TorrentView").get_selected_torrents())
def on_menuitem_open_folder_activate(self, data=None): def on_menuitem_open_folder_activate(self, data=None):
log.debug("on_menuitem_open_folder") log.debug("on_menuitem_open_folder")
def _on_torrent_status(status): def _on_torrent_status(status):
@ -350,11 +350,11 @@ class MenuBar(component.Component):
else: else:
client.get_torrent_status(self.show_move_storage_dialog, component.get("TorrentView").get_selected_torrent(), ["save_path"]) client.get_torrent_status(self.show_move_storage_dialog, component.get("TorrentView").get_selected_torrent(), ["save_path"])
client.force_call(False) client.force_call(False)
def show_move_storage_dialog(self, status): def show_move_storage_dialog(self, status):
log.debug("show_move_storage_dialog") log.debug("show_move_storage_dialog")
glade = gtk.glade.XML( glade = gtk.glade.XML(
pkg_resources.resource_filename("deluge.ui.gtkui", pkg_resources.resource_filename("deluge.ui.gtkui",
"glade/move_storage_dialog.glade")) "glade/move_storage_dialog.glade"))
dialog = glade.get_widget("move_storage_dialog") dialog = glade.get_widget("move_storage_dialog")
dialog.set_transient_for(self.window.window) dialog.set_transient_for(self.window.window)
@ -367,7 +367,7 @@ class MenuBar(component.Component):
dialog.hide() dialog.hide()
dialog.connect("response", _on_response_event) dialog.connect("response", _on_response_event)
dialog.show() dialog.show()
def on_menuitem_queue_top_activate(self, value): def on_menuitem_queue_top_activate(self, value):
log.debug("on_menuitem_queue_top_activate") log.debug("on_menuitem_queue_top_activate")
client.queue_top(None, component.get("TorrentView").get_selected_torrents()) client.queue_top(None, component.get("TorrentView").get_selected_torrents())
@ -375,24 +375,24 @@ class MenuBar(component.Component):
def on_menuitem_queue_up_activate(self, value): def on_menuitem_queue_up_activate(self, value):
log.debug("on_menuitem_queue_up_activate") log.debug("on_menuitem_queue_up_activate")
client.queue_up(None, component.get("TorrentView").get_selected_torrents()) client.queue_up(None, component.get("TorrentView").get_selected_torrents())
def on_menuitem_queue_down_activate(self, value): def on_menuitem_queue_down_activate(self, value):
log.debug("on_menuitem_queue_down_activate") log.debug("on_menuitem_queue_down_activate")
client.queue_down(None, component.get("TorrentView").get_selected_torrents()) client.queue_down(None, component.get("TorrentView").get_selected_torrents())
def on_menuitem_queue_bottom_activate(self, value): def on_menuitem_queue_bottom_activate(self, value):
log.debug("on_menuitem_queue_bottom_activate") log.debug("on_menuitem_queue_bottom_activate")
client.queue_bottom(None, component.get("TorrentView").get_selected_torrents()) client.queue_bottom(None, component.get("TorrentView").get_selected_torrents())
## View Menu ## ## View Menu ##
def on_menuitem_toolbar_toggled(self, value): def on_menuitem_toolbar_toggled(self, value):
log.debug("on_menuitem_toolbar_toggled") log.debug("on_menuitem_toolbar_toggled")
component.get("ToolBar").visible(value.get_active()) component.get("ToolBar").visible(value.get_active())
def on_menuitem_labels_toggled(self, value): def on_menuitem_sidebar_toggled(self, value):
log.debug("on_menuitem_labels_toggled") log.debug("on_menuitem_sidebar_toggled")
component.get("SideBar").visible(value.get_active()) component.get("SideBar").visible(value.get_active())
def on_menuitem_statusbar_toggled(self, value): def on_menuitem_statusbar_toggled(self, value):
log.debug("on_menuitem_statusbar_toggled") log.debug("on_menuitem_statusbar_toggled")
component.get("StatusBar").visible(value.get_active()) component.get("StatusBar").visible(value.get_active())
@ -426,7 +426,7 @@ class MenuBar(component.Component):
if widget.name in funcs.keys(): if widget.name in funcs.keys():
for torrent in component.get("TorrentView").get_selected_torrents(): for torrent in component.get("TorrentView").get_selected_torrents():
funcs[widget.name](torrent, -1) funcs[widget.name](torrent, -1)
def on_menuitem_set_other(self, widget): def on_menuitem_set_other(self, widget):
log.debug("widget.name: %s", widget.name) log.debug("widget.name: %s", widget.name)
funcs = { funcs = {
@ -436,7 +436,7 @@ class MenuBar(component.Component):
"menuitem_upload_slots": client.set_torrent_max_upload_slots "menuitem_upload_slots": client.set_torrent_max_upload_slots
} }
dialog_glade = gtk.glade.XML( dialog_glade = gtk.glade.XML(
pkg_resources.resource_filename("deluge.ui.gtkui", pkg_resources.resource_filename("deluge.ui.gtkui",
"glade/dgtkpopups.glade")) "glade/dgtkpopups.glade"))
speed_dialog = dialog_glade.get_widget("speed_dialog") speed_dialog = dialog_glade.get_widget("speed_dialog")
spin_title = dialog_glade.get_widget("spin_title") spin_title = dialog_glade.get_widget("spin_title")
@ -448,7 +448,7 @@ class MenuBar(component.Component):
spin_title.set_text(_("Set Max Connections:")) spin_title.set_text(_("Set Max Connections:"))
elif widget.name == "menuitem_upload_slots": elif widget.name == "menuitem_upload_slots":
spin_title.set_text(_("Set Max Upload Slots:")) spin_title.set_text(_("Set Max Upload Slots:"))
spin_speed = dialog_glade.get_widget("spin_speed") spin_speed = dialog_glade.get_widget("spin_speed")
spin_speed.set_value(-1) spin_speed.set_value(-1)
spin_speed.select_region(0, -1) spin_speed.select_region(0, -1)
@ -464,7 +464,7 @@ class MenuBar(component.Component):
speed_dialog.destroy() speed_dialog.destroy()
if widget.name in funcs.keys(): if widget.name in funcs.keys():
for torrent in component.get("TorrentView").get_selected_torrents(): for torrent in component.get("TorrentView").get_selected_torrents():
funcs[widget.name](torrent, value) funcs[widget.name](torrent, value)
def on_menuitem_set_automanaged_on(self, widget): def on_menuitem_set_automanaged_on(self, widget):
for torrent in component.get("TorrentView").get_selected_torrents(): for torrent in component.get("TorrentView").get_selected_torrents():

View file

@ -2,19 +2,20 @@
# sidebar.py # sidebar.py
# #
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com> # Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
# # Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
#
# Deluge is free software. # Deluge is free software.
# #
# You may redistribute it and/or modify it under the terms of the # You may redistribute it and/or modify it under the terms of the
# GNU General Public License, as published by the Free Software # GNU General Public License, as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) # Foundation; either version 2 of the License, or (at your option)
# any later version. # any later version.
# #
# deluge is distributed in the hope that it will be useful, # deluge is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details. # See the GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with deluge. If not, write to: # along with deluge. If not, write to:
# The Free Software Foundation, Inc., # The Free Software Foundation, Inc.,
@ -36,86 +37,55 @@ import gtk.glade
import deluge.component as component import deluge.component as component
import deluge.common import deluge.common
from deluge.configmanager import ConfigManager
from deluge.log import LOG as log from deluge.log import LOG as log
class SideBar(component.Component): class SideBar(component.Component):
"""
manages the sidebar-tabs.
purpose : plugins
"""
def __init__(self): def __init__(self):
component.Component.__init__(self, "SideBar") component.Component.__init__(self, "SideBar")
self.window = component.get("MainWindow") self.window = component.get("MainWindow")
glade = self.window.main_glade glade = self.window.main_glade
self.label_view = glade.get_widget("label_view") self.notebook = glade.get_widget("sidebar_notebook")
self.hpaned = glade.get_widget("hpaned") self.hpaned = glade.get_widget("hpaned")
self.scrolled = glade.get_widget("scrolledwindow_sidebar")
self.is_visible = True self.is_visible = True
self.config = ConfigManager("gtkui.conf")
# Create the liststore # Tabs holds references to the Tab widgets by their name
# state str, str that's visible, icon self.tabs = {}
self.liststore = gtk.ListStore(str, str, gtk.gdk.Pixbuf)
self.liststore.append(["All", _("All"), None])
self.liststore.append(["Downloading", _("Downloading"),
gtk.gdk.pixbuf_new_from_file(
deluge.common.get_pixmap("downloading16.png"))])
self.liststore.append(["Seeding", _("Seeding"),
gtk.gdk.pixbuf_new_from_file(
deluge.common.get_pixmap("seeding16.png"))])
self.liststore.append(["Queued", _("Queued"),
gtk.gdk.pixbuf_new_from_file(
deluge.common.get_pixmap("queued16.png"))])
self.liststore.append(["Paused", _("Paused"),
gtk.gdk.pixbuf_new_from_file(
deluge.common.get_pixmap("inactive16.png"))])
self.liststore.append(["Error", _("Error"),
gtk.gdk.pixbuf_new_from_file(
deluge.common.get_pixmap("alert16.png"))])
self.liststore.append(["Checking", _("Checking"),
gtk.gdk.pixbuf_new_from_file(
deluge.common.get_pixmap("checking16.png"))])
# Create the column
column = gtk.TreeViewColumn(_("Labels"))
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
render = gtk.CellRendererPixbuf()
column.pack_start(render, expand=False)
column.add_attribute(render, 'pixbuf', 2)
render = gtk.CellRendererText()
column.pack_start(render, expand=True)
column.add_attribute(render, 'text', 1)
self.label_view.append_column(column)
self.label_view.set_model(self.liststore)
self.label_view.get_selection().connect("changed",
self.on_selection_changed)
# Select the 'All' label on init
self.label_view.get_selection().select_iter(
self.liststore.get_iter_first())
# Hide if necessary
self.visible(self.config["show_sidebar"])
def visible(self, visible): def visible(self, visible):
if visible: if visible:
self.scrolled.show() self.notebook.show()
else: else:
self.scrolled.hide() log.debug("5")
self.notebook.hide()
log.debug("6")
self.hpaned.set_position(-1) self.hpaned.set_position(-1)
log.debug("7")
self.is_visible = visible self.is_visible = visible
self.config["show_sidebar"] = visible
def on_selection_changed(self, selection): def add_tab(self, widget, tab_name, label):
try: """Adds a tab object to the notebook."""
(model, row) = self.label_view.get_selection().get_selected() log.debug("add tab:%s" % tab_name )
except Exception, e: self.tabs[tab_name] = widget
log.debug(e) pos = self.notebook.insert_page(widget, gtk.Label(label), -1)
# paths is likely None .. so lets return None log.debug("1")
return None widget.show_all()
log.debug("2")
value = model.get_value(row, 0) if not self.notebook.get_property("visible"):
if value == "All": # If the notebook isn't visible, show it
component.get("TorrentView").set_filter(None, None) self.visible(True) #Shure?
else: log.debug("3")
component.get("TorrentView").set_filter("state", value) self.notebook.select_page(pos)
def remove_tab(self, tab_name):
"""Removes a tab by name."""
self.notebook.remove_page(self.notebook.page_num(self.tabs[tab_name]))
del self.tabs[tab_name]
# If there are no tabs visible, then do not show the notebook
if len(self.tabs) == 0:
self.visible(False)