UI improvements
authorFelix Bauckholt <felixbauckholt@gmail.com>
Sun, 31 Jan 2016 02:23:00 +0000 (21:23 -0500)
committerFelix Bauckholt <felixbauckholt@gmail.com>
Sat, 6 Feb 2016 21:17:51 +0000 (16:17 -0500)
Some are obvious and urgent (like adding *one*
category instead of one for every letter), some
are debatable (like changing the window size and
the scrolling behavior).

library/interface/browser.py
library/interface/form.py
library/interface/help_bar.py

index e1eef10..c327313 100644 (file)
@@ -13,7 +13,7 @@ class browserWindow:
     entries = []
     selected = list()
     commands = [(' /', 'search'), (' n', 'find next'), (' N', 'find previous'),
-                ('F6', 'Sort Column'), (' q', 'quit')]
+                ('F6', 'Sort Column'), (' q', 'quit'), ('Space', 'select'), ('Enter', 'view')]
     cs = []
     # column definitions are in (label, weight, specified width) triples
     columnDefs = [('something',1,None)]
@@ -134,7 +134,7 @@ class browserWindow:
     def scroll(self,delta):
         self.unHighlight()
         self.topline += delta
-        self.topline = min(self.topline,len(self.entries)-1)
+        self.topline = min(self.topline,len(self.entries)-self.pageSize)
         self.topline = max(self.topline,0)
         self.refresh()
 
@@ -195,13 +195,13 @@ class browserWindow:
         ch = self.w.getch()
         while ch != 27 and ch != 113:
             ch = self.handleInput(ch)
-            if ch==113:
+            if ch == 113:
                 return {}
             self.w.refresh()
             ch = self.w.getch()
             self.hb.refresh()
 
-    def handleInput(self,ch):
+    def handleInput(self,ch,isSortByColumn=False):
         if ch == curses.KEY_UP or ch == 107 or ch == 16:
             if self.hl == self.topline:
                 self.scroll(-self.pageSize//2-1)
@@ -247,7 +247,7 @@ class browserWindow:
                 self.mvHighlight(delta)
             else:
                 self.hb.display(self.last_search+' not found')
-        elif ch == 270: # F6 Sorts
+        elif ch == 270 and not isSortByColumn: # F6 Sorts
             w = curses.newwin(1,1)
             cl = columnSelector(w,self.hb,40,20)
             self.centreChild(w)
@@ -256,7 +256,7 @@ class browserWindow:
             self.sortByColumn(col)
             self.clear()
             self.refresh()
-        elif ch == 32:
+        elif ch == 32 and not isSortByColumn:
             if len(self.selected)>0:
                 self.selected[self.hl] = not self.selected[self.hl]
             self.displayRow(self.hl-self.topline)
@@ -310,7 +310,7 @@ class trashBrowser(browserWindow):
             book = self.highlightedEntry()
             self.viewSelection(book)
             self.refresh()
-        if ch==114: #restore books
+        if ch == 114: #restore books
             count=0
             for s in self.selected[0:self.hl-1]:
                 if s:
@@ -320,7 +320,7 @@ class trashBrowser(browserWindow):
             self.refresh()
             self.scroll(-count)
             self.mvHighlight(-count)
-        if ch==100: # delete books
+        if ch == 100: # delete books
             count=0
             for s in self.selected[0:self.hl-1]:
                 if s:
@@ -338,7 +338,7 @@ class bookBrowser(browserWindow):
                   ('Authors',30,None),
                   ('Title',60,None)]
 
-    cs = [(' u', 'update'), (' d', 'delete selected')]
+    cs = [(' u', 'update'), (' d', 'delete selected'), (' c', 'categorize')]
 
 
     # redefinable functions
@@ -368,7 +368,7 @@ class bookBrowser(browserWindow):
 
     def categorizeSelection(self,book):
         w = curses.newwin(1,1)
-        cs = categorySelector(w,self.hb,40,40)
+        cs = categorySelector(w,self.hb)
         self.centreChild(w)
         cs.book = book
         cs.refreshCategories()
@@ -466,14 +466,14 @@ class categoryBrowser(browserWindow):
 
     def handleInput(self,ch):
         browserWindow.handleInput(self,ch)
-        if ch==97:
+        if ch == 97:
             self.addCategory()
             self.refreshCategories()
             self.refresh()
-        if ch ==10:
+        if ch == 10:
             self.viewCategory()
             self.refresh()
-        if ch==100:
+        if ch == 100:
             count=0
             for s in self.selected[0:self.hl-1]:
                 if s:
@@ -487,7 +487,7 @@ class categoryBrowser(browserWindow):
 
 class categorySelector(browserWindow):
     columnDefs = [('Category',100,None)]
-    cs = [(' a', 'add category'), (' c', 'commit')]
+    cs = [(' a', 'commit & add category'), (' c', 'commit')]
     book = {'id':''}
     original=[]
 
@@ -517,10 +517,9 @@ class categorySelector(browserWindow):
         w = curses.newwin(1,1,10,10)
         cf = CategoryForm(w,self.hb)
         self.centreChild(w)
-        cats = cf.event_loop()
-        for c in cats:
-            db.addCategory(c)
+        cat = cf.event_loop()
         cf.clear()
+        db.addCategory(cat)
 
     @catch_error
     def updateCategories(self):
@@ -540,11 +539,12 @@ class categorySelector(browserWindow):
 
     def handleInput(self,ch):
         browserWindow.handleInput(self,ch)
-        if ch==97:
+        if ch == 97:
+            self.updateCategories()
             self.addCategory()
             self.refreshCategories()
             self.refresh()
-        if ch==99:
+        if ch == 99:
             self.updateCategories()
             return 113
 
@@ -552,6 +552,8 @@ class categorySelector(browserWindow):
 
 class columnSelector(browserWindow):
     columnDefs = [('Column',100,None)]
+    commands = [(' /', 'search'), (' n', 'find next'), (' N', 'find previous'),
+                (' q', 'quit'), ('Enter', 'done')]
     entries = [
             {'column': 'id'}, {'column': 'isbn'}, {'column': 'lccn'},
             {'column': 'title'}, {'column': 'subtitle'}, {'column': 'authors'},
@@ -563,8 +565,7 @@ class columnSelector(browserWindow):
     ]
 
     def __init__(self,window,helpbar,height=40,width=20):
-        self.selected = [False,False,False,False,False,False,False,
-                         False,False,False,False,False,False,False,False]
+        self.selected = [False for _ in self.entries]
         browserWindow.__init__(self,window,helpbar,height,width)
 
 
@@ -583,5 +584,5 @@ class columnSelector(browserWindow):
             self.hb.refresh()
 
     def handleInput(self,ch):
-        browserWindow.handleInput(self,ch)
+        browserWindow.handleInput(self,ch,True)
         return ch
index 85c09f0..9be8781 100644 (file)
@@ -183,13 +183,11 @@ class FormWindow:
         self.bwidth = [8,len(self.blabel)+2]
 
     def _set_entries(self,book):
-        e = 0
-        for l in self.labels:
+        for (e, l) in enumerate(self.labels):
             if l.lower() in book:
                 self.entries[e].value = str(book[l.lower()])
             else:
                 self.entries[e].value = ""
-            e += 1 
 
     def redraw(self):
         self.w.box()
index 880eeac..79a5bab 100644 (file)
@@ -14,8 +14,12 @@ class helpBar:
     def updateGeometry(self):
         (self.my, self.mx) = self.w.getmaxyx()
         (self.y, self.x) = self.w.getbegyx()
-        self.numCols = self.mx//self.colWidth
-        numRows = len(self.commands)//self.numCols +1
+        self.numCols = min(len(self.commands), self.mx//self.colWidth)
+        self.extraHspace = self.mx - self.colWidth*self.numCols
+        if self.commands:
+                numRows = len(self.commands)//self.numCols +1
+        else:
+                numRows = 1
         self.y += self.my - numRows
         self.my = numRows
         self.w.mvwin(0,0)
@@ -25,16 +29,17 @@ class helpBar:
     def refresh(self):
         self.clear()
         self.updateGeometry()
-        r=0
-        c=0
+        r=0; i=0
+        c=self.extraHspace//2
         for key,command in self.commands:
             self.w.addnstr(r,c,key+" "+command+" "*self.colWidth,
                            self.colWidth-1)
             self.w.chgat(r,c,2,curses.A_REVERSE)
             c+=self.colWidth
-            if c > self.colWidth*self.numCols:
-                c=0
-                r+=1
+            i+=1
+            if i >= self.numCols:
+                c=self.extraHspace//2
+                r+=1; i=0
         self.w.refresh()
 
     def clear(self):