deletion of books now works
authorJohn Ladan <jladan@uwaterloo.ca>
Tue, 27 Mar 2012 20:02:01 +0000 (16:02 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Tue, 27 Mar 2012 20:02:01 +0000 (16:02 -0400)
browser.py
dbLayer.py

index 92c35f2..c5b0dad 100644 (file)
@@ -166,6 +166,13 @@ class bookBrowser(browserWindow):
         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.removeBooks(books)
 
     def refreshBooks(self):
         self.entries = db.getBooks()
@@ -182,6 +189,16 @@ class bookBrowser(browserWindow):
             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)
 
 class categoryBrowser(browserWindow):
     columnDefs = [('Category',100,None)]
index 243b48a..e8beb6d 100644 (file)
@@ -167,15 +167,14 @@ def removeBook(bookid):
     conn.commit()
     c.close()
 
-def removeBooks(bookids):
+def removeBooks(books):
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
-    query1 = "DELETE FROM " +bookTable+ " WHERE id = ?;"
-    query2 = "DELETE FROM " +bookCategoryTable+ " WHERE id = ?;"
-    for book in bookids:
-        bid=(book,)
-        c.execute(query1, bid)
-        c.execute(query2, bid)
+    query1 = "DELETE FROM " +bookTable+ " WHERE id = :id;"
+    query2 = "DELETE FROM " +bookCategoryTable+ " WHERE id = :id;"
+    for book in books:
+        c.execute(query1, book)
+        c.execute(query2, book)
     conn.commit()
     c.close()
 
@@ -188,13 +187,12 @@ def deleteBook(bookid):
     conn.commit()
     c.close()
 
-def deleteBooks(bookids):
+def deleteBooks(books):
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
-    query = "DELETE FROM " +bookRemovedTable+ " WHERE id = ?;"
-    for book in bookids:
-        bid=(book,)
-        c.execute(query, bid)
+    query = "DELETE FROM " +bookRemovedTable+ " WHERE id = :id;"
+    for book in books:
+        c.execute(query, book)
     conn.commit()
     c.close()