diff --git a/libprs500/__init__.py b/libprs500/__init__.py index d0f66693c7..177b6e348c 100644 --- a/libprs500/__init__.py +++ b/libprs500/__init__.py @@ -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 " diff --git a/libprs500/gui/__init__.py b/libprs500/gui/__init__.py index cb0419836b..cc149ad4ed 100644 --- a/libprs500/gui/__init__.py +++ b/libprs500/gui/__init__.py @@ -40,7 +40,8 @@ def _Warning(msg, e): def Error(msg, e): if error_dialog: - if e: msg += "
" + traceback.format_exc(e) + if e: + msg += "
" + traceback.format_exc(e) msg = re.sub("Traceback", "Traceback", msg) msg = re.sub(r"\n", "
", msg) error_dialog.showMessage(msg) diff --git a/libprs500/gui/main.py b/libprs500/gui/main.py index 178c82e581..5bcf2908e7 100644 --- a/libprs500/gui/main.py +++ b/libprs500/gui/main.py @@ -48,6 +48,19 @@ DEVICE_BOOK_TEMPLATE = QString("
Title: %1 \ 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,7 +149,8 @@ class Main(QObject, Ui_MainWindow): if index == self.library_view.currentIndex(): self.show_book(index, index) - def delete(self, action): + @report_error + def delete(self, action): rows = self.current_view.selectionModel().selectedRows() if not len(rows): return @@ -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)