revamp networkgraph plugin - Ultrafusion
This commit is contained in:
parent
da8bd07ce7
commit
952f03a6cc
|
@ -14,12 +14,32 @@ def enable(core, interface):
|
|||
|
||||
from NetworkGraph.tab_graph import GraphTabManager
|
||||
|
||||
import gtk
|
||||
import deluge
|
||||
|
||||
class NetworkGraph:
|
||||
def __init__(self, path, core, interface):
|
||||
import gtk
|
||||
self.parent = interface
|
||||
self.location = path
|
||||
self.manager = core
|
||||
self.dialog_initialize = True
|
||||
self.glade = gtk.glade.XML(path + "/graph_preferences.glade")
|
||||
self.dialog = self.glade.get_widget("dialog")
|
||||
self.glade.signal_autoconnect({
|
||||
'on_Reset_Download_released' : self.reset_download,
|
||||
'on_Reset_Upload_released' : self.reset_upload,
|
||||
'on_button_cancel_pressed': self.cancel_pressed,
|
||||
'on_button_ok_pressed': self.ok_pressed
|
||||
})
|
||||
|
||||
self.config_file = deluge.common.CONFIG_DIR + "/graph.conf"
|
||||
self.config = deluge.pref.Preferences(self.config_file, False)
|
||||
try:
|
||||
self.config.load()
|
||||
except IOError:
|
||||
# File does not exist
|
||||
pass
|
||||
|
||||
scrolledWindow = gtk.ScrolledWindow()
|
||||
scrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
image = gtk.Image()
|
||||
|
@ -42,7 +62,9 @@ class NetworkGraph:
|
|||
import pango
|
||||
pangoContext = self.parent.window.get_pango_context()
|
||||
pangoLayout = pango.Layout(pangoContext)
|
||||
|
||||
self.tab_graph = GraphTabManager(scrolledWindow, image, pangoLayout, self.manager)
|
||||
self.update_config()
|
||||
|
||||
def unload(self): # Shutdown is called when the plugin is deactivated
|
||||
numPages = self.parentNotebook.get_n_pages()
|
||||
|
@ -50,13 +72,222 @@ class NetworkGraph:
|
|||
if self.parentNotebook.get_nth_page(page) == self.topWidget:
|
||||
self.parentNotebook.remove_page(page)
|
||||
break
|
||||
self.config.save(self.config_file)
|
||||
|
||||
def configure(self, window):
|
||||
self.dialog_initialize = True
|
||||
try:
|
||||
if self.config.get("enable_down_line"):
|
||||
self.glade.get_widget("Download_Line_Check").set_active(True)
|
||||
else:
|
||||
self.glade.get_widget("Download_Line_Check").set_active(False)
|
||||
|
||||
if self.config.get("enable_down_fill"):
|
||||
self.glade.get_widget("Download_Fill_Check").set_active(True)
|
||||
else:
|
||||
self.glade.get_widget("Download_Fill_Check").set_active(False)
|
||||
|
||||
if self.config.get("enable_up_line"):
|
||||
self.glade.get_widget("Upload_Line_Check").set_active(True)
|
||||
else:
|
||||
self.glade.get_widget("Upload_Line_Check").set_active(False)
|
||||
|
||||
if self.config.get("enable_up_fill"):
|
||||
self.glade.get_widget("Upload_Fill_Check").set_active(True)
|
||||
else:
|
||||
self.glade.get_widget("Upload_Fill_Check").set_active(False)
|
||||
|
||||
if (self.config.get("line_size") > 0) & (self.config.get("line_size") < 6):
|
||||
self.glade.get_widget("Line_Scale").get_adjustment().set_value(self.config.get("line_size"))
|
||||
else:
|
||||
self.glade.get_widget("Line_Scale").get_adjustment().set_value(2);
|
||||
|
||||
if self.config.get("colors_set"):
|
||||
dl_color = self.config.get("down_line_color")
|
||||
df_color = self.config.get("down_fill_color")
|
||||
ul_color = self.config.get("up_line_color")
|
||||
uf_color = self.config.get("up_fill_color")
|
||||
self.glade.get_widget("Download_Line").set_color(gtk.gdk.Color(int(dl_color[0]*65535),int(dl_color[1]*65535),int(dl_color[2]*65535)))
|
||||
self.glade.get_widget("Download_Line").set_alpha(int(dl_color[3]*65535))
|
||||
self.glade.get_widget("Download_Fill").set_color(gtk.gdk.Color(int(df_color[0]*65535),int(df_color[1]*65535),int(df_color[2]*65535)))
|
||||
self.glade.get_widget("Download_Fill").set_alpha(int(df_color[3]*65535))
|
||||
self.glade.get_widget("Upload_Line").set_color(gtk.gdk.Color(int(ul_color[0]*65535),int(ul_color[1]*65535),int(ul_color[2]*65535)))
|
||||
self.glade.get_widget("Upload_Line").set_alpha(int(ul_color[3]*65535))
|
||||
self.glade.get_widget("Upload_Fill").set_color(gtk.gdk.Color(int(uf_color[0]*65535),int(uf_color[1]*65535),int(uf_color[2]*65535)))
|
||||
self.glade.get_widget("Upload_Fill").set_alpha(int(uf_color[3]*65535))
|
||||
else:
|
||||
self.glade.get_widget("Download_Line").set_color(gtk.gdk.Color(0,49151,0))
|
||||
self.glade.get_widget("Download_Line").set_alpha(65535)
|
||||
self.glade.get_widget("Download_Fill").set_color(gtk.gdk.Color(32768,65535,32768))
|
||||
self.glade.get_widget("Download_Fill").set_alpha(65535)
|
||||
self.glade.get_widget("Upload_Line").set_color(gtk.gdk.Color(0,0,65535))
|
||||
self.glade.get_widget("Upload_Line").set_alpha(49151)
|
||||
self.glade.get_widget("Upload_Fill").set_color(gtk.gdk.Color(21627,21627,65535))
|
||||
self.glade.get_widget("Upload_Fill").set_alpha(32768)
|
||||
|
||||
self.glade.get_widget("Mean_Speed_Check").set_active(self.config.get("mean_selected"))
|
||||
self.glade.get_widget("Max_Speed_Check").set_active(self.config.get("max_selected"))
|
||||
self.glade.get_widget("Legend_Check").set_active(self.config.get("legend_selected"))
|
||||
|
||||
except:
|
||||
self.glade.get_widget("Download_Line_Check").set_active(True)
|
||||
self.glade.get_widget("Download_Fill_Check").set_active(True)
|
||||
self.glade.get_widget("Upload_Line_Check").set_active(True)
|
||||
self.glade.get_widget("Upload_Fill_Check").set_active(True)
|
||||
self.glade.get_widget("Mean_Speed_Check").set_active(True)
|
||||
self.glade.get_widget("Max_Speed_Check").set_active(True)
|
||||
self.glade.get_widget("Download_Line").set_color(gtk.gdk.Color(0,49151,0))
|
||||
self.glade.get_widget("Download_Line").set_alpha(65535)
|
||||
self.glade.get_widget("Download_Fill").set_color(gtk.gdk.Color(32768,65535,32768))
|
||||
self.glade.get_widget("Download_Fill").set_alpha(65535)
|
||||
self.glade.get_widget("Upload_Line").set_color(gtk.gdk.Color(0,0,65535))
|
||||
self.glade.get_widget("Upload_Line").set_alpha(49151)
|
||||
self.glade.get_widget("Upload_Fill").set_color(gtk.gdk.Color(21627,21627,65535))
|
||||
self.glade.get_widget("Upload_Fill").set_alpha(32768)
|
||||
self.glade.get_widget("Line_Scale").get_adjustment().set_value(4);
|
||||
self.glade.get_widget("Mean_Speed_Check").set_active(True)
|
||||
self.glade.get_widget("Max_Speed_Check").set_active(False)
|
||||
self.glade.get_widget("Legend_Check").set_active(True)
|
||||
|
||||
self.dialog_initialize = False
|
||||
self.dialog.set_transient_for(window)
|
||||
self.dialog.show()
|
||||
|
||||
def update(self):
|
||||
if (not self.parentNotebook.get_nth_page(self.parentNotebook.get_current_page()) == \
|
||||
self.topWidget\
|
||||
or not self.parent.update_interface)\
|
||||
and not self.bootupRuns > 0:
|
||||
self.topWidget\
|
||||
or not self.parent.update_interface)\
|
||||
and not self.bootupRuns > 0:
|
||||
return
|
||||
self.bootupRuns = max(self.bootupRuns - 1, 0)
|
||||
self.tab_graph.update_graph_store()
|
||||
self.tab_graph.update_graph_view()
|
||||
|
||||
def update_config(self):
|
||||
if self.config.get("exists"):
|
||||
if self.config.get("enable_down_line"):
|
||||
self.tab_graph.enable_download_line()
|
||||
else:
|
||||
self.tab_graph.disable_download_line()
|
||||
|
||||
if self.config.get("enable_down_fill"):
|
||||
self.tab_graph.enable_download_fill()
|
||||
else:
|
||||
self.tab_graph.disable_download_fill()
|
||||
|
||||
if self.config.get("enable_up_line"):
|
||||
self.tab_graph.enable_upload_line()
|
||||
else:
|
||||
self.tab_graph.disable_upload_line()
|
||||
|
||||
if self.config.get("enable_up_fill"):
|
||||
self.tab_graph.enable_upload_fill()
|
||||
else:
|
||||
self.tab_graph.disable_upload_fill()
|
||||
|
||||
|
||||
if self.config.get("down_line_color"):
|
||||
self.tab_graph.download_line_color = self.config.get("down_line_color")
|
||||
else:
|
||||
self.tab_graph.download_line_color = (0, 0.75,0, 1.0)
|
||||
|
||||
if self.config.get("down_fill_color"):
|
||||
self.tab_graph.download_fill_color = self.config.get("down_fill_color")
|
||||
else:
|
||||
self.tab_graph.download_fill_color = (0.5,1, 0.5, 1.0)
|
||||
|
||||
if self.config.get("up_line_color"):
|
||||
self.tab_graph.upload_line_color = self.config.get("up_line_color")
|
||||
else:
|
||||
self.tab_graph.upload_line_color = (0, 0, 1.0, 0.75)
|
||||
|
||||
if self.config.get("up_fill_color"):
|
||||
self.tab_graph.upload_fill_color = self.config.get("up_fill_color")
|
||||
else:
|
||||
self.tab_graph.upload_fill_color = (0.33,0.33,1.0, 0.5)
|
||||
|
||||
|
||||
if (self.config.get("line_size") > 0) & (self.config.get("line_size") < 6):
|
||||
self.tab_graph.line_size = self.config.get("line_size")
|
||||
else:
|
||||
self.tab_graph.line_size = 4
|
||||
|
||||
if self.config.get("mean_selected"):
|
||||
self.tab_graph.enable_mean()
|
||||
else:
|
||||
self.tab_graph.disable_mean()
|
||||
|
||||
if self.config.get("max_selected"):
|
||||
self.tab_graph.enable_max()
|
||||
else:
|
||||
self.tab_graph.disable_max()
|
||||
|
||||
if self.config.get("legend_selected"):
|
||||
self.tab_graph.enable_legend()
|
||||
else:
|
||||
self.tab_graph.disable_legend()
|
||||
else:
|
||||
self.tab_graph.enable_download_line()
|
||||
self.tab_graph.enable_download_fill()
|
||||
self.tab_graph.enable_upload_line()
|
||||
self.tab_graph.enable_upload_fill()
|
||||
self.tab_graph.download_line_color = (0, 0.75,0, 1.0)
|
||||
self.tab_graph.download_fill_color = (0.5,1, 0.5, 1.0)
|
||||
self.tab_graph.upload_line_color = (0, 0, 1.0, 0.75)
|
||||
self.tab_graph.upload_fill_color = (0.33,0.33,1.0, 0.5)
|
||||
self.tab_graph.enable_mean()
|
||||
self.tab_graph.enable_legend()
|
||||
self.tab_graph.line_size = 4
|
||||
|
||||
def reset_download(self,src):
|
||||
self.glade.get_widget("Download_Line_Check").set_active(True)
|
||||
self.glade.get_widget("Download_Fill_Check").set_active(True)
|
||||
self.glade.get_widget("Download_Line").set_color(gtk.gdk.Color(0,49151,0))
|
||||
self.glade.get_widget("Download_Line").set_alpha(65535)
|
||||
self.glade.get_widget("Download_Fill").set_color(gtk.gdk.Color(32768,65535,32768))
|
||||
self.glade.get_widget("Download_Line").set_,sralpha(65535)
|
||||
|
||||
def reset_upload(self,src):
|
||||
self.glade.get_widget("Upload_Line_Check").set_active(True)
|
||||
self.glade.get_widget("Upload_Fill_Check").set_active(True)
|
||||
self.glade.get_widget("Upload_Line").set_color(gtk.gdk.Color(0,0,65535))
|
||||
self.glade.get_widget("Upload_Line").set_alpha(49151)
|
||||
self.glade.get_widget("Upload_Fill").set_color(gtk.gdk.Color(21627,21627,65535))
|
||||
self.glade.get_widget("Upload_Fill").set_alpha(32768)
|
||||
|
||||
def ok_pressed(self, src):
|
||||
self.dialog.hide()
|
||||
self.config.set("exists",True)
|
||||
self.config.set("enable_down_line",self.glade.get_widget("Download_Line_Check").get_active())
|
||||
self.config.set("down_line_color",(self.glade.get_widget("Download_Line").get_color().red/65535.0,\
|
||||
self.glade.get_widget("Download_Line").get_color().green/65535.0,\
|
||||
self.glade.get_widget("Download_Line").get_color().blue/65535.0,\
|
||||
self.glade.get_widget("Download_Line").get_alpha()/65535.0))
|
||||
|
||||
self.config.set("enable_down_fill",self.glade.get_widget("Download_Fill_Check").get_active())
|
||||
self.config.set("down_fill_color",(self.glade.get_widget("Download_Fill").get_color().red/65535.0,\
|
||||
self.glade.get_widget("Download_Fill").get_color().green/65535.0,\
|
||||
self.glade.get_widget("Download_Fill").get_color().blue/65535.0,\
|
||||
self.glade.get_widget("Download_Fill").get_alpha()/65535.0))
|
||||
|
||||
self.config.set("enable_up_line",self.glade.get_widget("Upload_Line_Check").get_active())
|
||||
self.config.set("up_line_color",(self.glade.get_widget("Upload_Line").get_color().red/65535.0,\
|
||||
self.glade.get_widget("Upload_Line").get_color().green/65535.0,\
|
||||
self.glade.get_widget("Upload_Line").get_color().blue/65535.0,\
|
||||
self.glade.get_widget("Upload_Line").get_alpha()/65535.0))
|
||||
|
||||
self.config.set("enable_up_fill",self.glade.get_widget("Upload_Fill_Check").get_active())
|
||||
self.config.set("up_fill_color",(self.glade.get_widget("Upload_Fill").get_color().red/65535.0,\
|
||||
self.glade.get_widget("Upload_Fill").get_color().green/65535.0,\
|
||||
self.glade.get_widget("Upload_Fill").get_color().blue/65535.0,\
|
||||
self.glade.get_widget("Upload_Fill").get_alpha()/65535.0))
|
||||
|
||||
self.config.set("colors_set",True)
|
||||
self.config.set("line_size",self.glade.get_widget("Line_Scale").get_adjustment().get_value())
|
||||
self.config.set("mean_selected",self.glade.get_widget("Mean_Speed_Check").get_active())
|
||||
self.config.set("max_selected",self.glade.get_widget("Max_Speed_Check").get_active())
|
||||
self.config.set("legend_selected",self.glade.get_widget("Legend_Check").get_active())
|
||||
self.update_config()
|
||||
|
||||
def cancel_pressed(self, src):
|
||||
self.dialog.hide()
|
||||
|
|
|
@ -0,0 +1,428 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
|
||||
<!--Generated with glade3 3.2.0 on Thu Aug 9 02:38:25 2007 by root@chris-laptop-->
|
||||
<glade-interface>
|
||||
<widget class="GtkDialog" id="dialog">
|
||||
<property name="border_width">5</property>
|
||||
<property name="title" translatable="yes">Network Activity Graph Preferences</property>
|
||||
<property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
|
||||
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
|
||||
<property name="has_separator">False</property>
|
||||
<child internal-child="vbox">
|
||||
<widget class="GtkVBox" id="dialog-vbox">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<child>
|
||||
<widget class="GtkTable" id="table">
|
||||
<property name="visible">True</property>
|
||||
<property name="events"></property>
|
||||
<property name="n_rows">9</property>
|
||||
<property name="n_columns">7</property>
|
||||
<property name="column_spacing">4</property>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="Legend_Check">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Show Legend</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="top_attach">8</property>
|
||||
<property name="bottom_attach">9</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHSeparator" id="hseparator5">
|
||||
<property name="width_request">20</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="events"></property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">5</property>
|
||||
<property name="right_attach">6</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
<property name="x_padding">10</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHSeparator" id="hseparator4">
|
||||
<property name="width_request">20</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="events"></property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">5</property>
|
||||
<property name="right_attach">6</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
<property name="x_padding">10</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="Reset_Download">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip" translatable="yes">Reset colors to their defaults</property>
|
||||
<property name="xalign">1</property>
|
||||
<signal name="released" handler="on_Reset_Download_released"/>
|
||||
<child>
|
||||
<widget class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-clear</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">6</property>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHSeparator" id="hseparator3">
|
||||
<property name="width_request">20</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="events"></property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">2</property>
|
||||
<property name="right_attach">3</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
<property name="x_padding">10</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHSeparator" id="hseparator1">
|
||||
<property name="width_request">20</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="events"></property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">2</property>
|
||||
<property name="right_attach">3</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
<property name="x_padding">10</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="label1">
|
||||
<property name="visible">True</property>
|
||||
<property name="label" translatable="yes">Line Size</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHScale" id="Line_Scale">
|
||||
<property name="visible">True</property>
|
||||
<property name="adjustment">4 1 5 0 0 0</property>
|
||||
<property name="digits">0</property>
|
||||
<property name="value_pos">GTK_POS_RIGHT</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">2</property>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="top_attach">5</property>
|
||||
<property name="bottom_attach">6</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="Misc_Label">
|
||||
<property name="height_request">30</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">1</property>
|
||||
<property name="label" translatable="yes"><b>Misc</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="top_attach">4</property>
|
||||
<property name="bottom_attach">5</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="Mean_Speed_Check">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Show Mean Speed</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="top_attach">7</property>
|
||||
<property name="bottom_attach">8</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkColorButton" id="Upload_Fill">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_alpha">True</property>
|
||||
<property name="color">#54545454ffff</property>
|
||||
<property name="alpha">32768</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">4</property>
|
||||
<property name="right_attach">5</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="Upload_Fill_Check">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Fill</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">3</property>
|
||||
<property name="right_attach">4</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkColorButton" id="Upload_Line">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_alpha">True</property>
|
||||
<property name="color">#00000000ffff</property>
|
||||
<property name="alpha">49153</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="Upload_Line_Check">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Line</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkColorButton" id="Download_Fill">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_alpha">True</property>
|
||||
<property name="color">#8080ffff8080</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">4</property>
|
||||
<property name="right_attach">5</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="Download_Fill_Check">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Fill</property>
|
||||
<property name="xalign">1</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">3</property>
|
||||
<property name="right_attach">4</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkColorButton" id="Download_Line">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="use_alpha">True</property>
|
||||
<property name="color">#0000c0c00000</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">1</property>
|
||||
<property name="right_attach">2</property>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="Upload_Label">
|
||||
<property name="height_request">30</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="events"></property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">1</property>
|
||||
<property name="label" translatable="yes"><b>Upload</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="top_attach">2</property>
|
||||
<property name="bottom_attach">3</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="Download_Line_Check">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Line</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="top_attach">1</property>
|
||||
<property name="bottom_attach">2</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkLabel" id="Download_Label">
|
||||
<property name="visible">True</property>
|
||||
<property name="xalign">0</property>
|
||||
<property name="yalign">1</property>
|
||||
<property name="label" translatable="yes"><b>Download</b></property>
|
||||
<property name="use_markup">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkCheckButton" id="Max_Speed_Check">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label" translatable="yes">Show Max Speed</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="top_attach">6</property>
|
||||
<property name="bottom_attach">7</property>
|
||||
<property name="x_options">GTK_FILL</property>
|
||||
<property name="y_options">GTK_FILL</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="Reset_Upload">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip" translatable="yes">Reset colors to their defaults</property>
|
||||
<signal name="released" handler="on_Reset_Upload_released"/>
|
||||
<child>
|
||||
<widget class="GtkImage" id="image3">
|
||||
<property name="visible">True</property>
|
||||
<property name="stock">gtk-clear</property>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="left_attach">6</property>
|
||||
<property name="right_attach">7</property>
|
||||
<property name="top_attach">3</property>
|
||||
<property name="bottom_attach">4</property>
|
||||
<property name="x_options"></property>
|
||||
<property name="y_options"></property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child internal-child="action_area">
|
||||
<widget class="GtkHButtonBox" id="dialog-action_area">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK</property>
|
||||
<property name="layout_style">GTK_BUTTONBOX_END</property>
|
||||
<child>
|
||||
<widget class="GtkButton" id="button_cancel">
|
||||
<property name="visible">True</property>
|
||||
<property name="label">gtk-cancel</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="pressed" handler="on_button_cancel_pressed"/>
|
||||
</widget>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="button_ok">
|
||||
<property name="visible">True</property>
|
||||
<property name="label">gtk-ok</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">1</property>
|
||||
<signal name="pressed" handler="on_button_ok_pressed"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="pack_type">GTK_PACK_END</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
</child>
|
||||
</widget>
|
||||
</glade-interface>
|
|
@ -1,5 +1,8 @@
|
|||
import gtk
|
||||
import pango
|
||||
import cairo
|
||||
import math
|
||||
import deluge.common
|
||||
|
||||
class GraphTabManager:
|
||||
def __init__(self, scrolledWindow, image, pangoLayout, manager):
|
||||
|
@ -15,6 +18,67 @@ class GraphTabManager:
|
|||
self.savedUpSpeeds = []
|
||||
self.savedDownSpeeds = []
|
||||
|
||||
self.download_line = None
|
||||
self.download_line_color = None
|
||||
self.download_fill = None
|
||||
self.download_fill_color = None
|
||||
self.upload_line = None
|
||||
self.upload_line_color = None
|
||||
self.upload_fill = None
|
||||
self.upload_fill_color = None
|
||||
self.max_selected = None
|
||||
self.mean_selected = None
|
||||
self.legend_selected = None
|
||||
self.line_size = 4
|
||||
|
||||
#Download
|
||||
def enable_download_line(self):
|
||||
self.download_line = True
|
||||
|
||||
def disable_download_line(self):
|
||||
self.download_line = False
|
||||
|
||||
def enable_download_fill(self):
|
||||
self.download_fill = True
|
||||
|
||||
def disable_download_fill(self):
|
||||
self.download_fill = False
|
||||
|
||||
#Upload
|
||||
def enable_upload_line(self):
|
||||
self.upload_line = True
|
||||
|
||||
def disable_upload_line(self):
|
||||
self.upload_line = False
|
||||
|
||||
def enable_upload_fill(self):
|
||||
self.upload_fill = True
|
||||
|
||||
def disable_upload_fill(self):
|
||||
self.upload_fill = False
|
||||
|
||||
#Mean
|
||||
def enable_mean(self):
|
||||
self.mean_selected = True
|
||||
|
||||
def disable_mean(self):
|
||||
self.mean_selected = False
|
||||
|
||||
#Max
|
||||
def enable_max(self):
|
||||
self.max_selected = True
|
||||
|
||||
def disable_max(self):
|
||||
self.max_selected = False
|
||||
|
||||
#Legend
|
||||
def enable_legend(self):
|
||||
self.legend_selected = True
|
||||
|
||||
def disable_legend(self):
|
||||
self.legend_selected = False
|
||||
|
||||
|
||||
def update_graph_store(self):
|
||||
session_info = self.manager.get_state()
|
||||
self.savedUpSpeeds.insert(0, session_info['upload_rate'])
|
||||
|
@ -24,8 +88,7 @@ class GraphTabManager:
|
|||
if len(self.savedDownSpeeds) > self.length:
|
||||
self.savedDownSpeeds.pop()
|
||||
|
||||
def update_graph_view(self):
|
||||
|
||||
def update_graph_view(self):
|
||||
extraWidth = self.scrolledWindow.get_vscrollbar().get_allocation().width * 1.5
|
||||
extraHeight = self.scrolledWindow.get_hscrollbar().get_allocation().height * 1.5
|
||||
allocation = self.scrolledWindow.get_allocation()
|
||||
|
@ -34,80 +97,85 @@ class GraphTabManager:
|
|||
# Don't try to allocate a size too small, or you might crash
|
||||
if allocation.width < 2 or allocation.height < 2:
|
||||
return
|
||||
|
||||
|
||||
# savedDownSpeeds = [1,2,3,2,1]
|
||||
# savedUpSpeeds = [5,8,0,0,1,2]
|
||||
|
||||
|
||||
# allocation = self.image.get_allocation()
|
||||
# allocation.width = 300
|
||||
# allocation.height = 200
|
||||
|
||||
|
||||
if not allocation.width == self.width or not allocation.height == self.height:
|
||||
# print "New Pixmap!"
|
||||
self.width = allocation.width
|
||||
self.height = allocation.height
|
||||
|
||||
self.networkPixmap = gtk.gdk.Pixmap(None, self.width,
|
||||
self.height, gtk.gdk.visual_get_system().depth)
|
||||
|
||||
self.networkPixmap = gtk.gdk.Pixmap(None, self.width,self.height,gtk.gdk.visual_get_system().depth)
|
||||
self.image.set_from_pixmap(self.networkPixmap, None)
|
||||
self.ctx = self.networkPixmap.cairo_create()
|
||||
|
||||
|
||||
self.networkPixmap.draw_rectangle(self.image.get_style().white_gc,True, 0, 0, self.width, self.height)
|
||||
|
||||
if (self.download_fill or self.download_line) and (self.upload_fill or self.upload_line):
|
||||
maxSpeed = max(max(self.savedDownSpeeds),max(self.savedUpSpeeds))
|
||||
meanSpeed = max(sum(self.savedUpSpeeds) /len(self.savedUpSpeeds), sum(self.savedDownSpeeds)/len(self.savedDownSpeeds))
|
||||
elif self.download_fill or self.download_line:
|
||||
maxSpeed = max(self.savedDownSpeeds)
|
||||
meanSpeed = sum(self.savedDownSpeeds)/len(self.savedDownSpeeds)
|
||||
elif self.upload_fill or self.upload_line:
|
||||
maxSpeed = max(self.savedUpSpeeds)
|
||||
meanSpeed = sum(self.savedUpSpeeds) /len(self.savedUpSpeeds)
|
||||
else:
|
||||
maxSpeed = 0
|
||||
|
||||
maxSpeed = max(max(self.savedDownSpeeds),max(self.savedUpSpeeds))
|
||||
if self.legend_selected:
|
||||
self.drawLegend()
|
||||
|
||||
if maxSpeed > 0:
|
||||
if self.download_fill:
|
||||
self.drawSpeedPoly(self.savedDownSpeeds,self.download_fill_color, maxSpeed, True)
|
||||
|
||||
if self.download_line:
|
||||
self.drawSpeedPoly(self.savedDownSpeeds,self.download_line_color,maxSpeed, False)
|
||||
|
||||
if self.upload_fill:
|
||||
self.drawSpeedPoly(self.savedUpSpeeds,self.upload_fill_color,maxSpeed, True)
|
||||
|
||||
if self.upload_line:
|
||||
self.drawSpeedPoly(self.savedUpSpeeds,self.upload_line_color,maxSpeed, False)
|
||||
|
||||
if self.max_selected:
|
||||
self.drawText(deluge.common.fspeed(maxSpeed),self.image.get_style().black_gc,4,2)
|
||||
|
||||
if maxSpeed == 0:
|
||||
return
|
||||
|
||||
maxSpeed = maxSpeed*1.1 # Give some extra room on top
|
||||
|
||||
self.drawSpeedPoly(self.savedDownSpeeds, (0.5,1, 0.5, 1.0), maxSpeed, True)
|
||||
self.drawSpeedPoly(self.savedDownSpeeds, (0, 0.75,0, 1.0), maxSpeed, False)
|
||||
|
||||
self.drawSpeedPoly(self.savedUpSpeeds, (0.33,0.33,1.0, 0.5), maxSpeed, True)
|
||||
self.drawSpeedPoly(self.savedUpSpeeds, (0, 0, 1.0, 0.75), maxSpeed, False)
|
||||
|
||||
meanUpSpeed = sum(self.savedUpSpeeds) /len(self.savedUpSpeeds)
|
||||
meanDownSpeed = sum(self.savedDownSpeeds)/len(self.savedDownSpeeds)
|
||||
shownSpeed = max(meanUpSpeed, meanDownSpeed)
|
||||
|
||||
import deluge.common
|
||||
|
||||
self.pangoLayout.set_text(deluge.common.fspeed(shownSpeed))
|
||||
self.networkPixmap.draw_layout(self.image.get_style().black_gc,
|
||||
4,
|
||||
int(self.height - 1 - (self.height*shownSpeed/maxSpeed)),
|
||||
self.pangoLayout)
|
||||
|
||||
self.networkPixmap.draw_line(self.image.get_style().black_gc,
|
||||
0,
|
||||
int(self.height - (self.height*shownSpeed/maxSpeed)),
|
||||
self.width,
|
||||
int(self.height - (self.height*shownSpeed/maxSpeed)))
|
||||
|
||||
if self.mean_selected:
|
||||
self.pangoLayout.set_text(deluge.common.fspeed(meanSpeed))
|
||||
self.networkPixmap.draw_layout(self.image.get_style().black_gc,
|
||||
4,
|
||||
int(self.height - 1 - ((self.height-28)*meanSpeed/maxSpeed)),
|
||||
self.pangoLayout)
|
||||
self.networkPixmap.draw_line(self.image.get_style().black_gc,
|
||||
0,
|
||||
int(self.height - ((self.height-28)*meanSpeed/maxSpeed)),
|
||||
self.width,
|
||||
int(self.height - ((self.height-28)*meanSpeed/maxSpeed)))
|
||||
|
||||
self.networkPixmap.draw_rectangle(self.image.get_style().black_gc,False, 0, 0, self.width-1, self.height-1)
|
||||
|
||||
self.image.queue_draw()
|
||||
|
||||
|
||||
def tracePath(self, speeds, maxSpeed):
|
||||
lineWidth = 4
|
||||
lineWidth = self.line_size
|
||||
|
||||
self.ctx.set_line_width(lineWidth)
|
||||
|
||||
self.ctx.move_to(self.width + lineWidth,self.height + lineWidth)
|
||||
self.ctx.line_to(self.width + lineWidth,int(self.height-(self.height*speeds[0]/maxSpeed)))
|
||||
self.ctx.line_to(self.width + lineWidth,int(self.height-((self.height-28)*speeds[0]/maxSpeed)))
|
||||
|
||||
for i in range(len(speeds)):
|
||||
self.ctx.line_to(int(self.width-1-((i*self.width)/(self.length-1))),
|
||||
int(self.height-1-(self.height*speeds[i]/maxSpeed)))
|
||||
|
||||
self.ctx.line_to(int(self.width-1-(((len(speeds)-1)*self.width)/(self.length-1))),
|
||||
int(self.height)-1 + lineWidth)
|
||||
self.ctx.line_to(int(self.width-1-((i*self.width)/(self.length-1))),int(self.height-1-((self.height-28)*speeds[i]/maxSpeed)))
|
||||
|
||||
self.ctx.line_to(int(self.width-1-(((len(speeds)-1)*self.width)/(self.length-1))),int(self.height)-1 + lineWidth)
|
||||
self.ctx.close_path()
|
||||
|
||||
def drawSpeedPoly(self, speeds, color, maxSpeed, fill):
|
||||
|
||||
self.tracePath(speeds, maxSpeed)
|
||||
self.ctx.set_source_rgba(color[0],color[1],color[2], color[3])
|
||||
|
||||
|
@ -115,3 +183,56 @@ class GraphTabManager:
|
|||
self.ctx.fill()
|
||||
else:
|
||||
self.ctx.stroke()
|
||||
|
||||
def drawLegend(self):
|
||||
showDown = self.download_fill or self.download_line
|
||||
showUp = self.upload_fill or self.upload_line
|
||||
downBox_X = self.width-113
|
||||
|
||||
if showDown and showUp:
|
||||
self.networkPixmap.draw_line(self.image.get_style().black_gc,self.width-186,1,self.width-186,21)
|
||||
self.networkPixmap.draw_line(self.image.get_style().black_gc,self.width-185,21,self.width-1,21)
|
||||
self.drawText("Download:",self.image.get_style().black_gc,self.width-181,2)
|
||||
self.drawText("Upload:",self.image.get_style().black_gc,self.width-81,2)
|
||||
elif showDown:
|
||||
self.networkPixmap.draw_line(self.image.get_style().black_gc,self.width-103,1,self.width-103,21)
|
||||
self.networkPixmap.draw_line(self.image.get_style().black_gc,self.width-102,21,self.width-1,21)
|
||||
self.drawText("Download:",self.image.get_style().black_gc,self.width-98,2)
|
||||
downBox_X = self.width-30
|
||||
elif showUp:
|
||||
self.networkPixmap.draw_line(self.image.get_style().black_gc,self.width-86,1,self.width-86,21)
|
||||
self.networkPixmap.draw_line(self.image.get_style().black_gc,self.width-85,21,self.width-1,21)
|
||||
self.drawText("Upload:",self.image.get_style().black_gc,self.width-81,2)
|
||||
|
||||
if self.download_fill and self.download_line:
|
||||
self.drawRect(self.download_line_color,downBox_X,5,12,12)
|
||||
self.drawRect(self.download_fill_color,downBox_X+12,5,12,12)
|
||||
elif self.download_fill:
|
||||
self.drawRect(self.download_fill_color,downBox_X,5,24,12)
|
||||
elif self.download_line:
|
||||
self.drawRect(self.download_line_color,downBox_X,5,24,12)
|
||||
|
||||
if self.upload_fill and self.upload_line:
|
||||
self.drawRect(self.upload_line_color,self.width-30,5,12,12)
|
||||
self.drawRect(self.upload_fill_color,self.width-18,5,12,12)
|
||||
elif self.upload_fill:
|
||||
self.drawRect(self.upload_fill_color,self.width-30,5,24,12)
|
||||
elif self.upload_line:
|
||||
self.drawRect(self.upload_line_color,self.width-30,5,24,12)
|
||||
|
||||
def drawText(self,text,color,x,y):
|
||||
self.pangoLayout.set_text(text)
|
||||
self.networkPixmap.draw_layout(color,x,y,self.pangoLayout)
|
||||
|
||||
def drawRect(self,color,x,y,height,width):
|
||||
self.ctx.set_source_rgba(color[0],color[1],color[2],color[3],)
|
||||
self.ctx.rectangle(x,y,height,width)
|
||||
self.ctx.fill()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue