|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
import curses |
|
|
|
|
import library.database as db |
|
|
|
|
from library.interface.form import BookForm,CategoryForm |
|
|
|
|
from library.interface.form import BookForm,CategoryForm,error_form,catch_error |
|
|
|
|
from library.exceptions import NoHighlightedEntry |
|
|
|
|
|
|
|
|
|
class browserWindow: |
|
|
|
|
# These are actually class variables, not member variables? :< |
|
|
|
@ -118,12 +119,18 @@ class browserWindow: |
|
|
|
|
|
|
|
|
|
def mvHighlight(self,delta): |
|
|
|
|
new = self.hl+delta |
|
|
|
|
new = max(new,0) |
|
|
|
|
new = min(new,len(self.entries)-1) |
|
|
|
|
new = max(new,0) |
|
|
|
|
self.unHighlight() |
|
|
|
|
self.hl = new |
|
|
|
|
self.highlight() |
|
|
|
|
|
|
|
|
|
def highlightedEntry(self): |
|
|
|
|
try: |
|
|
|
|
return self.entries[self.hl] |
|
|
|
|
except: |
|
|
|
|
raise NoHighlightedEntry() |
|
|
|
|
|
|
|
|
|
def scroll(self,delta): |
|
|
|
|
self.unHighlight() |
|
|
|
|
self.topline += delta |
|
|
|
@ -277,6 +284,7 @@ class trashBrowser(browserWindow): |
|
|
|
|
bf.event_loop() |
|
|
|
|
bf.clear() |
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def restoreSelected(self): |
|
|
|
|
books = [] |
|
|
|
|
for sel,book in zip(self.selected, self.entries): |
|
|
|
@ -284,6 +292,7 @@ class trashBrowser(browserWindow): |
|
|
|
|
books.append(book) |
|
|
|
|
db.restoreBooks(books) |
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def delSelected(self): |
|
|
|
|
books = [] |
|
|
|
|
for sel,book in zip(self.selected, self.entries): |
|
|
|
@ -294,10 +303,11 @@ class trashBrowser(browserWindow): |
|
|
|
|
def refreshBooks(self): |
|
|
|
|
self.load_data(db.getRemovedBooks()) |
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def handleInput(self,ch): |
|
|
|
|
browserWindow.handleInput(self,ch) |
|
|
|
|
if ch == 10: |
|
|
|
|
book = self.entries[self.hl] |
|
|
|
|
book = self.highlightedEntry() |
|
|
|
|
self.viewSelection(book) |
|
|
|
|
self.refresh() |
|
|
|
|
if ch==114: #restore books |
|
|
|
@ -332,6 +342,7 @@ class bookBrowser(browserWindow): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# redefinable functions |
|
|
|
|
@catch_error |
|
|
|
|
def updateSelection(self,book): |
|
|
|
|
bookid = book['id'] |
|
|
|
|
|
|
|
|
@ -341,9 +352,9 @@ class bookBrowser(browserWindow): |
|
|
|
|
bf.caption='Update Book '+str(bookid) |
|
|
|
|
bf.blabel='update' |
|
|
|
|
newbook = bf.event_loop() |
|
|
|
|
bf.clear() |
|
|
|
|
if len(newbook)!=0: |
|
|
|
|
db.updateBook(newbook,bookid) |
|
|
|
|
bf.clear() |
|
|
|
|
|
|
|
|
|
def viewSelection(self,book): |
|
|
|
|
bookid = book['id'] |
|
|
|
@ -363,7 +374,9 @@ class bookBrowser(browserWindow): |
|
|
|
|
cs.refreshCategories() |
|
|
|
|
cs.eventLoop() |
|
|
|
|
cs.clear() |
|
|
|
|
self.refreshBooks() |
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def delSelected(self): |
|
|
|
|
books = [] |
|
|
|
|
for sel,book in zip(self.selected, self.entries): |
|
|
|
@ -390,22 +403,23 @@ class bookBrowser(browserWindow): |
|
|
|
|
self.refreshBooks = lambda : self.load_data(db.get_onshelf_books()) |
|
|
|
|
self.refreshBooks() |
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def handleInput(self,ch): |
|
|
|
|
browserWindow.handleInput(self,ch) |
|
|
|
|
if ch == 117: #update on 'u' |
|
|
|
|
book = self.entries[self.hl] |
|
|
|
|
book = self.highlightedEntry() |
|
|
|
|
self.updateSelection(book) |
|
|
|
|
self.entries[self.hl]=db.get_book(book['id']) |
|
|
|
|
self.refresh() |
|
|
|
|
elif ch == 10: |
|
|
|
|
book = self.entries[self.hl] |
|
|
|
|
book = self.highlightedEntry() |
|
|
|
|
self.viewSelection(book) |
|
|
|
|
self.refresh() |
|
|
|
|
elif ch == 99: |
|
|
|
|
book = self.entries[self.hl] |
|
|
|
|
elif ch == 99: #c |
|
|
|
|
book = self.highlightedEntry() |
|
|
|
|
self.categorizeSelection(book) |
|
|
|
|
self.refresh() |
|
|
|
|
if ch==100: |
|
|
|
|
if ch == 100: |
|
|
|
|
count=0 |
|
|
|
|
for s in self.selected[0:self.hl-1]: |
|
|
|
|
if s: |
|
|
|
@ -425,22 +439,24 @@ class categoryBrowser(browserWindow): |
|
|
|
|
self.load_data(db.getCategories()) |
|
|
|
|
self.sortByColumn('category') |
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def addCategory(self): |
|
|
|
|
w = curses.newwin(1,1,10,10) |
|
|
|
|
cf = CategoryForm(w,self.hb) |
|
|
|
|
self.centreChild(w) |
|
|
|
|
cat = cf.event_loop() |
|
|
|
|
db.addCategory(cat) |
|
|
|
|
cf.clear() |
|
|
|
|
db.addCategory(cat) |
|
|
|
|
|
|
|
|
|
def viewCategory(self): |
|
|
|
|
w = curses.newwin(3,5) |
|
|
|
|
b = bookBrowser(w,self.hb) |
|
|
|
|
self.centreChild(w) |
|
|
|
|
b.refreshBooksInCategory(self.entries[self.hl]) |
|
|
|
|
b.refreshBooksInCategory(self.highlightedEntry()) |
|
|
|
|
b.eventLoop() |
|
|
|
|
b.clear() |
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def delSelected(self): |
|
|
|
|
categories = [] |
|
|
|
|
for sel,cat in zip(self.selected, self.entries): |
|
|
|
@ -496,7 +512,7 @@ class categorySelector(browserWindow): |
|
|
|
|
j+=1 |
|
|
|
|
self.selected = self.original[:] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def addCategory(self): |
|
|
|
|
w = curses.newwin(1,1,10,10) |
|
|
|
|
cf = CategoryForm(w,self.hb) |
|
|
|
@ -506,6 +522,7 @@ class categorySelector(browserWindow): |
|
|
|
|
db.addCategory(c) |
|
|
|
|
cf.clear() |
|
|
|
|
|
|
|
|
|
@catch_error |
|
|
|
|
def updateCategories(self): |
|
|
|
|
# first removed the deselected ones |
|
|
|
|
uncats = [] |
|
|
|
@ -558,8 +575,8 @@ class columnSelector(browserWindow): |
|
|
|
|
ch = self.w.getch() |
|
|
|
|
while ch != 27 and ch != 113: |
|
|
|
|
ch = self.handleInput(ch) |
|
|
|
|
if ch==10: |
|
|
|
|
col = self.entries[self.hl] |
|
|
|
|
if ch == 10: |
|
|
|
|
col = self.highlightedEntry() |
|
|
|
|
return col['column'] |
|
|
|
|
self.w.refresh() |
|
|
|
|
ch = self.w.getch() |
|
|
|
|