fetch icons asynchronously (closes #756)
This commit is contained in:
parent
8d15911d67
commit
33d7a8d466
2 changed files with 41 additions and 12 deletions
|
|
@ -464,6 +464,9 @@ class Repositories(object):
|
||||||
repository = Repository(os.path.join(self.repos_dir, name))
|
repository = Repository(os.path.join(self.repos_dir, name))
|
||||||
self.repositories.append(repository)
|
self.repositories.append(repository)
|
||||||
|
|
||||||
|
def get_module_icon_path(self, module):
|
||||||
|
return os.path.join(self.icons_dir, '%s.png' % module.name)
|
||||||
|
|
||||||
def retrieve_icon(self, module):
|
def retrieve_icon(self, module):
|
||||||
"""
|
"""
|
||||||
Retrieve the icon of a module and save it in ~/.weboob/icons/.
|
Retrieve the icon of a module and save it in ~/.weboob/icons/.
|
||||||
|
|
@ -471,7 +474,7 @@ class Repositories(object):
|
||||||
if not isinstance(module, ModuleInfo):
|
if not isinstance(module, ModuleInfo):
|
||||||
module = self.get_module_info(module)
|
module = self.get_module_info(module)
|
||||||
|
|
||||||
dest_path = os.path.join(self.icons_dir, '%s.png' % module.name)
|
dest_path = self.get_module_icon_path(module)
|
||||||
|
|
||||||
if module.is_local():
|
if module.is_local():
|
||||||
icon_path = os.path.join(module.path, module.name, 'favicon.png')
|
icon_path = os.path.join(module.path, module.name, 'favicon.png')
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ from PyQt4.QtGui import QDialog, QTreeWidgetItem, QLabel, QFormLayout, \
|
||||||
QMessageBox, QPixmap, QImage, QIcon, QHeaderView, \
|
QMessageBox, QPixmap, QImage, QIcon, QHeaderView, \
|
||||||
QListWidgetItem, QTextDocument, QVBoxLayout, \
|
QListWidgetItem, QTextDocument, QVBoxLayout, \
|
||||||
QDialogButtonBox, QProgressDialog
|
QDialogButtonBox, QProgressDialog
|
||||||
from PyQt4.QtCore import SIGNAL, Qt, QVariant, QUrl
|
from PyQt4.QtCore import SIGNAL, Qt, QVariant, QUrl, QThread
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
|
|
@ -38,6 +38,17 @@ from weboob.tools.misc import to_unicode
|
||||||
from .qt import QtValue
|
from .qt import QtValue
|
||||||
|
|
||||||
|
|
||||||
|
class IconFetcher(QThread):
|
||||||
|
def __init__(self, weboob, item, minfo):
|
||||||
|
QThread.__init__(self)
|
||||||
|
self.weboob = weboob
|
||||||
|
self.items = [item]
|
||||||
|
self.minfo = minfo
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.weboob.repositories.retrieve_icon(self.minfo)
|
||||||
|
self.emit(SIGNAL('retrieved'), self)
|
||||||
|
|
||||||
class BackendCfg(QDialog):
|
class BackendCfg(QDialog):
|
||||||
def __init__(self, weboob, caps=None, parent=None):
|
def __init__(self, weboob, caps=None, parent=None):
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
|
|
@ -64,6 +75,7 @@ class BackendCfg(QDialog):
|
||||||
self.ui.configFrame.hide()
|
self.ui.configFrame.hide()
|
||||||
|
|
||||||
self.icon_cache = {}
|
self.icon_cache = {}
|
||||||
|
self.icon_threads = {}
|
||||||
|
|
||||||
for name, module in sorted(self.weboob.repositories.get_all_modules_info(self.caps).iteritems()):
|
for name, module in sorted(self.weboob.repositories.get_all_modules_info(self.caps).iteritems()):
|
||||||
item = QListWidgetItem(name.capitalize())
|
item = QListWidgetItem(name.capitalize())
|
||||||
|
|
@ -91,22 +103,36 @@ class BackendCfg(QDialog):
|
||||||
return self.icon_cache[path]
|
return self.icon_cache[path]
|
||||||
|
|
||||||
def set_icon(self, item, minfo):
|
def set_icon(self, item, minfo):
|
||||||
icon_path = os.path.join(self.weboob.repositories.icons_dir, '%s.png' % minfo.name)
|
icon_path = self.weboob.repositories.get_module_icon_path(minfo)
|
||||||
|
|
||||||
icon = self.icon_cache.get(icon_path, None)
|
icon = self.icon_cache.get(icon_path, None)
|
||||||
if icon is None:
|
if icon is None and not os.path.exists(icon_path):
|
||||||
if not os.path.exists(icon_path):
|
if minfo.name in self.icon_threads:
|
||||||
self.weboob.repositories.retrieve_icon(minfo)
|
self.icon_threads[minfo.name].items.append(item)
|
||||||
if not os.path.exists(icon_path):
|
else:
|
||||||
|
thread = IconFetcher(self.weboob, item, minfo)
|
||||||
|
self.connect(thread, SIGNAL('retrieved'), lambda t: self._set_icon(t.items, t.minfo))
|
||||||
|
self.icon_threads[minfo.name] = thread
|
||||||
|
thread.start()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self._set_icon([item], minfo)
|
||||||
|
|
||||||
|
def _set_icon(self, items, minfo):
|
||||||
|
icon_path = self.weboob.repositories.get_module_icon_path(minfo)
|
||||||
icon = self.get_icon_cache(icon_path)
|
icon = self.get_icon_cache(icon_path)
|
||||||
|
|
||||||
|
if icon is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
for item in items:
|
||||||
try:
|
try:
|
||||||
item.setIcon(icon)
|
item.setIcon(icon)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
item.setIcon(0, icon)
|
item.setIcon(0, icon)
|
||||||
|
|
||||||
|
self.icon_threads.pop(minfo.name, None)
|
||||||
|
|
||||||
def askInstallModule(self, minfo):
|
def askInstallModule(self, minfo):
|
||||||
reply = QMessageBox.question(self, self.tr('Install a module'),
|
reply = QMessageBox.question(self, self.tr('Install a module'),
|
||||||
unicode(self.tr("Module %s is not installed. Do you want to install it?")) % minfo.name,
|
unicode(self.tr("Module %s is not installed. Do you want to install it?")) % minfo.name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue