Exemplo 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)
Exemplo n.º 2
0
class ParameterSliderTextInput(Group):
    '''
    Custom Vanilla object consisting mainly of a Slider & and text input linked together (through a parameter object)
    '''
    def __init__(self, parameter, posSize, title=None, callback=None):
        super(ParameterSliderTextInput, self).__init__(posSize)
        self.parameter = parameter
        self.callback = callback
        editTextPosSize = (-65, 0, 40, 22)
        if title is None:
            sliderPosSize = (5, 3, -80, 15)
        elif title is not None:
            title = title.capitalize()
            sliderPosSize = (70, 3, -80, 15)
            self.title = TextBox((0, 3, 65, 30), title, sizeStyle='small')
        if parameter.dissociable:
            editTextPosSize = (-65, 0, 40, 22)
            self.checkBox = CheckBox((-22, 5, 22, 25),
                                     u'∞',
                                     callback=self.setFree,
                                     value=True,
                                     sizeStyle='mini')
        self.slider = Slider(sliderPosSize,
                             minValue=parameter.limits[0],
                             maxValue=parameter.limits[1],
                             value=parameter.value,
                             callback=self.valueInput,
                             sizeStyle='small')
        self.textInput = EditText(editTextPosSize,
                                  str(parameter.value),
                                  callback=self.valueInput,
                                  continuous=False,
                                  sizeStyle='small')
        self.parameter.bind(self)

    def get(self):
        return self.parameter.get()

    def enable(self, b):
        self.slider.enable(b)
        self.textInput.enable(b)
        if hasattr(self, checkBox):
            self.checkBox.enable(b)

    def valueInput(self, sender):
        value = sender.get()
        parameter = self.parameter
        if value == 'R':
            parameter.reset()
            parameter.update()
            if self.callback is not None:
                self.callback(self)
            return
        elif value != '*':
            parameter.setInput(value, sender=sender)
            parameter.update()
            if self.callback is not None:
                self.callback(self)

    def update(self, sender):
        value = self.parameter.get()
        self.textInput.set(str(value))
        if (value != '*'):
            self.slider.set(value)
        if hasattr(self, 'checkBox'):
            free = self.parameter.hasMaster
            self.checkBox.set(free)

    def setFree(self, sender):
        value = not bool(sender.get())
        self.parameter.setFree(value)
class ParameterSliderTextInput(Group):

    """
    Custom Vanilla object consisting mainly of a Slider & and text input linked together (through a parameter object)
    """

    def __init__(self, parameter, posSize, title=None, callback=None):
        super(ParameterSliderTextInput, self).__init__(posSize)
        self.parameter = parameter
        self.callback = callback
        editTextPosSize = (-65, 0, 40, 22)
        if title is None:
            sliderPosSize = (5, 3, -80, 15)
        elif title is not None:
            if "point" in title:
                title = title.lstrip("point")
                title = "p. " + title
            title = title.capitalize()
            sliderPosSize = (70, 3, -80, 15)
            self.title = TextBox((0, 3, 65, 30), title, sizeStyle="small")
        if parameter.dissociable:
            editTextPosSize = (-65, 0, 40, 22)
            self.checkBox = CheckBox((-22, 5, 22, 25), u"∞", callback=self.setFree, value=True, sizeStyle="mini")
            self.parameter.bind(self.checkBox)
        self.slider = Slider(
            sliderPosSize,
            minValue=parameter.limits[0],
            maxValue=parameter.limits[1],
            value=parameter.value,
            callback=self.valueInput,
            sizeStyle="small",
        )
        self.textInput = EditText(
            editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle="small"
        )
        self.parameter.bind(self)
        self.parameter.bind(self.slider)
        self.parameter.bind(self.textInput)

    def enable(self, b):
        self.slider.enable(b)
        self.textInput.enable(b)
        if hasattr(self, checkBox):
            self.checkBox.enable(b)

    def valueInput(self, sender):
        value = sender.get()
        parameter = self.parameter
        if value == "R":
            parameter.reset()
            parameter.update()
            if self.callback is not None:
                self.callback(self)
            return
        elif value != "*":
            parameter.setInput(value, sender=sender)
            parameter.update()
            if self.callback is not None:
                self.callback(self)

    def setFree(self, sender):
        value = bool(sender.get())
        self.parameter.setFree(value)
class ParameterSliderTextInput(Group):

    '''
    Custom Vanilla object consisting mainly of a Slider & and text input linked together (through a parameter object)
    '''

    def __init__(self, parameter, posSize, title=None, callback=None):
        super(ParameterSliderTextInput, self).__init__(posSize)
        self.parameter = parameter
        self.callback = callback
        editTextPosSize = (-45, 0, 45, 22)
        if title is None:
            sliderPosSize = (5, 3, -80, 15)
        elif title is not None:
            if len(title) > 15:
                title = '{0}.'.format(title[:16])
            title = title.capitalize()
            sliderPosSize = (120, 3, -55, 15)
            self.title = TextBox((0, 3, 115, 30), title, sizeStyle='small')
        if parameter.dissociable:
            editTextPosSize = (-65, 0, 40, 22)
            self.checkBox = CheckBox((-22, 5, 22, 25), u'∞', callback=self.setFree, value=True, sizeStyle='mini')
        self.slider = Slider(sliderPosSize, minValue=parameter.limits[0], maxValue=parameter.limits[1], value=parameter.value, callback=self.valueInput, sizeStyle='small')
        self.textInput = EditText(editTextPosSize, str(parameter.value), callback=self.valueInput, continuous=False, sizeStyle='small')
        self.parameter.bind(self)

    def get(self):
        return self.parameter.get()

    def enable(self, b):
        self.slider.enable(b)
        self.textInput.enable(b)
        if hasattr(self, checkBox):
            self.checkBox.enable(b)

    def valueInput(self, sender):
        value = sender.get()
        parameter = self.parameter
        if value == 'R':
            parameter.reset()
            parameter.update()
            if self.callback is not None:
                self.callback(self)
            return
        elif value != '*':
            parameter.setInput(value, sender=sender)
            parameter.update()
            if self.callback is not None:
                self.callback(self)

    def update(self, sender):
        value = self.parameter.get()
        self.textInput.set(str(value))
        if (value != '*'):
            self.slider.set(value)
        if hasattr(self, 'checkBox'):
            free = self.parameter.hasMaster
            self.checkBox.set(free)

    def setFree(self, sender):
        value = not bool(sender.get())
        self.parameter.setFree(value)