[tor-commits] [arm/master] Use a tree view for prettifying log entries.

atagar at torproject.org atagar at torproject.org
Mon Jul 4 15:40:30 UTC 2011


commit c9ac18befb91178fdcd4fb86c9fcbd503396c889
Author: Kamran Riaz Khan <krkhan at inspirated.com>
Date:   Mon Jun 20 18:14:30 2011 +0500

    Use a tree view for prettifying log entries.
    
    (In future, this can prove to be helpful by being sortable.)
---
 src/gui/arm.xml     |   52 +++++++++++++++++++++++++++++++++++++++++++++++++-
 src/gui/logPanel.py |   21 +++++++------------
 2 files changed, 58 insertions(+), 15 deletions(-)

diff --git a/src/gui/arm.xml b/src/gui/arm.xml
index 8cbb924..f067542 100644
--- a/src/gui/arm.xml
+++ b/src/gui/arm.xml
@@ -134,6 +134,18 @@
       </row>
     </data>
   </object>
+  <object class="GtkListStore" id="liststore_log">
+    <columns>
+      <!-- column-name timestamp -->
+      <column type="gchararray"/>
+      <!-- column-name type -->
+      <column type="gchararray"/>
+      <!-- column-name msg -->
+      <column type="gchararray"/>
+      <!-- column-name foreground -->
+      <column type="gchararray"/>
+    </columns>
+  </object>
   <object class="GtkWindow" id="window_main">
     <property name="title" translatable="yes">arm</property>
     <property name="default_width">640</property>
@@ -672,10 +684,46 @@ each direction. (Default: 0) &lt;/span&gt;</property>
                 <property name="hscrollbar_policy">automatic</property>
                 <property name="vscrollbar_policy">automatic</property>
                 <child>
-                  <object class="GtkTextView" id="textview_log">
+                  <object class="GtkTreeView" id="treeview_log">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
-                    <property name="buffer">textbuffer_log</property>
+                    <property name="model">liststore_log</property>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn_log_timestamp">
+                        <property name="title">Time</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="cellrenderertext_log_timestamp"/>
+                          <attributes>
+                            <attribute name="foreground">3</attribute>
+                            <attribute name="markup">0</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn_log_type">
+                        <property name="title">Type</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="cellrenderertext_log_type"/>
+                          <attributes>
+                            <attribute name="foreground">3</attribute>
+                            <attribute name="markup">1</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkTreeViewColumn" id="treeviewcolumn_msg">
+                        <property name="title">Message</property>
+                        <child>
+                          <object class="GtkCellRendererText" id="cellrenderertext_log_msg"/>
+                          <attributes>
+                            <attribute name="foreground">3</attribute>
+                            <attribute name="markup">2</attribute>
+                          </attributes>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                 </child>
               </object>
diff --git a/src/gui/logPanel.py b/src/gui/logPanel.py
index 174ed64..bacc6f2 100644
--- a/src/gui/logPanel.py
+++ b/src/gui/logPanel.py
@@ -4,6 +4,7 @@ Base class for implementing graphing functionality.
 
 import random
 import sys
+import time
 
 from collections import deque
 
@@ -28,24 +29,18 @@ class LogPanel:
     finally:
       log.LOG_LOCK.release()
 
-    textbuffer = self.builder.get_object('textbuffer_log')
-
-    for color in RUNLEVEL_EVENT_COLOR.values():
-      textbuffer.create_tag(color, foreground=color)
-
-    gobject.timeout_add(1000, self.print_log)
-
-  def print_log(self):
-    textbuffer = self.builder.get_object('textbuffer_log')
-    start, end = textbuffer.get_bounds()
-    textbuffer.delete(start, end)
+  def fill_log(self):
+    liststore = self.builder.get_object('liststore_log')
+    liststore.clear()
 
     for entry in self.msgLog:
-      iter = textbuffer.get_iter_at_mark(textbuffer.get_insert())
-      textbuffer.insert_with_tags_by_name(iter, entry.getDisplayMessage() + "\n", entry.color)
+      timeLabel = time.strftime('%H:%M:%S', time.localtime(entry.timestamp))
+      row = (timeLabel, entry.type, entry.msg, entry.color)
+      liststore.append(row)
 
   def register_event(self, event):
     self.msgLog.appendleft(event)
+    self.fill_log()
 
   def pack_widgets(self):
     pass





More information about the tor-commits mailing list