remove default-sidebar, make plug-in-able

This commit is contained in:
Martijn Voncken 2008-07-28 18:22:44 +00:00
parent 7128b129d4
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

@ -104,7 +104,7 @@ class MenuBar(component.Component):
# 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"])
@ -128,7 +128,7 @@ class MenuBar(component.Component):
## 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
@ -389,8 +389,8 @@ class MenuBar(component.Component):
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):

View File

@ -2,6 +2,7 @@
# 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.
# #
@ -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")
if not self.notebook.get_property("visible"):
# If the notebook isn't visible, show it
self.visible(True) #Shure?
log.debug("3")
self.notebook.select_page(pos)
value = model.get_value(row, 0) def remove_tab(self, tab_name):
if value == "All": """Removes a tab by name."""
component.get("TorrentView").set_filter(None, None) self.notebook.remove_page(self.notebook.page_num(self.tabs[tab_name]))
else: del self.tabs[tab_name]
component.get("TorrentView").set_filter("state", value)
# If there are no tabs visible, then do not show the notebook
if len(self.tabs) == 0:
self.visible(False)