commit 1bd068fab1fae856d7ca64114fcae03c769b9246 Author: Kamran Riaz Khan krkhan@inspirated.com Date: Thu Jul 14 14:08:38 2011 +0500
Derive sticky panel values from CLI HeaderPanel. --- src/gui/arm.xml | 47 ------------------- src/gui/controller.py | 5 ++- src/gui/stickyPanel.py | 118 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 48 deletions(-)
diff --git a/src/gui/arm.xml b/src/gui/arm.xml index 67409ae..f71d0b7 100644 --- a/src/gui/arm.xml +++ b/src/gui/arm.xml @@ -11,53 +11,6 @@ <!-- column-name foreground --> <column type="gchararray"/> </columns> - <data> - <row> - <col id="0" translatable="yes">arm</col> - <col id="1" translatable="yes">orthanc (Linux 2.6.35.11-83.fc14)</col> - <col id="2" translatable="yes">black</col> - </row> - <row> - <col id="0" translatable="yes">Tor</col> - <col id="1" translatable="yes">0.2.1.28 (obsolete)</col> - <col id="2" translatable="yes">black</col> - </row> - <row> - <col id="0" translatable="yes">Relaying</col> - <col id="1" translatable="yes">Disabled</col> - <col id="2" translatable="yes">red</col> - </row> - <row> - <col id="0" translatable="yes">Control Port</col> - <col id="1" translatable="yes">9051 (open)</col> - <col id="2" translatable="yes">black</col> - </row> - <row> - <col id="0" translatable="yes">CPU Tor</col> - <col id="1" translatable="yes">0.0%</col> - <col id="2" translatable="yes">black</col> - </row> - <row> - <col id="0" translatable="yes">CPU arm</col> - <col id="1" translatable="yes">0.0%</col> - <col id="2" translatable="yes">black</col> - </row> - <row> - <col id="0" translatable="yes">Memory</col> - <col id="1" translatable="yes">20 MB (1.0%)</col> - <col id="2" translatable="yes">black</col> - </row> - <row> - <col id="0" translatable="yes">PID</col> - <col id="1" translatable="yes">3980</col> - <col id="2" translatable="yes">black</col> - </row> - <row> - <col id="0" translatable="yes">Uptime</col> - <col id="1" translatable="yes">01:01:34</col> - <col id="2" translatable="yes">black</col> - </row> - </data> </object> <object class="GtkTreeStore" id="treestore_conn"> <columns> diff --git a/src/gui/controller.py b/src/gui/controller.py index a69fdef..854e388 100644 --- a/src/gui/controller.py +++ b/src/gui/controller.py @@ -6,7 +6,7 @@ import time
from util import log, torTools from connections import connPanel -from gui import logPanel +from gui import logPanel, stickyPanel from gui.graphing import bandwidthStats
gobject.threads_init() @@ -29,6 +29,9 @@ class GuiController: self.connPanel.pack_widgets() self.connPanel.start()
+ self.stickyPanel = stickyPanel.StickyPanel(self.builder) + self.stickyPanel.pack_widgets() + def run(self): window = self.builder.get_object('window_main')
diff --git a/src/gui/stickyPanel.py b/src/gui/stickyPanel.py new file mode 100644 index 0000000..89b5485 --- /dev/null +++ b/src/gui/stickyPanel.py @@ -0,0 +1,118 @@ +""" +Sticky panel. +""" + +import random +import sys +import time + +from collections import deque + +import gobject +import gtk + +from cli.headerPanel import (HeaderPanel as CliHeaderPanel, VERSION_STATUS_COLORS) +from TorCtl import TorCtl +from util import connections, sysTools, gtkTools, uiTools, torTools + +class StickyPanel(CliHeaderPanel): + def __init__(self, builder): + CliHeaderPanel.__init__(self, None, time.time()) + + self.builder = builder + + gobject.timeout_add(3000, self._fill_entries) + + def pack_widgets(self): + pass + + def _fill_entries(self): + self.valsLock.acquire() + + liststore = self.builder.get_object('liststore_sticky') + theme = gtkTools.Theme() + + 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) + + 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) + + includeControlPort = True + key = "Relaying" + if self.vals["tor/orPort"]: + myAddress = "Unknown" + if self.vals["tor/orListenAddr"]: myAddress = self.vals["tor/orListenAddr"] + elif self.vals["tor/address"]: myAddress = self.vals["tor/address"] + + dirPortLabel = ", Dir Port: %s" % self.vals["tor/dirPort"] if self.vals["tor/dirPort"] != "0" else "" + + value = "%s%s%s" % (self.vals["tor/nickname"], " - " + myAddress, ":" + self.vals["tor/orPort"], dirPortLabel) + else: + if self._isTorConnected: + value = "Disabled" + else: + statusTime = torTools.getConn().getStatus()[1] + + if statusTime: + statusTimeLabel = time.strftime("%H:%M %m/%d/%Y, ", time.localtime(statusTime)) + else: statusTimeLabel = "" + + value = "%s%s" % ("Tor Disconnected", statusTimeLabel) + includeControlPort = False + row = (key, value, theme.colors['active']) + liststore.append(row) + + key = "Control Port" + if includeControlPort: + if self.vals["tor/isAuthPassword"]: authType = "password" + elif self.vals["tor/isAuthCookie"]: authType = "cookie" + else: authType = "open" + + 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) + + + if self.vals["stat/rss"] != "0": memoryLabel = uiTools.getSizeLabel(int(self.vals["stat/rss"])) + else: memoryLabel = "0" + + if self.vals["tor/startTime"]: + if self.isPaused() or not self._isTorConnected: + uptimeLabel = uiTools.getShortTimeLabel(self.getPauseTime() - self.vals["tor/startTime"]) + else: + uptimeLabel = uiTools.getShortTimeLabel(time.time() - self.vals["tor/startTime"]) + + key = "CPU" + value = "%s%% Tor, %s%% arm" % (self.vals["stat/%torCpu"], self.vals["stat/%armCpu"]) + row = (key, value, theme.colors['active']) + liststore.append(row) + + key = "Memory" + value = "%s (%s%%)" % (memoryLabel, self.vals["stat/%mem"]) + row = (key, value, theme.colors['active']) + liststore.append(row) + + key = "PID" + value = "%s" % (self.vals["tor/pid"] if self._isTorConnected else "") + row = (key, value, theme.colors['active']) + liststore.append(row) + + key = "Uptime" + value = uptimeLabel + row = (key, value, theme.colors['active']) + liststore.append(row) + + self.valsLock.release() + + return True +
tor-commits@lists.torproject.org