Using Kivy.garden.knob, and having an issue:
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.
from threading import Thread
from cmd import Cmd
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
def __init__(self, **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")
def on_knob(self, value):
sm = ScreenManager()
sm.add_widget(FirstTimeConnect(name='First Time Connect'))
class MyCmd(Cmd, object):
if __name__ == '__main__':
app = MyApp()
To override a method in a widget/class you need to inherit from the class. The thing you did is "overriding"
on_knob method of
Screen and as
Screen has no such method as
on_knob, it just created a new one.
class MyKnob(Knob): def on_knob(self, value): print("hello!")
Also notice that there's no property
knob and that it's bound kind of "manually" with
_value. In a casual Kivy behavior
on_* methods are events and to override them you'd need to do this:
class MyKnob(Knob): def on_my_property(self, <arguments if it has any>): super(MyKnob, self).on_my_property(<arguments>) print("hello!")
depending on what you want to execute first i.e.
In case of completly rewriting it, just remove
super() from the method and it won't do the default behavior e.g. let's say if you override
on_touch_down with this:
class MyWidget(Widget): def on_touch_down(self, touch): pass
there will be no touch event if a touch collides with an area of your widget (if you touch the widget).