1
# -*- coding: utf-8 -*-
3
''' This module contains the PreseceCombo class'''
7
import PyQt4.QtGui as QtGui
8
import PyQt4.QtCore as QtCore
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.
17
log = logging.getLogger('qt4ui.widgets.StatusCombo')
19
class StatusCombo(QtGui.QComboBox):
20
'''A presence selection widget'''
21
# pylint: disable=W0612
23
DESCRIPTION = 'The widget used to to select the status'
24
AUTHOR = 'Gabriele "Whisky" Visconti'
26
# pylint: enable=W0612
28
status_changed = QtCore.pyqtSignal(int)
30
def __init__(self, parent=None):
32
QtGui.QComboBox.__init__(self, parent)
34
self._status_strings = {}
35
self._status_values = e3.status.ALL
37
for status_key in self._status_values:
38
self._status_strings[status_key] = \
39
unicode(e3.status.STATUS[status_key]).capitalize()
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)
48
self.set_status(e3.status.ONLINE)
49
self.currentIndexChanged.connect(self._emit_status_changed)
52
def set_status(self, status):
53
"""Sets the status in the StatusCombo.
55
@type status: e3.status
56
@param status: the status to set
58
if not status in e3.status.ALL:
60
QtGui.QComboBox.setCurrentIndex(self, self.findData(status))
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()
68
def _emit_status_changed(self, index=None):
69
''' emits a status_changed signal '''
70
self.status_changed.emit( self.itemData(index).toPyObject() )
73
# -------------------- QT_OVERRIDE
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)