oops! never added helpbar.py
[library/.git] / helpBar.py
1 import curses
2
3 class helpBar:
4     # commands is in the form (key, command_name)
5     commands = []
6     mx=my=0
7     x=y=0
8     colWidth = 10
9     numCols=1
10
11     def __init__(self, window):
12         self.w = window
13
14     def updateGeometry(self):
15         (self.my, self.mx) = self.w.getmaxyx()
16         (self.y, self.x) = self.w.getbegyx()
17         self.numCols = self.mx/self.colWidth
18         numRows = len(self.commands)/self.numCols +1
19         self.y += self.my - numRows
20         self.my = numRows
21         self.w.mvwin(self.y,self.x)
22         self.w.resize(self.my,self.mx)
23
24     def refresh(self):
25         self.clear()
26         self.updateGeometry()
27         r=0
28         c=0
29         for key,command in self.commands:
30             self.w.addnstr(r,c,key+" "+command+" "*self.colWidth,self.colWidth-1)
31             self.w.chgat(r,c,2,curses.A_REVERSE)
32             c+=self.colWidth
33             if c > self.colWidth*self.numCols:
34                 c=0
35                 r+=1
36         self.w.refresh()
37
38     def clear(self):
39         self.w.erase()
40         self.w.refresh()
41
42     def getSearch(self):
43         self.clear()
44         self.w.addstr(0,0,"/")
45         string = ""
46         done = False
47         self.w.keypad(1)
48         ch = self.w.getch()
49         while (not done):
50             if ch == curses.KEY_ENTER or ch == 10:
51                 return string
52             elif ch == 27: # escape
53                 return ""
54             elif ch == curses.KEY_BACKSPACE and string !="":
55                 self.w.addstr(0,1," "*len(string))
56                 string = string[0:len(string)-1]
57                 self.w.addstr(0,1,string)
58             elif ch>=32 and ch<=126:
59                 char = curses.keyname(ch)
60                 string = string + char
61                 self.w.addstr(0,1,string)
62             self.w.refresh()
63             ch = self.w.getch()
64
65     def display(self,string):
66         self.clear()
67         self.w.addstr(0,1,string)
68         self.w.refresh()