Tweaked exception handling, specifically small screen failures
Changes the dialog window that pops up for any exception to tell the user to read Python's output (i.e. the stacktrace). Also, handles the common failure of having too small a window and trying to create a new ncurses dialog box. There is now a specific failure message, so people know to make their terminal bigger. Useful!
This commit is contained in:
parent
4ce53141e0
commit
d18ff562fc
1
TODO
1
TODO
|
@ -6,6 +6,7 @@ Support for multiple copies
|
|||
- (better support, that is)
|
||||
Search function in db_layer
|
||||
- eventually something which takes things like "title:foo author:bar some other keywords"
|
||||
Don't let patrons with overdue books checkout more books
|
||||
|
||||
|
||||
_Code Quality Improvements_
|
||||
|
|
36
librarian
36
librarian
|
@ -10,7 +10,9 @@ import library.interface.sendemails as sendemails
|
|||
|
||||
from library import book_data
|
||||
|
||||
|
||||
class SmallScreenException(Exception):
|
||||
def __init__(self, *args, **kwargs):
|
||||
Exception.__init__(self, *args, **kwargs)
|
||||
|
||||
stdscr=0
|
||||
hb=0
|
||||
|
@ -36,11 +38,16 @@ def menutest(s, l):
|
|||
try:
|
||||
menu(w, l)
|
||||
except SystemExit: pass
|
||||
except SmallScreenException:
|
||||
text = """That's a small screen!
|
||||
This librarian program won't work with a small screen.
|
||||
Make your terminal window bigger and try again."""
|
||||
form.error_form(text, stdscr, hb)
|
||||
raise
|
||||
except:
|
||||
text = """An unexpected error occured.
|
||||
You can contact the librarian (librarian@csclub.uwaterloo.ca),
|
||||
but given the history of the library system, it seems unlikely
|
||||
that somebody will be around to care.
|
||||
Email the librarian (librarian@csclub.uwaterloo.ca)
|
||||
with python's output after this program quits.
|
||||
The program will now quit."""
|
||||
form.error_form(text, stdscr, hb)
|
||||
raise
|
||||
|
@ -101,7 +108,10 @@ def addForm():
|
|||
(my,mx)=stdscr.getmaxyx()
|
||||
bf = form.BookForm(w,hb,width=mx-20)
|
||||
(r,c)=w.getmaxyx()
|
||||
try:
|
||||
w.mvwin((my-r)//2,(mx-c)//2)
|
||||
except curses.error as exc:
|
||||
raise SmallScreenException("Terminal screen too small. Try again with a bigger terminal.") from exc
|
||||
bf.lookup_isbn=book_data.openLibrary_isbn
|
||||
bf.lookup_lccn=book_data.openLibrary_lccn
|
||||
bf.caption='Add a Book'
|
||||
|
@ -116,7 +126,10 @@ def browseMenu():
|
|||
b = browser.bookBrowser(w,hb)
|
||||
(r,c) = w.getmaxyx()
|
||||
(my,mx)=stdscr.getmaxyx()
|
||||
try:
|
||||
w.mvwin((my-r)//2 -2, (mx-c)//2)
|
||||
except curses.error as exc:
|
||||
raise SmallScreenException("Terminal screen too small. Try again with a bigger terminal.") from exc
|
||||
b.refreshBooks()
|
||||
b.eventLoop()
|
||||
b.clear()
|
||||
|
@ -126,7 +139,10 @@ def trashMenu():
|
|||
b = browser.trashBrowser(w,hb)
|
||||
(r,c) = w.getmaxyx()
|
||||
(my,mx)=stdscr.getmaxyx()
|
||||
try:
|
||||
w.mvwin((my-r)//2 -2, (mx-c)//2)
|
||||
except curses.error as exc:
|
||||
raise SmallScreenException("Terminal screen too small. Try again with a bigger terminal.") from exc
|
||||
b.refreshBooks()
|
||||
b.eventLoop()
|
||||
b.clear()
|
||||
|
@ -136,7 +152,10 @@ def uncategorizedMenu():
|
|||
b = browser.bookBrowser(w,hb)
|
||||
(r,c) = w.getmaxyx()
|
||||
(my,mx)=stdscr.getmaxyx()
|
||||
try:
|
||||
w.mvwin((my-r)//2 -2, (mx-c)//2)
|
||||
except curses.error as exc:
|
||||
raise SmallScreenException("Terminal screen too small. Try again with a bigger terminal.") from exc
|
||||
b.refreshBooksUncategorized()
|
||||
b.eventLoop()
|
||||
b.clear()
|
||||
|
@ -146,7 +165,10 @@ def checkedout_menu():
|
|||
b = browser.bookBrowser(w,hb)
|
||||
(r,c) = w.getmaxyx()
|
||||
(my,mx)=stdscr.getmaxyx()
|
||||
try:
|
||||
w.mvwin((my-r)//2 -2, (mx-c)//2)
|
||||
except curses.error as exc:
|
||||
raise SmallScreenException("Terminal screen too small. Try again with a bigger terminal.") from exc
|
||||
b.refreshBooksCheckedout()
|
||||
b.columnDefs = [("id",0,3),
|
||||
("uwid",0,8),
|
||||
|
@ -161,7 +183,10 @@ def onshelf_menu():
|
|||
b = browser.bookBrowser(w,hb)
|
||||
(r,c) = w.getmaxyx()
|
||||
(my,mx)=stdscr.getmaxyx()
|
||||
try:
|
||||
w.mvwin((my-r)//2 -2, (mx-c)//2)
|
||||
except curses.error as exc:
|
||||
raise SmallScreenException("Terminal screen too small. Try again with a bigger terminal.") from exc
|
||||
b.refreshBooksOnshelf()
|
||||
b.eventLoop()
|
||||
b.clear()
|
||||
|
@ -181,7 +206,10 @@ def catMenu():
|
|||
w=curses.newwin(3,5)
|
||||
cat = browser.categoryBrowser(w,hb)
|
||||
(r,c) = w.getmaxyx()
|
||||
try:
|
||||
w.mvwin((my-r)//2 -2, (mx-c)//2)
|
||||
except curses.error as exc:
|
||||
raise SmallScreenException("Terminal screen too small. Try again with a bigger terminal.") from exc
|
||||
cat.refreshCategories()
|
||||
cat.sortByColumn('category')
|
||||
cat.eventLoop()
|
||||
|
|
|
@ -23,6 +23,8 @@ Our records indicate that you have had the book {} signed out for {} days.
|
|||
|
||||
If you would like to keep this book checked out, tell us when in the next month you will return this book.
|
||||
|
||||
If you think you have received this message in error, reply back to this email please!
|
||||
|
||||
Otherwise, please return the book to the CS Club office (MC 3036) at your earliest convenience.
|
||||
|
||||
Thank you for using the CS Club library!
|
||||
|
|
Loading…
Reference in New Issue