make qweboobcfg an application
This commit is contained in:
parent
3ccd0dc8ab
commit
e34b8a6541
13 changed files with 109 additions and 18 deletions
|
|
@ -1,13 +0,0 @@
|
|||
UI_FILES = $(wildcard *.ui)
|
||||
UI_PY_FILES = $(UI_FILES:%.ui=%_ui.py)
|
||||
PYUIC = pyuic4
|
||||
|
||||
all: $(UI_PY_FILES)
|
||||
|
||||
%_ui.py: %.ui
|
||||
$(PYUIC) -o $@ $^
|
||||
|
||||
clean:
|
||||
rm -f *.pyc
|
||||
rm -f $(UI_PY_FILES)
|
||||
|
||||
|
|
@ -1 +0,0 @@
|
|||
from .qt import QtApplication, QtMainWindow, QtDo, HTMLDelegate
|
||||
|
|
@ -1,250 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010 Romain Bignon
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
from PyQt4.QtGui import QDialog, QTreeWidgetItem, QLabel, QLineEdit, QCheckBox, \
|
||||
QMessageBox, QPixmap, QImage, QIcon, QHeaderView, \
|
||||
QListWidgetItem, QTextDocument
|
||||
from PyQt4.QtCore import SIGNAL, Qt, QVariant, QUrl
|
||||
|
||||
import re
|
||||
from logging import warning
|
||||
|
||||
from weboob.tools.application.qt.backendcfg_ui import Ui_BackendCfg
|
||||
|
||||
class BackendCfg(QDialog):
|
||||
def __init__(self, weboob, caps=None, parent=None):
|
||||
QDialog.__init__(self, parent)
|
||||
self.ui = Ui_BackendCfg()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
self.weboob = weboob
|
||||
self.caps = caps
|
||||
self.config_widgets = {}
|
||||
|
||||
self.weboob.modules_loader.load()
|
||||
|
||||
self.ui.backendsList.header().setResizeMode(QHeaderView.ResizeToContents)
|
||||
self.ui.configFrame.hide()
|
||||
|
||||
for name, module in self.weboob.modules_loader.modules.iteritems():
|
||||
if not self.caps or module.has_caps(*self.caps):
|
||||
item = QListWidgetItem(name.capitalize())
|
||||
|
||||
if module.get_icon_path():
|
||||
img = QImage(module.get_icon_path())
|
||||
item.setIcon(QIcon(QPixmap.fromImage(img)))
|
||||
|
||||
self.ui.modulesList.addItem(item)
|
||||
|
||||
self.loadBackendsList()
|
||||
|
||||
self.connect(self.ui.backendsList, SIGNAL('itemClicked(QTreeWidgetItem *, int)'), self.backendClicked)
|
||||
self.connect(self.ui.modulesList, SIGNAL('itemSelectionChanged()'), self.modulesSelectionChanged)
|
||||
self.connect(self.ui.proxyBox, SIGNAL('toggled(bool)'), self.proxyEditEnabled)
|
||||
self.connect(self.ui.addButton, SIGNAL('clicked()'), self.addEvent)
|
||||
self.connect(self.ui.removeButton, SIGNAL('clicked()'), self.removeEvent)
|
||||
self.connect(self.ui.configButtonBox, SIGNAL('accepted()'), self.acceptBackend)
|
||||
self.connect(self.ui.configButtonBox, SIGNAL('rejected()'), self.rejectBackend)
|
||||
|
||||
def loadBackendsList(self):
|
||||
self.ui.backendsList.clear()
|
||||
for instance_name, name, params in self.weboob.backends_config.iter_backends():
|
||||
module = self.weboob.modules_loader.modules[name]
|
||||
if self.caps and not module.has_caps(*self.caps):
|
||||
continue
|
||||
|
||||
item = QTreeWidgetItem(None, [instance_name, name])
|
||||
|
||||
if module.get_icon_path():
|
||||
img = QImage(module.get_icon_path())
|
||||
item.setIcon(0, QIcon(QPixmap.fromImage(img)))
|
||||
|
||||
self.ui.backendsList.addTopLevelItem(item)
|
||||
|
||||
def closeEvent(self, event):
|
||||
event.accept()
|
||||
|
||||
def backendClicked(self, item, col):
|
||||
bname = unicode(item.text(0))
|
||||
|
||||
self.editBackend(bname)
|
||||
|
||||
def addEvent(self):
|
||||
self.editBackend()
|
||||
|
||||
def removeEvent(self):
|
||||
item = self.ui.backendsList.currentItem()
|
||||
if not item:
|
||||
return
|
||||
|
||||
bname = unicode(item.text(0))
|
||||
reply = QMessageBox.question(self, self.tr('Remove a backend'),
|
||||
unicode(self.tr("Are you sure you want to remove the backend '%s'?")) % bname,
|
||||
QMessageBox.Yes|QMessageBox.No)
|
||||
|
||||
if reply != QMessageBox.Yes:
|
||||
return
|
||||
|
||||
self.weboob.backends_config.remove_backend(bname)
|
||||
self.loadBackendsList()
|
||||
|
||||
def editBackend(self, bname=None):
|
||||
self.ui.configFrame.show()
|
||||
|
||||
if bname is not None:
|
||||
mname, params = self.weboob.backends_config.get_backend(bname)
|
||||
|
||||
items = self.ui.modulesList.findItems(mname, Qt.MatchFixedString)
|
||||
if not items:
|
||||
print 'Module not found'
|
||||
else:
|
||||
self.ui.modulesList.setCurrentItem(items[0])
|
||||
self.ui.modulesList.setEnabled(False)
|
||||
|
||||
self.ui.nameEdit.setText(bname)
|
||||
self.ui.nameEdit.setEnabled(False)
|
||||
if '_proxy' in params:
|
||||
self.ui.proxyBox.setChecked(True)
|
||||
self.ui.proxyEdit.setText(params.pop('_proxy'))
|
||||
else:
|
||||
self.ui.proxyBox.setChecked(False)
|
||||
self.ui.proxyEdit.clear()
|
||||
|
||||
for key, value in params.iteritems():
|
||||
l, widget = self.config_widgets[key]
|
||||
if isinstance(widget, QLineEdit):
|
||||
widget.setText(unicode(value))
|
||||
elif isinstance(widget, QCheckBox):
|
||||
widget.setChecked(value.lower() in ('1', 'true', 'yes', 'on'))
|
||||
else:
|
||||
warning('Unknown type field "%s": %s', key, widget)
|
||||
else:
|
||||
self.ui.nameEdit.clear()
|
||||
self.ui.nameEdit.setEnabled(True)
|
||||
self.ui.proxyBox.setChecked(False)
|
||||
self.ui.proxyEdit.clear()
|
||||
self.ui.modulesList.setEnabled(True)
|
||||
self.ui.modulesList.setCurrentRow(-1)
|
||||
|
||||
def acceptBackend(self):
|
||||
bname = unicode(self.ui.nameEdit.text())
|
||||
selection = self.ui.modulesList.selectedItems()
|
||||
|
||||
if not selection:
|
||||
QMessageBox.critical(self, self.tr('Unable to add a backend'),
|
||||
self.tr('Please select a module'))
|
||||
return
|
||||
|
||||
module = self.weboob.modules_loader.modules[unicode(selection[0].text()).lower()]
|
||||
|
||||
params = {}
|
||||
missing = []
|
||||
|
||||
if not bname:
|
||||
missing.append(self.tr('Name'))
|
||||
|
||||
if self.ui.proxyBox.isChecked():
|
||||
params['_proxy'] = unicode(self.ui.proxyEdit.text())
|
||||
if not params['_proxy']:
|
||||
missing.append(self.tr('Proxy'))
|
||||
|
||||
for key, field in module.get_config().iteritems():
|
||||
label, value = self.config_widgets[key]
|
||||
|
||||
if isinstance(value, QLineEdit):
|
||||
params[key] = unicode(value.text())
|
||||
elif isinstance(value, QCheckBox):
|
||||
params[key] = '1' if value.isChecked() else '0'
|
||||
else:
|
||||
warning('Unknown type field "%s": %s', key, value)
|
||||
|
||||
if not params[key]:
|
||||
params[key] = field.default
|
||||
|
||||
if not params[key]:
|
||||
missing.append(field.description)
|
||||
elif field.regexp and not re.match(field.regexp, params[key]):
|
||||
QMessageBox.critical(self,
|
||||
self.tr('Invalid value'),
|
||||
unicode(self.tr('Invalid value for field "%s":\n\n%s')) % (field.description, params[key]))
|
||||
return
|
||||
|
||||
if missing:
|
||||
QMessageBox.critical(self,
|
||||
self.tr('Missing fields'),
|
||||
unicode(self.tr('Please set a value in this fields:\n%s')) % ('\n'.join(['- %s' % s for s in missing])))
|
||||
return
|
||||
|
||||
self.weboob.backends_config.add_backend(bname, module.get_name(), params, edit=not self.ui.nameEdit.isEnabled())
|
||||
self.ui.configFrame.hide()
|
||||
|
||||
self.loadBackendsList()
|
||||
|
||||
def rejectBackend(self):
|
||||
self.ui.configFrame.hide()
|
||||
|
||||
def modulesSelectionChanged(self):
|
||||
for key, (label, value) in self.config_widgets.iteritems():
|
||||
label.hide()
|
||||
value.hide()
|
||||
self.ui.configLayout.removeWidget(label)
|
||||
self.ui.configLayout.removeWidget(value)
|
||||
self.config_widgets.clear()
|
||||
self.ui.moduleInfo.clear()
|
||||
|
||||
selection = self.ui.modulesList.selectedItems()
|
||||
if not selection:
|
||||
return
|
||||
|
||||
module = self.weboob.modules_loader.modules[unicode(selection[0].text()).lower()]
|
||||
|
||||
if module.get_icon_path():
|
||||
img = QImage(module.get_icon_path())
|
||||
self.ui.moduleInfo.document().addResource(QTextDocument.ImageResource, QUrl('mydata://logo.png'), QVariant(img))
|
||||
|
||||
self.ui.moduleInfo.setText(unicode(self.tr(
|
||||
'<h1>%s Module %s</h1>'
|
||||
'<b>Version</b>: %s<br />'
|
||||
'<b>Maintainer</b>: %s<br />'
|
||||
'<b>License</b>: %s<br />'
|
||||
'<b>Description</b>: %s<br />'
|
||||
'<b>Capabilities</b>: %s<br />'))
|
||||
% ('<img src="mydata://logo.png" />' if module.get_icon_path() else '',
|
||||
module.get_name().capitalize(),
|
||||
module.get_version(),
|
||||
module.get_maintainer().replace('&', '&').replace('<', '<').replace('>', '>'),
|
||||
module.get_license(),
|
||||
module.get_description(),
|
||||
', '.join([cap.__name__ for cap in module.iter_caps()])))
|
||||
|
||||
for key, field in module.get_config().iteritems():
|
||||
label = QLabel(u'%s:' % field.description)
|
||||
if isinstance(field.default, bool):
|
||||
value = QCheckBox()
|
||||
if field.default:
|
||||
value.setChecked(True)
|
||||
else:
|
||||
value = QLineEdit()
|
||||
if field.default is not None:
|
||||
value.setText(unicode(field.default))
|
||||
if field.is_masked:
|
||||
value.setEchoMode(value.Password)
|
||||
self.ui.configLayout.addRow(label, value)
|
||||
self.config_widgets[key] = (label, value)
|
||||
|
||||
def proxyEditEnabled(self, state):
|
||||
self.ui.proxyEdit.setEnabled(state)
|
||||
|
|
@ -1,255 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>BackendCfg</class>
|
||||
<widget class="QDialog" name="BackendCfg">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>626</width>
|
||||
<height>614</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Backends configuration</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="backendsList">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>48</width>
|
||||
<height>48</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="rootIsDecorated">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="uniformRowHeights">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="itemsExpandable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="animated">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="expandsOnDoubleClick">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<attribute name="headerCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="headerHighlightSections">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="headerCascadingSectionResizes">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<attribute name="headerHighlightSections">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Module</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="addButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="removeButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QFrame" name="configFrame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QListWidget" name="modulesList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="spacing">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QFrame" name="frame_2">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="configLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="nameEdit"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="proxyBox">
|
||||
<property name="text">
|
||||
<string>Proxy:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="proxyEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="configButtonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="moduleInfo">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>clicked(QAbstractButton*)</signal>
|
||||
<receiver>BackendCfg</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>312</x>
|
||||
<y>591</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>312</x>
|
||||
<y>306</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
|
|
@ -1,165 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2010 Romain Bignon
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
import sys
|
||||
from PyQt4.QtCore import QTimer, SIGNAL, QObject, QString, QSize
|
||||
from PyQt4.QtGui import QMainWindow, QApplication, QStyledItemDelegate, \
|
||||
QStyleOptionViewItemV4, QTextDocument, QStyle, \
|
||||
QAbstractTextDocumentLayout, QPalette
|
||||
|
||||
from weboob.core.engine import Weboob
|
||||
from weboob.core.scheduler import IScheduler
|
||||
|
||||
from ..base import BaseApplication
|
||||
|
||||
__all__ = ['QtApplication', 'QtMainWindow', 'QtDo', 'HTMLDelegate']
|
||||
|
||||
class QtScheduler(IScheduler):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.timers = {}
|
||||
|
||||
def schedule(self, interval, function, *args):
|
||||
timer = QTimer()
|
||||
timer.setInterval(interval)
|
||||
timer.setSingleShot(False)
|
||||
self.app.connect(timer, SIGNAL("timeout()"), lambda: self.timeout(timer.timerId(), False, function, *args))
|
||||
self.timers[timer.timerId()] = timer
|
||||
|
||||
def repeat(self, interval, function, *args):
|
||||
timer = QTimer()
|
||||
timer.setInterval(interval)
|
||||
timer.setSingleShot(True)
|
||||
self.app.connect(timer, SIGNAL("timeout()"), lambda: self.timeout(timer.timerId(), True, function, *args))
|
||||
self.timers[timer.timerId()] = timer
|
||||
|
||||
def timeout(self, _id, single, function, *args):
|
||||
function(*args)
|
||||
if single:
|
||||
self.timers.pop(_id)
|
||||
|
||||
def want_stop(self):
|
||||
self.app.quit()
|
||||
|
||||
def run(self):
|
||||
self.app.exec_()
|
||||
|
||||
class QtApplication(QApplication, BaseApplication):
|
||||
def __init__(self):
|
||||
QApplication.__init__(self, sys.argv)
|
||||
self.setApplicationName(self.APPNAME)
|
||||
|
||||
BaseApplication.__init__(self)
|
||||
|
||||
def create_weboob(self):
|
||||
return Weboob(scheduler=QtScheduler(self))
|
||||
|
||||
class QtMainWindow(QMainWindow):
|
||||
def __init__(self, parent=None):
|
||||
QMainWindow.__init__(self, parent)
|
||||
|
||||
class QtDo(QObject):
|
||||
def __init__(self, weboob, cb, eb=None):
|
||||
QObject.__init__(self)
|
||||
|
||||
if not eb:
|
||||
eb = self.default_eb
|
||||
|
||||
self.weboob = weboob
|
||||
self.process = None
|
||||
self.cb = cb
|
||||
self.eb = eb
|
||||
|
||||
self.connect(self, SIGNAL('cb'), self.local_cb)
|
||||
self.connect(self, SIGNAL('eb'), self.local_eb)
|
||||
|
||||
def run_thread(func):
|
||||
def inner(self, *args, **kwargs):
|
||||
self.process = func(self, *args, **kwargs)
|
||||
self.process.callback_thread(self.thread_cb, self.thread_eb)
|
||||
return inner
|
||||
|
||||
@run_thread
|
||||
def do(self, *args, **kwargs):
|
||||
return self.weboob.do(*args, **kwargs)
|
||||
|
||||
@run_thread
|
||||
def do_caps(self, *args, **kwargs):
|
||||
return self.weboob.do_caps(*args, **kwargs)
|
||||
|
||||
@run_thread
|
||||
def do_backends(self, *args, **kwargs):
|
||||
return self.weboob.do_backends(*args, **kwargs)
|
||||
|
||||
def default_eb(self, backend, error, backtrace):
|
||||
# TODO display a messagebox
|
||||
print error
|
||||
print backtrace
|
||||
|
||||
def local_cb(self, backend, data):
|
||||
self.cb(backend, data)
|
||||
if not backend:
|
||||
self.disconnect(self, SIGNAL('cb'), self.local_cb)
|
||||
self.disconnect(self, SIGNAL('eb'), self.local_eb)
|
||||
|
||||
def local_eb(self, backend, error, backtrace):
|
||||
self.eb(backend, error, backtrace)
|
||||
self.disconnect(self, SIGNAL('cb'), self.local_cb)
|
||||
self.disconnect(self, SIGNAL('eb'), self.local_eb)
|
||||
|
||||
def thread_cb(self, backend, data):
|
||||
self.emit(SIGNAL('cb'), backend, data)
|
||||
|
||||
def thread_eb(self, backend, error, backtrace):
|
||||
self.emit(SIGNAL('eb'), backend, error, backtrace)
|
||||
|
||||
class HTMLDelegate(QStyledItemDelegate):
|
||||
def paint(self, painter, option, index):
|
||||
optionV4 = QStyleOptionViewItemV4(option)
|
||||
self.initStyleOption(optionV4, index)
|
||||
|
||||
style = optionV4.widget.style() if optionV4.widget else QApplication.style()
|
||||
|
||||
doc = QTextDocument()
|
||||
doc.setHtml(optionV4.text)
|
||||
|
||||
# painting item without text
|
||||
optionV4.text = QString()
|
||||
style.drawControl(QStyle.CE_ItemViewItem, optionV4, painter)
|
||||
|
||||
ctx = QAbstractTextDocumentLayout.PaintContext()
|
||||
|
||||
# Hilight text if item is selected
|
||||
if optionV4.state & QStyle.State_Selected:
|
||||
ctx.palette.setColor(QPalette.Text, optionV4.palette.color(QPalette.Active, QPalette.HighlightedText))
|
||||
|
||||
textRect = style.subElementRect(QStyle.SE_ItemViewItemText, optionV4)
|
||||
painter.save()
|
||||
painter.translate(textRect.topLeft())
|
||||
painter.setClipRect(textRect.translated(-textRect.topLeft()))
|
||||
doc.documentLayout().draw(painter, ctx)
|
||||
painter.restore()
|
||||
|
||||
def sizeHint(self, option, index):
|
||||
optionV4 = QStyleOptionViewItemV4(option)
|
||||
self.initStyleOption(optionV4, index)
|
||||
|
||||
doc = QTextDocument()
|
||||
doc.setHtml(optionV4.text)
|
||||
doc.setTextWidth(optionV4.rect.width())
|
||||
|
||||
return QSize(doc.idealWidth(), max(doc.size().height(), optionV4.decorationSize.height()))
|
||||
Loading…
Add table
Add a link
Reference in a new issue