~ubuntu-branches/ubuntu/oneiric/emesene/oneiric

« back to all changes in this revision

Viewing changes to emesene/gui/qt4ui/widgets/StatusCombo.py

  • Committer: Package Import Robot
  • Author(s): Piotr Ożarowski, Fabrizio Regalli
  • Date: 2011-08-22 20:48:17 UTC
  • mfrom: (1.1.12 upstream) (5.2.11 sid)
  • Revision ID: package-import@ubuntu.com-20110822204817-ctdvj2g7byl7icpd
Tags: 2.11.7+dfsg-1
* Team upload.

[ Fabrizio Regalli ]
* New upstream release (Closes: #633614)
* Added 01-fix-spelling-error.diff patch
* Fix spelling-error-in-description lintian message
* Removed libclearlooks.dll file also in d/rules
* Added imagemagick as B-D to resize icon via d/rules
* Fixed typo in description (Closes: #633483)
* Added override for dh_install, dh_installdir and dh_clean rules

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
''' This module contains the PreseceCombo class'''
 
4
 
 
5
import logging
 
6
 
 
7
import PyQt4.QtGui      as QtGui
 
8
import PyQt4.QtCore     as QtCore
 
9
 
 
10
import e3
 
11
import gui
 
12
 
 
13
#Maybe we need another class which makes status info more abstract?
 
14
#(a Qt Delegate?! Does KComboBox support them?)
 
15
#TODO: put inizialization out of constructor, add setstatusValues method.
 
16
 
 
17
log = logging.getLogger('qt4ui.widgets.StatusCombo')
 
18
 
 
19
class StatusCombo(QtGui.QComboBox):
 
20
    '''A presence selection widget'''
 
21
    # pylint: disable=W0612
 
22
    NAME = 'MainPage'
 
23
    DESCRIPTION = 'The widget used to to select the status'
 
24
    AUTHOR = 'Gabriele "Whisky" Visconti'
 
25
    WEBSITE = ''
 
26
    # pylint: enable=W0612
 
27
 
 
28
    status_changed = QtCore.pyqtSignal(int)
 
29
 
 
30
    def __init__(self, parent=None):
 
31
        '''Constructor'''
 
32
        QtGui.QComboBox.__init__(self, parent)
 
33
 
 
34
        self._status_strings = {}
 
35
        self._status_values = e3.status.ALL
 
36
 
 
37
        for status_key in self._status_values:
 
38
            self._status_strings[status_key] = \
 
39
                        unicode(e3.status.STATUS[status_key]).capitalize()
 
40
 
 
41
        #status_key is of e3.status.ALL type
 
42
        #statusValue is a dict wich associates a e3.status with a string
 
43
        for status_key in self._status_values:
 
44
            icon_path = gui.theme.image_theme.status_icons[status_key]
 
45
            self.addItem(QtGui.QIcon(icon_path),
 
46
                         self._status_strings[status_key], status_key)
 
47
 
 
48
        self.set_status(e3.status.ONLINE)
 
49
        self.currentIndexChanged.connect(self._emit_status_changed)
 
50
 
 
51
 
 
52
    def set_status(self, status):
 
53
        """Sets the status in the StatusCombo.
 
54
 
 
55
        @type status: e3.status
 
56
        @param status: the status to set
 
57
        """
 
58
        if not status in e3.status.ALL:
 
59
            return
 
60
        QtGui.QComboBox.setCurrentIndex(self,  self.findData(status))
 
61
 
 
62
    def status(self):
 
63
        '''Return the status selected'''
 
64
        #we don't say "get_status" to make it more Qt-Stylish
 
65
        return self.itemData( self.currentIndex() ).toPyObject()
 
66
 
 
67
 
 
68
    def _emit_status_changed(self, index=None):
 
69
        ''' emits a status_changed signal '''
 
70
        self.status_changed.emit( self.itemData(index).toPyObject() )
 
71
 
 
72
 
 
73
# -------------------- QT_OVERRIDE
 
74
 
 
75
    def setCurrentIndex(self, index):
 
76
        '''sets the status by the index'''
 
77
        # pylint: disable=C0103
 
78
        log.warning('Oh, boy.... what an ugly way to set the displayed status!<br>\
 
79
                    Come on, use set_status() instead! :(')
 
80
        #the personalinfoview holds a string... so this is necessary...
 
81
        #maybe this will be removed in the future... I hope...
 
82
        QtGui.QComboBox.setCurrentIndex(self, index)
 
83
 
 
84
 
 
85
 
 
86