added some desired features
[public/library.git] / librarian.py
index 3035b40..eee1ec6 100755 (executable)
@@ -3,7 +3,7 @@
 import curses
 import dbLayer as db
 import browser
-import bookForm
+import form
 import helpBar
 
 import bookData
@@ -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
@@ -40,14 +39,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
@@ -83,10 +82,11 @@ def redrawMenu(w,items,highlight):
 def addForm():
     w=curses.newwin(1,1)
     (my,mx)=stdscr.getmaxyx()
+    bf = form.bookForm(w,hb)
     (r,c)=w.getmaxyx()
     w.mvwin((my-r)/2,(mx-c)/2)
-    bf = bookForm.bookForm(w)
-    bf.lookup=bookData.openLibrary
+    bf.lookup_isbn=bookData.openLibrary_isbn
+    bf.lookup_lccn=bookData.openLibrary_lccn
     bf.caption='Add a Book'
     bf.blabel = 'Add'
     book = bf.eventLoop()
@@ -94,31 +94,41 @@ 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")
     w.refresh()
 
-def deleteMenu():
-    w=curses.newwin(1,50,10,10)
-    w.addstr("I will be used to delete book records")
-    w.refresh()
+def trashMenu():
+    (my,mx)=stdscr.getmaxyx()
+    w=curses.newwin(20,80,(my-20)/2,(mx-80)/2)
+    b = browser.trashBrowser(w,hb)
+    b.refreshBooks()
+    b.eventLoop()
+    b.clear()
 
 def browseMenu():
     (my,mx)=stdscr.getmaxyx()
     w=curses.newwin(20,80,(my-20)/2,(mx-80)/2)
-    b = browser.bookBrowser(w)
-    hb.commands=browser_commands
-    hb.refresh()
+    b = browser.bookBrowser(w,hb)
+    b.refreshBooks()
     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,hb)
+    c.refreshCategories()
+    c.sortByColumn('category')
+    c.eventLoop()
+    c.clear()
+
 
 m = [("Browse Library", browseMenu),
-     ("Add Book or other item", addForm),
-     ("Modify/Update record", updateMenu),
-     ("Remove book from catalogue", deleteMenu),
+     ("Add Book", addForm),
+     ("Categories", catMenu),
+     ("View Trash", trashMenu),
      ("",exit),
      ("Exit", exit)]
 curses.wrapper(menutest, m)