[tor-commits] [arm/master] Minor api, formatting, and documentation changes

atagar at torproject.org atagar at torproject.org
Sat Jun 4 21:12:31 UTC 2011


commit b5c7dca851bb7f1e13c90bd667136398fa89ce01
Author: Damian Johnson <atagar at torproject.org>
Date:   Tue May 31 20:50:03 2011 -0700

    Minor api, formatting, and documentation changes
    
    Revising some of the merged changes for the menus.
---
 src/cli/controller.py |   10 +++-------
 src/cli/popups.py     |   15 +++++----------
 src/util/menuItem.py  |   22 ++++++++++++----------
 src/util/panel.py     |   25 +++++++++++++++++--------
 4 files changed, 37 insertions(+), 35 deletions(-)

diff --git a/src/cli/controller.py b/src/cli/controller.py
index bb258c3..fcbaed5 100644
--- a/src/cli/controller.py
+++ b/src/cli/controller.py
@@ -7,6 +7,7 @@ import time
 import curses
 import threading
 
+import cli.menu
 import cli.popups
 import cli.headerPanel
 import cli.logPanel
@@ -17,7 +18,6 @@ import cli.graphing.bandwidthStats
 import cli.graphing.connStats
 import cli.graphing.resourceStats
 import cli.connections.connPanel
-import cli.menu
 
 from util import connections, conf, enum, log, panel, sysTools, torConfig, torTools
 
@@ -77,9 +77,6 @@ def initController(stdscr, startTime):
   # fourth page: torrc
   pagePanels.append([cli.torrcPanel.TorrcPanel(stdscr, cli.torrcPanel.Config.TORRC, config)])
   
-  # top menu
-  menu = cli.menu.Menu()
-  
   # initializes the controller
   ARM_CONTROLLER = Controller(stdscr, stickyPanels, pagePanels)
   
@@ -110,7 +107,7 @@ class LabelPanel(panel.Panel):
   """
   
   def __init__(self, stdscr):
-    panel.Panel.__init__(self, stdscr, "msg", 0, 1)
+    panel.Panel.__init__(self, stdscr, "msg", 0, height=1)
     self.msgText = ""
     self.msgAttr = curses.A_NORMAL
   
@@ -144,7 +141,6 @@ class Controller:
       stdscr       - curses window
       stickyPanels - panels shown at the top of each page
       pagePanels   - list of pages, each being a list of the panels on it
-      menu         - popup drop-down menu
     """
     
     self._screen = stdscr
@@ -304,7 +300,7 @@ class Controller:
       
       if attr == None:
         if not self._isPaused:
-          msg = "page %i / %i - m: menu, q: quit, p: pause, h: page help" % (self._page + 1, len(self._pagePanels))
+          msg = "page %i / %i - m: menu, p: pause, h: page help, q: quit" % (self._page + 1, len(self._pagePanels))
           attr = curses.A_NORMAL
         else:
           msg = "Paused"
diff --git a/src/cli/popups.py b/src/cli/popups.py
index b3eb105..0e50aa1 100644
--- a/src/cli/popups.py
+++ b/src/cli/popups.py
@@ -8,7 +8,7 @@ import cli.controller
 
 from util import panel, uiTools
 
-def init(height = -1, width = -1, top = -1, left = -1):
+def init(height = -1, width = -1, top = 0, left = 0):
   """
   Preparation for displaying a popup. This creates a popup with a valid
   subwindow instance. If that's successful then the curses lock is acquired
@@ -19,19 +19,14 @@ def init(height = -1, width = -1, top = -1, left = -1):
   Arguments:
     height - maximum height of the popup
     width  - maximum width of the popup
+    top    - top position, relative to the sticky content
+    left   - left position from the screen
   """
   
   control = cli.controller.getController()
-  topSize = sum(stickyPanel.getHeight() for stickyPanel in control.getStickyPanels())
-  leftSize = 0
-
-  if top != -1:
-    topSize = topSize + top
-  if left != -1:
-    leftSize = left
+  stickyHeight = sum(stickyPanel.getHeight() for stickyPanel in control.getStickyPanels())
   
-  popup = panel.Panel(control.getScreen(), "popup", topSize, height, width)
-  popup.setLeft(leftSize)
+  popup = panel.Panel(control.getScreen(), "popup", top + stickyHeight, left, height, width)
   popup.setVisible(True)
   
   # Redraws the popup to prepare a subwindow instance. If none is spawned then
diff --git a/src/util/menuItem.py b/src/util/menuItem.py
index b48c433..277c78a 100644
--- a/src/util/menuItem.py
+++ b/src/util/menuItem.py
@@ -1,25 +1,27 @@
 """
-Menu Item class, used by the drop-down menus
+Menu Item class, used by the drop-down menus.
 """
 
 class MenuItem():
-  """Contains title, callback handler and possible children"""
-
+  """
+  Contains title, callback handler and possible children.
+  """
+  
   def __init__(self, label=None, callback=None, children=[], enabled=None):
     self._label = label
     self._callback = callback
     self._children = children
     self._enabled = enabled
-
+  
   def getLabel(self):
     return self._label
-
+  
   def isLeaf(self):
     return self._children == []
-
+  
   def isParent(self):
     return self._children != []
-
+  
   def isEnabled(self):
     if self._enabled == None:
       return True
@@ -27,13 +29,13 @@ class MenuItem():
       return self._enabled()
     else:
       return self._enabled
-
+  
   def getChildren(self):
     return self._children
-
+  
   def getChildrenCount(self):
     return len(self._children)
-
+  
   def select(self):
     return self._callback(self)
 
diff --git a/src/util/panel.py b/src/util/panel.py
index 4fc2158..93b44c2 100644
--- a/src/util/panel.py
+++ b/src/util/panel.py
@@ -43,7 +43,7 @@ class Panel():
   redraw().
   """
   
-  def __init__(self, parent, name, top, height=-1, width=-1):
+  def __init__(self, parent, name, top, left=0, height=-1, width=-1):
     """
     Creates a durable wrapper for a curses subwindow in the given parent.
     
@@ -51,6 +51,7 @@ class Panel():
       parent - parent curses window
       name   - identifier for the panel
       top    - positioning of top within parent
+      left   - positioning of the left edge within the parent
       height - maximum height of panel (uses all available space if -1)
       width  - maximum width of panel (uses all available space if -1)
     """
@@ -74,7 +75,7 @@ class Panel():
     self.pauseTime = -1
     
     self.top = top
-    self.left = 0
+    self.left = left
     self.height = height
     self.width = width
     
@@ -256,25 +257,33 @@ class Panel():
       self.top = top
       self.win = None
   
-  def getHeight(self):
+  def getLeft(self):
     """
-    Provides the height used for subwindows (-1 if it isn't limited).
+    Provides the left position where this subwindow is placed within its
+    parent.
     """
     
-    return self.height
-
+    return self.left
+  
   def setLeft(self, left):
     """
-    Changes the position where subwindows are placed within its parent.
+    Changes the left position where this subwindow is placed within its parent.
     
     Arguments:
-      top - positioning of top within parent
+      left - positioning of top within parent
     """
     
     if self.left != left:
       self.left = left
       self.win = None
   
+  def getHeight(self):
+    """
+    Provides the height used for subwindows (-1 if it isn't limited).
+    """
+    
+    return self.height
+  
   def setHeight(self, height):
     """
     Changes the height used for subwindows. This uses all available space if -1.





More information about the tor-commits mailing list