qt: display a dialog to ask user to update repositories at run if error

This commit is contained in:
Romain Bignon 2013-03-26 09:53:17 +01:00
commit 0a603ff42a
2 changed files with 35 additions and 3 deletions

View file

@ -36,6 +36,9 @@ from weboob.tools.log import getLogger
__all__ = ['Weboob']
class VersionsMismatchError(ConfigError):
pass
class Weboob(object):
"""
The main class of Weboob, used to manage backends and call methods.
@ -196,7 +199,7 @@ class Weboob(object):
if not self.repositories.check_repositories():
self.logger.error(u'Repositories are not consistent with the sources.list')
raise ConfigError(u'Versions mismatch, please run "weboob-config update"')
raise VersionsMismatchError(u'Versions mismatch, please run "weboob-config update"')
for instance_name, module_name, params in self.backends_config.iter_backends():
if '_enabled' in params and not params['_enabled'].lower() in ('1', 'y', 'true', 'on', 'yes') or \

View file

@ -22,14 +22,16 @@ import logging
import re
from threading import Event
from copy import copy
from PyQt4.QtCore import QTimer, SIGNAL, QObject, QString, QSize, QVariant, QMutex
from PyQt4.QtCore import QTimer, SIGNAL, QObject, QString, QSize, QVariant, QMutex, Qt
from PyQt4.QtGui import QMainWindow, QApplication, QStyledItemDelegate, \
QStyleOptionViewItemV4, QTextDocument, QStyle, \
QAbstractTextDocumentLayout, QPalette, QMessageBox, \
QSpinBox, QLineEdit, QComboBox, QCheckBox, QInputDialog
from weboob.core.ouiboube import Weboob
from weboob.core.ouiboube import Weboob, VersionsMismatchError
from weboob.core.scheduler import IScheduler
from weboob.core.repositories import ModuleInstallError
from weboob.tools.config.iconfig import ConfigError
from weboob.tools.browser import BrowserUnavailable, BrowserIncorrectPassword, BrowserForbidden
from weboob.tools.value import ValueInt, ValueBool, ValueBackendPassword
from weboob.tools.misc import to_unicode
@ -37,6 +39,7 @@ from weboob.capabilities import UserError
from ..base import BaseApplication
__all__ = ['QtApplication', 'QtMainWindow', 'QtDo', 'HTMLDelegate']
@ -146,6 +149,32 @@ class QtApplication(QApplication, BaseApplication):
def create_weboob(self):
return Weboob(scheduler=QtScheduler(self))
def load_backends(self, *args, **kwargs):
while 1:
try:
return BaseApplication.load_backends(self, *args, **kwargs)
except VersionsMismatchError, e:
msg = 'Versions of modules mismatch with version of weboob.'
except ConfigError, e:
msg = unicode(e)
res = QMessageBox.question(None, 'Configuration error', u'%s\n\nDo you want to update repositories?' % msg, QMessageBox.Yes|QMessageBox.No)
if res == QMessageBox.No:
raise e
# Do not import it globally, it causes circular imports
from .backendcfg import ProgressDialog
pd = ProgressDialog('Update of repositories', "Cancel", 0, 100)
pd.setWindowModality(Qt.WindowModal)
try:
self.weboob.update(pd)
except ModuleInstallError, err:
QMessageBox.critical(None, self.tr('Update error'),
unicode(self.tr('Unable to update repositories: %s' % err)),
QMessageBox.Ok)
pd.setValue(100)
QMessageBox.information(None, self.tr('Update of repositories'),
self.tr('Repositories updated!'), QMessageBox.Ok)
class QtMainWindow(QMainWindow):
def __init__(self, parent=None):