From 399304b8d4b484e1def63bf09ed3f2e58c839346 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Sun, 5 Oct 2008 16:04:11 +0000 Subject: [PATCH] rename the graph plugin to the stats plugin --- deluge/plugins/graph/create_dev_link.sh | 6 -- deluge/plugins/stats/create_dev_link.sh | 6 ++ deluge/plugins/{graph => stats}/setup.py | 12 ++-- .../{graph/graph => stats/stats}/__init__.py | 0 .../{graph/graph => stats/stats}/core.py | 4 +- .../graph => stats/stats}/data/config.glade | 0 .../{graph/graph => stats/stats}/graph.py | 31 ++++++---- .../{graph/graph => stats/stats}/gtkui.py | 62 +++++++++++++++---- .../graph => stats/stats}/template/graph.html | 0 .../{graph/graph => stats/stats}/test.html | 0 .../{graph/graph => stats/stats}/test.py | 0 .../graph => stats/stats}/test_total.py | 0 .../{graph/graph => stats/stats}/webui.py | 10 +-- 13 files changed, 90 insertions(+), 41 deletions(-) delete mode 100755 deluge/plugins/graph/create_dev_link.sh create mode 100755 deluge/plugins/stats/create_dev_link.sh rename deluge/plugins/{graph => stats}/setup.py (90%) rename deluge/plugins/{graph/graph => stats/stats}/__init__.py (100%) rename deluge/plugins/{graph/graph => stats/stats}/core.py (97%) rename deluge/plugins/{graph/graph => stats/stats}/data/config.glade (100%) rename deluge/plugins/{graph/graph => stats/stats}/graph.py (91%) rename deluge/plugins/{graph/graph => stats/stats}/gtkui.py (53%) rename deluge/plugins/{graph/graph => stats/stats}/template/graph.html (100%) rename deluge/plugins/{graph/graph => stats/stats}/test.html (100%) rename deluge/plugins/{graph/graph => stats/stats}/test.py (100%) rename deluge/plugins/{graph/graph => stats/stats}/test_total.py (100%) rename deluge/plugins/{graph/graph => stats/stats}/webui.py (93%) diff --git a/deluge/plugins/graph/create_dev_link.sh b/deluge/plugins/graph/create_dev_link.sh deleted file mode 100755 index 0001a4273..000000000 --- a/deluge/plugins/graph/create_dev_link.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -mkdir temp -export PYTHONPATH=./temp -python setup.py build develop --install-dir ./temp -cp ./temp/Graph.egg-link ~/.config/deluge/plugins -rm -fr ./temp diff --git a/deluge/plugins/stats/create_dev_link.sh b/deluge/plugins/stats/create_dev_link.sh new file mode 100755 index 000000000..35e5c2a5c --- /dev/null +++ b/deluge/plugins/stats/create_dev_link.sh @@ -0,0 +1,6 @@ +#!/bin/bash +mkdir temp +export PYTHONPATH=./temp +python setup.py develop --install-dir ./temp +cp ./temp/Stats.egg-link ~/.config/deluge/plugins +rm -fr ./temp diff --git a/deluge/plugins/graph/setup.py b/deluge/plugins/stats/setup.py similarity index 90% rename from deluge/plugins/graph/setup.py rename to deluge/plugins/stats/setup.py index 401c64572..682a1fd63 100644 --- a/deluge/plugins/graph/setup.py +++ b/deluge/plugins/stats/setup.py @@ -39,18 +39,18 @@ from setuptools import setup __author__ = "Martijn Voncken " setup( - name="Graph", + name="Stats", version="0.1", description=__doc__, author=__author__, - packages=["graph"], - package_data = {"graph": ["template/*","data/*"]}, + packages=["stats"], + package_data = {"stats": ["template/*","data/*"]}, entry_points=""" [deluge.plugin.core] - Graph = graph:CorePlugin + Stats = stats:CorePlugin [deluge.plugin.webui] - Graph = graph:WebUIPlugin + Stats = stats:WebUIPlugin [deluge.plugin.gtkui] - Graph = graph:GtkUIPlugin + Stats = stats:GtkUIPlugin """ ) diff --git a/deluge/plugins/graph/graph/__init__.py b/deluge/plugins/stats/stats/__init__.py similarity index 100% rename from deluge/plugins/graph/graph/__init__.py rename to deluge/plugins/stats/stats/__init__.py diff --git a/deluge/plugins/graph/graph/core.py b/deluge/plugins/stats/stats/core.py similarity index 97% rename from deluge/plugins/graph/graph/core.py rename to deluge/plugins/stats/stats/core.py index 9cb9ae410..78c085324 100644 --- a/deluge/plugins/graph/graph/core.py +++ b/deluge/plugins/stats/stats/core.py @@ -62,8 +62,8 @@ class Core(CorePluginBase): self.core = component.get("Core") self.stats ={} - self.config = configmanager.ConfigManager("graph.conf", DEFAULT_PREFS) - self.saved_stats = configmanager.ConfigManager("graph.totals", DEFAULT_TOTALS) + self.config = configmanager.ConfigManager("stats.conf", DEFAULT_PREFS) + self.saved_stats = configmanager.ConfigManager("stats.totals", DEFAULT_TOTALS) if self.totals == {}: self.totals.update(self.saved_stats.config) diff --git a/deluge/plugins/graph/graph/data/config.glade b/deluge/plugins/stats/stats/data/config.glade similarity index 100% rename from deluge/plugins/graph/graph/data/config.glade rename to deluge/plugins/stats/stats/data/config.glade diff --git a/deluge/plugins/graph/graph/graph.py b/deluge/plugins/stats/stats/graph.py similarity index 91% rename from deluge/plugins/graph/graph/graph.py rename to deluge/plugins/stats/stats/graph.py index 9363d25ef..709aabc23 100644 --- a/deluge/plugins/graph/graph/graph.py +++ b/deluge/plugins/stats/stats/graph.py @@ -35,12 +35,9 @@ """ port of old plugin by markybob. """ -import cairo -import math -from deluge.log import LOG as log -import deluge.common import time -from datetime import datetime +import cairo +from deluge.log import LOG as log from deluge.ui.client import aclient black = (0, 0, 0) @@ -94,8 +91,8 @@ class Graph: } def async_request(self): - aclient.graph_get_stats(self.set_stats, self.stat_info.keys()) - aclient.graph_get_config(self.set_config) + aclient.stats_get_stats(self.set_stats, self.stat_info.keys()) + aclient.stats_get_config(self.set_config) def set_stats(self, stats): self.stats = stats @@ -103,6 +100,17 @@ class Graph: def set_config(self, config): self.length = config["length"] self.interval = config["update_interval"] + + def draw_to_context(self, context, width, height): + self.ctx = context + self.width, self.height = width, height + self.draw_rect(white, 0, 0, self.width, self.height) + self.draw_x_axis() + self.draw_left_axis() + + if self.legend_selected: + self.draw_legend() + return self.ctx def draw(self, width, height): self.width = width @@ -155,14 +163,15 @@ class Graph: max_value = self.left_axis['min'] height = self.height - self.line_size - 22 - high = float(max_value) - ratio = height / high + #max_value = float(round(max_value, len(str(max_value)) * -1)) + max_value = float(max_value) + ratio = height / max_value for i in xrange(1, 6): - y = int(ratio * ((high / 5) * i)) - 0.5 + y = int(ratio * ((max_value / 5) * i)) - 0.5 if i < 5: self.draw_dotted_line(gray, 60, y, self.width, y) - text = self.left_axis['formatter']((high / 5) * (5 - i)) + text = self.left_axis['formatter']((max_value / 5) * (5 - i)) self.draw_text(text, 0, y - 6) self.draw_dotted_line(gray, 60.5, 20, 60.5, self.height - 20) diff --git a/deluge/plugins/graph/graph/gtkui.py b/deluge/plugins/stats/stats/gtkui.py similarity index 53% rename from deluge/plugins/graph/graph/gtkui.py rename to deluge/plugins/stats/stats/gtkui.py index 933a2ade4..70f7e2977 100644 --- a/deluge/plugins/graph/graph/gtkui.py +++ b/deluge/plugins/stats/stats/gtkui.py @@ -34,37 +34,77 @@ # but you are not obligated to do so. If you do not wish to do so, delete # this exception statement from your version. If you delete this exception -from deluge.log import LOG as log -from deluge.ui.client import aclient import gtk +import gobject +from gtk.glade import XML + +import graph +from deluge import component +from deluge.log import LOG as log +from deluge.common import fspeed +from deluge.ui.client import aclient +from deluge.ui.gtkui.torrentdetails import Tab + +class GraphsTab(Tab): + def __init__(self, glade): + Tab.__init__(self) + self._name = 'Graphs' + 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.bandwidth_graph = self.glade.get_widget('bandwidth_graph') + self.bandwidth_graph.connect('expose_event', self.bandwidth_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('download_rate', color=graph.green) + self.graph.add_stat('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 + context = self.graph_widget.window.cairo_create() + self.graph.async_request() + aclient.force_call(True) + self.graph.draw_to_context(context, width, height) + return True class GtkUI(object): def __init__(self, plugin_api, plugin_name): - log.debug("Calling Graph UI init") + log.debug("Calling Stats UI init") self.plugin = plugin_api def enable(self): - self.glade = gtk.glade.XML(self.get_resource("config.glade")) - - self.plugin.add_preferences_page("Graph", self.glade.get_widget("prefs_box")) + self.glade = XML(self.get_resource("config.glade")) + self.plugin.add_preferences_page("Stats", self.glade.get_widget("prefs_box")) self.plugin.register_hook("on_apply_prefs", self.on_apply_prefs) self.plugin.register_hook("on_show_prefs", self.on_show_prefs) self.on_show_prefs() + + 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) def disable(self): - self.plugin.remove_preferences_page("Graph") + self.plugin.remove_preferences_page("Stats") self.plugin.deregister_hook("on_apply_prefs", self.on_apply_prefs) self.plugin.deregister_hook("on_show_prefs", self.on_show_prefs) def on_apply_prefs(self): - log.debug("applying prefs for Graph") + log.debug("applying prefs for Stats") config = { "test":self.glade.get_widget("txt_test").get_text() } - aclient.graph_set_config(None, config) + aclient.stats_set_config(None, config) def on_show_prefs(self): - aclient.graph_get_config(self.cb_get_config) + aclient.stats_get_config(self.cb_get_config) def cb_get_config(self, config): "callback for on show_prefs" @@ -72,4 +112,4 @@ class GtkUI(object): def get_resource(self, filename): import pkg_resources, os - return pkg_resources.resource_filename("graph", os.path.join("data", filename)) + return pkg_resources.resource_filename("stats", os.path.join("data", filename)) diff --git a/deluge/plugins/graph/graph/template/graph.html b/deluge/plugins/stats/stats/template/graph.html similarity index 100% rename from deluge/plugins/graph/graph/template/graph.html rename to deluge/plugins/stats/stats/template/graph.html diff --git a/deluge/plugins/graph/graph/test.html b/deluge/plugins/stats/stats/test.html similarity index 100% rename from deluge/plugins/graph/graph/test.html rename to deluge/plugins/stats/stats/test.html diff --git a/deluge/plugins/graph/graph/test.py b/deluge/plugins/stats/stats/test.py similarity index 100% rename from deluge/plugins/graph/graph/test.py rename to deluge/plugins/stats/stats/test.py diff --git a/deluge/plugins/graph/graph/test_total.py b/deluge/plugins/stats/stats/test_total.py similarity index 100% rename from deluge/plugins/graph/graph/test_total.py rename to deluge/plugins/stats/stats/test_total.py diff --git a/deluge/plugins/graph/graph/webui.py b/deluge/plugins/stats/stats/webui.py similarity index 93% rename from deluge/plugins/graph/graph/webui.py rename to deluge/plugins/stats/stats/webui.py index 4e6dac027..75636d092 100644 --- a/deluge/plugins/graph/graph/webui.py +++ b/deluge/plugins/stats/stats/webui.py @@ -49,7 +49,7 @@ forms = api.forms class graph_page: @api.deco.deluge_page def GET(self, args): - return api.render.graph.graph() + return api.render.stats.graph() class network_png: @api.deco.check_session @@ -103,12 +103,12 @@ class WebUI(WebUIPluginBase): ] def enable(self): - api.config_page_manager.register('plugins', 'graph' ,ConfigForm) - api.menu_manager.register_admin_page("graph", _("Graph"), "/graph") #<--top menu + api.config_page_manager.register('plugins', 'stats' ,ConfigForm) + api.menu_manager.register_admin_page("stats", _("Stats"), "/graph") #<--top menu def disable(self): - api.config_page_manager.deregister('graph2') - api.menu_manager.deregister_admin_page("graph2") #<--top menu + api.config_page_manager.deregister('stats') + api.menu_manager.deregister_admin_page("stats") #<--top menu class ConfigForm(forms.Form):