Error handling improved. Version bump

This commit is contained in:
Kovid Goyal 2006-12-24 22:36:22 +00:00
parent 57e216f0c7
commit 73e021ef08
3 changed files with 22 additions and 5 deletions

View File

@ -37,6 +37,6 @@ the following rule in C{/etc/udev/rules.d/90-local.rules} ::
You may have to adjust the GROUP and the location of the rules file to
suit your distribution.
"""
__version__ = "0.3.0a5"
__version__ = "0.3.0a6"
__docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"

View File

@ -40,7 +40,8 @@ def _Warning(msg, e):
def Error(msg, e):
if error_dialog:
if e: msg += "<br>" + traceback.format_exc(e)
if e:
msg += "<br>" + traceback.format_exc(e)
msg = re.sub("Traceback", "<b>Traceback</b>", msg)
msg = re.sub(r"\n", "<br>", msg)
error_dialog.showMessage(msg)

View File

@ -48,6 +48,19 @@ DEVICE_BOOK_TEMPLATE = QString("<table><tr><td><b>Title: </b>%1</td><td> \
Ui_MainWindow = import_ui("main.ui")
class Main(QObject, Ui_MainWindow):
def report_error(func):
"""
Decorator to ensure that unhandled exceptions are displayed
to users via the GUI
"""
def function(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception, e:
Error("There was an error calling " + func.__name__, e)
raise
return function
""" Create GUI """
def show_device(self, yes):
"""
@ -136,6 +149,7 @@ class Main(QObject, Ui_MainWindow):
if index == self.library_view.currentIndex():
self.show_book(index, index)
@report_error
def delete(self, action):
rows = self.current_view.selectionModel().selectedRows()
if not len(rows):
@ -186,6 +200,7 @@ class Main(QObject, Ui_MainWindow):
self.write_settings()
e.accept()
@report_error
def add(self, action):
settings = QSettings()
_dir = settings.value("add books dialog dir", \
@ -213,7 +228,7 @@ class Main(QObject, Ui_MainWindow):
self.library_view.model().sort(col, order)
self.window.setCursor(Qt.ArrowCursor)
@report_error
def edit(self, action):
if self.library_view.isVisible():
rows = self.library_view.selectionModel().selectedRows()
@ -255,7 +270,7 @@ class Main(QObject, Ui_MainWindow):
def update_tags_and_comments(self, index, tags, comments):
self.library_model.update_tags_and_comments(index, tags, comments)
@report_error
def update_cover(self, pix):
if not pix.isNull():
try:
@ -265,6 +280,7 @@ class Main(QObject, Ui_MainWindow):
except Exception, e:
Error("Unable to change cover", e)
@report_error
def upload_books(self, to, files, ids):
oncard = False if to == "reader" else True
booklists = (self.reader_model.booklist, self.card_model.booklist)