added category viewer
authorJohn Ladan <jladan@uwaterloo.ca>
Sat, 24 Mar 2012 16:12:12 +0000 (12:12 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Sat, 24 Mar 2012 16:12:12 +0000 (12:12 -0400)
browser.py
librarian.py

index da70bfe..7eaa80d 100644 (file)
@@ -105,11 +105,11 @@ class browserWindow:
             ch = self.w.getch()
 
     def handleInput(self,ch):
-        if ch == curses.KEY_UP:
+        if ch == curses.KEY_UP or ch == 107 or ch == 16:
             if self.hl == self.topline:
                 self.scroll(-self.pageSize/2-1)
             self.mvHighlight(-1)
-        elif ch == curses.KEY_DOWN:
+        elif ch == curses.KEY_DOWN or ch == 106 or ch == 14:
             if self.hl == self.topline+self.pageSize-1:
                 self.scroll(+self.pageSize/2+1)
             self.mvHighlight(+1)
@@ -166,10 +166,11 @@ class bookBrowser(browserWindow):
             self.viewSelection(book)
             self.refresh()
 
-def categoryBrowser():
+class categoryBrowser(browserWindow):
     columnDefs = [('ID',0,3),
                   ('Category',100,None)]
 
+
     def refreshCategories(self):
         self.entries = []
         cats = db.getCategories()
index 3035b40..f72de11 100755 (executable)
@@ -40,14 +40,14 @@ def menu(w, items):
     w.refresh()
     ch=w.getch()
     while (ch!=113 and ch!=27): # leave on q or ESC
-        if ch==curses.KEY_UP:
+        if ch==curses.KEY_UP or ch==107 or ch==16:
             if highlight!=0:
                 w.chgat(highlight,0, 0)
                 highlight -= 1
                 while(items[highlight][0]==""):
                     highlight -=1
                 w.chgat(highlight,0, curses.A_REVERSE)
-        if ch==curses.KEY_DOWN:
+        if ch==curses.KEY_DOWN or ch==106 or ch==14:
             if highlight!=len(items)-1:
                 w.chgat(highlight,0, 0)
                 highlight += 1
@@ -94,7 +94,6 @@ def addForm():
     if len(book)!=0:
         db.addBook(book)
 
-
 def updateMenu():
     w=curses.newwin(1,50,10,10)
     w.addstr("I will be used to update or modify book records")
@@ -109,6 +108,17 @@ def browseMenu():
     (my,mx)=stdscr.getmaxyx()
     w=curses.newwin(20,80,(my-20)/2,(mx-80)/2)
     b = browser.bookBrowser(w)
+    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)
+    b = browser.categoryBrowser(w)
+    b.refreshCategories()
     hb.commands=browser_commands
     hb.refresh()
     b.eventLoop()
@@ -117,7 +127,7 @@ def browseMenu():
 
 m = [("Browse Library", browseMenu),
      ("Add Book or other item", addForm),
-     ("Modify/Update record", updateMenu),
+     ("View the categories", catMenu),
      ("Remove book from catalogue", deleteMenu),
      ("",exit),
      ("Exit", exit)]