[tor-commits] [arm/master] Added support for File->Exit and Configuation->Reset Tor.
atagar at torproject.org
atagar at torproject.org
Sat Jun 4 21:12:31 UTC 2011
commit 62f118867dca5848d798bc2747a87b517bf81db9
Author: Kamran Riaz Khan <krkhan at inspirated.com>
Date: Thu Jun 2 15:28:07 2011 +0500
Added support for File->Exit and Configuation->Reset Tor.
Event handlers can return a key which shall be carried all the way
back to the controller which can use it for the next override in case
it's recognized. Exit and Reset Tor return 'q' and 'x' keys
respectively.
cli.__all__ is updated to include menu module.
---
src/cli/__init__.py | 2 +-
src/cli/controller.py | 5 ++++-
src/cli/menu.py | 15 +++++++++++----
src/util/menuItem.py | 2 +-
4 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/cli/__init__.py b/src/cli/__init__.py
index 1564f68..81fabeb 100644
--- a/src/cli/__init__.py
+++ b/src/cli/__init__.py
@@ -2,5 +2,5 @@
Panels, popups, and handlers comprising the arm user interface.
"""
-__all__ = ["configPanel", "controller", "descriptorPopup", "headerPanel", "logPanel", "popups", "torrcPanel"]
+__all__ = ["configPanel", "controller", "descriptorPopup", "headerPanel", "logPanel", "menu", "popups", "torrcPanel"]
diff --git a/src/cli/controller.py b/src/cli/controller.py
index d073312..bb258c3 100644
--- a/src/cli/controller.py
+++ b/src/cli/controller.py
@@ -518,7 +518,10 @@ def drawTorMonitor(stdscr, startTime):
menu = cli.menu.Menu()
menuKeys = menu.showMenu(keys=menuKeys)
if menuKeys != []:
- overrideKey = ord('m')
+ for key in (ord('m'), ord('q'), ord('x')):
+ if key in menuKeys:
+ menuKeys.remove(key)
+ overrideKey = key
elif key == ord('q') or key == ord('Q'):
# provides prompt to confirm that arm should exit
if CONFIG["features.confirmQuit"]:
diff --git a/src/cli/menu.py b/src/cli/menu.py
index beceb01..47e8d09 100644
--- a/src/cli/menu.py
+++ b/src/cli/menu.py
@@ -19,7 +19,7 @@ class Menu():
DEFAULT_ROOT = menuItem.MenuItem(label="Root", children=(
menuItem.MenuItem(label="File", children=(
menuItem.MenuItem(label="Exit",
- callback=self._callbackDefault),)),
+ callback=lambda item: self._callbackReturnKey(ord('q'))),)),
menuItem.MenuItem(label="Logs", children=(
menuItem.MenuItem(label="Events",
callback=lambda item: self._callbackPressKey('log', ord('e'))),
@@ -88,7 +88,7 @@ class Menu():
menuItem.MenuItem(label="Reload",
callback=lambda item: self._callbackPressKey('configFile', ord('r'))),
menuItem.MenuItem(label="Reset Tor",
- callback=self._callbackDefault),))
+ callback=lambda item: self._callbackReturnKey(ord('x'))),))
))
self._first = [0]
@@ -291,6 +291,7 @@ class Menu():
cascaded, returnkeys = self._cascadeNLevel()
if cascaded == False:
index = self._first[TOPLEVEL] + self._selection[TOPLEVEL] + 1
+ returnkeys.append(ord('m'))
for i in range(index):
returnkeys.append(curses.KEY_RIGHT)
returnkeys.append(curses.KEY_DOWN)
@@ -298,6 +299,7 @@ class Menu():
elif key == curses.KEY_LEFT:
index = self._first[TOPLEVEL] + self._selection[TOPLEVEL] - 1
index = index % self._rootItem.getChildrenCount()
+ returnkeys.append(ord('m'))
for i in range(index):
returnkeys.append(curses.KEY_RIGHT)
returnkeys.append(curses.KEY_DOWN)
@@ -306,7 +308,9 @@ class Menu():
self._removeLevel()
break
elif uiTools.isSelectionKey(key):
- self._handleEvent()
+ returnkey = self._handleEvent()
+ if returnkey:
+ returnkeys.append(returnkey)
self._removeLevel()
break
@@ -374,7 +378,7 @@ class Menu():
item = self._getCurrentItem()
if item.isLeaf():
- item.select()
+ return item.select()
else:
self._cascadeNLevel()
@@ -429,3 +433,6 @@ class Menu():
panel = control.getPanel(panel)
panel.handleKey(key)
+ def _callbackReturnKey(self, key):
+ return key
+
diff --git a/src/util/menuItem.py b/src/util/menuItem.py
index 6868db6..b48c433 100644
--- a/src/util/menuItem.py
+++ b/src/util/menuItem.py
@@ -35,5 +35,5 @@ class MenuItem():
return len(self._children)
def select(self):
- self._callback(self)
+ return self._callback(self)
More information about the tor-commits
mailing list