[GTKUI] Cleanup code duplication in Tabs

This commit is contained in:
Calum Lind 2015-12-12 17:59:28 +00:00
parent 50bde1a607
commit 382a99ad61
5 changed files with 17 additions and 33 deletions

View File

@ -18,7 +18,6 @@ from deluge.core.rpcserver import RPCServer
from deluge.core.torrent import Torrent
from deluge.core.torrentmanager import TorrentState
config_setup = False
core = None
rpcserver = None

View File

@ -84,17 +84,7 @@ class DetailsTab(Tab):
# Update all the label widgets
for widget in self.label_widgets:
if widget[1] is not None:
try:
args = [status[key] for key in widget[2]]
except KeyError as ex:
log.debug("Unable to get status value: %s", ex)
continue
txt = widget[1](*args)
else:
txt = status[widget[2][0]]
txt = xml_escape(txt)
txt = xml_escape(self.get_status_for_widget(widget, status))
if widget[0].get_text() != txt:
if widget[2][0] == "comment" and is_url(txt):
widget[0].set_markup('<a href="%s">%s</a>' % (txt, txt))

View File

@ -123,16 +123,7 @@ class StatusTab(Tab):
# Update all the label widgets
for widget in self.label_widgets:
if widget[1] is not None:
try:
args = [status[key] for key in widget[2]]
except KeyError as ex:
log.debug("Unable to get status value: %s", ex)
continue
txt = widget[1](*args)
else:
txt = status[widget[2][0]]
txt = self.get_status_for_widget(widget, status)
if widget[0].get_text() != txt:
widget[0].set_text(txt)

View File

@ -21,7 +21,7 @@ from deluge.ui.gtkui.common import load_pickled_state_file, save_pickled_state_f
log = logging.getLogger(__name__)
class Tab:
class Tab(object):
def __init__(self):
self.is_visible = True
self.position = -1
@ -45,6 +45,19 @@ class Tab:
return self._tab_label
def get_status_for_widget(self, widget, status):
if widget[1] is None:
txt = status[widget[2][0]]
else:
try:
args = [status[key] for key in widget[2]]
except KeyError as ex:
log.debug("Unable to get status value: %s", ex)
txt = ""
else:
txt = widget[1](*args)
return txt
class TorrentDetails(component.Component):
def __init__(self):

View File

@ -71,16 +71,7 @@ class TrackersTab(Tab):
# Update all the label widgets
for widget in self.label_widgets:
if widget[1] is None:
txt = status[widget[2][0]]
else:
try:
args = [status[key] for key in widget[2]]
except KeyError as ex:
log.debug("Unable to get status value: %s", ex)
continue
txt = widget[1](*args)
txt = self.get_status_for_widget(widget, status)
if widget[0].get_text() != txt:
widget[0].set_text(txt)