本文整理汇总了Python中weboob.tools.application.qt.QtDo.do方法的典型用法代码示例。如果您正苦于以下问题:Python QtDo.do方法的具体用法?Python QtDo.do怎么用?Python QtDo.do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weboob.tools.application.qt.QtDo
的用法示例。
在下文中一共展示了QtDo.do方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addHousing
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
def addHousing(self, backend, housing):
if not backend:
self.ui.queriesList.setEnabled(True)
self.ui.bookmarksButton.setEnabled(True)
self.process = None
return
if not housing:
return
item = HousingListWidgetItem(housing)
item.setAttrs(self.storage)
if housing.photos is NotLoaded:
process = QtDo(self.weboob, lambda b, c: self.setPhoto(c, item))
process.do('fillobj', housing, ['photos'], backends=housing.backend)
self.process_photo[housing.id] = process
elif housing.photos is not NotAvailable and len(housing.photos) > 0:
if not self.setPhoto(housing, item):
photo = housing.photos[0]
process = QtDo(self.weboob, lambda b, p: self.setPhoto(housing, item))
process.do('fillobj', photo, ['data'], backends=housing.backend)
self.process_photo[housing.id] = process
self.ui.housingsList.addItem(item)
if housing.fullid in self.process_bookmarks:
self.process_bookmarks.pop(housing.fullid)
示例2: ContactNotes
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class ContactNotes(QWidget):
""" Widget for storing notes about a contact """
def __init__(self, weboob, contact, parent=None):
QWidget.__init__(self, parent)
self.ui = Ui_Notes()
self.ui.setupUi(self)
self.weboob = weboob
self.contact = contact
self.ui.textEdit.setEnabled(False)
self.ui.saveButton.setEnabled(False)
self.process = QtDo(self.weboob, self._getNotes_cb, self._getNotes_eb)
self.process.do('get_notes', self.contact.id, backends=(self.contact.backend,))
self.connect(self.ui.saveButton, SIGNAL('clicked()'), self.saveNotes)
def _getNotes_cb(self, backend, data):
if not backend or not data:
self.process = None
self.ui.textEdit.setEnabled(True)
self.ui.saveButton.setEnabled(True)
return
self.ui.textEdit.setText(data)
def _getNotes_eb(self, backend, error, backtrace):
if isinstance(error, NotImplementedError):
return
self.ui.textEdit.setEnabled(True)
self.ui.saveButton.setEnabled(True)
content = unicode(self.tr('Unable to load notes:\n%s\n')) % to_unicode(error)
if logging.root.level == logging.DEBUG:
content += '\n%s\n' % to_unicode(backtrace)
QMessageBox.critical(self, self.tr('Error while loading notes'),
content, QMessageBox.Ok)
def saveNotes(self):
text = unicode(self.ui.textEdit.toPlainText())
self.ui.saveButton.setEnabled(False)
self.ui.textEdit.setEnabled(False)
self.process = QtDo(self.weboob, self._saveNotes_cb, self._saveNotes_eb)
self.process.do('save_notes', self.contact.id, text, backends=(self.contact.backend,))
def _saveNotes_cb(self, backend, data):
self.ui.saveButton.setEnabled(True)
self.ui.textEdit.setEnabled(True)
pass
def _saveNotes_eb(self, backend, error, backtrace):
self.ui.saveButton.setEnabled(True)
self.ui.textEdit.setEnabled(True)
content = unicode(self.tr('Unable to save notes:\n%s\n')) % to_unicode(error)
if logging.root.level == logging.DEBUG:
content += '\n%s\n' % to_unicode(backtrace)
QMessageBox.critical(self, self.tr('Error while saving notes'),
content, QMessageBox.Ok)
示例3: gotEvent
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
def gotEvent(self, event):
found = False
for i in xrange(self.ui.typeBox.count()):
s = self.ui.typeBox.itemData(i)
if s == event.type:
found = True
if not found:
print(event.type)
self.ui.typeBox.addItem(event.type.capitalize(), event.type)
if event.type == self.event_filter:
self.ui.typeBox.setCurrentIndex(self.ui.typeBox.count()-1)
if self.event_filter and self.event_filter != event.type:
return
if not event.contact:
return
contact = event.contact
contact.backend = event.backend
status = ''
if contact.status == contact.STATUS_ONLINE:
status = u'Online'
status_color = 0x00aa00
elif contact.status == contact.STATUS_OFFLINE:
status = u'Offline'
status_color = 0xff0000
elif contact.status == contact.STATUS_AWAY:
status = u'Away'
status_color = 0xffad16
else:
status = u'Unknown'
status_color = 0xaaaaaa
if contact.status_msg:
status += u' — %s' % contact.status_msg
name = '<h2>%s</h2><font color="#%06X">%s</font><br /><i>%s</i>' % (contact.name, status_color, status, event.backend)
date = event.date.strftime('%Y-%m-%d %H:%M')
type = event.type
message = event.message
item = QTreeWidgetItem(None, [name, date, type, message])
item.setData(0, Qt.UserRole, event)
if contact.photos is NotLoaded:
process = QtDo(self.weboob, lambda c: self.setPhoto(c, item))
process.do('fillobj', contact, ['photos'], backends=contact.backend)
self.photo_processes[contact.id] = process
elif len(contact.photos) > 0:
if not self.setPhoto(contact, item):
photo = contact.photos.values()[0]
process = QtDo(self.weboob, lambda p: self.setPhoto(contact, item))
process.do('fillobj', photo, ['thumbnail_data'], backends=contact.backend)
self.photo_processes[contact.id] = process
self.ui.eventsList.addTopLevelItem(item)
self.ui.eventsList.resizeColumnToContents(0)
self.ui.eventsList.resizeColumnToContents(1)
示例4: MiniVideo
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class MiniVideo(QFrame):
def __init__(self, weboob, backend, video, parent=None):
QFrame.__init__(self, parent)
self.ui = Ui_MiniVideo()
self.ui.setupUi(self)
self.weboob = weboob
self.backend = backend
self.video = video
self.ui.titleLabel.setText(video.title)
self.ui.backendLabel.setText(backend.name)
self.ui.durationLabel.setText(unicode(video.duration))
self.ui.authorLabel.setText(unicode(video.author))
self.ui.dateLabel.setText(video.date and unicode(video.date) or '')
if video.rating_max:
self.ui.ratingLabel.setText('%s / %s' % (video.rating, video.rating_max))
else:
self.ui.ratingLabel.setText('%s' % video.rating)
self.process_thumbnail = QtDo(self.weboob, self.gotThumbnail)
self.process_thumbnail.do('fillobj', self.video, ['thumbnail'], backends=backend)
def gotThumbnail(self, backend, video):
if not backend:
return
if video.thumbnail and video.thumbnail.data:
img = QImage.fromData(video.thumbnail.data)
self.ui.imageLabel.setPixmap(QPixmap.fromImage(img))
def enterEvent(self, event):
self.setFrameShadow(self.Sunken)
QFrame.enterEvent(self, event)
def leaveEvent(self, event):
self.setFrameShadow(self.Raised)
QFrame.leaveEvent(self, event)
def mousePressEvent(self, event):
QFrame.mousePressEvent(self, event)
video = self.backend.get_video(self.video.id)
if video:
video_widget = Video(video, self)
video_widget.show()
示例5: MetaGroup
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class MetaGroup(IGroup):
def iter_contacts(self, cb):
if self.id == 'online':
status = Contact.STATUS_ONLINE|Contact.STATUS_AWAY
elif self.id == 'offline':
status = Contact.STATUS_OFFLINE
else:
status = Contact.STATUS_ALL
self.process = QtDo(self.weboob, lambda b, d: self.cb(cb, b, d))
self.process.do('iter_contacts', status, caps=ICapContact)
def cb(self, cb, backend, contact):
if contact:
cb(contact)
elif not backend:
self.process = None
cb(None)
示例6: addContact
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
def addContact(self, contact):
if not contact:
self.ui.refreshButton.setEnabled(True)
return
status = ''
if contact.status == Contact.STATUS_ONLINE:
status = u'Online'
status_color = 0x00aa00
elif contact.status == Contact.STATUS_OFFLINE:
status = u'Offline'
status_color = 0xff0000
elif contact.status == Contact.STATUS_AWAY:
status = u'Away'
status_color = 0xffad16
else:
status = u'Unknown'
status_color = 0xaaaaaa
if contact.status_msg:
status += u' — %s' % contact.status_msg
item = QListWidgetItem()
item.setText('<h2>%s</h2><font color="#%06X">%s</font><br /><i>%s</i>' % (contact.name, status_color, status, contact.backend))
item.setData(Qt.UserRole, contact)
if contact.photos is NotLoaded:
process = QtDo(self.weboob, lambda b, c: self.setPhoto(c, item))
process.do('fillobj', contact, ['photos'], backends=contact.backend)
self.photo_processes[contact.id] = process
elif len(contact.photos) > 0:
if not self.setPhoto(contact, item):
photo = contact.photos.values()[0]
process = QtDo(self.weboob, lambda b, p: self.setPhoto(contact, item))
process.do('fillobj', photo, ['thumbnail_data'], backends=contact.backend)
self.photo_processes[contact.id] = process
for i in xrange(self.ui.contactList.count()):
if self.ui.contactList.item(i).data(Qt.UserRole).toPyObject().status > contact.status:
self.ui.contactList.insertItem(i, item)
return
self.ui.contactList.addItem(item)
示例7: MetaGroup
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class MetaGroup(IGroup):
def iter_contacts(self, cb):
if self.id == 'online':
status = Contact.STATUS_ONLINE|Contact.STATUS_AWAY
elif self.id == 'offline':
status = Contact.STATUS_OFFLINE
else:
status = Contact.STATUS_ALL
self.process = QtDo(self.weboob, lambda d: self.cb(cb, d), fb=lambda: self.fb(cb))
self.process.do('iter_contacts', status, caps=CapContact)
def cb(self, cb, contact):
if contact:
cb(contact)
def fb(self, fb):
self.process = None
if fb:
fb(None)
示例8: ContactProfile
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class ContactProfile(QWidget):
def __init__(self, weboob, contact, parent=None):
QWidget.__init__(self, parent)
self.ui = Ui_Profile()
self.ui.setupUi(self)
self.connect(self.ui.previousButton, SIGNAL('clicked()'), self.previousClicked)
self.connect(self.ui.nextButton, SIGNAL('clicked()'), self.nextClicked)
self.weboob = weboob
self.contact = contact
self.loaded_profile = False
self.displayed_photo_idx = 0
self.process_photo = {}
missing_fields = self.gotProfile(self.weboob.get_backend(contact.backend), contact)
if len(missing_fields) > 0:
self.process_contact = QtDo(self.weboob, self.gotProfile, self.gotError)
self.process_contact.do('fillobj', self.contact, missing_fields, backends=self.contact.backend)
def gotError(self, backend, error, backtrace):
#self.process_contact.default_eb(backend, error, backtrace)
self.ui.frame_photo.hide()
self.ui.descriptionEdit.setText('<h1>Unable to show profile</h1><p>%s</p>' % error)
def gotProfile(self, backend, contact):
if not backend:
return []
missing_fields = set()
self.display_photo()
self.ui.nicknameLabel.setText('<h1>%s</h1>' % contact.name)
if contact.status == Contact.STATUS_ONLINE:
status_color = 0x00aa00
elif contact.status == Contact.STATUS_OFFLINE:
status_color = 0xff0000
elif contact.status == Contact.STATUS_AWAY:
status_color = 0xffad16
else:
status_color = 0xaaaaaa
self.ui.statusLabel.setText('<font color="#%06X">%s</font>' % (status_color, contact.status_msg))
self.ui.contactUrlLabel.setText('<b>URL:</b> <a href="%s">%s</a>' % (contact.url, contact.url))
if contact.summary is NotLoaded:
self.ui.descriptionEdit.setText('<h1>Description</h1><p><i>Receiving...</i></p>')
missing_fields.add('summary')
else:
self.ui.descriptionEdit.setText('<h1>Description</h1><p>%s</p>' % contact.summary.replace('\n', '<br />'))
if not contact.profile:
missing_fields.add('profile')
elif not self.loaded_profile:
self.loaded_profile = True
for head in contact.profile:
if head.flags & head.HEAD:
widget = self.ui.headWidget
else:
widget = self.ui.profileTab
self.process_node(head, widget)
return missing_fields
def process_node(self, node, widget):
# Set the value widget
value = None
if node.flags & node.SECTION:
value = QWidget()
value.setLayout(QFormLayout())
for sub in node.value:
self.process_node(sub, value)
elif isinstance(node.value, list):
value = QLabel('<br />'.join([unicode(s) for s in node.value]))
value.setWordWrap(True)
elif isinstance(node.value, tuple):
value = QLabel(', '.join([unicode(s) for s in node.value]))
value.setWordWrap(True)
elif isinstance(node.value, (basestring,int,long,float)):
value = QLabel(unicode(node.value))
else:
logging.warning('Not supported value: %r' % node.value)
return
# Insert the value widget into the parent widget, depending
# of its type.
if isinstance(widget, QTabWidget):
widget.addTab(value, node.label)
elif isinstance(widget.layout(), QFormLayout):
label = QLabel(u'<b>%s:</b> ' % node.label)
widget.layout().addRow(label, value)
elif isinstance(widget.layout(), QVBoxLayout):
widget.layout().addWidget(QLabel(u'<h3>%s</h3>' % node.label))
widget.layout().addWidget(value)
else:
logging.warning('Not supported widget: %r' % widget)
def previousClicked(self):
self.displayed_photo_idx = (self.displayed_photo_idx - 1) % len(self.contact.photos)
#.........这里部分代码省略.........
示例9: EventsWidget
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class EventsWidget(QWidget):
def __init__(self, weboob, parent=None):
QWidget.__init__(self, parent)
self.ui = Ui_Events()
self.ui.setupUi(self)
self.weboob = weboob
self.photo_processes = {}
self.event_filter = None
self.connect(self.ui.eventsList, SIGNAL('itemDoubleClicked(QTreeWidgetItem*, int)'), self.eventDoubleClicked)
self.connect(self.ui.typeBox, SIGNAL('currentIndexChanged(int)'), self.typeChanged)
self.connect(self.ui.refreshButton, SIGNAL('clicked()'), self.refreshEventsList)
self.ui.eventsList.setItemDelegate(HTMLDelegate())
self.ui.eventsList.sortByColumn(1, Qt.DescendingOrder)
def load(self):
self.refreshEventsList()
def typeChanged(self, i):
if self.ui.refreshButton.isEnabled():
self.refreshEventsList()
def refreshEventsList(self):
self.ui.eventsList.clear()
self.ui.refreshButton.setEnabled(False)
if self.ui.typeBox.currentIndex() >= 0:
# XXX strangely, in gotEvent() in the loop to check if there is already the
# event type to try to introduce it in list, itemData() returns the right value.
# But, I don't know why, here, it will ALWAYS return None...
# So the filter does not work currently.
self.events_filter = self.ui.typeBox.itemData(self.ui.typeBox.currentIndex())
else:
self.event_filter = None
self.ui.typeBox.setEnabled(False)
self.ui.typeBox.clear()
self.ui.typeBox.addItem('All', None)
def finished():
self.ui.refreshButton.setEnabled(True)
self.ui.typeBox.setEnabled(True)
self.process = QtDo(self.weboob, self.gotEvent, fb=finished)
self.process.do('iter_events')
def setPhoto(self, contact, item):
if not contact:
return False
try:
self.photo_processes.pop(contact.id, None)
except KeyError:
pass
img = None
for photo in contact.photos.itervalues():
if photo.thumbnail_data:
img = QImage.fromData(photo.thumbnail_data)
break
if img:
item.setIcon(0, QIcon(QPixmap.fromImage(img)))
self.ui.eventsList.resizeColumnToContents(0)
return True
return False
def gotEvent(self, event):
found = False
for i in xrange(self.ui.typeBox.count()):
s = self.ui.typeBox.itemData(i)
if s == event.type:
found = True
if not found:
print(event.type)
self.ui.typeBox.addItem(event.type.capitalize(), event.type)
if event.type == self.event_filter:
self.ui.typeBox.setCurrentIndex(self.ui.typeBox.count()-1)
if self.event_filter and self.event_filter != event.type:
return
if not event.contact:
return
contact = event.contact
contact.backend = event.backend
status = ''
if contact.status == contact.STATUS_ONLINE:
status = u'Online'
status_color = 0x00aa00
elif contact.status == contact.STATUS_OFFLINE:
status = u'Offline'
status_color = 0xff0000
elif contact.status == contact.STATUS_AWAY:
status = u'Away'
status_color = 0xffad16
else:
#.........这里部分代码省略.........
示例10: SearchWidget
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class SearchWidget(QWidget):
def __init__(self, weboob, parent=None):
QWidget.__init__(self, parent)
self.ui = Ui_Search()
self.ui.setupUi(self)
self.weboob = weboob
self.contacts = []
self.accounts = []
self.current = None
self.connect(self.ui.nextButton, SIGNAL('clicked()'), self.next)
self.connect(self.ui.queryButton, SIGNAL('clicked()'), self.sendQuery)
def load(self):
while self.ui.statusFrame.layout().count() > 0:
item = self.ui.statusFrame.layout().takeAt(0)
if item.widget():
item.widget().deinit()
item.widget().hide()
item.widget().deleteLater()
self.accounts = []
for backend in self.weboob.iter_backends():
account = Account(self.weboob, backend)
account.title.setText(u'<h2>%s</h2>' % backend.name)
self.accounts.append(account)
self.ui.statusFrame.layout().addWidget(account)
self.ui.statusFrame.layout().addStretch()
self.getNewProfiles()
def updateStats(self):
for account in self.accounts:
account.updateStats()
def getNewProfiles(self):
self.newprofiles_process = QtDo(self.weboob, self.retrieveNewContacts_cb)
self.newprofiles_process.do('iter_new_contacts')
def retrieveNewContacts_cb(self, backend, contact):
if not backend:
return
self.contacts.insert(0, contact)
self.ui.queueLabel.setText('%d' % len(self.contacts))
if self.current is None:
self.next()
def next(self):
try:
contact = self.contacts.pop()
except IndexError:
contact = None
self.ui.queueLabel.setText('%d' % len(self.contacts))
self.setContact(contact)
self.updateStats()
def setContact(self, contact):
self.current = contact
if contact is not None:
widget = ContactProfile(self.weboob, contact)
self.ui.scrollArea.setWidget(widget)
else:
self.ui.scrollArea.setWidget(None)
def sendQuery(self):
self.newprofiles_process = QtDo(self.weboob, self.querySent)
self.newprofiles_process.do('send_query', self.current.id, backends=[self.current.backend])
def querySent(self, backend, query):
if backend is None:
self.next()
示例11: MainWindow
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class MainWindow(QtMainWindow):
def __init__(self, config, weboob, parent=None):
QtMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.config = config
self.weboob = weboob
self.backend = None
self.connect(self.ui.idEdit,
SIGNAL("returnPressed()"),
self.loadPage)
self.connect(self.ui.loadButton,
SIGNAL("clicked()"),
self.loadPage)
self.connect(self.ui.tabWidget,
SIGNAL("currentChanged(int)"),
self._currentTabChanged)
self.connect(self.ui.saveButton,
SIGNAL("clicked()"),
self.savePage)
self.connect(self.ui.actionBackends,
SIGNAL("triggered()"),
self.backendsConfig)
self.connect(self.ui.contentEdit,
SIGNAL("textChanged()"),
self._textChanged)
self.connect(self.ui.loadHistoryButton,
SIGNAL("clicked()"),
self.loadHistory)
if hasattr(self.ui.descriptionEdit, "setPlaceholderText"):
self.ui.descriptionEdit.setPlaceholderText("Edit summary")
if self.weboob.count_backends() == 0:
self.backendsConfig()
else:
self.loadBackends()
def backendsConfig(self):
""" Opens backends configuration dialog when 'Backends' is clicked """
bckndcfg = BackendCfg(self.weboob, (ICapContent,), self)
if bckndcfg.run():
self.loadBackends()
def loadBackends(self):
""" Fills the backends comboBox with available backends """
self.ui.backendBox.clear()
for backend in self.weboob.iter_backends():
self.ui.backendBox.insertItem(0, backend.name)
def _currentTabChanged(self):
""" Loads history or preview when the corresponding tabs are shown """
if self.ui.tabWidget.currentIndex() == 1:
if self.backend is not None:
self.loadPreview()
elif self.ui.tabWidget.currentIndex() == 2:
if self.backend is not None:
self.loadHistory()
def _textChanged(self):
""" The text in the content QPlainTextEdit has changed """
if self.backend:
self.ui.saveButton.setEnabled(True)
self.ui.saveButton.setText('Save')
def loadPage(self):
""" Loads a page's source into the 'content' QPlainTextEdit """
_id = unicode(self.ui.idEdit.text())
if not _id:
return
self.ui.loadButton.setEnabled(False)
self.ui.loadButton.setText('Loading...')
self.ui.contentEdit.setReadOnly(True)
backend = str(self.ui.backendBox.currentText())
self.process = QtDo(self.weboob,
self._loadedPage,
self._errorLoadPage)
self.process.do('get_content', _id, backends=(backend,))
def _loadedPage(self, backend, data):
""" Callback for loadPage """
if not backend:
# Loading is finished
self.process = None
if self.backend:
self.ui.contentEdit.setReadOnly(False)
self.ui.loadButton.setEnabled(True)
self.ui.loadButton.setText('Load')
return
if not data:
self.content = None
self.backend = None
QMessageBox.critical(self, self.tr('Unable to open page'),
'Unable to open page "%s" on %s: it does not exist.'
% (self.ui.idEdit.text(),
self.ui.backendBox.currentText()),
#.........这里部分代码省略.........
示例12: Account
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class Account(QFrame):
def __init__(self, weboob, backend, parent=None):
QFrame.__init__(self, parent)
self.setFrameShape(QFrame.StyledPanel)
self.setFrameShadow(QFrame.Raised)
self.weboob = weboob
self.backend = backend
self.setLayout(QVBoxLayout())
self.timer = None
head = QHBoxLayout()
headw = QWidget()
headw.setLayout(head)
self.title = QLabel(u'<h1>%s — %s</h1>' % (backend.name, backend.DESCRIPTION))
self.body = QLabel()
if backend.ICON:
self.icon = QLabel()
img = QImage(backend.ICON)
self.icon.setPixmap(QPixmap.fromImage(img))
head.addWidget(self.icon)
head.addWidget(self.title)
head.addStretch()
self.layout().addWidget(headw)
if backend.has_caps(ICapAccount):
self.body.setText(u'<i>Waiting...</i>')
self.layout().addWidget(self.body)
self.timer = self.weboob.repeat(60, self.updateStats)
def deinit(self):
if self.timer is not None:
self.weboob.stop(self.timer)
def updateStats(self):
self.process = QtDo(self.weboob, self.updateStats_cb, self.updateStats_eb)
self.process.body = u''
self.process.in_p = False
self.process.do('get_account_status', backends=self.backend)
def updateStats_cb(self, backend, field):
if not field:
if self.process.in_p:
self.process.body += u"</p>"
self.body.setText(self.process.body)
self.process = None
return
if field.flags & StatusField.FIELD_HTML:
value = u'%s' % field.value
else:
value = (u'%s' % field.value).replace('&', '&').replace('<', '<').replace('>', '>')
if field.flags & StatusField.FIELD_TEXT:
if self.process.in_p:
self.process.body += u'</p>'
self.process.body += u'<p>%s</p>' % value
self.process.in_p = False
else:
if not self.process.in_p:
self.process.body += u"<p>"
self.process.in_p = True
else:
self.process.body += u"<br />"
self.process.body += u'<b>%s</b>: %s' % (field.label, field.value)
def updateStats_eb(self, backend, err, backtrace):
self.body.setText(u'<b>Unable to connect:</b> %s' % to_unicode(err))
self.title.setText(u'<font color=#ff0000>%s</font>' % unicode(self.title.text()))
示例13: MainWindow
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class MainWindow(QtMainWindow):
def __init__(self, config, storage, weboob, parent=None):
QtMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.config = config
self.storage = storage
self.weboob = weboob
self.process = None
self.displayed_photo_idx = 0
self.process_photo = {}
self.process_bookmarks = {}
# search history is a list of patterns which have been searched
self.search_history = self.loadSearchHistory()
self.updateCompletion()
self.ui.jobFrame.hide()
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
self.connect(self.ui.searchEdit, SIGNAL('returnPressed()'), self.doSearch)
self.connect(self.ui.jobList, SIGNAL('currentItemChanged(QListWidgetItem*, QListWidgetItem*)'), self.jobSelected)
self.connect(self.ui.searchButton, SIGNAL('clicked()'), self.doSearch)
self.connect(self.ui.refreshButton, SIGNAL('clicked()'), self.doAdvancedSearch)
self.connect(self.ui.queriesTabWidget, SIGNAL('currentChanged(int)'), self.tabChange)
self.connect(self.ui.jobListAdvancedSearch, SIGNAL('currentItemChanged(QListWidgetItem*, QListWidgetItem*)'), self.jobSelected)
self.connect(self.ui.idEdit, SIGNAL('returnPressed()'), self.openJob)
if self.weboob.count_backends() == 0:
self.backendsConfig()
def loadSearchHistory(self):
''' Return search string history list loaded from history file
'''
result = []
history_path = os.path.join(self.weboob.workdir, 'qhandjoob_history')
if os.path.exists(history_path):
f = codecs.open(history_path, 'r', 'utf-8')
conf_hist = f.read()
f.close()
if conf_hist is not None and conf_hist.strip() != '':
result = conf_hist.strip().split('\n')
return result
def saveSearchHistory(self):
''' Save search history in history file
'''
if len(self.search_history) > 0:
history_path = os.path.join(self.weboob.workdir, 'qhandjoob_history')
f = codecs.open(history_path, 'w', 'utf-8')
f.write('\n'.join(self.search_history))
f.close()
def updateCompletion(self):
qc = QCompleter(QStringList(self.search_history), self)
qc.setCaseSensitivity(Qt.CaseInsensitive)
self.ui.searchEdit.setCompleter(qc)
def tabChange(self, index):
if index == 1:
self.doAdvancedSearch()
def doAdvancedSearch(self):
QApplication.setOverrideCursor(Qt.WaitCursor)
self.ui.jobListAdvancedSearch.clear()
self.process = QtDo(self.weboob, self.addJobAdvancedSearch)
self.process.do('advanced_search_job')
def doSearch(self):
QApplication.setOverrideCursor(Qt.WaitCursor)
pattern = unicode(self.ui.searchEdit.text())
# arbitrary max number of completion word
if pattern:
if len(self.search_history) > 50:
self.search_history.pop(0)
if pattern not in self.search_history:
self.search_history.append(pattern)
self.updateCompletion()
self.ui.jobList.clear()
self.process = QtDo(self.weboob, self.addJobSearch)
self.process.do('search_job', pattern)
def addJobSearch(self, backend, job):
item = self.addJob(backend, job)
if item:
self.ui.jobList.addItem(item)
if not backend:
QApplication.restoreOverrideCursor()
def addJobAdvancedSearch(self, backend, job):
item = self.addJob(backend, job)
if item:
self.ui.jobListAdvancedSearch.addItem(item)
#.........这里部分代码省略.........
示例14: QueryDialog
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class QueryDialog(QDialog):
def __init__(self, weboob, parent=None):
QDialog.__init__(self, parent)
self.ui = Ui_QueryDialog()
self.ui.setupUi(self)
self.weboob = weboob
self.ui.resultsList.setItemDelegate(HTMLDelegate())
self.ui.citiesList.setItemDelegate(HTMLDelegate())
self.search_process = None
self.connect(self.ui.cityEdit, SIGNAL('returnPressed()'), self.searchCity)
self.connect(self.ui.resultsList, SIGNAL('itemDoubleClicked(QListWidgetItem*)'), self.insertCity)
self.connect(self.ui.citiesList, SIGNAL('itemDoubleClicked(QListWidgetItem*)'), self.removeCity)
self.connect(self.ui.buttonBox, SIGNAL('accepted()'), self.okButton)
if hasattr(self.ui.cityEdit, "setPlaceholderText"):
self.ui.cityEdit.setPlaceholderText("Press enter to search city")
def keyPressEvent(self, event):
"""
Disable handler <Enter> and <Escape> to prevent closing the window.
"""
event.ignore()
def selectComboValue(self, box, value):
for i in xrange(box.count()):
if box.itemText(i) == str(value):
box.setCurrentIndex(i)
break
def searchCity(self):
pattern = unicode(self.ui.cityEdit.text())
self.ui.resultsList.clear()
self.ui.cityEdit.clear()
self.ui.cityEdit.setEnabled(False)
self.search_process = QtDo(self.weboob, self.addResult, fb=self.addResultEnd)
self.search_process.do('search_city', pattern)
def addResultEnd(self):
self.search_process = None
self.ui.cityEdit.setEnabled(True)
def addResult(self, city):
if not city:
return
item = self.buildCityItem(city)
self.ui.resultsList.addItem(item)
self.ui.resultsList.sortItems()
def buildCityItem(self, city):
item = QListWidgetItem()
item.setText('<b>%s</b> (%s)' % (city.name, city.backend))
item.setData(Qt.UserRole, city)
return item
def insertCity(self, i):
item = QListWidgetItem()
item.setText(i.text())
item.setData(Qt.UserRole, i.data(Qt.UserRole))
self.ui.citiesList.addItem(item)
def removeCity(self, item):
self.ui.citiesList.removeItemWidget(item)
def okButton(self):
if not self.ui.nameEdit.text():
QMessageBox.critical(self, self.tr('Error'), self.tr('Please enter a name to your query.'), QMessageBox.Ok)
return
if self.ui.citiesList.count() == 0:
QMessageBox.critical(self, self.tr('Error'), self.tr('Please add at least one city.'), QMessageBox.Ok)
return
self.accept()
示例15: MainWindow
# 需要导入模块: from weboob.tools.application.qt import QtDo [as 别名]
# 或者: from weboob.tools.application.qt.QtDo import do [as 别名]
class MainWindow(QtMainWindow):
def __init__(self, config, weboob, app, parent=None):
QtMainWindow.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.config = config
self.weboob = weboob
self.app = app
self.minis = []
self.current_info_widget = None
# search history is a list of patterns which have been searched
self.search_history = self.loadSearchHistory()
self.updateCompletion()
# action history is composed by the last action and the action list
# An action is a function, a list of arguments and a description string
self.action_history = {'last_action': None, 'action_list': []}
self.connect(self.ui.backButton, SIGNAL("clicked()"), self.doBack)
self.ui.backButton.hide()
self.connect(self.ui.stopButton, SIGNAL("clicked()"), self.stopProcess)
self.ui.stopButton.hide()
self.connect(self.ui.searchEdit, SIGNAL("returnPressed()"), self.search)
self.connect(self.ui.idEdit, SIGNAL("returnPressed()"), self.searchId)
count = self.config.get('settings', 'maxresultsnumber')
self.ui.countSpin.setValue(int(count))
self.connect(self.ui.actionBackends, SIGNAL("triggered()"), self.backendsConfig)
self.connect(self.ui.actionQuit, SIGNAL("triggered()"), self.close)
self.loadBackendsList()
if self.ui.backendEdit.count() == 0:
self.backendsConfig()
def backendsConfig(self):
bckndcfg = BackendCfg(self.weboob, (CapRecipe, ), self)
if bckndcfg.run():
self.loadBackendsList()
def loadBackendsList(self):
self.ui.backendEdit.clear()
for i, backend in enumerate(self.weboob.iter_backends()):
if i == 0:
self.ui.backendEdit.addItem('All backends', '')
self.ui.backendEdit.addItem(backend.name, backend.name)
if backend.name == self.config.get('settings', 'backend'):
self.ui.backendEdit.setCurrentIndex(i+1)
if self.ui.backendEdit.count() == 0:
self.ui.searchEdit.setEnabled(False)
else:
self.ui.searchEdit.setEnabled(True)
def loadSearchHistory(self):
''' Return search string history list loaded from history file
'''
result = []
history_path = os.path.join(self.weboob.workdir, 'qcookboob_history')
if os.path.exists(history_path):
f = codecs.open(history_path, 'r', 'utf-8')
conf_hist = f.read()
f.close()
if conf_hist is not None and conf_hist.strip() != '':
result = conf_hist.strip().split('\n')
return result
def saveSearchHistory(self):
''' Save search history in history file
'''
if len(self.search_history) > 0:
history_path = os.path.join(self.weboob.workdir, 'qcookboob_history')
f = codecs.open(history_path, 'w', 'utf-8')
f.write('\n'.join(self.search_history))
f.close()
def updateCompletion(self):
qc = QCompleter(QStringList(self.search_history), self)
qc.setCaseSensitivity(Qt.CaseInsensitive)
self.ui.searchEdit.setCompleter(qc)
def getCount(self):
num = self.ui.countSpin.value()
if num == 0:
return None
else:
return num
def stopProcess(self):
self.process.process.finish_event.set()
def doAction(self, description, fun, args):
''' Call fun with args as arguments
and save it in the action history
'''
self.ui.currentActionLabel.setText(description)
if self.action_history['last_action'] is not None:
#.........这里部分代码省略.........