commit 7d14b821ccabf017dbe023aa25edccdf1d0323e4
Author: Sambuddha Basu <sambuddhaba...@gmail.com>
Date:   Mon May 9 01:06:19 2016 +0400

    Event selection dialog takes care of previous selected event types
    Tor runlevels are followed by the rest of the events in the event selection 
dialog
---
 nyx/panel/log.py |  2 +-
 nyx/popups.py    | 18 ++++++++++--------
 2 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/nyx/panel/log.py b/nyx/panel/log.py
index f2183a7..b0789c3 100644
--- a/nyx/panel/log.py
+++ b/nyx/panel/log.py
@@ -147,7 +147,7 @@ class LogPanel(nyx.panel.DaemonPanel):
     Prompts the user to select the events being listened for.
     TODO: Replace show_event_selection_prompt() with this method.
     """
-    event_types = nyx.popups.new_select_event_types()
+    event_types = nyx.popups.new_select_event_types(self._event_types)
 
     if event_types and event_types != self._event_types:
       self._event_types = nyx.log.listen_for_events(self._register_tor_event, 
event_types)
diff --git a/nyx/popups.py b/nyx/popups.py
index 559f006..87e65e3 100644
--- a/nyx/popups.py
+++ b/nyx/popups.py
@@ -25,6 +25,7 @@ import nyx
 import nyx.arguments
 import nyx.controller
 import nyx.curses
+import nyx.log
 import nyx.panel
 
 from nyx.curses import RED, GREEN, YELLOW, CYAN, WHITE, NORMAL, BOLD, HIGHLIGHT
@@ -417,7 +418,7 @@ def select_event_types():
     return None
 
 
-def new_select_event_types():
+def new_select_event_types(initial_selection):
   """
   Presents a chart of event types Tor supports. The user can select a set of
   events.
@@ -433,8 +434,9 @@ def new_select_event_types():
     return
 
   events = events.split()
+  events = nyx.log.TOR_RUNLEVELS + [event for event in events if event not in 
nyx.log.TOR_RUNLEVELS]
   selection = 0
-  selected_events = []
+  selected_events = initial_selection
 
   def _render(subwindow):
     subwindow.box()
@@ -444,7 +446,7 @@ def new_select_event_types():
 
     for i, line in enumerate(tor_events):
       for j, in_line in enumerate(line):
-        x = subwindow.addstr(j * 30 + 1, i + 1, '[X]' if (i * 3 + j) in 
selected_events else '[ ]')
+        x = subwindow.addstr(j * 30 + 1, i + 1, '[X]' if in_line in 
selected_events else '[ ]')
         x = subwindow.addstr(x, i + 1, in_line, HIGHLIGHT if selection == (i * 
3 + j) else NORMAL)
 
     x = 30
@@ -467,14 +469,14 @@ def new_select_event_types():
       elif key.match('right'):
         selection = min(len(events) + 1, selection + 1)
       elif key.is_selection():
-        if selection in selected_events:
-          selected_events.remove(selection)
-        elif selection == len(events):
-          return set([events[i] for i in selected_events])
+        if selection == len(events):
+          return set(selected_events)
         elif selection == (len(events) + 1):
           return None
+        elif events[selection] in selected_events:
+          selected_events.remove(events[selection])
         else:
-          selected_events.append(selection)
+          selected_events.append(events[selection])
       elif key.match('esc'):
         return None
 



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

Reply via email to