commit e5ae0d0a95b2739e3e1ec281eeab4f76d779087a Author: Kamran Riaz Khan krkhan@inspirated.com Date: Tue Jun 21 16:38:18 2011 +0500
Allow user to sort log entries in preferred order. --- src/gui/arm.xml | 18 +++++++++++------- src/gui/controller.py | 11 +++++++++-- src/gui/logPanel.py | 13 +++++++++++-- 3 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/src/gui/arm.xml b/src/gui/arm.xml index f067542..1e3681c 100644 --- a/src/gui/arm.xml +++ b/src/gui/arm.xml @@ -136,6 +136,8 @@ </object> <object class="GtkListStore" id="liststore_log"> <columns> + <!-- column-name timestamp_raw --> + <column type="gulong"/> <!-- column-name timestamp --> <column type="gchararray"/> <!-- column-name type --> @@ -691,11 +693,14 @@ each direction. (Default: 0) </span></property> <child> <object class="GtkTreeViewColumn" id="treeviewcolumn_log_timestamp"> <property name="title">Time</property> + <property name="sort_indicator">True</property> + <property name="sort_order">descending</property> + <property name="sort_column_id">1</property> <child> <object class="GtkCellRendererText" id="cellrenderertext_log_timestamp"/> <attributes> - <attribute name="foreground">3</attribute> - <attribute name="markup">0</attribute> + <attribute name="foreground">4</attribute> + <attribute name="markup">1</attribute> </attributes> </child> </object> @@ -706,8 +711,8 @@ each direction. (Default: 0) </span></property> <child> <object class="GtkCellRendererText" id="cellrenderertext_log_type"/> <attributes> - <attribute name="foreground">3</attribute> - <attribute name="markup">1</attribute> + <attribute name="foreground">4</attribute> + <attribute name="markup">2</attribute> </attributes> </child> </object> @@ -718,8 +723,8 @@ each direction. (Default: 0) </span></property> <child> <object class="GtkCellRendererText" id="cellrenderertext_log_msg"/> <attributes> - <attribute name="foreground">3</attribute> - <attribute name="markup">2</attribute> + <attribute name="foreground">4</attribute> + <attribute name="markup">3</attribute> </attributes> </child> </object> @@ -740,5 +745,4 @@ each direction. (Default: 0) </span></property> </object> </child> </object> - <object class="GtkTextBuffer" id="textbuffer_log"/> </interface> diff --git a/src/gui/controller.py b/src/gui/controller.py index 8f27df4..c5c8767 100644 --- a/src/gui/controller.py +++ b/src/gui/controller.py @@ -1,6 +1,9 @@ import gobject import gtk
+import thread +import time + from util import log, torTools from gui import logPanel from gui.graphing import bandwidthStats @@ -21,8 +24,12 @@ class GuiController: self.logPanel = logPanel.LogPanel(self.builder) self.logPanel.pack_widgets()
- log.log(log.DEBUG, "Hello World!") - log.log(log.ERR, "Hello Again!") + def random_entries(): + while True: + log.log(log.DEBUG, "Hello World at %s" % time.asctime(time.localtime())) + time.sleep(5) + + thread.start_new_thread(random_entries, ())
def run(self): window = self.builder.get_object('window_main') diff --git a/src/gui/logPanel.py b/src/gui/logPanel.py index bacc6f2..7197178 100644 --- a/src/gui/logPanel.py +++ b/src/gui/logPanel.py @@ -35,7 +35,7 @@ class LogPanel:
for entry in self.msgLog: timeLabel = time.strftime('%H:%M:%S', time.localtime(entry.timestamp)) - row = (timeLabel, entry.type, entry.msg, entry.color) + row = (long(entry.timestamp), timeLabel, entry.type, entry.msg, entry.color) liststore.append(row)
def register_event(self, event): @@ -43,7 +43,16 @@ class LogPanel: self.fill_log()
def pack_widgets(self): - pass + liststore = self.builder.get_object('liststore_log') + + liststore.set_sort_func(1, self._compare_rows) + liststore.set_sort_column_id(1, gtk.SORT_DESCENDING) + + def _compare_rows(self, treemodel, iter1, iter2, data=None): + timestamp_raw1 = treemodel.get(iter1, 0) + timestamp_raw2 = treemodel.get(iter2, 0) + + return cmp(timestamp_raw1, timestamp_raw2)
def _register_arm_event(self, level, msg, eventTime): eventColor = RUNLEVEL_EVENT_COLOR[level]
tor-commits@lists.torproject.org