implement photo caroussel

This commit is contained in:
Christophe Benz 2010-11-19 04:38:28 +01:00 committed by Romain Bignon
commit 2921a17a3e
2 changed files with 99 additions and 49 deletions

View file

@ -26,7 +26,7 @@ from weboob.tools.application.qt import QtDo, HTMLDelegate
from weboob.capabilities.contact import ICapContact, Contact
from weboob.capabilities.chat import ICapChat
from weboob.capabilities.messages import ICapMessages, ICapMessagesPost, Message
from weboob.capabilities.base import NotLoaded
from weboob.capabilities.base import NotLoaded, NotLoadedMeta
from .ui.contacts_ui import Ui_Contacts
from .ui.contact_thread_ui import Ui_ContactThread
@ -190,11 +190,17 @@ class ContactThread(QWidget):
self.process_reply = None
class ContactProfile(QWidget):
displayed_photo_idx = 0
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
@ -214,26 +220,19 @@ class ContactProfile(QWidget):
return []
missing_fields = set(['photos'])
first = True
for photo in contact.photos.itervalues():
photo = contact.photos.values()[0]
if photo.data:
data = photo.data
try:
missing_fields.remove('photos')
except KeyError:
pass
elif photo.thumbnail_data:
data = photo.thumbnail_data
else:
continue
if first:
img = QImage.fromData(data)
self.ui.photoLabel.setPixmap(QPixmap.fromImage(img))
first = False
else:
# TODO display thumbnails
photo = contact.photos.values()[0]
data = None
if photo.data:
self.displayed_photo_idx = 0
data = photo.data
try:
missing_fields.remove('photos')
except KeyError:
pass
elif photo.thumbnail_data:
data = photo.thumbnail_data
if data:
self.display_photo(photo, data)
self.ui.nicknameLabel.setText('<h1>%s</h1>' % contact.name)
self.ui.statusLabel.setText('%s' % contact.status_msg)
@ -289,6 +288,22 @@ class ContactProfile(QWidget):
else:
logging.warning('Not supported widget: %r' % widget)
def previousClicked(self):
self.displayed_photo_idx = (self.displayed_photo_idx - 1) % len(self.contact.photos)
self.display_photo(self.contact.photos.values()[self.displayed_photo_idx])
def nextClicked(self):
self.displayed_photo_idx = (self.displayed_photo_idx + 1) % len(self.contact.photos)
self.display_photo(self.contact.photos.values()[self.displayed_photo_idx])
def display_photo(self, photo, data=None):
img = QImage.fromData(data if data else photo.data)
self.ui.photoLabel.setPixmap(QPixmap.fromImage(img))
if not isinstance(photo.url, NotLoadedMeta):
self.ui.photoURLEdit.setText(photo.url)
self.ui.shownLabel.setText('' if photo.shown else 'Hidden photo')
class IGroup(object):
def __init__(self, weboob, id, name):
self.id = id

View file

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>576</width>
<width>755</width>
<height>647</height>
</rect>
</property>
@ -33,7 +33,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>576</width>
<width>755</width>
<height>647</height>
</rect>
</property>
@ -53,38 +53,6 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QFrame" name="frame_photo">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="photoLabel">
<property name="text">
<string>&lt;i&gt;Receiving...&lt;/i&gt;</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="headFrame">
<property name="sizePolicy">
@ -133,6 +101,73 @@
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_photo">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="previousButton">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="nextButton">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLineEdit" name="photoURLEdit"/>
</item>
<item>
<widget class="QLabel" name="shownLabel">
<property name="styleSheet">
<string notr="true">color: rgb(255, 0, 0);</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="photoLabel">
<property name="text">
<string>&lt;i&gt;Receiving...&lt;/i&gt;</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>13</width>
<height>13</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>