Use new method to add plugin tab
Stop graph tearing Patches from Ian Martin
This commit is contained in:
parent
9a0b6030e6
commit
b680ff48e5
|
@ -1,6 +1,7 @@
|
||||||
#
|
#
|
||||||
# core.py
|
# core.py
|
||||||
#
|
#
|
||||||
|
# Copyright (C) 2009 Ian Martin <ianmartin@cantab.net>
|
||||||
# Copyright (C) 2008 Damien Churchill <damoxc@gmail.com>
|
# Copyright (C) 2008 Damien Churchill <damoxc@gmail.com>
|
||||||
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
|
# Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com>
|
||||||
# Copyright (C) Marcos Pinto 2007 <markybob@gmail.com>
|
# Copyright (C) Marcos Pinto 2007 <markybob@gmail.com>
|
||||||
|
@ -44,6 +45,7 @@
|
||||||
# this exception statement from your version. If you delete this exception
|
# this exception statement from your version. If you delete this exception
|
||||||
|
|
||||||
from twisted.internet.task import LoopingCall
|
from twisted.internet.task import LoopingCall
|
||||||
|
import time
|
||||||
|
|
||||||
import deluge
|
import deluge
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
@ -111,6 +113,7 @@ class Core(CorePluginBase):
|
||||||
for stat_list in self.stats.values():
|
for stat_list in self.stats.values():
|
||||||
if len(stat_list) > self.config["length"]:
|
if len(stat_list) > self.config["length"]:
|
||||||
stat_list.pop()
|
stat_list.pop()
|
||||||
|
self.last_update = time.time()
|
||||||
|
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
@ -132,6 +135,7 @@ class Core(CorePluginBase):
|
||||||
for key in keys:
|
for key in keys:
|
||||||
if key in self.stats:
|
if key in self.stats:
|
||||||
stats_dict[key] = self.stats[key]
|
stats_dict[key] = self.stats[key]
|
||||||
|
stats_dict["_last_update"] = self.last_update
|
||||||
return stats_dict
|
return stats_dict
|
||||||
|
|
||||||
@export
|
@export
|
||||||
|
|
|
@ -85,7 +85,7 @@ class Graph:
|
||||||
self.legend_selected = True
|
self.legend_selected = True
|
||||||
self.max_selected = True
|
self.max_selected = True
|
||||||
self.black = (0, 0 , 0,)
|
self.black = (0, 0 , 0,)
|
||||||
self.interval = 2000 # 2 secs
|
self.interval = 2 # 2 secs
|
||||||
self.text_bg = (255, 255 , 255, 128) # prototyping
|
self.text_bg = (255, 255 , 255, 128) # prototyping
|
||||||
self.set_left_axis()
|
self.set_left_axis()
|
||||||
|
|
||||||
|
@ -102,6 +102,9 @@ class Graph:
|
||||||
}
|
}
|
||||||
|
|
||||||
def set_stats(self, stats):
|
def set_stats(self, stats):
|
||||||
|
self.last_update = stats["_last_update"]
|
||||||
|
log.debug("Last update: %s" % self.last_update)
|
||||||
|
del stats["_last_update"]
|
||||||
self.stats = stats
|
self.stats = stats
|
||||||
|
|
||||||
def set_config(self, config):
|
def set_config(self, config):
|
||||||
|
@ -137,9 +140,8 @@ class Graph:
|
||||||
return self.surface
|
return self.surface
|
||||||
|
|
||||||
def draw_x_axis(self):
|
def draw_x_axis(self):
|
||||||
now = time.time()
|
duration = float(self.length * self.interval)
|
||||||
duration = self.length * (self.interval / 1000.0)
|
start = self.last_update - duration
|
||||||
start = now - duration
|
|
||||||
ratio = (self.width - 40) / duration
|
ratio = (self.width - 40) / duration
|
||||||
seconds_to_minute = 60 - time.localtime(start)[5]
|
seconds_to_minute = 60 - time.localtime(start)[5]
|
||||||
|
|
||||||
|
|
|
@ -65,26 +65,35 @@ class GraphsTab(Tab):
|
||||||
self._name = 'Graphs'
|
self._name = 'Graphs'
|
||||||
self.glade = glade
|
self.glade = glade
|
||||||
self.window = self.glade.get_widget('graph_tab')
|
self.window = self.glade.get_widget('graph_tab')
|
||||||
|
self._child_widget = self.window
|
||||||
self.notebook = self.glade.get_widget('graph_notebook')
|
self.notebook = self.glade.get_widget('graph_notebook')
|
||||||
self.label = self.glade.get_widget('graph_label')
|
self.label = self.glade.get_widget('graph_label')
|
||||||
|
self._tab_label = self.label
|
||||||
self.bandwidth_graph = self.glade.get_widget('bandwidth_graph')
|
self.bandwidth_graph = self.glade.get_widget('bandwidth_graph')
|
||||||
self.bandwidth_graph.connect('expose_event', self.bandwidth_expose)
|
self.bandwidth_graph.connect('expose_event', self.expose)
|
||||||
self.window.unparent()
|
self.window.unparent()
|
||||||
self.label.unparent()
|
self.label.unparent()
|
||||||
|
|
||||||
def bandwidth_expose(self, widget, event):
|
|
||||||
self.graph_widget = self.bandwidth_graph
|
self.graph_widget = self.bandwidth_graph
|
||||||
self.graph = graph.Graph()
|
self.graph = graph.Graph()
|
||||||
self.graph.add_stat('payload_download_rate', label='Download Rate', color=graph.green)
|
self.graph.add_stat('payload_download_rate', label='Download Rate', color=graph.green)
|
||||||
self.graph.add_stat('payload_upload_rate', label='Upload Rate', color=graph.blue)
|
self.graph.add_stat('payload_upload_rate', label='Upload Rate', color=graph.blue)
|
||||||
self.graph.set_left_axis(formatter=fspeed, min=10240)
|
self.graph.set_left_axis(formatter=fspeed, min=10240)
|
||||||
self.update_timer = gobject.timeout_add(2000, self.update_graph)
|
|
||||||
self.update_graph()
|
|
||||||
|
|
||||||
def update_graph(self):
|
def expose(self, widget, event):
|
||||||
width, height = self.graph_widget.allocation.width, self.graph_widget.allocation.height
|
"""Redraw"""
|
||||||
context = self.graph_widget.window.cairo_create()
|
context = self.graph_widget.window.cairo_create()
|
||||||
|
# set a clip region
|
||||||
|
context.rectangle(event.area.x, event.area.y,
|
||||||
|
event.area.width, event.area.height)
|
||||||
|
context.clip()
|
||||||
|
|
||||||
|
width, height = self.graph_widget.allocation.width, self.graph_widget.allocation.height
|
||||||
|
self.graph.draw_to_context(context, width, height)
|
||||||
|
#Do not propagate the event
|
||||||
|
return False
|
||||||
|
|
||||||
|
def update(self):
|
||||||
log.debug("getstat keys: %s", self.graph.stat_info.keys())
|
log.debug("getstat keys: %s", self.graph.stat_info.keys())
|
||||||
d1 = client.stats.get_stats(self.graph.stat_info.keys())
|
d1 = client.stats.get_stats(self.graph.stat_info.keys())
|
||||||
d1.addCallback(self.graph.set_stats)
|
d1.addCallback(self.graph.set_stats)
|
||||||
|
@ -92,14 +101,21 @@ class GraphsTab(Tab):
|
||||||
d2.addCallback(self.graph.set_config)
|
d2.addCallback(self.graph.set_config)
|
||||||
dl = defer.DeferredList([d1, d2])
|
dl = defer.DeferredList([d1, d2])
|
||||||
|
|
||||||
def draw_context(result):
|
def _on_update(result):
|
||||||
self.graph.draw_to_context(context, width, height)
|
width, height = self.graph_widget.allocation.width, self.graph_widget.allocation.height
|
||||||
dl.addCallback(draw_context)
|
rect = gtk.gdk.Rectangle(0, 0, width, height)
|
||||||
|
self.graph_widget.window.invalidate_rect(rect, True)
|
||||||
|
|
||||||
|
dl.addCallback(_on_update)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
class GtkUI(GtkPluginBase):
|
class GtkUI(GtkPluginBase):
|
||||||
def enable(self):
|
def enable(self):
|
||||||
|
log.debug("Stats plugin enable called")
|
||||||
self.glade = XML(self.get_resource("config.glade"))
|
self.glade = XML(self.get_resource("config.glade"))
|
||||||
component.get("Preferences").add_page("Stats", self.glade.get_widget("prefs_box"))
|
component.get("Preferences").add_page("Stats", self.glade.get_widget("prefs_box"))
|
||||||
component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs)
|
component.get("PluginManager").register_hook("on_apply_prefs", self.on_apply_prefs)
|
||||||
|
@ -108,12 +124,13 @@ class GtkUI(GtkPluginBase):
|
||||||
|
|
||||||
self.graphs_tab = GraphsTab(XML(self.get_resource("tabs.glade")))
|
self.graphs_tab = GraphsTab(XML(self.get_resource("tabs.glade")))
|
||||||
self.torrent_details = component.get('TorrentDetails')
|
self.torrent_details = component.get('TorrentDetails')
|
||||||
self.torrent_details.notebook.append_page(self.graphs_tab.window, self.graphs_tab.label)
|
self.torrent_details.add_tab(self.graphs_tab)
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
component.get("Preferences").remove_page("Stats")
|
component.get("Preferences").remove_page("Stats")
|
||||||
component.get("PluginManager").deregister_hook("on_apply_prefs", self.on_apply_prefs)
|
component.get("PluginManager").deregister_hook("on_apply_prefs", self.on_apply_prefs)
|
||||||
component.get("PluginManager").deregister_hook("on_show_prefs", self.on_show_prefs)
|
component.get("PluginManager").deregister_hook("on_show_prefs", self.on_show_prefs)
|
||||||
|
self.torrent_details.remove_tab(self.graphs_tab.get_name())
|
||||||
|
|
||||||
def on_apply_prefs(self):
|
def on_apply_prefs(self):
|
||||||
log.debug("applying prefs for Stats")
|
log.debug("applying prefs for Stats")
|
||||||
|
|
Loading…
Reference in New Issue