Sidebar: Enabled strings for translation and added icons to Trackers filter
This commit is contained in:
parent
7d36a4fa51
commit
4490cd371a
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 683 B |
|
@ -38,6 +38,7 @@
|
||||||
import gtk
|
import gtk
|
||||||
import gtk.glade
|
import gtk.glade
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
|
import glib
|
||||||
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
import deluge.common
|
import deluge.common
|
||||||
|
@ -56,20 +57,37 @@ STATE_PIX = {
|
||||||
"Active": "active"
|
"Active": "active"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TRACKER_PIX = {
|
||||||
TRANSLATE = {
|
"All": "tracker_all",
|
||||||
"state": "States",
|
"Error": "tracker_warning",
|
||||||
"tracker_host": "Trackers",
|
|
||||||
"label": "Labels"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FILTER_COLUMN = 5
|
def _(message): return message
|
||||||
|
|
||||||
|
TRANSLATE = {
|
||||||
|
"state": _("States"),
|
||||||
|
"tracker_host": _("Trackers"),
|
||||||
|
"label": _("Labels"),
|
||||||
|
"All": _("All"),
|
||||||
|
"Downloading": _("Downloading"),
|
||||||
|
"Seeding": _("Seeding"),
|
||||||
|
"Paused": _("Paused"),
|
||||||
|
"Checking": _("Checking"),
|
||||||
|
"Queued": _("Queued"),
|
||||||
|
"Error": _("Error"),
|
||||||
|
"Active": _("Active"),
|
||||||
|
"none": _("None"),
|
||||||
|
"no_label": _("No Label"),
|
||||||
|
}
|
||||||
|
|
||||||
|
del _
|
||||||
|
|
||||||
def _t(text):
|
def _t(text):
|
||||||
if text in TRANSLATE:
|
if text in TRANSLATE:
|
||||||
text = TRANSLATE[text]
|
text = TRANSLATE[text]
|
||||||
return _(text)
|
return _(text)
|
||||||
|
|
||||||
|
FILTER_COLUMN = 5
|
||||||
|
|
||||||
#sidebar-treeview
|
#sidebar-treeview
|
||||||
class FilterTreeView(component.Component):
|
class FilterTreeView(component.Component):
|
||||||
|
@ -84,7 +102,7 @@ class FilterTreeView(component.Component):
|
||||||
self.tracker_icons = component.get("TrackerIcons")
|
self.tracker_icons = component.get("TrackerIcons")
|
||||||
|
|
||||||
self.label_view = gtk.TreeView()
|
self.label_view = gtk.TreeView()
|
||||||
self.sidebar.add_tab(self.label_view, "filters", _("Filters"))
|
self.sidebar.add_tab(self.label_view, "filters", "Filters")
|
||||||
|
|
||||||
#set filter to all when hidden:
|
#set filter to all when hidden:
|
||||||
self.sidebar.notebook.connect("hide", self._on_hide)
|
self.sidebar.notebook.connect("hide", self._on_hide)
|
||||||
|
@ -106,7 +124,7 @@ class FilterTreeView(component.Component):
|
||||||
self.treestore = gtk.TreeStore(str, str, str, int, gtk.gdk.Pixbuf, bool)
|
self.treestore = gtk.TreeStore(str, str, str, int, gtk.gdk.Pixbuf, bool)
|
||||||
|
|
||||||
# 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)
|
||||||
render = gtk.CellRendererPixbuf()
|
render = gtk.CellRendererPixbuf()
|
||||||
self.renderpix = render
|
self.renderpix = render
|
||||||
|
@ -125,7 +143,7 @@ class FilterTreeView(component.Component):
|
||||||
# Force the theme to use an expander-size of 15 so that we don't cut out
|
# Force the theme to use an expander-size of 15 so that we don't cut out
|
||||||
# entries due to our indentation hack.
|
# entries due to our indentation hack.
|
||||||
gtk.rc_parse_string('style "treeview-style" { GtkTreeView::expander-size = 15 } class "GtkTreeView" style "treeview-style"')
|
gtk.rc_parse_string('style "treeview-style" { GtkTreeView::expander-size = 15 } class "GtkTreeView" style "treeview-style"')
|
||||||
|
|
||||||
self.label_view.set_model(self.treestore)
|
self.label_view.set_model(self.treestore)
|
||||||
self.label_view.get_selection().connect("changed", self.on_selection_changed)
|
self.label_view.get_selection().connect("changed", self.on_selection_changed)
|
||||||
self.create_model_filter()
|
self.create_model_filter()
|
||||||
|
@ -144,7 +162,7 @@ class FilterTreeView(component.Component):
|
||||||
self.filters = {}
|
self.filters = {}
|
||||||
|
|
||||||
#initial order of state filter:
|
#initial order of state filter:
|
||||||
self.cat_nodes["state"] = self.treestore.append(None, ["cat", "state", _("State"), 0, None, False])
|
self.cat_nodes["state"] = self.treestore.append(None, ["cat", "state", _t("State"), 0, None, False])
|
||||||
self.update_row("state", "All" , 0)
|
self.update_row("state", "All" , 0)
|
||||||
self.update_row("state", "Downloading" , 0)
|
self.update_row("state", "Downloading" , 0)
|
||||||
self.update_row("state", "Seeding" , 0)
|
self.update_row("state", "Seeding" , 0)
|
||||||
|
@ -152,6 +170,11 @@ class FilterTreeView(component.Component):
|
||||||
self.update_row("state", "Paused" , 0)
|
self.update_row("state", "Paused" , 0)
|
||||||
self.update_row("state", "Queued" , 0)
|
self.update_row("state", "Queued" , 0)
|
||||||
|
|
||||||
|
self.cat_nodes["tracker_host"] = self.treestore.append(None, ["cat", "tracker_host", _t("Trackers"), 0, None, False])
|
||||||
|
self.update_row("tracker_host", "All" , 0)
|
||||||
|
self.update_row("tracker_host", "Error" , 0)
|
||||||
|
self.update_row("tracker_host", "" , 0)
|
||||||
|
|
||||||
# We set to this expand the rows on start-up
|
# We set to this expand the rows on start-up
|
||||||
self.expand_rows = True
|
self.expand_rows = True
|
||||||
|
|
||||||
|
@ -208,8 +231,16 @@ class FilterTreeView(component.Component):
|
||||||
else:
|
else:
|
||||||
pix = self.get_pixmap(cat, value)
|
pix = self.get_pixmap(cat, value)
|
||||||
label = value
|
label = value
|
||||||
if cat == "state":
|
|
||||||
label = _(value)
|
if cat == "state" or cat == "tracker_host":
|
||||||
|
label = _t(value)
|
||||||
|
|
||||||
|
if label == "":
|
||||||
|
if cat == "tracker_host":
|
||||||
|
label = _t("none")
|
||||||
|
elif cat == "label":
|
||||||
|
label = _t("no_label")
|
||||||
|
|
||||||
row = self.treestore.append(self.cat_nodes[cat],[cat, value, label, count , pix, True])
|
row = self.treestore.append(self.cat_nodes[cat],[cat, value, label, count , pix, True])
|
||||||
self.filters[(cat, value)] = row
|
self.filters[(cat, value)] = row
|
||||||
|
|
||||||
|
@ -228,9 +259,6 @@ class FilterTreeView(component.Component):
|
||||||
count = model.get_value(row, 3)
|
count = model.get_value(row, 3)
|
||||||
pix = model.get_value(row, 4)
|
pix = model.get_value(row, 4)
|
||||||
|
|
||||||
if label == "" and cat == "label":
|
|
||||||
label = _("no label")
|
|
||||||
|
|
||||||
if pix:
|
if pix:
|
||||||
self.renderpix.set_property("visible", True)
|
self.renderpix.set_property("visible", True)
|
||||||
else:
|
else:
|
||||||
|
@ -248,11 +276,23 @@ class FilterTreeView(component.Component):
|
||||||
cell.set_property('text', txt)
|
cell.set_property('text', txt)
|
||||||
|
|
||||||
def get_pixmap(self, cat, value):
|
def get_pixmap(self, cat, value):
|
||||||
|
pix = None
|
||||||
if cat == "state":
|
if cat == "state":
|
||||||
pix = STATE_PIX.get(value, "dht")
|
pix = STATE_PIX.get(value, None)
|
||||||
return gtk.gdk.pixbuf_new_from_file(deluge.common.get_pixmap("%s16.png" % pix))
|
elif cat == "tracker_host":
|
||||||
|
pix = TRACKER_PIX.get(value, None)
|
||||||
|
|
||||||
return None
|
if pix:
|
||||||
|
try:
|
||||||
|
return gtk.gdk.pixbuf_new_from_file(deluge.common.get_pixmap("%s16.png" % pix))
|
||||||
|
except glib.GError as e:
|
||||||
|
log.warning(e)
|
||||||
|
return self.get_transparent_pix(16, 16)
|
||||||
|
|
||||||
|
def get_transparent_pix(self, width, height):
|
||||||
|
pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height)
|
||||||
|
pix.fill(0x0000000)
|
||||||
|
return pix
|
||||||
|
|
||||||
def set_row_image(self, cat, value, filename):
|
def set_row_image(self, cat, value, filename):
|
||||||
pix = None
|
pix = None
|
||||||
|
@ -262,8 +302,7 @@ class FilterTreeView(component.Component):
|
||||||
log.debug(e)
|
log.debug(e)
|
||||||
|
|
||||||
if not pix:
|
if not pix:
|
||||||
pix = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 16, 16)
|
pix = self.get_transparent_pix(16, 16)
|
||||||
pix.fill(0x00000000)
|
|
||||||
row = self.filters[(cat, value)]
|
row = self.filters[(cat, value)]
|
||||||
self.treestore.set_value(row, 4, pix)
|
self.treestore.set_value(row, 4, pix)
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue