From 676574ff1953647fd2989f035889dbd0eb7b2238 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Fri, 17 Mar 2017 23:35:36 +0000 Subject: [PATCH] [Stats] Update gtkui from libglade to gtkbuilder - Additionally fixes #2977 num_connections KeyError and #2947 AttributeError. --- .../Stats/deluge/plugins/stats/core.py | 8 +- .../stats/data/{config.glade => config.ui} | 131 ++++++++++-------- .../stats/data/{tabs.glade => tabs.ui} | 118 ++++++++-------- .../Stats/deluge/plugins/stats/gtkui.py | 45 +++--- 4 files changed, 171 insertions(+), 131 deletions(-) rename deluge/plugins/Stats/deluge/plugins/stats/data/{config.glade => config.ui} (75%) rename deluge/plugins/Stats/deluge/plugins/stats/data/{tabs.glade => tabs.ui} (60%) diff --git a/deluge/plugins/Stats/deluge/plugins/stats/core.py b/deluge/plugins/Stats/deluge/plugins/stats/core.py index 6b03e762f..59394d4bb 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/core.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/core.py @@ -77,14 +77,15 @@ class Core(CorePluginBase): self.length = self.config['length'] # self.stats = get_key(self.saved_stats, 'stats') or {} - self.stats_keys = [] + self.stats_keys = ['peer.num_peers_half_open', 'dht.dht_node_cache'] self.add_stats( 'upload_rate', 'download_rate', 'dht_nodes', - 'dht_node_cache', + 'dht_cache_nodes', 'dht_torrents', 'num_peers', + 'num_connections' ) self.update_stats() @@ -122,7 +123,8 @@ class Core(CorePluginBase): stats.update(self.core.get_session_status([key])) except AttributeError: pass - stats['num_connections'] = stats['num_peers'] + stats['num_connections'] = stats['num_peers'] + stats['peer.num_peers_half_open'] + stats['dht_cache_nodes'] = stats['dht.dht_node_cache'] stats.update(self.core.get_config_values(['max_download', 'max_upload', 'max_num_connections'])) diff --git a/deluge/plugins/Stats/deluge/plugins/stats/data/config.glade b/deluge/plugins/Stats/deluge/plugins/stats/data/config.ui similarity index 75% rename from deluge/plugins/Stats/deluge/plugins/stats/data/config.glade rename to deluge/plugins/Stats/deluge/plugins/stats/data/config.ui index 858acd767..68958c15a 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/data/config.glade +++ b/deluge/plugins/Stats/deluge/plugins/stats/data/config.ui @@ -1,34 +1,39 @@ - - - + + + - + + False - + True - vertical + False - + True + False 0 none - + True + False 15 - + True + False 10 2 15 - + + False True True True #000000000000 - + 1 2 @@ -38,34 +43,37 @@ - + True + False 0 Download color: - + 1 2 - + True + False 0 Upload color: - + 2 3 - + + False True True True #000000000000 - + 1 2 @@ -75,12 +83,13 @@ - + True + False 0 <b>Connections Graph</b> True - + 2 3 @@ -88,23 +97,25 @@ - + True + False 0 <b>Bandwidth Graph</b> True - + 2 - + + False True True True #000000000000 - + 1 2 @@ -114,23 +125,25 @@ - + True + False 0 DHT nodes: - + 4 5 - + + False True True True #000000000000 - + 1 2 @@ -140,45 +153,49 @@ - + True + False 0 Cached DHT nodes: - + 5 6 - + True + False 0 DHT torrents: - + 6 7 - + True + False 0 Connections: - + 7 8 - + + False True True True #000000000000 - + 1 2 @@ -188,12 +205,13 @@ - + + False True True True #000000000000 - + 1 2 @@ -203,12 +221,13 @@ - + True + False 0 <b>Seeds / Peers</b> True - + 2 8 @@ -216,12 +235,13 @@ - + + False True True True #000000000000 - + 1 2 @@ -231,36 +251,37 @@ - + True + False 0 Peers: - + 9 10 - + - + - - + + True + False <b>Graph Colors</b> True - - - label_item - + - + + True + True 0 - + - - + + diff --git a/deluge/plugins/Stats/deluge/plugins/stats/data/tabs.glade b/deluge/plugins/Stats/deluge/plugins/stats/data/tabs.ui similarity index 60% rename from deluge/plugins/Stats/deluge/plugins/stats/data/tabs.glade rename to deluge/plugins/Stats/deluge/plugins/stats/data/tabs.ui index 8732caeaf..bf6332a11 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/data/tabs.glade +++ b/deluge/plugins/Stats/deluge/plugins/stats/data/tabs.ui @@ -1,60 +1,62 @@ - - + + - + + False - + True + False - + True + False - + True - gtk-page-setup - + False + Stats + + True + True 0 - - - True - Graphs - - - 1 - - - + + True + True 0 - + True True automatic automatic - + True + False queue none - + True - vertical + False - + True + False - + True + False Resolution - + False False @@ -62,16 +64,17 @@ - + True - + False + False False 1 - + False False @@ -79,78 +82,85 @@ - + True True left - + True - + False + - - + + True + False Bandwidth - + False - tab - + True - + False + 1 - - + + True + False Connections - + 1 False - tab - + True - + False + 2 - - + + True + False Seeds/Peers - + 2 False - tab - + + True + True 1 - + - + - + + True + True 1 - + - - + + diff --git a/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py b/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py index a9b8452a0..2409206c7 100644 --- a/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py +++ b/deluge/plugins/Stats/deluge/plugins/stats/gtkui.py @@ -17,8 +17,6 @@ from __future__ import division, unicode_literals import logging import gtk -import gtk.glade -from gtk.glade import XML import deluge from deluge import component @@ -27,7 +25,7 @@ from deluge.plugins.pluginbase import GtkPluginBase from deluge.ui.client import client from deluge.ui.gtkui.torrentdetails import Tab -from . import common +from .common import get_resource from .graph import Graph, size_formatter_scale log = logging.getLogger(__name__) @@ -69,6 +67,10 @@ def int_str(number): return str(int(number)) +def fspeed_shortform(value): + return fspeed(value, shortform=True) + + def gtk_to_graph_color(color): """Turns a gtk.gdk.Color into a tuple with range 0-1 as used by the graph""" gtk_color = gtk.gdk.Color(color) @@ -79,26 +81,28 @@ def gtk_to_graph_color(color): class GraphsTab(Tab): - def __init__(self, glade, colors): + def __init__(self, colors): super(GraphsTab, self).__init__() - self.glade = glade - self.window = self.glade.get_widget('graph_tab') - self.notebook = self.glade.get_widget('graph_notebook') - self.label = self.glade.get_widget('graph_label') - self._name = 'Graphs' + builder = gtk.Builder() + builder.add_from_file(get_resource('tabs.ui')) + self.window = builder.get_object('graph_tab') + self.notebook = builder.get_object('graph_notebook') + self.label = builder.get_object('graph_label') + + self._name = 'Stats' self._child_widget = self.window self._tab_label = self.label self.colors = colors - self.bandwidth_graph = self.glade.get_widget('bandwidth_graph') + self.bandwidth_graph = builder.get_object('bandwidth_graph') self.bandwidth_graph.connect('expose_event', self.graph_expose) - self.connections_graph = self.glade.get_widget('connections_graph') + self.connections_graph = builder.get_object('connections_graph') self.connections_graph.connect('expose_event', self.graph_expose) - self.seeds_graph = self.glade.get_widget('seeds_graph') + self.seeds_graph = builder.get_object('seeds_graph') self.seeds_graph.connect('expose_event', self.graph_expose) self.notebook.connect('switch-page', self._on_notebook_switch_page) @@ -110,7 +114,7 @@ class GraphsTab(Tab): self.label.unparent() self.intervals = None - self.intervals_combo = self.glade.get_widget('combo_intervals') + self.intervals_combo = builder.get_object('combo_intervals') cell = gtk.CellRendererText() self.intervals_combo.pack_start(cell, True) self.intervals_combo.set_cell_data_func(cell, neat_time) @@ -153,7 +157,7 @@ class GraphsTab(Tab): color=gtk_to_graph_color(colors['download_rate'])) self.graph.add_stat('upload_rate', label='Upload Rate', color=gtk_to_graph_color(colors['upload_rate'])) - self.graph.set_left_axis(formatter=fspeed, min=10240, + self.graph.set_left_axis(formatter=fspeed_shortform, min=10240, formatter_scale=size_formatter_scale) def select_connections_graph(self): @@ -221,13 +225,16 @@ class GtkUI(GtkPluginBase): def enable(self): log.debug('Stats plugin enable called') self.config = deluge.configmanager.ConfigManager('stats.gtkui.conf', DEFAULT_CONF) - self.glade = XML(common.get_resource('config.glade')) - component.get('Preferences').add_page('Stats', self.glade.get_widget('prefs_box')) + + self.builder = gtk.Builder() + self.builder.add_from_file(get_resource('config.ui')) + + component.get('Preferences').add_page('Stats', self.builder.get_object('prefs_box')) component.get('PluginManager').register_hook('on_apply_prefs', self.on_apply_prefs) component.get('PluginManager').register_hook('on_show_prefs', self.on_show_prefs) self.on_show_prefs() - self.graphs_tab = GraphsTab(XML(common.get_resource('tabs.glade')), self.config['colors']) + self.graphs_tab = GraphsTab(self.config['colors']) self.torrent_details = component.get('TorrentDetails') self.torrent_details.add_tab(self.graphs_tab) @@ -244,7 +251,7 @@ class GtkUI(GtkPluginBase): gtkconf[graph] = {} for value, color in colors.items(): try: - color_btn = self.glade.get_widget('%s_%s_color' % (graph, value)) + color_btn = self.builder.get_object('%s_%s_color' % (graph, value)) gtkconf[graph][value] = str(color_btn.get_color()) except Exception: gtkconf[graph][value] = DEFAULT_CONF['colors'][graph][value] @@ -258,7 +265,7 @@ class GtkUI(GtkPluginBase): for graph, colors in self.config['colors'].items(): for value, color in colors.items(): try: - color_btn = self.glade.get_widget('%s_%s_color' % (graph, value)) + color_btn = self.builder.get_object('%s_%s_color' % (graph, value)) color_btn.set_color(gtk.gdk.Color(color)) except Exception: log.debug('Unable to set %s %s %s', graph, value, color)