Kivy Slider on_value: event not firing

1k views Asked by At

I am using kivy and I have split my application out over .py and .kv files. In the .kv file, I have created a popup window with two buttons and a slider:

<SettingsPopup>:
    cols:1
    Label:
        text: root.text
    GridLayout:
        cols: 2
        size_hint_y: None
        height: '44sp'

        Label:
            id: mylabel
            text: 'XXX'

        Slider:
            value: 50
            max: 10
            on_value: root.dispatch('on_brightness', args[1])

        Button:
            text: 'Yes'
            on_release: root.dispatch('on_settings','yes')
        Button:
            text: 'No'
            on_release: root.dispatch('on_settings', 'no')

I bound the on_settings events to python methods and they work as expected, i.e. the string is printed.

Here is the SettingsPopup class:

class SettingsPopup(GridLayout):
    text = StringProperty()
    a = NumericProperty(1.0)
    def __init__(self, **kwargs):
        self.register_event_type('on_settings')
        self.register_event_type('on_brightness')
        super(SettingsPopup, self).__init__(**kwargs)

    def on_settings(self, *args):
        pass

    def on_brightness(self, *args):
        pass

and the methods within another class to test the functionality:

def settings(self, *largs):
    content = SettingsPopup(text='Please edit the experimental settings')
    content.bind(on_settings=self._on_settings)
    content.bind(on_settings=self._on_brightness)
    self.popup = Popup(title="Experimental Settings",
                       content=content,
                       size_hint=(None, None),
                       size=(200, 200),
                       auto_dismiss=False)
    self.popup.open()

def _on_settings(self, instance, answer):
    print "USER Name: ", repr(answer)
    self.popup.dismiss()

def _on_brightness(self, instance, answer):
    print "Brightness Level: ", repr(answer)
    self.popup.dismiss()

The code which describes the button is based on another example from SO, from which I have do not have the reference. However, I have tried extending it for the slider, but on-brightness never fires. I tried adding a = NumericProperty(1.0) but it has had no effect.

I started by having on_value: print(args[1]) in the .kv file and this printed when I moved the slider, so I know the event works, but I cannot get it to call the event in python.

0

There are 0 answers