Sidebar: Enabled strings for translation and added icons to Trackers filter

This commit is contained in:
Calum Lind 2011-02-11 20:24:27 +00:00
parent f8737777b1
commit 98ca371b15
3 changed files with 59 additions and 20 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 683 B

View File

@ -39,6 +39,7 @@ import gtk
import gtk.glade import gtk.glade
import logging import logging
import pkg_resources import pkg_resources
import glib
import deluge.component as component import deluge.component as component
import deluge.common import deluge.common
@ -58,21 +59,38 @@ STATE_PIX = {
"Active": "active" "Active": "active"
} }
TRACKER_PIX = {
TRANSLATE = { "All": "tracker_all",
"state": "States", "Error": "tracker_warning",
"tracker_host": "Trackers",
"label": "Labels",
"owner": "Owner"
} }
FILTER_COLUMN = 5 def _(message): return message
TRANSLATE = {
"state": _("States"),
"tracker_host": _("Trackers"),
"label": _("Labels"),
"owner": _("Owner"),
"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):
@ -87,7 +105,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)
@ -109,7 +127,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
@ -147,7 +165,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)
@ -155,6 +173,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
@ -211,8 +234,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
@ -231,9 +262,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:
@ -251,11 +279,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
@ -265,8 +305,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