remove default-sidebar, make plug-in-able
This commit is contained in:
parent
7128b129d4
commit
7cd83f8d05
|
@ -55,12 +55,12 @@ class LabelSideBar(component.Component):
|
|||
component.Component.__init__(self, "LabelSideBar", interval=2000)
|
||||
self.window = component.get("MainWindow")
|
||||
glade = self.window.main_glade
|
||||
self.label_view = glade.get_widget("label_view")
|
||||
self.hpaned = glade.get_widget("hpaned")
|
||||
self.scrolled = glade.get_widget("scrolledwindow_sidebar")
|
||||
self.is_visible = True
|
||||
self.filters = {}
|
||||
self.first_expand = True
|
||||
self.label_view = gtk.TreeView()
|
||||
|
||||
# Create the liststore
|
||||
#cat,value,count , pixmap , visible
|
||||
|
@ -76,11 +76,6 @@ class LabelSideBar(component.Component):
|
|||
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])
|
||||
|
||||
|
||||
#remove all old columns:
|
||||
for c in self.label_view.get_columns():
|
||||
self.label_view.remove_column(c)
|
||||
|
||||
# Create the column
|
||||
column = gtk.TreeViewColumn(_("Filters"))
|
||||
column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
|
||||
|
@ -104,8 +99,8 @@ class LabelSideBar(component.Component):
|
|||
self.on_selection_changed)
|
||||
|
||||
# Select the 'All' label on init
|
||||
self.label_view.get_selection().select_iter(
|
||||
self.treestore.get_iter_first())
|
||||
#self.label_view.get_selection().select_iter(
|
||||
# self.treestore.get_iter_first())
|
||||
|
||||
self.create_model_filter()
|
||||
#init.....
|
||||
|
@ -113,15 +108,16 @@ class LabelSideBar(component.Component):
|
|||
self.label_view.expand_all()
|
||||
self.hpaned.set_position(170)
|
||||
|
||||
|
||||
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):
|
||||
#hacks!
|
||||
self.label_view.set_headers_visible(True)
|
||||
old_sidebar = component.get("SideBar")
|
||||
del old_sidebar
|
||||
new_sidebar = deluge.ui.gtkui.sidebar.SideBar()
|
||||
log.debug("unload..")
|
||||
sidebar = component.get("SideBar")
|
||||
sidebar.remove_tab("filters")
|
||||
log.debug("unload-end")
|
||||
|
||||
|
||||
def create_model_filter(self):
|
||||
|
@ -153,8 +149,6 @@ class LabelSideBar(component.Component):
|
|||
self.filters[(cat, value)] = row
|
||||
self.treestore.set_value(row, 4, True)
|
||||
|
||||
|
||||
|
||||
def render_cell_data(self, column, cell, model, row, data):
|
||||
"cell renderer"
|
||||
cat = model.get_value(row, 0)
|
||||
|
@ -169,9 +163,12 @@ class LabelSideBar(component.Component):
|
|||
if cat == "cat":
|
||||
txt = value
|
||||
col = gtk.gdk.color_parse('#EEEEEE')
|
||||
cell.set_property("ypad",1)
|
||||
else:
|
||||
txt = "%s (%s)" % (value, count)
|
||||
col = gtk.gdk.color_parse('white')
|
||||
cell.set_property("ypad",1)
|
||||
|
||||
cell.set_property('text', txt)
|
||||
cell.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):
|
||||
try:
|
||||
(model, row) = self.label_view.get_selection().get_selected()
|
||||
if not row:
|
||||
log.debug("nothing selected")
|
||||
return
|
||||
|
||||
cat = model.get_value(row, 0)
|
||||
value = model.get_value(row, 1)
|
||||
|
|
|
@ -147,13 +147,12 @@
|
|||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckMenuItem" id="menuitem_labels">
|
||||
<property name="visible">True</property>
|
||||
<widget class="GtkCheckMenuItem" id="menuitem_sidebar">
|
||||
<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="active">True</property>
|
||||
<signal name="toggled" handler="on_menuitem_labels_toggled"/>
|
||||
<signal name="toggled" handler="on_menuitem_sidebar_toggled"/>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -440,28 +439,13 @@
|
|||
<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>
|
||||
<child>
|
||||
<widget class="GtkScrolledWindow" id="scrolledwindow_sidebar">
|
||||
<property name="width_request">110</property>
|
||||
<property name="visible">True</property>
|
||||
<widget class="GtkNotebook" id="sidebar_notebook">
|
||||
<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="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>
|
||||
<property name="scrollable">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">False</property>
|
||||
<property name="shrink">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
|
|
@ -104,7 +104,7 @@ class MenuBar(component.Component):
|
|||
# Make sure the view menuitems are showing the correct active state
|
||||
self.window.main_glade.get_widget("menuitem_toolbar").set_active(
|
||||
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.window.main_glade.get_widget("menuitem_statusbar").set_active(
|
||||
self.config["show_statusbar"])
|
||||
|
@ -128,7 +128,7 @@ class MenuBar(component.Component):
|
|||
|
||||
## View Menu
|
||||
"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,
|
||||
|
||||
## Help Menu
|
||||
|
@ -389,8 +389,8 @@ class MenuBar(component.Component):
|
|||
log.debug("on_menuitem_toolbar_toggled")
|
||||
component.get("ToolBar").visible(value.get_active())
|
||||
|
||||
def on_menuitem_labels_toggled(self, value):
|
||||
log.debug("on_menuitem_labels_toggled")
|
||||
def on_menuitem_sidebar_toggled(self, value):
|
||||
log.debug("on_menuitem_sidebar_toggled")
|
||||
component.get("SideBar").visible(value.get_active())
|
||||
|
||||
def on_menuitem_statusbar_toggled(self, value):
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
# sidebar.py
|
||||
#
|
||||
# Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
|
||||
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
|
||||
#
|
||||
# Deluge is free software.
|
||||
#
|
||||
|
@ -36,86 +37,55 @@ import gtk.glade
|
|||
|
||||
import deluge.component as component
|
||||
import deluge.common
|
||||
from deluge.configmanager import ConfigManager
|
||||
from deluge.log import LOG as log
|
||||
|
||||
class SideBar(component.Component):
|
||||
"""
|
||||
manages the sidebar-tabs.
|
||||
purpose : plugins
|
||||
"""
|
||||
def __init__(self):
|
||||
component.Component.__init__(self, "SideBar")
|
||||
self.window = component.get("MainWindow")
|
||||
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.scrolled = glade.get_widget("scrolledwindow_sidebar")
|
||||
self.is_visible = True
|
||||
self.config = ConfigManager("gtkui.conf")
|
||||
|
||||
# Create the liststore
|
||||
# state str, str that's visible, icon
|
||||
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"])
|
||||
# Tabs holds references to the Tab widgets by their name
|
||||
self.tabs = {}
|
||||
|
||||
def visible(self, visible):
|
||||
if visible:
|
||||
self.scrolled.show()
|
||||
self.notebook.show()
|
||||
else:
|
||||
self.scrolled.hide()
|
||||
log.debug("5")
|
||||
self.notebook.hide()
|
||||
log.debug("6")
|
||||
self.hpaned.set_position(-1)
|
||||
log.debug("7")
|
||||
|
||||
self.is_visible = visible
|
||||
self.config["show_sidebar"] = visible
|
||||
|
||||
def on_selection_changed(self, selection):
|
||||
try:
|
||||
(model, row) = self.label_view.get_selection().get_selected()
|
||||
except Exception, e:
|
||||
log.debug(e)
|
||||
# paths is likely None .. so lets return None
|
||||
return None
|
||||
def add_tab(self, widget, tab_name, label):
|
||||
"""Adds a tab object to the notebook."""
|
||||
log.debug("add tab:%s" % tab_name )
|
||||
self.tabs[tab_name] = widget
|
||||
pos = self.notebook.insert_page(widget, gtk.Label(label), -1)
|
||||
log.debug("1")
|
||||
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)
|
||||
if value == "All":
|
||||
component.get("TorrentView").set_filter(None, None)
|
||||
else:
|
||||
component.get("TorrentView").set_filter("state", value)
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue