rename the graph plugin to the stats plugin
This commit is contained in:
parent
90ccd65ea9
commit
399304b8d4
|
@ -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
|
|
|
@ -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
|
|
@ -39,18 +39,18 @@ from setuptools import setup
|
||||||
__author__ = "Martijn Voncken <mvoncken@gmail.com>"
|
__author__ = "Martijn Voncken <mvoncken@gmail.com>"
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="Graph",
|
name="Stats",
|
||||||
version="0.1",
|
version="0.1",
|
||||||
description=__doc__,
|
description=__doc__,
|
||||||
author=__author__,
|
author=__author__,
|
||||||
packages=["graph"],
|
packages=["stats"],
|
||||||
package_data = {"graph": ["template/*","data/*"]},
|
package_data = {"stats": ["template/*","data/*"]},
|
||||||
entry_points="""
|
entry_points="""
|
||||||
[deluge.plugin.core]
|
[deluge.plugin.core]
|
||||||
Graph = graph:CorePlugin
|
Stats = stats:CorePlugin
|
||||||
[deluge.plugin.webui]
|
[deluge.plugin.webui]
|
||||||
Graph = graph:WebUIPlugin
|
Stats = stats:WebUIPlugin
|
||||||
[deluge.plugin.gtkui]
|
[deluge.plugin.gtkui]
|
||||||
Graph = graph:GtkUIPlugin
|
Stats = stats:GtkUIPlugin
|
||||||
"""
|
"""
|
||||||
)
|
)
|
|
@ -62,8 +62,8 @@ class Core(CorePluginBase):
|
||||||
self.core = component.get("Core")
|
self.core = component.get("Core")
|
||||||
self.stats ={}
|
self.stats ={}
|
||||||
|
|
||||||
self.config = configmanager.ConfigManager("graph.conf", DEFAULT_PREFS)
|
self.config = configmanager.ConfigManager("stats.conf", DEFAULT_PREFS)
|
||||||
self.saved_stats = configmanager.ConfigManager("graph.totals", DEFAULT_TOTALS)
|
self.saved_stats = configmanager.ConfigManager("stats.totals", DEFAULT_TOTALS)
|
||||||
if self.totals == {}:
|
if self.totals == {}:
|
||||||
self.totals.update(self.saved_stats.config)
|
self.totals.update(self.saved_stats.config)
|
||||||
|
|
|
@ -35,12 +35,9 @@
|
||||||
"""
|
"""
|
||||||
port of old plugin by markybob.
|
port of old plugin by markybob.
|
||||||
"""
|
"""
|
||||||
import cairo
|
|
||||||
import math
|
|
||||||
from deluge.log import LOG as log
|
|
||||||
import deluge.common
|
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
import cairo
|
||||||
|
from deluge.log import LOG as log
|
||||||
from deluge.ui.client import aclient
|
from deluge.ui.client import aclient
|
||||||
|
|
||||||
black = (0, 0, 0)
|
black = (0, 0, 0)
|
||||||
|
@ -94,8 +91,8 @@ class Graph:
|
||||||
}
|
}
|
||||||
|
|
||||||
def async_request(self):
|
def async_request(self):
|
||||||
aclient.graph_get_stats(self.set_stats, self.stat_info.keys())
|
aclient.stats_get_stats(self.set_stats, self.stat_info.keys())
|
||||||
aclient.graph_get_config(self.set_config)
|
aclient.stats_get_config(self.set_config)
|
||||||
|
|
||||||
def set_stats(self, stats):
|
def set_stats(self, stats):
|
||||||
self.stats = stats
|
self.stats = stats
|
||||||
|
@ -103,6 +100,17 @@ class Graph:
|
||||||
def set_config(self, config):
|
def set_config(self, config):
|
||||||
self.length = config["length"]
|
self.length = config["length"]
|
||||||
self.interval = config["update_interval"]
|
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):
|
def draw(self, width, height):
|
||||||
self.width = width
|
self.width = width
|
||||||
|
@ -155,14 +163,15 @@ class Graph:
|
||||||
max_value = self.left_axis['min']
|
max_value = self.left_axis['min']
|
||||||
|
|
||||||
height = self.height - self.line_size - 22
|
height = self.height - self.line_size - 22
|
||||||
high = float(max_value)
|
#max_value = float(round(max_value, len(str(max_value)) * -1))
|
||||||
ratio = height / high
|
max_value = float(max_value)
|
||||||
|
ratio = height / max_value
|
||||||
|
|
||||||
for i in xrange(1, 6):
|
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:
|
if i < 5:
|
||||||
self.draw_dotted_line(gray, 60, y, self.width, y)
|
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_text(text, 0, y - 6)
|
||||||
self.draw_dotted_line(gray, 60.5, 20, 60.5, self.height - 20)
|
self.draw_dotted_line(gray, 60.5, 20, 60.5, self.height - 20)
|
||||||
|
|
|
@ -34,37 +34,77 @@
|
||||||
# but you are not obligated to do so. If you do not wish to do so, delete
|
# 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
|
# 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 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):
|
class GtkUI(object):
|
||||||
def __init__(self, plugin_api, plugin_name):
|
def __init__(self, plugin_api, plugin_name):
|
||||||
log.debug("Calling Graph UI init")
|
log.debug("Calling Stats UI init")
|
||||||
self.plugin = plugin_api
|
self.plugin = plugin_api
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
self.glade = gtk.glade.XML(self.get_resource("config.glade"))
|
self.glade = XML(self.get_resource("config.glade"))
|
||||||
|
self.plugin.add_preferences_page("Stats", self.glade.get_widget("prefs_box"))
|
||||||
self.plugin.add_preferences_page("Graph", self.glade.get_widget("prefs_box"))
|
|
||||||
self.plugin.register_hook("on_apply_prefs", self.on_apply_prefs)
|
self.plugin.register_hook("on_apply_prefs", self.on_apply_prefs)
|
||||||
self.plugin.register_hook("on_show_prefs", self.on_show_prefs)
|
self.plugin.register_hook("on_show_prefs", self.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):
|
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_apply_prefs", self.on_apply_prefs)
|
||||||
self.plugin.deregister_hook("on_show_prefs", self.on_show_prefs)
|
self.plugin.deregister_hook("on_show_prefs", self.on_show_prefs)
|
||||||
|
|
||||||
def on_apply_prefs(self):
|
def on_apply_prefs(self):
|
||||||
log.debug("applying prefs for Graph")
|
log.debug("applying prefs for Stats")
|
||||||
config = {
|
config = {
|
||||||
"test":self.glade.get_widget("txt_test").get_text()
|
"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):
|
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):
|
def cb_get_config(self, config):
|
||||||
"callback for on show_prefs"
|
"callback for on show_prefs"
|
||||||
|
@ -72,4 +112,4 @@ class GtkUI(object):
|
||||||
|
|
||||||
def get_resource(self, filename):
|
def get_resource(self, filename):
|
||||||
import pkg_resources, os
|
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))
|
|
@ -49,7 +49,7 @@ forms = api.forms
|
||||||
class graph_page:
|
class graph_page:
|
||||||
@api.deco.deluge_page
|
@api.deco.deluge_page
|
||||||
def GET(self, args):
|
def GET(self, args):
|
||||||
return api.render.graph.graph()
|
return api.render.stats.graph()
|
||||||
|
|
||||||
class network_png:
|
class network_png:
|
||||||
@api.deco.check_session
|
@api.deco.check_session
|
||||||
|
@ -103,12 +103,12 @@ class WebUI(WebUIPluginBase):
|
||||||
]
|
]
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
api.config_page_manager.register('plugins', 'graph' ,ConfigForm)
|
api.config_page_manager.register('plugins', 'stats' ,ConfigForm)
|
||||||
api.menu_manager.register_admin_page("graph", _("Graph"), "/graph") #<--top menu
|
api.menu_manager.register_admin_page("stats", _("Stats"), "/graph") #<--top menu
|
||||||
|
|
||||||
def disable(self):
|
def disable(self):
|
||||||
api.config_page_manager.deregister('graph2')
|
api.config_page_manager.deregister('stats')
|
||||||
api.menu_manager.deregister_admin_page("graph2") #<--top menu
|
api.menu_manager.deregister_admin_page("stats") #<--top menu
|
||||||
|
|
||||||
|
|
||||||
class ConfigForm(forms.Form):
|
class ConfigForm(forms.Form):
|
Loading…
Reference in New Issue