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