Package Camelot :: Package camelot :: Package view :: Package controls :: Package editors :: Module smileyeditor |
[frames] | no frames]

# Source Code for Module Camelot.camelot.view.controls.editors.smileyeditor

     1  from PyQt4 import QtCore, QtGui
     2  from PyQt4.QtCore import Qt
     3

     4  from customeditor import CustomEditor
     5  from camelot.view.art import Icon
     6

     7 -class SmileyEditor(CustomEditor):
     8

     9 -    def __init__(self, parent, img='face-plain', editable=True, **kwargs):
    10          CustomEditor.__init__(self, parent)
    11          self.box = QtGui.QComboBox()
    12          self.box.setFrame(True)
    13          self.box.setEditable(False)
    14          self.allSmileys = []
    15

    16          self.allSmileys.append('face-angel')
    17          self.allSmileys.append('face-crying')
    18          self.allSmileys.append('face-devilish')
    19          self.allSmileys.append('face-glasses')
    20          self.allSmileys.append('face-grin')
    21          self.allSmileys.append('face-kiss')
    22          self.allSmileys.append('face-monkey')
    23          self.allSmileys.append('face-plain')
    24          self.allSmileys.append('face-sad')
    25          self.allSmileys.append('face-smile')
    26          self.allSmileys.append('face-smile-big')
    27          self.allSmileys.append('face-surprise')
    28          self.allSmileys.append('face-wink')
    29

    30          for i, value in enumerate(self.allSmileys):
    31              imgPath = 'tango/16x16/emotes/' + value + '.png'
    32              icon = Icon(imgPath).getQIcon()
    33

    34              self.box.addItem(icon, '')
    35              self.box.setFixedHeight(self.get_height())
    36

    37              if value == 'face-plain':
    38                  self.box.setCurrentIndex(i)
    39

    40

    41          self.setFocusPolicy(Qt.StrongFocus)
    42          layout = QtGui.QHBoxLayout(self)
    43          layout.setMargin(0)
    44          layout.setSpacing(0)
    45          self.img = img
    46          self.imgPath = 'tango/16x16/emotes/' + img + '.png'
    47          self.Icon = Icon(self.imgPath).getQIcon()
    48          self.setAutoFillBackground(True)
    49          #self.starCount = maximum

    50          if not editable:
    51              self.box.setEnabled(False)
    52          else:
    53              self.box.setEnabled(True)
    54

    55

    56          self.connect(self.box,

    57                       QtCore.SIGNAL('currentIndexChanged()'),

    58                       self.smileyChanged)
    59

    60

    61          layout.addWidget(self.box)
    62          layout.addStretch()
    63          self.setLayout(layout)
    64

    65 -    def get_value(self):
    66          imgIndex = self.box.currentIndex()
    67

    68          for i, emot in enumerate(self.allSmileys):
    69              if imgIndex == i:
    70                  imgName = emot
    71

    72          return CustomEditor.get_value(self) or imgName
    73

    74

    75 -    def set_enabled(self, editable=True):
    76          self.box.setEnabled(editable)
    77

    78 -    def smileyChanged(self):
    79

    80          value = self.box.currentIndex()
    81

    82          for i, emot in enumerate(self.allSmileys):
    83              if value == i:
    84                  imgName = emot
    85

    86          self.emit(QtCore.SIGNAL('editingFinished()'), imgName)
    87

    88 -    def set_value(self, value):
    89          value = CustomEditor.set_value(self, value) or 'face-plain'
    90          self.img = value
    91          #self.imgPath = 'tango/16x16/emotes/' + self.img + '.png'

    92

    93          for i, smiley in enumerate(self.allSmileys):
    94              if smiley == self.img:
    95                  self.box.setCurrentIndex(i)
    96