From 952f03a6ccc5f2f6fb45ef223e513fc385d5fb7a Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sun, 12 Aug 2007 23:23:21 +0000 Subject: [PATCH] revamp networkgraph plugin - Ultrafusion --- plugins/NetworkGraph/__init__.py | 239 ++++++++++- plugins/NetworkGraph/graph_preferences.glade | 428 +++++++++++++++++++ plugins/NetworkGraph/tab_graph.py | 221 +++++++--- 3 files changed, 834 insertions(+), 54 deletions(-) create mode 100644 plugins/NetworkGraph/graph_preferences.glade diff --git a/plugins/NetworkGraph/__init__.py b/plugins/NetworkGraph/__init__.py index 865c98948..0904b4b79 100644 --- a/plugins/NetworkGraph/__init__.py +++ b/plugins/NetworkGraph/__init__.py @@ -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() diff --git a/plugins/NetworkGraph/graph_preferences.glade b/plugins/NetworkGraph/graph_preferences.glade new file mode 100644 index 000000000..7048ad64c --- /dev/null +++ b/plugins/NetworkGraph/graph_preferences.glade @@ -0,0 +1,428 @@ + + + + + + 5 + Network Activity Graph Preferences + GTK_WIN_POS_CENTER_ON_PARENT + GDK_WINDOW_TYPE_HINT_DIALOG + False + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + + + True + + 9 + 7 + 4 + + + True + True + Show Legend + True + + + 7 + 8 + 9 + GTK_FILL + GTK_FILL + + + + + 20 + True + + + + 5 + 6 + 3 + 4 + GTK_FILL + GTK_FILL + 10 + + + + + 20 + True + + + + 5 + 6 + 1 + 2 + GTK_FILL + GTK_FILL + 10 + + + + + True + True + True + Reset colors to their defaults + 1 + + + + True + gtk-clear + + + + + 6 + 7 + 1 + 2 + + + + + + + 20 + True + + + + 2 + 3 + 3 + 4 + GTK_FILL + GTK_FILL + 10 + + + + + 20 + True + + + + 2 + 3 + 1 + 2 + GTK_FILL + GTK_FILL + 10 + + + + + True + Line Size + + + 2 + 5 + 6 + + GTK_FILL + + + + + True + 4 1 5 0 0 0 + 0 + GTK_POS_RIGHT + + + 2 + 7 + 5 + 6 + GTK_FILL + + + + + + 30 + True + 0 + 1 + <b>Misc</b> + True + + + 7 + 4 + 5 + GTK_FILL + GTK_FILL + + + + + True + True + Show Mean Speed + True + + + 7 + 7 + 8 + GTK_FILL + GTK_FILL + + + + + True + True + True + True + #54545454ffff + 32768 + + + 4 + 5 + 3 + 4 + + + + + + + True + True + Fill + True + + + 3 + 4 + 3 + 4 + + GTK_FILL + + + + + True + True + True + True + #00000000ffff + 49153 + + + 1 + 2 + 3 + 4 + + + + + + + True + True + Line + True + + + 3 + 4 + + GTK_FILL + + + + + True + True + True + True + #8080ffff8080 + + + 4 + 5 + 1 + 2 + + + + + + + True + True + Fill + 1 + True + + + 3 + 4 + 1 + 2 + + GTK_FILL + + + + + True + True + True + True + #0000c0c00000 + + + 1 + 2 + 1 + 2 + + + + + + + 30 + True + + 0 + 1 + <b>Upload</b> + True + + + 7 + 2 + 3 + GTK_FILL + GTK_FILL + + + + + True + True + Line + True + + + 1 + 2 + + GTK_FILL + + + + + True + 0 + 1 + <b>Download</b> + True + + + 7 + GTK_FILL + GTK_FILL + + + + + True + True + Show Max Speed + True + + + 7 + 6 + 7 + GTK_FILL + GTK_FILL + + + + + True + True + True + Reset colors to their defaults + + + + True + gtk-clear + + + + + 6 + 7 + 3 + 4 + + + + + + + False + False + 1 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK + GTK_BUTTONBOX_END + + + True + gtk-cancel + True + + + + + + True + gtk-ok + True + 1 + + + + 1 + + + + + False + GTK_PACK_END + + + + + + diff --git a/plugins/NetworkGraph/tab_graph.py b/plugins/NetworkGraph/tab_graph.py index d040c9020..d66cdc47e 100644 --- a/plugins/NetworkGraph/tab_graph.py +++ b/plugins/NetworkGraph/tab_graph.py @@ -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() + + + + + + + +