[weboob] [PATCH] base: Use a QMessageBox to display config error messages in Qt apps.

Cyril Brulebois kibi at mraw.org
Mon Mar 25 23:20:07 CET 2013


Make it possible to pass an extra “variant” parameter in __init__(), and
use it in the Qt case to record this variant. This makes it possible to
special-cases those qt applications and to use a QMessageBox to display
the error message, instead of simply logging to stderr. That should help
GUI users.

Fix for: https://symlink.me/issues/1072

Signed-off-by: Cyril Brulebois <kibi at mraw.org>
---
 weboob/tools/application/base.py  |    7 ++++++-
 weboob/tools/application/qt/qt.py |    2 +-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/weboob/tools/application/base.py b/weboob/tools/application/base.py
index bb0accf..ac17c9b 100644
--- a/weboob/tools/application/base.py
+++ b/weboob/tools/application/base.py
@@ -127,7 +127,7 @@ class BaseApplication(object):
 
     # ------ BaseApplication methods -------------------------------
 
-    def __init__(self, option_parser=None):
+    def __init__(self, option_parser=None, variant=None):
         self.logger = getLogger(self.APPNAME)
         self.weboob = self.create_weboob()
         if self.CONFDIR is None:
@@ -138,6 +138,7 @@ class BaseApplication(object):
             self._parser = OptionParser(self.SYNOPSIS, version=self._get_optparse_version())
         else:
             self._parser = option_parser
+        self._variant = variant
         if self.DESCRIPTION:
             self._parser.description = self.DESCRIPTION
         app_options = OptionGroup(self._parser, '%s Options' % self.APPNAME.capitalize())
@@ -398,7 +399,11 @@ class BaseApplication(object):
                 sys.exit(0)
             except ConfigError, e:
                 print >>sys.stderr, 'Configuration error: %s' % e
+                if app._variant == 'qt':
+                    from PyQt4.QtGui import QMessageBox
+                    QMessageBox.critical(None, 'Configuration error', str(e), QMessageBox.Ok)
                 sys.exit(1)
+
             except CallErrors, e:
                 app.bcall_errors_handler(e)
                 sys.exit(1)
diff --git a/weboob/tools/application/qt/qt.py b/weboob/tools/application/qt/qt.py
index 81000c6..7bdd9d1 100644
--- a/weboob/tools/application/qt/qt.py
+++ b/weboob/tools/application/qt/qt.py
@@ -140,7 +140,7 @@ class QtApplication(QApplication, BaseApplication):
         QApplication.__init__(self, sys.argv)
         self.setApplicationName(self.APPNAME)
 
-        BaseApplication.__init__(self)
+        BaseApplication.__init__(self, variant='qt')
         self.cbmanager = QCallbacksManager(self.weboob, self)
 
     def create_weboob(self):
-- 
1.7.10.4




More information about the weboob mailing list