source: qutecom-coip/examples/python/pyqutecomphone/src/chat/emoticons/EmoticonsWidget.py @ 274:a56c9ce15c61

Last change on this file since 274:a56c9ce15c61 was 274:a56c9ce15c61, checked in by laurent <laurent@…>, 22 months ago

move examples

File size: 2.6 KB
Line 
1# -*- coding: utf-8 -*-
2#
3# QuteCom, a voice over Internet phone
4# Copyright (C) 2010 Mbdsys
5#
6# This program is free software you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with self program if not, write to the Free Software
18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19#
20# @author Aurelien Gateau
21# @author Ovidiu Ciule
22
23from EmoticonsManager import *
24from EmoticonButton import *
25from Emoticon import *
26from util.SafeConnect import *
27from PyQt4.QtCore import *
28from PyQt4.QtGui import *
29
30import logging
31
32log = logging.getLogger("PyQuteCom.EmoticonsWidget")
33
34class EmoticonsWidget(QWidget):
35    """
36    Emoticons widget
37    """
38    def __init__(self, parent, protocol = "default"):
39        QWidget.__init__(self, parent)
40        self.initLayout()
41        self.__parent = parent
42        self.initButtons(protocol)
43
44    def emoticonClickedSlot(self, emoticon):
45        """
46        Centralizes the emoticon clicked signals
47        """
48        log.info("emoticonClicked"+emoticon.getText()[0])
49        self.__parent.close()
50        self.emit(SIGNAL("emoticonClicked"), emoticon)
51
52    def initLayout(self):
53        self.__layout = QGridLayout(self)
54        self.__layout.setMargin(0)
55        self.__layout.setSpacing(0)
56 
57    def initButtons(self, protocol):
58        """
59        Loads the emoticons of the protocol
60        """
61        for child in self.__layout.children():
62            self.__layout.removeWidget(child)
63            del(child)
64        self.__buttonX = 0
65        self.__buttonY = 0
66        emoticonsManager = EmoticonsManager.getInstance()
67        emoticonList = emoticonsManager.getEmoticonList(protocol)
68        for emoticon in emoticonList: 
69            self.addButton(emoticon)
70       
71    def addButton(self, emoticon):
72        """
73        Adds a button; uses a grid 'layout'
74        """
75        if (self.__buttonX == 10):
76                self.__buttonX = 0
77                self.__buttonY += 1
78       
79        button = EmoticonButton(self, emoticon)
80        self.__layout.addWidget(button, self.__buttonY, self.__buttonX)
81        connect(button, SIGNAL("buttonClicked"), self.emoticonClickedSlot)
82        self.__buttonX += 1
Note: See TracBrowser for help on using the repository browser.