deletion of categories now supported
authorJohn Ladan <jladan@uwaterloo.ca>
Tue, 27 Mar 2012 19:53:42 +0000 (15:53 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Tue, 27 Mar 2012 19:53:42 +0000 (15:53 -0400)
browser.py
dbLayer.py

index adcdc55..92c35f2 100644 (file)
@@ -197,16 +197,31 @@ class categoryBrowser(browserWindow):
         w = curses.newwin(1,1,10,10)
         cf = categoryForm(w,self.hb)
         cats = cf.eventLoop()
         w = curses.newwin(1,1,10,10)
         cf = categoryForm(w,self.hb)
         cats = cf.eventLoop()
-        print >> sys.stderr, cats
         for c in cats:
         for c in cats:
-            print >> sys.stderr, "adding "+str(c)
             db.addCategory(c)
         cf.clear()
 
             db.addCategory(c)
         cf.clear()
 
+    def delSelected(self):
+        categories = []
+        for sel,cat in zip(self.selected, self.entries):
+            if sel:
+                categories.append(cat)
+        db.deleteCategories(categories)
+
     def handleInput(self,ch):
         browserWindow.handleInput(self,ch)
         if ch==97:
             self.addCategory()
             self.refreshCategories()
             self.refresh()
     def handleInput(self,ch):
         browserWindow.handleInput(self,ch)
         if ch==97:
             self.addCategory()
             self.refreshCategories()
             self.refresh()
+        if ch==100:
+            count=0
+            for s in self.selected[0:self.hl-1]:
+                if s:
+                    count+=1
+            self.delSelected()
+            self.refreshCategories()
+            self.refresh()
+            self.scroll(-count)
+            self.mvHighlight(-count)
 
 
index cc46e73..243b48a 100644 (file)
@@ -224,11 +224,21 @@ def addCategory(cat):
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
     query = "INSERT OR IGNORE INTO "+categoryTable+" (category) VALUES ("+stringify(cat)+");"
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
     query = "INSERT OR IGNORE INTO "+categoryTable+" (category) VALUES ("+stringify(cat)+");"
-    print >>sys.stderr, query
     c.execute(query)
     conn.commit()
     c.close()
 
     c.execute(query)
     conn.commit()
     c.close()
 
+def deleteCategories(cats):
+    conn = sqlite3.connect(dbFile)
+    c = conn.cursor()
+    query1 = "DELETE FROM " +categoryTable+ " WHERE cat_id = :id;"
+    query2 = "DELETE FROM " +bookCategoryTable+ " WHERE cat_id = :id;"
+    for cat in cats:
+        c.execute(query1, cat)
+        c.execute(query2, cat)
+    conn.commit()
+    c.close()
+
 #########################################
 # Database initialization
 #########################################
 #########################################
 # Database initialization
 #########################################