[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [arm/release] Binding handlers for the actions submenu
commit 66e10cc08f300e46d8c6eb9857a664d824bf1159
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sat Jun 11 19:19:41 2011 -0700
Binding handlers for the actions submenu
Making a functional actions submenu which includes options for...
- Close Menu
- Pause / Unpause
- Reset Tor
- Quit
---
src/cli/controller.py | 23 +++++++++++++++++++----
src/cli/menu/actions.py | 30 ++++++++++++++++++++++++++----
src/cli/menu/item.py | 7 +++++--
3 files changed, 50 insertions(+), 10 deletions(-)
diff --git a/src/cli/controller.py b/src/cli/controller.py
index 997d9d3..faf9248 100644
--- a/src/cli/controller.py
+++ b/src/cli/controller.py
@@ -150,6 +150,7 @@ class Controller:
self._page = 0
self._isPaused = False
self._forceRedraw = False
+ self._isDone = False
self.setMsg() # initializes our control message
def getScreen(self):
@@ -312,6 +313,20 @@ class Controller:
if redraw: controlPanel.redraw(True)
else: self._forceRedraw = True
+
+ def isDone(self):
+ """
+ True if arm should be terminated, false otherwise.
+ """
+
+ return self._isDone
+
+ def quit(self):
+ """
+ Terminates arm after the input is processed.
+ """
+
+ self._isDone = True
def shutdownDaemons():
"""
@@ -477,7 +492,7 @@ def drawTorMonitor(stdscr, startTime):
menuKeys = []
- while True:
+ while not control.isDone():
displayPanels = control.getDisplayPanels()
isUnresponsive = heartbeatCheck(isUnresponsive)
@@ -529,9 +544,7 @@ def drawTorMonitor(stdscr, startTime):
quitConfirmed = confirmationKey in (ord('q'), ord('Q'))
else: quitConfirmed = True
- if quitConfirmed:
- shutdownDaemons()
- break
+ if quitConfirmed: control.quit()
elif key == ord('x') or key == ord('X'):
# provides prompt to confirm that arm should issue a sighup
msg = "This will reset Tor's internal state. Are you sure (x again to confirm)?"
@@ -547,4 +560,6 @@ def drawTorMonitor(stdscr, startTime):
for panelImpl in displayPanels:
isKeystrokeConsumed = panelImpl.handleKey(key)
if isKeystrokeConsumed: break
+
+ shutdownDaemons()
diff --git a/src/cli/menu/actions.py b/src/cli/menu/actions.py
index f6f88ba..751751f 100644
--- a/src/cli/menu/actions.py
+++ b/src/cli/menu/actions.py
@@ -2,18 +2,20 @@
Generates the menu for arm, binding options with their related actions.
"""
+import functools
+
+import cli.controller
import cli.menu.item
+from util import torTools
+
def makeMenu():
"""
Constructs the base menu and all of its contents.
"""
baseMenu = cli.menu.item.Submenu("")
-
- fileMenu = cli.menu.item.Submenu("File")
- fileMenu.add(cli.menu.item.MenuItem("Exit", None))
- baseMenu.add(fileMenu)
+ baseMenu.add(makeActionsMenu())
logsMenu = cli.menu.item.Submenu("Logs")
logsMenu.add(cli.menu.item.MenuItem("Events", None))
@@ -70,4 +72,24 @@ def makeMenu():
return baseMenu
+def makeActionsMenu():
+ """
+ Submenu consisting of...
+ Close Menu
+ Pause / Unpause
+ Reset Tor
+ Exit
+ """
+
+ control = cli.controller.getController()
+ actionsMenu = cli.menu.item.Submenu("Actions")
+ actionsMenu.add(cli.menu.item.MenuItem("Close Menu", None))
+
+ if control.isPaused(): label, arg = "Unpause", False
+ else: label, arg = "Pause", True
+ actionsMenu.add(cli.menu.item.MenuItem(label, functools.partial(control.setPaused, arg)))
+
+ actionsMenu.add(cli.menu.item.MenuItem("Reset Tor", torTools.getConn().reload))
+ actionsMenu.add(cli.menu.item.MenuItem("Exit", control.quit))
+ return actionsMenu
diff --git a/src/cli/menu/item.py b/src/cli/menu/item.py
index bfc7ffd..8c5d314 100644
--- a/src/cli/menu/item.py
+++ b/src/cli/menu/item.py
@@ -53,8 +53,8 @@ class MenuItem():
the menu and false otherwise.
"""
- if self._callback: return self._callback()
- else: return False
+ if self._callback: self._callback()
+ return True
def next(self):
"""
@@ -143,4 +143,7 @@ class Submenu(MenuItem):
"""
return not bool(self._children)
+
+ def select(self):
+ return False
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits