Added permission checking. Added unit tests for the db_layer and permissions.
[library/.git] / help_bar.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,
32                            self.colWidth-1)
33             self.w.chgat(r,c,2,curses.A_REVERSE)
34             c+=self.colWidth
35             if c > self.colWidth*self.numCols:
36                 c=0
37                 r+=1
38         self.w.refresh()
39
40     def clear(self):
41         self.w.erase()
42         self.w.refresh()
43
44     def getSearch(self):
45         self.clear()
46         self.w.addstr(0,0,"/")
47         string = ""
48         done = False
49         self.w.keypad(1)
50         ch = self.w.getch()
51         while (not done):
52             if ch == curses.KEY_ENTER or ch == 10:
53                 return string
54             elif ch == 27: # escape
55                 return ""
56             elif ch == curses.KEY_BACKSPACE and string !="":
57                 self.w.addstr(0,1," "*len(string))
58                 string = string[0:len(string)-1]
59                 self.w.addstr(0,1,string)
60             elif ch>=32 and ch<=126:
61                 char = curses.keyname(ch).decode('utf-8')
62                 string = string + char
63                 self.w.addstr(0,1,string)
64             self.w.refresh()
65             ch = self.w.getch()
66
67     def display(self,string):
68         self.clear()
69         self.w.addstr(0,1,string)
70         self.w.refresh()