kivy garden knob - how to override on_knob

253 views
Skip to first unread message

f....@hotmail.it

unread,
Nov 18, 2016, 4:53:11 AM11/18/16
to Kivy users support
Hello,

I'm trying to post the knob value to the command line when I move it, but I'm unable to make it work, any suggestions?
Here the whole code, thanks in advance, FD.

#!/usr/bin/python

from threading import Thread
from cmd import Cmd
import logging
logging.getLogger("kivy").disabled = True


from kivy.app import App
from kivy.core.window import Window
from kivy.garden.knob import  Knob
from kivy.uix.gridlayout import GridLayout
from kivy.uix.screenmanager import ScreenManager, Screen

class FirstTimeConnect(Screen):
def __init__(self, **kwargs):
super(FirstTimeConnect, self).__init__(**kwargs)
layout = GridLayout(cols=2)
layout.knob1 = Knob(knobimg_source="/Users/admin/Dropbox/Strumenti/Concatenativa_PyCpp/knob_img/knob_black.png", marker_img="/Users/admin/Dropbox/Strumenti/Concatenativa_PyCpp/knob_img/bline.png")
layout.add_widget(layout.knob1)
def on_knob(self, value):
print "hi"
layout.knob1.bind(on_knob=on_knob)
self.add_widget(layout)

sm = ScreenManager()
sm.add_widget(FirstTimeConnect(name='First Time Connect'))

class MyCmd(Cmd, object):
    pass

class MyApp(App):

    def build(self):
        #return LogScreen()
        return sm

if __name__ == '__main__':
    app = MyApp()
    Thread(target=app.run()).start()
    MyCmd(app).cmdloop()

Bill Janssen

unread,
Nov 18, 2016, 8:02:50 PM11/18/16
to Kivy users support
There's no "knob" property, and no "on_knob" event, in that garden widget.

Try "layout.knob1.bind(value=my_function)".  Generally speaking, when you use bind, it's foo.bind(PROPERTYNAME=FUNCTION), not foo.bind(on_PROPERTY=FUNCTION).

The documentation of EventDispatcher is evidently broken; this should work but doesn't:

$ python -c "from kivy.garden.knob import Knob; print Knob.events()"
[INFO              ] [Logger      ] Record log in /home/wjanssen/.kivy/logs/kivy_16-11-18_42.txt
[WARNING           ] [Modules     ] Module <clipboard> not found
[WARNING           ] [Modules     ] Module <cutbuffer> not found
[INFO              ] [Factory     ] 179 symbols loaded
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO              ] [Text        ] Provider: sdl2
[INFO              ] [Kivy        ] v1.9.1
[INFO              ] [Python      ] v2.7.12 |Continuum Analytics, Inc.| (default, Jul  2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]
 
Traceback (most recent call last):
   
File "<string>", line 1, in <module>
 
TypeError: descriptor 'events' of 'kivy._event.EventDispatcher' object needs an argument
$


But you can display the available events with this:

$ python -c "from kivy.garden.knob import Knob; print Knob.__events__"

It really doesn't define any additional events.

Bill

ZenCODE

unread,
Nov 19, 2016, 3:05:52 PM11/19/16
to Kivy users support
@Bill Janssen

That code will not work. your need to instantiate the knob to read the events.

$ python -c "from kivy.garden.knob import Knob; print Knob().events()"

Bill Janssen

unread,
Nov 19, 2016, 8:01:38 PM11/19/16
to Kivy users support
As you say.  Assuming Knob has no required constructor arguments.  But "events()" should really be a classmethod, I'd think.  It's not really about the Instance, it's about the class.  And you'd still get the results if you called it on an instance.

Bill

ZenCODE

unread,
Nov 20, 2016, 1:08:41 AM11/20/16
to Kivy users support
I think it's because the event construction happens dynamically, as the widget is constructed. So there is really no logical way to know what events it will have until you construct it. Kivy properties and event are heavily based on the EventDispatcher, which adds these things on-the-fly and in way even static analysis of the code cannot reveal an compile/write time.

Bill Janssen

unread,
Nov 21, 2016, 5:06:55 PM11/21/16
to Kivy users support
How would anyone know what events to catch and use, then?  Not sure I believe this.

Bill

Bill Janssen

unread,
Nov 21, 2016, 5:08:54 PM11/21/16
to Kivy users support
Do you have an example?

Bill

ZenCODE

unread,
Nov 22, 2016, 12:55:12 AM11/22/16
to Kivy users support
An example of what exactly? We have seen that we can get the events once it's instantiated. Sorry, I'm not clear on what we are looking for here.

Bill Janssen

unread,
Dec 2, 2016, 3:29:43 PM12/2/16
to Kivy users support
An example of dynamic event construction.  I find it hard to believe that you can't tell what events an instance will have merely by knowing what events its class provides.  Not impossible, just would be interested in seeing an example of that.

ZenCODE

unread,
Dec 2, 2016, 5:53:33 PM12/2/16
to Kivy users support
Okay. How about mixing in FocusBehavior or ButtonBehavior with and Image or other such widget? You'd have to analyze the whole inheritance tree to get the full picture of events.

Also consider that kivy may use different providers e.g. WindowBase types for different OS's and libraries, you clearly have something that you cannot statically analyze. Well, certainly not easily...

Tim Checkley

unread,
Mar 22, 2019, 12:34:25 AM3/22/19
to Kivy users support
Just wanna say THANKS for this thread, and for anyone other noobs out there searching for it, the simple syntax I was looking for is here:

myKnob.bind(value=myKnobAction) 

with

def myKnobAction(instance, value):
    print('%s - %s  ' % (instance.id,value))

is what you need to get the value out of the Kivy Garden Knob ;-) 
Reply all
Reply to author
Forward
0 new messages