help bar more sensible now
authorJohn Ladan <jladan@uwaterloo.ca>
Tue, 27 Mar 2012 19:24:29 +0000 (15:24 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Tue, 27 Mar 2012 19:24:29 +0000 (15:24 -0400)
browser.py
form.py
librarian.py

index ae14b25..adcdc55 100644 (file)
@@ -8,6 +8,7 @@ class browserWindow:
     topline = 0
     entries = []
     selected = []
+    commands = [(' q', 'quit')]
     # column definitions are in (label, weight, specified width) triples
     columnDefs = [('something',1,None)]
     mx = my = 0
@@ -17,8 +18,9 @@ class browserWindow:
         self.w.erase()
         self.w.refresh()
 
-    def __init__(self,window):
+    def __init__(self,window,helpbar):
         self.w = window
+        self.hb = helpbar
         self.updateGeometry()
 
     def sortByColumn(self, col):
@@ -48,6 +50,8 @@ class browserWindow:
         self.columns=cols
 
     def refresh(self):
+        self.hb.commands = self.commands
+        self.hb.refresh()
         self.displayHeader()
         for r in range(0,self.pageSize):
             self.displayRow(r)
@@ -138,15 +142,17 @@ class bookBrowser(browserWindow):
                   ('ISBN',0,13),
                   ('Authors',30,None),
                   ('Title',60,None)]
+    
+    commands = [(' u', 'update'), (' d', 'delete selected'), (' q', 'quit')]
+    
     # redefinable functions
     def updateSelection(self,book):
         bookid = book['id']
         
         w=curses.newwin(1,1,20,20)
-        bf=bookForm(w)
+        bf=bookForm(w,self.hb,book)
         bf.caption='Update Book '+str(bookid)
         bf.blabel='update'
-        bf.updateEntries(book)
         newbook = bf.eventLoop()
         if len(newbook)!=0:
             db.updateBook(newbook,bookid)
@@ -155,10 +161,9 @@ class bookBrowser(browserWindow):
     def viewSelection(self,book):
         bookid = book['id']
         w=curses.newwin(1,1,20,20)
-        bf = bookForm(w)
+        bf = bookForm(w,self.hb,book)
         bf.caption='Viewing Book '+str(bookid)
         bf.blabel='done'
-        bf.updateEntries(book)
         bf.eventLoop()
         bf.clear()
 
@@ -170,7 +175,7 @@ class bookBrowser(browserWindow):
         browserWindow.handleInput(self,ch)
         if ch == 117: #update on 'u'
             book = self.entries[self.hl]
-            self.updateSelection(entries)
+            self.updateSelection(book)
             self.entries[self.hl]=db.getBookByID(book['id'])
             self.refresh()
         elif ch == 10:
@@ -180,6 +185,7 @@ class bookBrowser(browserWindow):
 
 class categoryBrowser(browserWindow):
     columnDefs = [('Category',100,None)]
+    commands = [(' a', 'add category'), (' d', 'delete selected'), (' q', 'quit')]
 
 
     def refreshCategories(self):
@@ -189,7 +195,7 @@ class categoryBrowser(browserWindow):
 
     def addCategory(self):
         w = curses.newwin(1,1,10,10)
-        cf = categoryForm(w)
+        cf = categoryForm(w,self.hb)
         cats = cf.eventLoop()
         print >> sys.stderr, cats
         for c in cats:
diff --git a/form.py b/form.py
index cacdc87..2bef3a6 100644 (file)
--- a/form.py
+++ b/form.py
@@ -14,13 +14,16 @@ class formWindow:
     labels = ["label1"]
     entries = []
 
+    commands = [('pU', 'top'),('pD', 'bottom'),('Es', 'cancel')]
+
     def clear(self):
         self.w.erase()
         self.w.refresh()
 
-    def __init__(self,window,book={}):
+    def __init__(self,window,helpbar,book={}):
         self.w = window
         self.w.resize(len(self.labels)+6,50)
+        self.hb = helpbar
         self.updateEntries(book)
         self.updateGeometry()
 
@@ -45,6 +48,8 @@ class formWindow:
                 self.entries.append("")
 
     def refresh(self):
+        self.hb.commands = self.commands
+        self.hb.refresh()
         self.updateGeometry()
         self.w.box()
         self.w.addstr(0,(self.mx-len(self.caption))/2,self.caption)
index f61a649..56dcb34 100755 (executable)
@@ -13,7 +13,6 @@ stdscr=0
 hb=0
 
 menu_commands = [(' q','quit')]
-browser_commands = [(' u','update'), (' d','delete'), (' q','quit')]
 
 def menutest(s, l):
     global stdscr
@@ -83,7 +82,7 @@ def redrawMenu(w,items,highlight):
 def addForm():
     w=curses.newwin(1,1)
     (my,mx)=stdscr.getmaxyx()
-    bf = form.bookForm(w)
+    bf = form.bookForm(w,hb)
     (r,c)=w.getmaxyx()
     w.mvwin((my-r)/2,(mx-c)/2)
     bf.lookup=bookData.openLibrary
@@ -107,21 +106,17 @@ def deleteMenu():
 def browseMenu():
     (my,mx)=stdscr.getmaxyx()
     w=curses.newwin(20,80,(my-20)/2,(mx-80)/2)
-    b = browser.bookBrowser(w)
+    b = browser.bookBrowser(w,hb)
     b.refreshBooks()
-    hb.commands=browser_commands
-    hb.refresh()
     b.eventLoop()
     b.clear()
 
 def catMenu():
     (my,mx)=stdscr.getmaxyx()
     w=curses.newwin(10,40,(my-10)/2,(mx-40)/2)
-    c = browser.categoryBrowser(w)
+    c = browser.categoryBrowser(w,hb)
     c.refreshCategories()
     c.sortByColumn('category')
-    hb.commands=browser_commands
-    hb.refresh()
     c.eventLoop()
     c.clear()