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

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

     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 StarEditor(CustomEditor):
     8

     9 -    def __init__(self, parent, maximum=5, editable=True, **kwargs):
    10          CustomEditor.__init__(self, parent)
    11          self.setFocusPolicy(Qt.StrongFocus)
    12          layout = QtGui.QHBoxLayout(self)
    13          layout.setMargin(0)
    14          layout.setSpacing(0)
    15          self.starIcon = Icon('tango/16x16/status/weather-clear.png').getQIcon()
    16          self.noStarIcon = Icon('tango/16x16/status/weather-clear-noStar.png').getQIcon()
    17          self.setAutoFillBackground(True)
    18          #self.starCount = maximum

    19          self.starCount = 5
    20          self.buttons = []
    21          for i in range(self.starCount):
    22              button = QtGui.QToolButton(self)
    23              button.setIcon(self.noStarIcon)
    24              if editable:
    25                  button.setAutoRaise(True)
    26              else:
    27                  button.setAutoRaise(True)
    28                  button.setDisabled(True)
    29              button.setFixedHeight(self.get_height())
    30              self.buttons.append(button)
    31

    32          def createStarClick(i):
    33              return lambda:self.starClick(i+1)
    34

    35          for i in range(self.starCount):
    36              self.connect(self.buttons[i],

    37                           QtCore.SIGNAL('clicked()'),

    38                           createStarClick(i))
    39          for i in range(self.starCount):
    40              layout.addWidget(self.buttons[i])
    41          layout.addStretch()
    42          self.setLayout(layout)
    43

    44 -    def get_value(self):
    45          return CustomEditor.get_value(self) or self.stars
    46

    47

    48 -    def set_enabled(self, editable=True):
    49          for button in self.buttons:
    50              button.setEnabled(editable)
    51              button.update()
    52          self.set_value(self.stars)
    53

    54 -    def starClick(self, value):
    55          if self.stars == value:
    56              self.stars -= 1
    57          else:
    58              self.stars = int(value)
    59          for i in range(self.starCount):
    60              if i+1 <= self.stars:
    61                  self.buttons[i].setIcon(self.starIcon)
    62              else:
    63                  self.buttons[i].setIcon(self.noStarIcon)
    64          self.emit(QtCore.SIGNAL('editingFinished()'))
    65

    66 -    def set_value(self, value):
    67          value = CustomEditor.set_value(self, value) or 0
    68          self.stars = int(value)
    69          for i in range(self.starCount):
    70              if i+1 <= self.stars:
    71                  self.buttons[i].setIcon(self.starIcon)
    72              else:
    73                  self.buttons[i].setIcon(self.noStarIcon)
    74

    75 -    def set_background_color(self, background_color):
    76          return False
    77