commit 14497c4ce277b370056b8fed59db45e3d175309f Author: Kamran Riaz Khan krkhan@inspirated.com Date: Sun Jul 17 04:57:43 2011 +0500
Minor formatting changes.
For consistency, use camelCase for all variables and underscores for method names. Use PEP 8 guidelines for specifying imports. --- src/gui/connections/circEntry.py | 12 ++-- src/gui/connections/connEntry.py | 10 ++-- src/gui/connections/connPanel.py | 40 ++++++++-------- src/gui/controller.py | 13 ++--- src/gui/generalPanel.py | 25 +++++----- src/gui/graphing/bandwidthStats.py | 8 ++-- src/gui/graphing/graphPanel.py | 90 ++++++++++++++++++----------------- src/gui/logPanel.py | 26 +++++----- src/starter.py | 2 +- 9 files changed, 113 insertions(+), 113 deletions(-)
diff --git a/src/gui/connections/circEntry.py b/src/gui/connections/circEntry.py index deb720a..abbb631 100644 --- a/src/gui/connections/circEntry.py +++ b/src/gui/connections/circEntry.py @@ -10,25 +10,25 @@ from util import gtkTools, uiTools
class CircEntry(circEntry.CircEntry): @classmethod - def convertToGui(self, instance): + def convert_to_gui(self, instance): instance.__class__ = self
class CircHeaderLine(circEntry.CircHeaderLine, connEntry.ConnectionLine): @classmethod - def convertToGui(self, instance): + def convert_to_gui(self, instance): instance.__class__ = self
- def getListingRow(self, listingType): - row = connEntry.ConnectionLine.getListingRow(self, listingType) + def get_listing_row(self, listingType): + row = connEntry.ConnectionLine.get_listing_row(self, listingType) theme = gtkTools.Theme() return row[:-1] + (theme.colors['active'],)
class CircLine(circEntry.CircLine, connEntry.ConnectionLine): @classmethod - def convertToGui(self, instance): + def convert_to_gui(self, instance): instance.__class__ = self
- def getListingRow(self, listingType): + def get_listing_row(self, listingType): dst, etc = "", ""
if listingType == entries.ListingType.IP_ADDRESS: diff --git a/src/gui/connections/connEntry.py b/src/gui/connections/connEntry.py index e7e666b..f8bcc84 100644 --- a/src/gui/connections/connEntry.py +++ b/src/gui/connections/connEntry.py @@ -6,20 +6,20 @@ Connection panel entries related to actual connections to or from the system import time
from cli.connections import connEntry, entries -from cli.connections.connEntry import CONFIG, Category -from util import gtkTools, uiTools, torTools +from cli.connections.connEntry import Category, CONFIG +from util import gtkTools, torTools, uiTools
class ConnectionEntry(connEntry.ConnectionEntry): @classmethod - def convertToGui(self, instance): + def convert_to_gui(self, instance): instance.__class__ = self
class ConnectionLine(connEntry.ConnectionLine): @classmethod - def convertToGui(self, instance): + def convert_to_gui(self, instance): instance.__class__ = self
- def getListingRow(self, listingType): + def get_listing_row(self, listingType): conn = torTools.getConn() myType = self.getType() dstAddress = self.getDestinationLabel(26, includeLocale = True) diff --git a/src/gui/connections/connPanel.py b/src/gui/connections/connPanel.py index af9bf06..4ab0ed8 100644 --- a/src/gui/connections/connPanel.py +++ b/src/gui/connections/connPanel.py @@ -14,12 +14,12 @@ import gtk from cli.connections import (circEntry as cliCircEntry, connEntry as cliConnEntry) from cli.connections.connPanel import ConnectionPanel as CliConnectionPanel from gui.connections import circEntry, connEntry -from TorCtl import TorCtl from util import connections, sysTools, uiTools, torTools +from TorCtl import TorCtl
REFRESH_RATE = 3
-def convertToGui(instance): +def convert_to_gui(instance): cliToGuiMap = [ (cliCircEntry.CircEntry, circEntry.CircEntry), (cliCircEntry.CircHeaderLine, circEntry.CircHeaderLine), (cliCircEntry.CircLine, circEntry.CircLine), @@ -28,10 +28,10 @@ def convertToGui(instance):
for (cliClass, guiClass) in cliToGuiMap: if isinstance(instance, cliClass): - guiClass.convertToGui(instance) + guiClass.convert_to_gui(instance) break
-def calculateCacheKey(entryLine): +def calculate_cache_key(entryLine): local = (entryLine.local.ipAddr, entryLine.local.port) foreign = (entryLine.foreign.ipAddr, entryLine.foreign.port)
@@ -53,7 +53,7 @@ class ConnectionPanel(CliConnectionPanel): gobject.timeout_add(3000, self._timeout_fill_entries)
def pack_widgets(self): - pass + self.start()
def _timeout_fill_entries(self): self._fill_entries() @@ -66,18 +66,18 @@ class ConnectionPanel(CliConnectionPanel): label = self.builder.get_object('label_conn_top') label.set_text(self._title)
- treestore = self.builder.get_object('treestore_conn') + treeStore = self.builder.get_object('treestore_conn')
# first pass checks whether we have enough entries cached to not update the treeview index = 0 for line in self._entryLines: - convertToGui(line) - cacheKey = calculateCacheKey(line) + convert_to_gui(line) + cacheKey = calculate_cache_key(line)
if self.cache.has_key(cacheKey): if not isinstance(line, circEntry.CircLine): timeLabel = "%d s" % (time.time() - line.startTime) - treestore.set_value(self.cache[cacheKey], 2, timeLabel) + treeStore.set_value(self.cache[cacheKey], 2, timeLabel) else: break
@@ -87,28 +87,28 @@ class ConnectionPanel(CliConnectionPanel): self.valsLock.release() return True
- # one of the entries was not found in cache, clear and repopulate the treestore - treestore.clear() - headeriter = None + # one of the entries was not found in cache, clear and repopulate the treeStore + treeStore.clear() + headerIter = None
for line in self._entryLines: - convertToGui(line) + convert_to_gui(line)
if isinstance(line, connEntry.ConnectionLine) and line.isUnresolvedApp(): self._resolveApps()
- row = line.getListingRow(self._listingType) + row = line.get_listing_row(self._listingType)
if isinstance(line, circEntry.CircHeaderLine): - currentiter = treestore.append(None, row) - headeriter = currentiter + currentIter = treeStore.append(None, row) + headerIter = currentIter elif isinstance(line, circEntry.CircLine): - currentiter = treestore.append(headeriter, row) + currentIter = treeStore.append(headerIter, row) else: - currentiter = treestore.append(None, row) + currentIter = treeStore.append(None, row)
- cacheKey = calculateCacheKey(line) - self.cache[cacheKey] = currentiter + cacheKey = calculate_cache_key(line) + self.cache[cacheKey] = currentIter
self.valsLock.release()
diff --git a/src/gui/controller.py b/src/gui/controller.py index 5736def..e6ffcbd 100644 --- a/src/gui/controller.py +++ b/src/gui/controller.py @@ -1,13 +1,13 @@ -import gobject -import gtk - import thread import time
-from util import log, torTools +import gobject +import gtk + from connections import connPanel -from gui import logPanel, generalPanel from gui.graphing import bandwidthStats +from gui import generalPanel, logPanel +from util import log, torTools
gobject.threads_init()
@@ -27,7 +27,6 @@ class GuiController:
self.connPanel = connPanel.ConnectionPanel(self.builder) self.connPanel.pack_widgets() - self.connPanel.start()
self.generalPanel = generalPanel.GeneralPanel(self.builder) self.generalPanel.pack_widgets() @@ -52,7 +51,7 @@ class GuiController: def on_window_main_delete_event(self, widget, data=None): gtk.main_quit()
-def startGui(): +def start_gui(): controller = GuiController() controller.run()
diff --git a/src/gui/generalPanel.py b/src/gui/generalPanel.py index 1f72b49..be84d65 100644 --- a/src/gui/generalPanel.py +++ b/src/gui/generalPanel.py @@ -12,8 +12,8 @@ import gobject import gtk
from cli.headerPanel import (HeaderPanel as CliHeaderPanel, VERSION_STATUS_COLORS) +from util import connections, gtkTools, sysTools, torTools, uiTools from TorCtl import TorCtl -from util import connections, sysTools, gtkTools, uiTools, torTools
class GeneralPanel(CliHeaderPanel): def __init__(self, builder): @@ -27,7 +27,7 @@ class GeneralPanel(CliHeaderPanel): gobject.timeout_add(3000, self._timeout_fill_entries)
def pack_widgets(self): - pass + return
def _timeout_fill_entries(self): self._fill_entries() @@ -37,22 +37,22 @@ class GeneralPanel(CliHeaderPanel): def _fill_entries(self): self.valsLock.acquire()
- liststore = self.builder.get_object('liststore_general') + listStore = self.builder.get_object('liststore_general') theme = gtkTools.Theme()
- liststore.clear() + listStore.clear()
key = "arm" value = "%s (%s %s)" % (self.vals['sys/hostname'], self.vals['sys/os'], self.vals['sys/version']) row = (key, value, theme.colors['active']) - liststore.append(row) + listStore.append(row)
versionColor = VERSION_STATUS_COLORS[self.vals["tor/versionStatus"]] if \ self.vals["tor/versionStatus"] in VERSION_STATUS_COLORS else "black" key = "Tor" value = "%s (<span foreground="%s">%s</span>)" % (self.vals['tor/version'], versionColor, self.vals['tor/versionStatus']) row = (key, value, theme.colors['active']) - liststore.append(row) + listStore.append(row)
includeControlPort = True key = "Relaying" @@ -77,7 +77,7 @@ class GeneralPanel(CliHeaderPanel): value = "%s%s" % ("Tor Disconnected", statusTimeLabel) includeControlPort = False row = (key, value, theme.colors['active']) - liststore.append(row) + listStore.append(row)
key = "Control Port" if includeControlPort: @@ -88,8 +88,7 @@ class GeneralPanel(CliHeaderPanel): authColor = "red" if authType == "open" else "green" value = "%s (<span foreground="%s">%s</span>)" % (self.vals['tor/controlPort'], authColor, authType) row = (key, value, theme.colors['active']) - liststore.append(row) - + listStore.append(row)
if self.vals["stat/rss"] != "0": memoryLabel = uiTools.getSizeLabel(int(self.vals["stat/rss"])) else: memoryLabel = "0" @@ -104,22 +103,22 @@ class GeneralPanel(CliHeaderPanel): key = "CPU" value = "%s%% Tor, %s%% arm" % (self.vals["stat/%torCpu"], self.vals["stat/%armCpu"]) row = (key, value, theme.colors['active']) - liststore.append(row) + listStore.append(row)
key = "Memory" value = "%s (%s%%)" % (memoryLabel, self.vals["stat/%mem"]) row = (key, value, theme.colors['active']) - liststore.append(row) + listStore.append(row)
key = "PID" value = "%s" % (self.vals["tor/pid"] if self._isTorConnected else "") row = (key, value, theme.colors['active']) - liststore.append(row) + listStore.append(row)
key = "Uptime" value = uptimeLabel row = (key, value, theme.colors['active']) - liststore.append(row) + listStore.append(row)
self.valsLock.release()
diff --git a/src/gui/graphing/bandwidthStats.py b/src/gui/graphing/bandwidthStats.py index f4aa490..672b98e 100644 --- a/src/gui/graphing/bandwidthStats.py +++ b/src/gui/graphing/bandwidthStats.py @@ -7,10 +7,10 @@ import sys import gobject import gtk
-from TorCtl import TorCtl -from starter import CONFIG from gui.graphing import graphPanel -from util import uiTools, torTools +from starter import CONFIG +from util import torTools, uiTools +from TorCtl import TorCtl
class BandwidthStats(graphPanel.GraphPanel): def __init__(self, builder): @@ -51,7 +51,7 @@ class BandwidthStats(graphPanel.GraphPanel): label.set_text(msg)
def bandwidth_event(self, event): - self._processEvent(event.read, event.written) + self._process_event(event.read, event.written)
msg = 'Download: %s/s' % uiTools.getSizeLabel(event.read, 2, isBytes=False) self.update_header('primary', msg) diff --git a/src/gui/graphing/graphPanel.py b/src/gui/graphing/graphPanel.py index 16370b4..b25180e 100644 --- a/src/gui/graphing/graphPanel.py +++ b/src/gui/graphing/graphPanel.py @@ -10,13 +10,13 @@ from collections import deque import gobject import gtk
+from util import gtkTools, torTools, uiTools from TorCtl import TorCtl -from util import gtkTools, 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.ca_graph import CaGraph from cagraph.series.area import CaGraphSeriesArea
GRAPH_INTERVAL = 30 @@ -27,7 +27,9 @@ class GraphPanel(TorCtl.PostEventListener):
self.builder = builder
- self.graphs = { 'primary' : None, 'secondary' : None } + self.graphs = { + 'primary' : None, + 'secondary' : None } self.data = { 'primary' : deque([0.0] * GRAPH_INTERVAL), 'secondary' : deque([0.0] * GRAPH_INTERVAL)} @@ -44,50 +46,13 @@ class GraphPanel(TorCtl.PostEventListener): gobject.timeout_add(1000, self.update_labels, 'primary') gobject.timeout_add(1000, self.update_labels, 'secondary')
- def _pack_graph_widget(self, name): - graph = CaGraph() - graph.set_size_request(200, 200) - - 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) - - theme = gtkTools.Theme() - primaryColor = theme.colors['normal'] - secondaryColor = theme.colors['insensitive'] - colors = { 'primary' : (primaryColor.red_float, primaryColor.green_float, primaryColor.blue_float, 0.5), - 'secondary' : (secondaryColor.red_float, secondaryColor.green_float, secondaryColor.blue_float, 0.5) } - - series.style.point_radius = 0.0 - series.style.line_color = colors[name] - series.style.fill_color = 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 = [] + packedData = []
for (index, value) in enumerate(self.data[name]): - packed_data.append((index, value)) + packedData.append((index, value))
- return packed_data + return packedData
def is_graph_data_zero(self, name): data = self.data[name] @@ -127,7 +92,44 @@ class GraphPanel(TorCtl.PostEventListener): label = self.builder.get_object('label_graph_%s_top' % name) label.set_text(msg)
- def _processEvent(self, primary, secondary): + def _pack_graph_widget(self, name): + graph = CaGraph() + graph.set_size_request(200, 200) + + 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) + + theme = gtkTools.Theme() + primaryColor = theme.colors['normal'] + secondaryColor = theme.colors['insensitive'] + colors = { 'primary' : (primaryColor.red_float, primaryColor.green_float, primaryColor.blue_float, 0.5), + 'secondary' : (secondaryColor.red_float, secondaryColor.green_float, secondaryColor.blue_float, 0.5) } + + series.style.point_radius = 0.0 + series.style.line_color = colors[name] + series.style.fill_color = colors[name] + + graph.seriess.append(series) + graph.grid = CaGraphGrid(graph, 0, 1) + + self.graphs[name] = graph + + return graph + + def _process_event(self, primary, secondary): values = {'primary' : primary, 'secondary' : secondary}
for name in ('primary', 'secondary'): diff --git a/src/gui/logPanel.py b/src/gui/logPanel.py index 192eb8d..7714dcd 100644 --- a/src/gui/logPanel.py +++ b/src/gui/logPanel.py @@ -12,12 +12,11 @@ from threading import RLock import gobject import gtk
-from TorCtl import TorCtl -from util import log, gtkTools, uiTools, torTools - from cli.logPanel import (expandEvents, setEventListening, getLogFileEntries, LogEntry, TorEventObserver, DEFAULT_CONFIG) +from util import gtkTools, log, torTools, uiTools +from TorCtl import TorCtl
RUNLEVEL_EVENT_COLOR = {log.DEBUG: 'insensitive', log.INFO: 'normal', log.NOTICE: 'normal', log.WARN: 'active', log.ERR: 'active'} @@ -73,17 +72,17 @@ class LogPanel: gobject.idle_add(self.fill_log)
def pack_widgets(self): - liststore = self.builder.get_object('liststore_log') + listStore = self.builder.get_object('liststore_log')
- liststore.set_sort_func(1, self._compare_rows) - liststore.set_sort_column_id(1, gtk.SORT_DESCENDING) + listStore.set_sort_func(1, self._compare_rows) + listStore.set_sort_column_id(1, gtk.SORT_DESCENDING)
def fill_log(self): if time.time() - self._lastUpdate < REFRESH_RATE: return
- liststore = self.builder.get_object('liststore_log') - liststore.clear() + listStore = self.builder.get_object('liststore_log') + listStore.clear()
self.lock.acquire() try: @@ -91,7 +90,7 @@ class LogPanel: timeLabel = time.strftime('%H:%M:%S', time.localtime(entry.timestamp))
row = (long(entry.timestamp), timeLabel, entry.type, entry.msg, entry.color) - liststore.append(row) + listStore.append(row) finally: self.lock.release()
@@ -106,6 +105,7 @@ class LogPanel: self.msgLog.appendleft(event) finally: self.lock.release() + gobject.idle_add(self.fill_log)
def _register_arm_event(self, level, msg, eventTime): @@ -118,9 +118,9 @@ class LogPanel: eventColor = theme.colors[RUNLEVEL_EVENT_COLOR[level]] self.register_event(LogEntry(time.time(), "TORCTL_%s" % level, msg, eventColor))
- def _compare_rows(self, treemodel, iter1, iter2, data=None): - timestamp_raw1 = treemodel.get(iter1, 0) - timestamp_raw2 = treemodel.get(iter2, 0) + def _compare_rows(self, treeModel, iter1, iter2, data=None): + timestampRaw1 = treeModel.get(iter1, 0) + timestampRaw2 = treeModel.get(iter2, 0)
- return cmp(timestamp_raw1, timestamp_raw2) + return cmp(timestampRaw1, timestampRaw2)
diff --git a/src/starter.py b/src/starter.py index 01acf24..6ff78b1 100644 --- a/src/starter.py +++ b/src/starter.py @@ -442,7 +442,7 @@ if __name__ == '__main__':
if launchGui == True: import gui.controller - gui.controller.startGui() + gui.controller.start_gui() else: cli.controller.startTorMonitor(time.time() - initTime)
tor-commits@lists.torproject.org