made tests use python3
[library/.git] / librarian.py
index 4677065..9415321 100755 (executable)
@@ -3,7 +3,7 @@
 import curses
 import db_layer as db
 import browser
-import form as form
+import form
 import help_bar as helpBar
 
 import book_data
@@ -82,14 +82,14 @@ def redrawMenu(w,items,highlight):
 def addForm():
     w=curses.newwin(1,1)
     (my,mx)=stdscr.getmaxyx()
-    bf = form.bookForm(w,hb)
+    bf = form.BookForm(w,hb,width=mx-20)
     (r,c)=w.getmaxyx()
     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)
@@ -101,34 +101,44 @@ def updateMenu():
 
 def trashMenu():
     (my,mx)=stdscr.getmaxyx()
-    w=curses.newwin(20,80,(my-20)//2,(mx-80)//2)
-    b = browser.trashBrowser(w,hb)
+    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,hb)
+    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()
     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", addForm),
-     ("Categories", catMenu),
-     ("View Trash", trashMenu),
-     ("",exit),
-     ("Exit", exit)]
-curses.wrapper(menutest, m)
+    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)
+
+