significant improvements to database (adding/removing books, categories, etc.)
[public/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 = 25
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(0,0)
22         self.w.resize(self.my,self.mx)
23         self.w.mvwin(self.y,self.x)
24
25     def refresh(self):
26         self.clear()
27         self.updateGeometry()
28         r=0
29         c=0
30         for key,command in self.commands:
31             self.w.addnstr(r,c,key+" "+command+" "*self.colWidth,self.colWidth-1)
32             self.w.chgat(r,c,2,curses.A_REVERSE)
33             c+=self.colWidth
34             if c > self.colWidth*self.numCols:
35                 c=0
36                 r+=1
37         self.w.refresh()
38
39     def clear(self):
40         self.w.erase()
41         self.w.refresh()
42
43     def getSearch(self):
44         self.clear()
45         self.w.addstr(0,0,"/")
46         string = ""
47         done = False
48         self.w.keypad(1)
49         ch = self.w.getch()
50         while (not done):
51             if ch == curses.KEY_ENTER or ch == 10:
52                 return string
53             elif ch == 27: # escape
54                 return ""
55             elif ch == curses.KEY_BACKSPACE and string !="":
56                 self.w.addstr(0,1," "*len(string))
57                 string = string[0:len(string)-1]
58                 self.w.addstr(0,1,string)
59             elif ch>=32 and ch<=126:
60                 char = curses.keyname(ch)
61                 string = string + char
62                 self.w.addstr(0,1,string)
63             self.w.refresh()
64             ch = self.w.getch()
65
66     def display(self,string):
67         self.clear()
68         self.w.addstr(0,1,string)
69         self.w.refresh()