Ejemplo n.º 1
0
class SliderGroup(Group):
    def __init__(self, posSize, text, minValue, maxValue, value, callback):
        Group.__init__(self, posSize)
        self.text = TextBox((0, 0, -0, 20), text)
        self.slider = Slider((2, 20, -60, 17),
                             minValue=minValue,
                             maxValue=maxValue,
                             value=value,
                             sizeStyle="small",
                             callback=self.sliderChanged)
        self.edit = EditText((-40, 15, -0, 22),
                             text=str(value),
                             placeholder=str(value),
                             callback=self.editChanged)
        self.callback = callback

    def sliderChanged(self, sender):
        self.edit.set(str(int(self.slider.get())))
        self.callback(sender)

    def editChanged(self, sender):
        try:
            value = int(float(self.edit.get()))
        except ValueError:
            value = int(self.edit.getPlaceholder())
            self.edit.set(value)
        self.slider.set(value)

    def enable(self):
        self.text.enable(True)
        self.slider.enable(True)
        self.edit.enable(True)

    def disable(self):
        self.text.enable(False)
        self.slider.enable(False)
        self.edit.enable(False)
Ejemplo n.º 2
0
class SingleGridController(Group):
    """this controller takes care of canvas grid drawing"""
    def __init__(self, posSize, index, isVertical, isHorizontal, step,
                 gridColor, callback):
        Group.__init__(self, posSize)

        # from arguments to attributes
        self.ctrlX, self.ctrlY, self.ctrlWidth, self.ctrlHeight = posSize
        self.index = index
        self.isVertical = isVertical
        self.isHorizontal = isHorizontal
        self.step = step
        self.gridColor = gridColor
        self.callback = callback

        # ctrls
        jumpin_X = 12
        self.indexText = TextBox(
            (jumpin_X, 0, 16, vanillaControlsSize['TextBoxRegularHeight']),
            '{:d})'.format(index))
        jumpin_X += self.indexText.getPosSize()[2]

        self.stepCtrl = EditText(
            (jumpin_X, 0, 38, vanillaControlsSize['EditTextRegularHeight']),
            callback=self.stepCtrlCallback)
        jumpin_X += self.stepCtrl.getPosSize()[2] + 16

        self.isHorizontalCheck = CheckBox(
            (jumpin_X, 0, 32, vanillaControlsSize['CheckBoxRegularHeight']),
            "H",
            value=self.isHorizontal,
            callback=self.isHorizontalCheckCallback)
        jumpin_X += self.isHorizontalCheck.getPosSize()[2] + 2

        self.isVerticalCheck = CheckBox(
            (jumpin_X, 0, 32, vanillaControlsSize['CheckBoxRegularHeight']),
            "V",
            value=self.isVertical,
            callback=self.isVerticalCheckCallback)
        jumpin_X += self.isVerticalCheck.getPosSize()[2] + 10

        self.whichColorWell = ColorWell(
            (jumpin_X, 0, 46, self.ctrlHeight),
            color=NSColor.colorWithCalibratedRed_green_blue_alpha_(*gridColor),
            callback=self.whichColorWellCallback)

    def enable(self, onOff):
        self.indexText.enable(onOff)
        self.stepCtrl.enable(onOff)
        self.isHorizontalCheck.enable(onOff)
        self.isVerticalCheck.enable(onOff)
        self.whichColorWell.enable(onOff)

    def get(self):
        return self.index - 1, {
            'horizontal': self.isHorizontal,
            'vertical': self.isVertical,
            'step': self.step,
            'color': self.gridColor
        }

    def stepCtrlCallback(self, sender):
        try:
            self.step = int(sender.get())
            self.callback(self)
        except ValueError as error:
            self.step = None
            self.stepCtrl.set('')

    def isHorizontalCheckCallback(self, sender):
        self.isHorizontal = bool(sender.get())
        self.callback(self)

    def isVerticalCheckCallback(self, sender):
        self.isVertical = bool(sender.get())
        self.callback(self)

    def whichColorWellCallback(self, sender):
        calibratedColor = sender.get()
        self.gridColor = (calibratedColor.redComponent(),
                          calibratedColor.greenComponent(),
                          calibratedColor.blueComponent(),
                          calibratedColor.alphaComponent())
        self.callback(self)