finishing fixing bugs from last commit
[public/library.git] / form.py
diff --git a/form.py b/form.py
index 2bef3a6..2e9110f 100644 (file)
--- a/form.py
+++ b/form.py
@@ -1,4 +1,5 @@
 import curses
+import sys
 
 class formWindow:
     mx = my = 0
@@ -52,7 +53,7 @@ class formWindow:
         self.hb.refresh()
         self.updateGeometry()
         self.w.box()
-        self.w.addstr(0,(self.mx-len(self.caption))/2,self.caption)
+        self.w.addstr(0,(self.mx-len(self.caption))//2,self.caption)
         r=self.top
         for l in self.labels:
             c = self.left-len(l)-2
@@ -86,7 +87,7 @@ class formWindow:
         self.hl = new
         self.row = self.hl + self.top
         if new == len(self.labels):
-            self.bt+=1
+            self.bt =1
             self.bt = min(self.bt,1)
             self.row+=1
         else:
@@ -105,7 +106,8 @@ class formWindow:
 
     def insert(self,ch):
         c = self.cursor
-        self.entries[self.hl]=self.entries[self.hl][:c] +ch+  self.entries[self.hl][c:]
+        #sys.stderr.write(str(type(ch)))
+        self.entries[self.hl]=self.entries[self.hl][:c] +ch.decode('utf-8')+  self.entries[self.hl][c:]
         self.drawRow(self.hl)
         self.mvCursor(+1)
         self.highlight()
@@ -165,7 +167,9 @@ class formWindow:
             if self.bt==-1:
                 self.mvCursor(-1)
             else:
+                self.unHighlight()
                 self.bt=0
+                self.highlight()
         elif ch==curses.KEY_HOME:
             if self.bt==-1:
                 self.mvCursor(-len(self.entries[self.hl]))
@@ -173,7 +177,9 @@ class formWindow:
             if self.bt==-1:
                 self.mvCursor(+1)
             else:
+                self.unHighlight()
                 self.bt=1
+                self.highlight()
         elif ch==curses.KEY_END:
             if self.bt==-1:
                 self.mvCursor(+len(self.entries[self.hl]))
@@ -200,20 +206,31 @@ class bookForm(formWindow):
 
     # redefineable functions lookup is called when 'enter' is pressed on ISBN
     # and returns the looked-up book. Default returns nothing
-    def lookup(self,isbn):
+    def lookup_isbn(self,isbn):
         return {'isbn':isbn}
+    
+    def lookup_lccn(self,lccn):
+        return {'lccn':lccn}
 
     def returnBook(self):
         return self.returnValues()
 
     def handleInput(self,ch):
         if ch==10 or ch==curses.KEY_ENTER:
-            if self.hl==0:
-                book = self.lookup(self.entries[0])
+            if self.hl==0:          # lookup by isbn
+                book = self.lookup_isbn(self.entries[0])
                 if book != {}:
                     self.updateEntries(book)
                 self.refresh()
-        formWindow.handleInput(self,ch)
+                self.mvHighlight(+7)
+            if self.hl==1:          # lookup by lccn
+                book = self.lookup_lccn(self.entries[1])
+                if book != {}:
+                    self.updateEntries(book)
+                self.refresh()
+                self.mvHighlight(+6)
+        else:
+            formWindow.handleInput(self,ch)
 
 class categoryForm(formWindow):
     caption = "Add a Category"