oops! never added helpbar.py
authorJohn Ladan <jladan@uwaterloo.ca>
Fri, 30 Mar 2012 18:25:08 +0000 (14:25 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Fri, 30 Mar 2012 18:25:08 +0000 (14:25 -0400)
helpBar.py [new file with mode: 0644]

diff --git a/helpBar.py b/helpBar.py
new file mode 100644 (file)
index 0000000..5b01a17
--- /dev/null
@@ -0,0 +1,68 @@
+import curses
+
+class helpBar:
+    # commands is in the form (key, command_name)
+    commands = []
+    mx=my=0
+    x=y=0
+    colWidth = 10
+    numCols=1
+
+    def __init__(self, window):
+        self.w = window
+
+    def updateGeometry(self):
+        (self.my, self.mx) = self.w.getmaxyx()
+        (self.y, self.x) = self.w.getbegyx()
+        self.numCols = self.mx/self.colWidth
+        numRows = len(self.commands)/self.numCols +1
+        self.y += self.my - numRows
+        self.my = numRows
+        self.w.mvwin(self.y,self.x)
+        self.w.resize(self.my,self.mx)
+
+    def refresh(self):
+        self.clear()
+        self.updateGeometry()
+        r=0
+        c=0
+        for key,command in self.commands:
+            self.w.addnstr(r,c,key+" "+command+" "*self.colWidth,self.colWidth-1)
+            self.w.chgat(r,c,2,curses.A_REVERSE)
+            c+=self.colWidth
+            if c > self.colWidth*self.numCols:
+                c=0
+                r+=1
+        self.w.refresh()
+
+    def clear(self):
+        self.w.erase()
+        self.w.refresh()
+
+    def getSearch(self):
+        self.clear()
+        self.w.addstr(0,0,"/")
+        string = ""
+        done = False
+        self.w.keypad(1)
+        ch = self.w.getch()
+        while (not done):
+            if ch == curses.KEY_ENTER or ch == 10:
+                return string
+            elif ch == 27: # escape
+                return ""
+            elif ch == curses.KEY_BACKSPACE and string !="":
+                self.w.addstr(0,1," "*len(string))
+                string = string[0:len(string)-1]
+                self.w.addstr(0,1,string)
+            elif ch>=32 and ch<=126:
+                char = curses.keyname(ch)
+                string = string + char
+                self.w.addstr(0,1,string)
+            self.w.refresh()
+            ch = self.w.getch()
+
+    def display(self,string):
+        self.clear()
+        self.w.addstr(0,1,string)
+        self.w.refresh()