[tor-commits] [arm/master] Moving descriptor popup out of the controller

atagar at torproject.org atagar at torproject.org
Thu May 12 16:39:25 UTC 2011


commit dd1bde92b4d9b564cccb9bbd6fa3ba44fe3b41db
Author: Damian Johnson <atagar at torproject.org>
Date:   Thu May 12 09:37:59 2011 -0700

    Moving descriptor popup out of the controller
    
    Putting descriptor popup triggering into the connection panel, and revising
    descriptorPopup.py to use new styled popups.
---
 src/cli/connections/connPanel.py |    4 +++
 src/cli/controller.py            |   17 ------------
 src/cli/descriptorPopup.py       |   52 ++++++++++++++++++++++----------------
 src/cli/popups.py                |    5 ++-
 4 files changed, 37 insertions(+), 41 deletions(-)

diff --git a/src/cli/connections/connPanel.py b/src/cli/connections/connPanel.py
index 8ecffc2..7fab33e 100644
--- a/src/cli/connections/connPanel.py
+++ b/src/cli/connections/connPanel.py
@@ -6,6 +6,7 @@ import time
 import curses
 import threading
 
+import cli.descriptorPopup
 import cli.popups
 
 from cli.connections import entries, connEntry, circEntry
@@ -191,6 +192,9 @@ class ConnectionPanel(panel.Panel, threading.Thread):
       
       # applies new setting
       if selection != -1: self.setListingType(options[selection])
+    elif key == ord('d') or key == ord('D'):
+      # presents popup for raw consensus data
+      cli.descriptorPopup.showDescriptorPopup(self)
     else: isKeystrokeConsumed = False
     
     self.valsLock.release()
diff --git a/src/cli/controller.py b/src/cli/controller.py
index c4b9442..20a4e7e 100644
--- a/src/cli/controller.py
+++ b/src/cli/controller.py
@@ -954,23 +954,6 @@ def drawTorMonitor(stdscr, startTime, loggedEvents, isBlindMode):
         setPauseState(panels, isPaused, page)
       finally:
         panel.CURSES_LOCK.release()
-    elif page == 1 and key in (ord('d'), ord('D')):
-      # presents popup for raw consensus data
-      panel.CURSES_LOCK.acquire()
-      try:
-        setPauseState(panels, isPaused, page, True)
-        curses.cbreak() # wait indefinitely for key presses (no timeout)
-        panelTitle = panels["conn"]._title
-        panels["conn"]._title = ""
-        panels["conn"].redraw(True)
-        
-        descriptorPopup.showDescriptorPopup(panels["popup"], stdscr, panels["conn"])
-        
-        panels["conn"]._title = panelTitle
-        setPauseState(panels, isPaused, page)
-        curses.halfdelay(REFRESH_RATE * 10) # reset normal pausing behavior
-      finally:
-        panel.CURSES_LOCK.release()
     else:
       for pagePanel in getPanels(page + 1):
         isKeystrokeConsumed = pagePanel.handleKey(key)
diff --git a/src/cli/descriptorPopup.py b/src/cli/descriptorPopup.py
index d57546c..920f2bc 100644
--- a/src/cli/descriptorPopup.py
+++ b/src/cli/descriptorPopup.py
@@ -7,6 +7,7 @@ import curses
 
 import controller
 import connections.connEntry
+import popups
 from util import panel, torTools, uiTools
 
 # field keywords used to identify areas for coloring
@@ -65,7 +66,7 @@ class PopupProperties:
     elif key == curses.KEY_PPAGE: self.scroll = max(self.scroll - height, 0)
     elif key == curses.KEY_NPAGE: self.scroll = max(0, min(self.scroll + height, len(self.text) - height))
 
-def showDescriptorPopup(popup, stdscr, connectionPanel):
+def showDescriptorPopup(connectionPanel):
   """
   Presents consensus descriptor in popup window with the following controls:
   Up, Down, Page Up, Page Down - scroll descriptor
@@ -73,10 +74,16 @@ def showDescriptorPopup(popup, stdscr, connectionPanel):
   Enter, Space, d, D - close popup
   """
   
+  # hides the title of the first panel on the page
+  topPanel = controller.getPanels(controller.getPage())[0]
+  topPanel.setTitleVisible(False)
+  topPanel.redraw(True)
+  
   properties = PopupProperties()
   isVisible = True
   
-  if not panel.CURSES_LOCK.acquire(False): return
+  panel.CURSES_LOCK.acquire()
+  
   try:
     while isVisible:
       selection = connectionPanel._scroller.getCursorSelection(connectionPanel._entryLines)
@@ -96,29 +103,30 @@ def showDescriptorPopup(popup, stdscr, connectionPanel):
         # tracks number of extra lines that will be taken due to text wrap
         height += (lineWidth - 2) / connectionPanel.maxX
       
-      popup.setHeight(min(len(properties.text) + height + 2, connectionPanel.maxY))
-      popup.recreate(stdscr, width)
-      
       while isVisible:
-        draw(popup, properties)
-        key = stdscr.getch()
+        popupHeight = min(len(properties.text) + height + 2, connectionPanel.maxY)
+        popup, _, _ = popups.init(popupHeight, width)
+        if not popup: break
         
-        if uiTools.isSelectionKey(key) or key in (ord('d'), ord('D')):
-          # closes popup
-          isVisible = False
-        elif key in (curses.KEY_LEFT, curses.KEY_RIGHT):
-          # navigation - pass on to connPanel and recreate popup
-          connectionPanel.handleKey(curses.KEY_UP if key == curses.KEY_LEFT else curses.KEY_DOWN)
-          break
-        else: properties.handleKey(key, popup.height - 2)
-    
-    popup.setHeight(9)
-    popup.recreate(stdscr, 80)
-  finally:
-    panel.CURSES_LOCK.release()
+        try:
+          draw(popup, properties)
+          key = controller.getScreen().getch()
+          
+          if uiTools.isSelectionKey(key) or key in (ord('d'), ord('D')):
+            # closes popup
+            isVisible = False
+          elif key in (curses.KEY_LEFT, curses.KEY_RIGHT):
+            # navigation - pass on to connPanel and recreate popup
+            connectionPanel.handleKey(curses.KEY_UP if key == curses.KEY_LEFT else curses.KEY_DOWN)
+            break
+          else: properties.handleKey(key, popup.height - 2)
+        finally: popups.finalize()
+  finally: panel.CURSES_LOCK.release()
+  
+  topPanel.setTitleVisible(True)
 
 def draw(popup, properties):
-  popup.clear()
+  popup.win.erase()
   popup.win.box()
   xOffset = 2
   
@@ -174,5 +182,5 @@ def draw(popup, properties):
       lineNum += 1
       if lineNum > pageHeight: break
       
-  popup.refresh()
+  popup.win.refresh()
 
diff --git a/src/cli/popups.py b/src/cli/popups.py
index 2b02685..de4bad6 100644
--- a/src/cli/popups.py
+++ b/src/cli/popups.py
@@ -301,9 +301,10 @@ def showMenu(title, options, oldSelection):
       elif key == curses.KEY_DOWN: selection = min(len(options) - 1, selection + 1)
       elif key == 27: selection, key = -1, curses.KEY_ENTER # esc - cancel
       
-    topPanel.setTitleVisible(True)
     curses.halfdelay(controller.REFRESH_RATE * 10) # reset normal pausing behavior
-  finally: finalize()
+  finally:
+    topPanel.setTitleVisible(True)
+    finalize()
   
   return selection
 



More information about the tor-commits mailing list