commit 5ffd3b0506cc6acb618456ae276dd0238c1e3936 Author: Kamran Riaz Khan krkhan@inspirated.com Date: Wed Jun 1 17:06:27 2011 +0500
Next top-level item is dropped down in case right/left arrow keys are pressed on leaf submenus.
In order to let the controller redraw before next top-level item is dropped down, "menu keys" are calculated and returned back to the controller. The controller overrides its key so that menu is redrawn, redraws all other panels and sends back the "menu keys" to the new menu instance. This maintains the illusion of top-level drop-down moving right/left while screen is cleared and redrawn once in between. --- src/cli/controller.py | 6 +++++- src/cli/menu.py | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/src/cli/controller.py b/src/cli/controller.py index 25c3051..d073312 100644 --- a/src/cli/controller.py +++ b/src/cli/controller.py @@ -477,6 +477,8 @@ def drawTorMonitor(stdscr, startTime): # main draw loop overrideKey = None # uses this rather than waiting on user input isUnresponsive = False # flag for heartbeat responsiveness check + + menuKeys = []
while True: displayPanels = control.getDisplayPanels() @@ -514,7 +516,9 @@ def drawTorMonitor(stdscr, startTime): control.setPaused(not control.isPaused()) elif key == ord('m') or key == ord('M'): menu = cli.menu.Menu() - menu.showMenu() + menuKeys = menu.showMenu(keys=menuKeys) + if menuKeys != []: + overrideKey = ord('m') 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 da45309..29b6f82 100644 --- a/src/cli/menu.py +++ b/src/cli/menu.py @@ -99,7 +99,10 @@ class Menu(): else: self._rootItem = DEFAULT_ROOT
- def showMenu(self): + def showMenu(self, keys=[]): + keys.reverse() + returnkeys = [] + popup, width, height = popups.init(height=3) if popup: try: @@ -112,14 +115,18 @@ class Menu(): popup.win.refresh()
control = cli.controller.getController() - key = control.getScreen().getch() + + if keys == []: + key = control.getScreen().getch() + else: + key = keys.pop()
if key == curses.KEY_RIGHT: self._moveTopLevelRight(width) elif key == curses.KEY_LEFT: self._moveTopLevelLeft(width) elif key == curses.KEY_DOWN: - self._cascadeNLevel() + cascaded, returnkeys = self._cascadeNLevel() break elif key == 27: break @@ -130,6 +137,8 @@ class Menu(): finally: popups.finalize()
+ return returnkeys + def _appendLevel(self): self._first.append(0) self._selection.append(0) @@ -245,7 +254,7 @@ class Menu(): parent = self._getCurrentItem()
if parent.isLeaf(): - return + return (False, [])
self._appendLevel()
@@ -261,6 +270,7 @@ class Menu(): self._moveNLevelDown(height)
if popup.win: + returnkeys = [] try: while True: popup.win.erase() @@ -278,7 +288,19 @@ class Menu(): elif key == curses.KEY_UP: self._moveNLevelUp(height) elif key == curses.KEY_RIGHT: - self._cascadeNLevel() + cascaded, returnkeys = self._cascadeNLevel() + if cascaded == False: + index = self._first[TOPLEVEL] + self._selection[TOPLEVEL] + 1 + for i in range(index): + returnkeys.append(curses.KEY_RIGHT) + returnkeys.append(curses.KEY_DOWN) + break + elif key == curses.KEY_LEFT: + index = self._first[TOPLEVEL] + self._selection[TOPLEVEL] - 1 + index = index % self._rootItem.getChildrenCount() + for i in range(index): + returnkeys.append(curses.KEY_RIGHT) + returnkeys.append(curses.KEY_DOWN) break elif key == 27: self._removeLevel() @@ -291,6 +313,10 @@ class Menu(): finally: popups.finalize()
+ return (True, returnkeys) + + return (False, []) + def _drawNLevel(self, popup, width, height): printable = self._calculateNLevelHeights(level=PARENTLEVEL) parent = self._getCurrentItem(level=PARENTLEVEL)
tor-commits@lists.torproject.org