[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/release] Moved cagraph packing from controller to graphing.



commit afeb960aa3d3e7f2d80e648fd837c53298ce55ae
Author: Kamran Riaz Khan <krkhan@xxxxxxxxxxxxxx>
Date:   Sun Jun 19 12:44:37 2011 +0500

    Moved cagraph packing from controller to graphing.
---
 src/gui/controller.py              |   49 ++--------------------------------
 src/gui/graphing/bandwidthStats.py |    4 +-
 src/gui/graphing/graphStats.py     |   51 +++++++++++++++++++++++++++++++++--
 3 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/src/gui/controller.py b/src/gui/controller.py
index 7f85b9a..4da82c9 100644
--- a/src/gui/controller.py
+++ b/src/gui/controller.py
@@ -2,13 +2,7 @@ import gobject
 import gtk
 
 from util import torTools
-from gui.graphing import graphStats, bandwidthStats
-
-from cagraph.ca_graph import CaGraph
-from cagraph.axis.xaxis import CaGraphXAxis
-from cagraph.axis.yaxis import CaGraphYAxis
-from cagraph.ca_graph_grid import CaGraphGrid
-from cagraph.series.area import CaGraphSeriesArea
+from gui.graphing import bandwidthStats
 
 gobject.threads_init()
 
@@ -20,18 +14,8 @@ class GuiController:
     self.builder.add_from_file(filename)
     self.builder.connect_signals(self)
 
-    # for custom widgets not present in builder xml
-    self.widgets = {}
-
-    self._pack_graph_widget('primary')
-    self._pack_graph_widget('secondary')
-
-    self.bwStats = bandwidthStats.BandwidthStats(self.builder, self.widgets)
-
-    gobject.timeout_add(1000, self.bwStats.draw_graph, 'primary')
-    gobject.timeout_add(1000, self.bwStats.draw_graph, 'secondary')
-    gobject.timeout_add(1000, self.bwStats.update_labels, 'primary')
-    gobject.timeout_add(1000, self.bwStats.update_labels, 'secondary')
+    self.bwStats = bandwidthStats.BandwidthStats(self.builder)
+    self.bwStats.pack_widgets()
 
   def run(self):
     window = self.builder.get_object('window_main')
@@ -47,33 +31,6 @@ class GuiController:
   def on_window_main_delete_event(self, widget, data=None):
     gtk.main_quit()
 
-  def _pack_graph_widget(self, name):
-    graph = CaGraph()
-    placeholder = self.builder.get_object('placeholder_graph_%s' % name)
-    placeholder.pack_start(graph)
-
-    xaxis = CaGraphXAxis(graph)
-    yaxis = CaGraphYAxis(graph)
-
-    xaxis.min = 0
-    xaxis.max = graphStats.GRAPH_INTERVAL - 1
-    xaxis.axis_style.draw_labels = False
-
-    graph.axiss.append(xaxis)
-    graph.axiss.append(yaxis)
-
-    series = CaGraphSeriesArea(graph, 0, 1)
-
-    line_colors = {'primary' : (1.0, 0.0, 1.0, 1.0), 'secondary' : (0.0, 1.0, 0.0, 1.0)}
-    fill_colors = {'primary' : (1.0, 0.0, 1.0, 0.3), 'secondary' : (0.0, 1.0, 0.0, 0.3)}
-    series.style.line_color = line_colors[name]
-    series.style.fill_color = fill_colors[name]
-
-    graph.seriess.append(series)
-    graph.grid = CaGraphGrid(graph, 0, 1)
-
-    self.widgets['graph_%s' % name] = graph
-
 def startGui():
   controller = GuiController()
   controller.run()
diff --git a/src/gui/graphing/bandwidthStats.py b/src/gui/graphing/bandwidthStats.py
index a8278d8..401302c 100644
--- a/src/gui/graphing/bandwidthStats.py
+++ b/src/gui/graphing/bandwidthStats.py
@@ -12,8 +12,8 @@ from gui.graphing import graphStats
 from util import uiTools, torTools
 
 class BandwidthStats(graphStats.GraphStats):
-  def __init__(self, builder, widgets):
-    graphStats.GraphStats.__init__(self, builder, widgets)
+  def __init__(self, builder):
+    graphStats.GraphStats.__init__(self, builder)
 
     conn = torTools.getConn()
     if not conn.isAlive():
diff --git a/src/gui/graphing/graphStats.py b/src/gui/graphing/graphStats.py
index c000ff4..fcd326f 100644
--- a/src/gui/graphing/graphStats.py
+++ b/src/gui/graphing/graphStats.py
@@ -13,15 +13,21 @@ import gtk
 from TorCtl import TorCtl
 from util import uiTools, torTools
 
+from cagraph.ca_graph import CaGraph
+from cagraph.axis.xaxis import CaGraphXAxis
+from cagraph.axis.yaxis import CaGraphYAxis
+from cagraph.ca_graph_grid import CaGraphGrid
+from cagraph.series.area import CaGraphSeriesArea
+
 GRAPH_INTERVAL = 30
 
 class GraphStats(TorCtl.PostEventListener):
-  def __init__(self, builder, widgets):
+  def __init__(self, builder):
     TorCtl.PostEventListener.__init__(self)
 
     self.builder = builder
-    self.widgets = widgets
 
+    self.graphs = { 'primary' : None, 'secondary' : None }
     self.data = {
         'primary'   : deque([0.0] * GRAPH_INTERVAL),
         'secondary' : deque([0.0] * GRAPH_INTERVAL)}
@@ -29,6 +35,45 @@ class GraphStats(TorCtl.PostEventListener):
     self.total = {'primary': 0.0,  'secondary' : 0.0}
     self.ticks = {'primary': 0,  'secondary' : 0}
 
+  def pack_widgets(self):
+    self._pack_graph_widget('primary')
+    self._pack_graph_widget('secondary')
+
+    gobject.timeout_add(1000, self.draw_graph, 'primary')
+    gobject.timeout_add(1000, self.draw_graph, 'secondary')
+    gobject.timeout_add(1000, self.update_labels, 'primary')
+    gobject.timeout_add(1000, self.update_labels, 'secondary')
+
+  def _pack_graph_widget(self, name):
+    graph = CaGraph()
+    placeholder = self.builder.get_object('placeholder_graph_%s' % name)
+    placeholder.pack_start(graph)
+
+    xaxis = CaGraphXAxis(graph)
+    yaxis = CaGraphYAxis(graph)
+
+    xaxis.min = 0
+    xaxis.max = GRAPH_INTERVAL - 1
+    xaxis.axis_style.draw_labels = False
+    yaxis.axis_style.label_color = (0, 0, 0)
+
+    graph.axiss.append(xaxis)
+    graph.axiss.append(yaxis)
+
+    series = CaGraphSeriesArea(graph, 0, 1)
+
+    line_colors = {'primary' : (1.0, 0.0, 1.0, 1.0), 'secondary' : (0.0, 1.0, 0.0, 1.0)}
+    fill_colors = {'primary' : (1.0, 0.0, 1.0, 0.3), 'secondary' : (0.0, 1.0, 0.0, 0.3)}
+    series.style.line_color = line_colors[name]
+    series.style.fill_color = fill_colors[name]
+
+    graph.seriess.append(series)
+    graph.grid = CaGraphGrid(graph, 0, 1)
+
+    self.graphs[name] = graph
+
+    return graph
+
   def get_graph_data(self, name):
     packed_data = []
 
@@ -42,7 +87,7 @@ class GraphStats(TorCtl.PostEventListener):
     return len(data) == map(int, data).count(0)
 
   def draw_graph(self, name):
-    graph = self.widgets['graph_%s' % name]
+    graph = self.graphs[name]
     data = self.get_graph_data(name)
 
     if self.is_graph_data_zero(name):



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits