made tests use python3
[library/.git] / librarian.py
index adee0d3..9415321 100755 (executable)
@@ -1,19 +1,18 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import curses
-import dbLayer as db
+import db_layer as db
 import browser
 import form
-import helpBar
+import help_bar as helpBar
 
-import bookData
+import book_data
 
 
 stdscr=0
 hb=0
 
 menu_commands = [(' q','quit')]
-browser_commands = [(' u','update'), (' d','delete'), (' q','quit')]
 
 def menutest(s, l):
     global stdscr
@@ -25,7 +24,7 @@ def menutest(s, l):
     hb = helpBar.helpBar(bar)
     hb.command=menu_commands
     hb.refresh()
-    w = curses.newwin(10,40,(rows-10)/2, (cols-40)/2)
+    w = curses.newwin(10,40,(rows-10)//2, (cols-40)//2)
 
     menu(w, l)
     
@@ -83,13 +82,14 @@ def redrawMenu(w,items,highlight):
 def addForm():
     w=curses.newwin(1,1)
     (my,mx)=stdscr.getmaxyx()
+    bf = form.BookForm(w,hb,width=mx-20)
     (r,c)=w.getmaxyx()
-    w.mvwin((my-r)/2,(mx-c)/2)
-    bf = form.bookForm(w)
-    bf.lookup=bookData.openLibrary
+    w.mvwin((my-r)//2,(mx-c)//2)
+    bf.lookup_isbn=book_data.openLibrary_isbn
+    bf.lookup_lccn=book_data.openLibrary_lccn
     bf.caption='Add a Book'
     bf.blabel = 'Add'
-    book = bf.eventLoop()
+    book = bf.event_loop()
     bf.clear()
     if len(book)!=0:
         db.addBook(book)
@@ -99,37 +99,46 @@ def updateMenu():
     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(3,5)
+    b = browser.trashBrowser(w,hb,my-10,mx-10)
+    (r,c) = w.getmaxyx()
+    w.mvwin((my-r)//2 -2, (mx-c)//2)
+    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)
+    w=curses.newwin(3,5)
+    b = browser.bookBrowser(w,hb, my-10, mx-10)
+    (r,c) = w.getmaxyx()
+    w.mvwin((my-r)//2 -2, (mx-c)//2)
     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.refreshCategories()
-    c.sortByColumn('category')
-    hb.commands=browser_commands
-    hb.refresh()
-    c.eventLoop()
-    c.clear()
+    w=curses.newwin(3,5)
+    cat = browser.categoryBrowser(w,hb, 10,40)
+    (r,c) = w.getmaxyx()
+    w.mvwin((my-r)//2 -2, (mx-c)//2)
+    cat.refreshCategories()
+    cat.sortByColumn('category')
+    cat.eventLoop()
+    cat.clear()
+
+
+if __name__ == "__main__":
+    db.initializeDatabase()
+    m = [("Browse Library", browseMenu),
+         ("Add Book", addForm),
+         ("Categories", catMenu),
+         ("View Trash", trashMenu),
+         ("",exit),
+         ("Exit", exit)]
+    curses.wrapper(menutest, m)
 
 
-m = [("Browse Library", browseMenu),
-     ("Add Book or other item", addForm),
-     ("View the categories", catMenu),
-     ("Remove book from catalogue", deleteMenu),
-     ("",exit),
-     ("Exit", exit)]
-curses.wrapper(menutest, m)