fetch and display messages
This commit is contained in:
parent
5bbe266c8c
commit
e88e00a793
3 changed files with 180 additions and 0 deletions
|
|
@ -22,6 +22,7 @@ from weboob.tools.application.qt.backendcfg import BackendCfg
|
|||
from weboob.capabilities.messages import ICapMessages
|
||||
|
||||
from .ui.main_window_ui import Ui_MainWindow
|
||||
from .messages_manager import MessagesManager
|
||||
|
||||
class MainWindow(QtMainWindow):
|
||||
def __init__(self, config, weboob, parent=None):
|
||||
|
|
@ -31,6 +32,9 @@ class MainWindow(QtMainWindow):
|
|||
|
||||
self.config = config
|
||||
self.weboob = weboob
|
||||
self.manager = MessagesManager(weboob, self)
|
||||
|
||||
self.setCentralWidget(self.manager)
|
||||
|
||||
self.connect(self.ui.actionModules, SIGNAL("triggered()"), self.modulesConfig)
|
||||
|
||||
|
|
|
|||
95
weboob/frontends/qboobmsg/messages_manager.py
Normal file
95
weboob/frontends/qboobmsg/messages_manager.py
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
# -*- 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 time
|
||||
|
||||
from PyQt4.QtGui import QWidget, QTreeWidgetItem, QListWidgetItem
|
||||
from PyQt4.QtCore import SIGNAL, Qt
|
||||
|
||||
from weboob.capabilities.messages import ICapMessages
|
||||
|
||||
from .ui.messages_manager_ui import Ui_MessagesManager
|
||||
|
||||
class MessagesManager(QWidget):
|
||||
def __init__(self, weboob, parent=None):
|
||||
QWidget.__init__(self, parent)
|
||||
self.ui = Ui_MessagesManager()
|
||||
self.ui.setupUi(self)
|
||||
|
||||
self.weboob = weboob
|
||||
|
||||
self.ui.backendsList.addItem('(All)')
|
||||
for backend in self.weboob.iter_backends():
|
||||
if not backend.has_caps(ICapMessages):
|
||||
continue
|
||||
|
||||
item = QListWidgetItem(backend.name.capitalize())
|
||||
item.setData(Qt.UserRole, backend)
|
||||
self.ui.backendsList.addItem(item)
|
||||
|
||||
self.ui.backendsList.setCurrentRow(0)
|
||||
self.backend = None
|
||||
|
||||
self.connect(self.ui.backendsList, SIGNAL('itemSelectionChanged()'), self._backendChanged)
|
||||
self.connect(self.ui.messagesTree, SIGNAL('itemClicked(QTreeWidgetItem *, int)'), self._messageSelected)
|
||||
self.connect(self, SIGNAL('gotMessage'), self._gotMessage)
|
||||
|
||||
self.refresh()
|
||||
|
||||
def _backendChanged(self):
|
||||
selection = self.ui.backendsList.selectedItems()
|
||||
if not selection:
|
||||
self.backend = None
|
||||
return
|
||||
|
||||
self.backend = selection[0].data(Qt.UserRole).toPyObject()
|
||||
|
||||
self.refresh()
|
||||
|
||||
def refresh(self):
|
||||
self.ui.backendsList.setEnabled(False)
|
||||
|
||||
def cb(backend, message):
|
||||
self.emit(SIGNAL('gotMessage'), backend, message)
|
||||
|
||||
def eb(backend, err, backtrace):
|
||||
print err
|
||||
print backtrace
|
||||
|
||||
if self.backend:
|
||||
process = self.weboob.do_backends(self.backend.name, 'iter_messages')
|
||||
else:
|
||||
process = self.weboob.do_caps(ICapMessages, 'iter_messages')
|
||||
self.process = process.callback_thread(cb, eb)
|
||||
|
||||
def _gotMessage(self, backend, message):
|
||||
if message is None:
|
||||
self.ui.backendsList.setEnabled(True)
|
||||
return
|
||||
|
||||
item = QTreeWidgetItem(self.ui.messagesTree, [time.strftime('%Y-%m-%d %H:%M:%S', message.get_date().timetuple()),
|
||||
message.sender, message.title])
|
||||
item.setData(0, Qt.UserRole, message)
|
||||
self.ui.messagesTree.addTopLevelItem(item)
|
||||
|
||||
def _messageSelected(self, item, column):
|
||||
message = item.data(0, Qt.UserRole).toPyObject()
|
||||
self.ui.messageBody.setText("<h1>%s</h1>"
|
||||
"<b>Date</b>: %s<br />"
|
||||
"<b>From</b>: %s<br />"
|
||||
"<p>%s</p>"
|
||||
% (message.title, str(message.date), message.sender, message.content))
|
||||
81
weboob/frontends/qboobmsg/ui/messages_manager.ui
Normal file
81
weboob/frontends/qboobmsg/ui/messages_manager.ui
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MessagesManager</class>
|
||||
<widget class="QWidget" name="MessagesManager">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>767</width>
|
||||
<height>591</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QListWidget" name="backendsList">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QTreeWidget" name="messagesTree">
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>100</number>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="headerDefaultSectionSize">
|
||||
<number>100</number>
|
||||
</attribute>
|
||||
<attribute name="headerStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Date</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignLeft|AlignVCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>From</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Title</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
<widget class="QTextEdit" name="messageBody">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Loading…
Add table
Add a link
Reference in a new issue