Stop graph tearin...
Content-type: text/plain
Author: andar
Revision: 5810
Log:
Use new method to add plugin tab
Stop graph tearing
Patches from Ian Martin
Diff:
Modified: trunk/deluge/plugins/stats/stats/core.py
===================================================================
--- trunk/deluge/plugins/stats/stats/core.py 2009-10-04 19:24:15 UTC (rev
5809)
+++ trunk/deluge/plugins/stats/stats/core.py 2009-10-04 19:25:10 UTC (rev
5810)
@@ -1,6 +1,7 @@
#
# core.py
#
+# Copyright (C) 2009 Ian Martin <[email protected]>
# Copyright (C) 2008 Damien Churchill <[email protected]>
# Copyright (C) 2008 Martijn Voncken <[email protected]>
# Copyright (C) Marcos Pinto 2007 <[email protected]>
@@ -44,6 +45,7 @@
# this exception statement from your version. If you delete this exception
from twisted.internet.task import LoopingCall
+import time
import deluge
from deluge.log import LOG as log
@@ -111,6 +113,7 @@
for stat_list in self.stats.values():
if len(stat_list) > self.config["length"]:
stat_list.pop()
+ self.last_update = time.time()
except Exception, e:
log.exception(e)
@@ -132,6 +135,7 @@
for key in keys:
if key in self.stats:
stats_dict[key] = self.stats[key]
+ stats_dict["_last_update"] = self.last_update
return stats_dict
@export
Modified: trunk/deluge/plugins/stats/stats/graph.py
===================================================================
--- trunk/deluge/plugins/stats/stats/graph.py 2009-10-04 19:24:15 UTC (rev
5809)
+++ trunk/deluge/plugins/stats/stats/graph.py 2009-10-04 19:25:10 UTC (rev
5810)
@@ -85,7 +85,7 @@
self.legend_selected = True
self.max_selected = True
self.black = (0, 0 , 0,)
- self.interval = 2000 # 2 secs
+ self.interval = 2 # 2 secs
self.text_bg = (255, 255 , 255, 128) # prototyping
self.set_left_axis()
@@ -102,6 +102,9 @@
}
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
def set_config(self, config):
@@ -137,9 +140,8 @@
return self.surface
def draw_x_axis(self):
- now = time.time()
- duration = self.length * (self.interval / 1000.0)
- start = now - duration
+ duration = float(self.length * self.interval)
+ start = self.last_update - duration
ratio = (self.width - 40) / duration
seconds_to_minute = 60 - time.localtime(start)[5]
Modified: trunk/deluge/plugins/stats/stats/gtkui.py
===================================================================
--- trunk/deluge/plugins/stats/stats/gtkui.py 2009-10-04 19:24:15 UTC (rev
5809)
+++ trunk/deluge/plugins/stats/stats/gtkui.py 2009-10-04 19:25:10 UTC (rev
5810)
@@ -65,26 +65,35 @@
self._name = 'Graphs'
self.glade = glade
self.window = self.glade.get_widget('graph_tab')
+ self._child_widget = self.window
self.notebook = self.glade.get_widget('graph_notebook')
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.connect('expose_event', self.bandwidth_expose)
+ self.bandwidth_graph.connect('expose_event', self.expose)
self.window.unparent()
self.label.unparent()
- def bandwidth_expose(self, widget, event):
self.graph_widget = self.bandwidth_graph
self.graph = graph.Graph()
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.set_left_axis(formatter=fspeed, min=10240)
- self.update_timer = gobject.timeout_add(2000, self.update_graph)
- self.update_graph()
- def update_graph(self):
- width, height = self.graph_widget.allocation.width,
self.graph_widget.allocation.height
+ def expose(self, widget, event):
+ """Redraw"""
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())
d1 = client.stats.get_stats(self.graph.stat_info.keys())
d1.addCallback(self.graph.set_stats)
@@ -92,14 +101,21 @@
d2.addCallback(self.graph.set_config)
dl = defer.DeferredList([d1, d2])
- def draw_context(result):
- self.graph.draw_to_context(context, width, height)
- dl.addCallback(draw_context)
+ def _on_update(result):
+ width, height = self.graph_widget.allocation.width,
self.graph_widget.allocation.height
+ rect = gtk.gdk.Rectangle(0, 0, width, height)
+ self.graph_widget.window.invalidate_rect(rect, True)
- return True
+ dl.addCallback(_on_update)
+ def clear(self):
+ pass
+
+
+
class GtkUI(GtkPluginBase):
def enable(self):
+ log.debug("Stats plugin enable called")
self.glade = XML(self.get_resource("config.glade"))
component.get("Preferences").add_page("Stats",
self.glade.get_widget("prefs_box"))
component.get("PluginManager").register_hook("on_apply_prefs",
self.on_apply_prefs)
@@ -108,12 +124,13 @@
self.graphs_tab = GraphsTab(XML(self.get_resource("tabs.glade")))
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):
component.get("Preferences").remove_page("Stats")
component.get("PluginManager").deregister_hook("on_apply_prefs",
self.on_apply_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):
log.debug("applying prefs for Stats")
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---