viewing and deleting trash works
authorJohn Ladan <jladan@uwaterloo.ca>
Sat, 31 Mar 2012 00:20:38 +0000 (20:20 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Sat, 31 Mar 2012 00:20:38 +0000 (20:20 -0400)
browser.py
librarian.py

index 7b8f9f2..5f01240 100644 (file)
@@ -229,6 +229,54 @@ class browserWindow:
 
 
 
+class trashBrowser(browserWindow):
+    columnDefs = [('ID',0,3),
+                  ('ISBN',0,13),
+                  ('Authors',30,None),
+                  ('Title',60,None)]
+    
+    cs = [(' r', 'restore selected'), (' d', 'delete selected')]
+    
+    # redefinable functions
+    def viewSelection(self,book):
+        bookid = book['id']
+        w=curses.newwin(1,1,20,20)
+        bf = bookForm(w,self.hb,book)
+        self.centreChild(w)
+        bf.caption='Viewing Book '+str(bookid)
+        bf.blabel='done'
+        bf.eventLoop()
+        bf.clear()
+
+    def delSelected(self):
+        books = []
+        for sel,book in zip(self.selected, self.entries):
+            if sel:
+                books.append(book)
+        db.deleteBooks(books)
+
+    def refreshBooks(self):
+        self.entries = db.getRemovedBooks()
+        self.selected = map(lambda x:False, self.entries)
+
+    def handleInput(self,ch):
+        browserWindow.handleInput(self,ch)
+        if ch == 10:
+            book = self.entries[self.hl]
+            self.viewSelection(book)
+            self.refresh()
+        if ch==100:
+            count=0
+            for s in self.selected[0:self.hl-1]:
+                if s:
+                    count+=1
+            self.delSelected()
+            self.refreshBooks()
+            self.refresh()
+            self.scroll(-count)
+            self.mvHighlight(-count)
+        return ch
+
 class bookBrowser(browserWindow):
     columnDefs = [('ID',0,3),
                   ('ISBN',0,13),
index 8864df5..7365a6a 100755 (executable)
@@ -98,10 +98,13 @@ 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(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()
@@ -124,7 +127,7 @@ def catMenu():
 m = [("Browse Library", browseMenu),
      ("Add Book", addForm),
      ("Categories", catMenu),
-     ("View Trash", deleteMenu),
+     ("View Trash", trashMenu),
      ("",exit),
      ("Exit", exit)]
 curses.wrapper(menutest, m)