From 382a99ad61b64ba9bc54b358d6b9a044c1a7868a Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Sat, 12 Dec 2015 17:59:28 +0000 Subject: [PATCH] [GTKUI] Cleanup code duplication in Tabs --- deluge/tests/test_torrent.py | 1 - deluge/ui/gtkui/details_tab.py | 12 +----------- deluge/ui/gtkui/status_tab.py | 11 +---------- deluge/ui/gtkui/torrentdetails.py | 15 ++++++++++++++- deluge/ui/gtkui/trackers_tab.py | 11 +---------- 5 files changed, 17 insertions(+), 33 deletions(-) diff --git a/deluge/tests/test_torrent.py b/deluge/tests/test_torrent.py index 9e31ab408..ce9e2afe5 100644 --- a/deluge/tests/test_torrent.py +++ b/deluge/tests/test_torrent.py @@ -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 diff --git a/deluge/ui/gtkui/details_tab.py b/deluge/ui/gtkui/details_tab.py index 567727c1b..55006cd65 100644 --- a/deluge/ui/gtkui/details_tab.py +++ b/deluge/ui/gtkui/details_tab.py @@ -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('%s' % (txt, txt)) diff --git a/deluge/ui/gtkui/status_tab.py b/deluge/ui/gtkui/status_tab.py index e4a8f5be8..7cf131c0f 100644 --- a/deluge/ui/gtkui/status_tab.py +++ b/deluge/ui/gtkui/status_tab.py @@ -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) diff --git a/deluge/ui/gtkui/torrentdetails.py b/deluge/ui/gtkui/torrentdetails.py index fee1a56d1..29401b2c8 100644 --- a/deluge/ui/gtkui/torrentdetails.py +++ b/deluge/ui/gtkui/torrentdetails.py @@ -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): diff --git a/deluge/ui/gtkui/trackers_tab.py b/deluge/ui/gtkui/trackers_tab.py index c971c804a..e61a1639d 100644 --- a/deluge/ui/gtkui/trackers_tab.py +++ b/deluge/ui/gtkui/trackers_tab.py @@ -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)