generalized the form to add inheritance options
This commit is contained in:
parent
13f6b211ac
commit
a3018cb7a6
|
@ -1,6 +1,6 @@
|
||||||
import curses
|
import curses
|
||||||
import dbLayer as db
|
import dbLayer as db
|
||||||
from bookForm import bookForm
|
from form import bookForm
|
||||||
|
|
||||||
class browserWindow:
|
class browserWindow:
|
||||||
hl=0
|
hl=0
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import curses
|
import curses
|
||||||
|
|
||||||
class bookForm:
|
class formWindow:
|
||||||
mx = my = 0
|
mx = my = 0
|
||||||
hl = 0
|
hl = 0
|
||||||
bt = -1
|
bt = -1
|
||||||
|
@ -9,18 +9,11 @@ class bookForm:
|
||||||
left = 0
|
left = 0
|
||||||
top = 2
|
top = 2
|
||||||
row = 2
|
row = 2
|
||||||
caption = "Add a Book"
|
caption = "Form"
|
||||||
blabel = "Add"
|
blabel = "Done"
|
||||||
labels = ["ISBN", "LCCN", "Title", "Subtitle", "Authors", "Edition",
|
labels = ["label1"]
|
||||||
"Publisher", "Publish Date", "Publish Year", "Publish Month", "Publish location",
|
|
||||||
"Pages", "Pagination", "Weight"]
|
|
||||||
entries = []
|
entries = []
|
||||||
|
|
||||||
# redefineable functions lookup is called when 'enter' is pressed on ISBN
|
|
||||||
# and returns the looked-up book. Default returns nothing
|
|
||||||
def lookup(self,isbn):
|
|
||||||
return {'isbn':isbn}
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.w.erase()
|
self.w.erase()
|
||||||
self.w.refresh()
|
self.w.refresh()
|
||||||
|
@ -125,7 +118,7 @@ class bookForm:
|
||||||
self.drawRow(self.hl)
|
self.drawRow(self.hl)
|
||||||
self.highlight()
|
self.highlight()
|
||||||
|
|
||||||
def returnBook(self):
|
def returnValues(self):
|
||||||
book = {}
|
book = {}
|
||||||
for k,v in zip(self.labels, self.entries):
|
for k,v in zip(self.labels, self.entries):
|
||||||
if v!="" and k.lower()!="publish date":
|
if v!="" and k.lower()!="publish date":
|
||||||
|
@ -140,53 +133,79 @@ class bookForm:
|
||||||
|
|
||||||
ch = self.w.getch()
|
ch = self.w.getch()
|
||||||
while ch != 27:
|
while ch != 27:
|
||||||
if ch==curses.KEY_UP:
|
self.handleInput(ch)
|
||||||
self.mvHighlight(-1)
|
if ch==10 or ch==curses.KEY_ENTER:
|
||||||
elif ch==curses.KEY_PPAGE:
|
if self.bt==0:
|
||||||
self.mvHighlight(-len(self.labels))
|
|
||||||
elif ch==curses.KEY_DOWN:
|
|
||||||
self.mvHighlight(+1)
|
|
||||||
elif ch==curses.KEY_NPAGE:
|
|
||||||
self.mvHighlight(+len(self.labels))
|
|
||||||
|
|
||||||
elif ch==curses.KEY_LEFT:
|
|
||||||
if self.bt==-1:
|
|
||||||
self.mvCursor(-1)
|
|
||||||
else:
|
|
||||||
self.bt=0
|
|
||||||
elif ch==curses.KEY_HOME:
|
|
||||||
if self.bt==-1:
|
|
||||||
self.mvCursor(-len(self.entries[self.hl]))
|
|
||||||
elif ch==curses.KEY_RIGHT:
|
|
||||||
if self.bt==-1:
|
|
||||||
self.mvCursor(+1)
|
|
||||||
else:
|
|
||||||
self.bt=1
|
|
||||||
elif ch==curses.KEY_END:
|
|
||||||
if self.bt==-1:
|
|
||||||
self.mvCursor(+len(self.entries[self.hl]))
|
|
||||||
|
|
||||||
elif ch>=32 and ch<=126:
|
|
||||||
if self.bt==-1:
|
|
||||||
self.insert(curses.keyname(ch))
|
|
||||||
elif ch==curses.KEY_BACKSPACE:
|
|
||||||
if self.bt==-1:
|
|
||||||
self.backspace()
|
|
||||||
elif ch==curses.KEY_DC:
|
|
||||||
if self.bt==-1:
|
|
||||||
self.delete()
|
|
||||||
|
|
||||||
elif ch==10 or ch==curses.KEY_ENTER:
|
|
||||||
if self.hl==0:
|
|
||||||
book = self.lookup(self.entries[0])
|
|
||||||
if book != {}:
|
|
||||||
self.updateEntries(book)
|
|
||||||
self.refresh()
|
|
||||||
elif self.bt==0:
|
|
||||||
return {}
|
return {}
|
||||||
elif self.bt==1:
|
elif self.bt==1:
|
||||||
return self.returnBook()
|
return self.returnValues()
|
||||||
self.mvHighlight(+1)
|
self.mvHighlight(+1)
|
||||||
self.w.refresh()
|
self.w.refresh()
|
||||||
ch = self.w.getch()
|
ch = self.w.getch()
|
||||||
|
curses.curs_set(0)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
def handleInput(self,ch):
|
||||||
|
if ch==curses.KEY_UP:
|
||||||
|
self.mvHighlight(-1)
|
||||||
|
elif ch==curses.KEY_PPAGE:
|
||||||
|
self.mvHighlight(-len(self.labels))
|
||||||
|
elif ch==curses.KEY_DOWN:
|
||||||
|
self.mvHighlight(+1)
|
||||||
|
elif ch==curses.KEY_NPAGE:
|
||||||
|
self.mvHighlight(+len(self.labels))
|
||||||
|
|
||||||
|
elif ch==curses.KEY_LEFT:
|
||||||
|
if self.bt==-1:
|
||||||
|
self.mvCursor(-1)
|
||||||
|
else:
|
||||||
|
self.bt=0
|
||||||
|
elif ch==curses.KEY_HOME:
|
||||||
|
if self.bt==-1:
|
||||||
|
self.mvCursor(-len(self.entries[self.hl]))
|
||||||
|
elif ch==curses.KEY_RIGHT:
|
||||||
|
if self.bt==-1:
|
||||||
|
self.mvCursor(+1)
|
||||||
|
else:
|
||||||
|
self.bt=1
|
||||||
|
elif ch==curses.KEY_END:
|
||||||
|
if self.bt==-1:
|
||||||
|
self.mvCursor(+len(self.entries[self.hl]))
|
||||||
|
|
||||||
|
elif ch>=32 and ch<=126:
|
||||||
|
if self.bt==-1:
|
||||||
|
self.insert(curses.keyname(ch))
|
||||||
|
elif ch==curses.KEY_BACKSPACE:
|
||||||
|
if self.bt==-1:
|
||||||
|
self.backspace()
|
||||||
|
elif ch==curses.KEY_DC:
|
||||||
|
if self.bt==-1:
|
||||||
|
self.delete()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class bookForm(formWindow):
|
||||||
|
caption = "Add a Book"
|
||||||
|
blabel = "Add"
|
||||||
|
labels = ["ISBN", "LCCN", "Title", "Subtitle", "Authors", "Edition",
|
||||||
|
"Publisher", "Publish Date", "Publish Year", "Publish Month", "Publish location",
|
||||||
|
"Pages", "Pagination", "Weight"]
|
||||||
|
|
||||||
|
|
||||||
|
# redefineable functions lookup is called when 'enter' is pressed on ISBN
|
||||||
|
# and returns the looked-up book. Default returns nothing
|
||||||
|
def lookup(self,isbn):
|
||||||
|
return {'isbn':isbn}
|
||||||
|
|
||||||
|
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 book != {}:
|
||||||
|
self.updateEntries(book)
|
||||||
|
self.refresh()
|
||||||
|
formWindow.handleInput(self,ch)
|
|
@ -3,7 +3,7 @@
|
||||||
import curses
|
import curses
|
||||||
import dbLayer as db
|
import dbLayer as db
|
||||||
import browser
|
import browser
|
||||||
import bookForm
|
import form
|
||||||
import helpBar
|
import helpBar
|
||||||
|
|
||||||
import bookData
|
import bookData
|
||||||
|
@ -85,7 +85,7 @@ def addForm():
|
||||||
(my,mx)=stdscr.getmaxyx()
|
(my,mx)=stdscr.getmaxyx()
|
||||||
(r,c)=w.getmaxyx()
|
(r,c)=w.getmaxyx()
|
||||||
w.mvwin((my-r)/2,(mx-c)/2)
|
w.mvwin((my-r)/2,(mx-c)/2)
|
||||||
bf = bookForm.bookForm(w)
|
bf = form.bookForm(w)
|
||||||
bf.lookup=bookData.openLibrary
|
bf.lookup=bookData.openLibrary
|
||||||
bf.caption='Add a Book'
|
bf.caption='Add a Book'
|
||||||
bf.blabel = 'Add'
|
bf.blabel = 'Add'
|
||||||
|
|
Loading…
Reference in New Issue