Search code examples
kivyosc

Kivy OSC Windows


Thanks for your quick answer laltin. The code lines are here in the .py file.

kivy 1.9.0

from kivy.app import App

from kivy.uix.floatlayout import FloatLayout

from kivy.uix.boxlayout import BoxLayout

from kivy.uix.button import Button

from kivy.uix.gridlayout import GridLayout

from kivy.uix.widget import Widget

from kivy.lang import Builder

from simpleOSC import initOSCClient, initOSCServer, closeOSC, \ setOSCHandler, sendOSCMsg

class OscShowcase(BoxLayout):

pass

class TestOscApp(App):

def build(self):
    return OscShowcase()

def send_Osc(self, *l):
    sendOSCMsg('activate', [3.0])
    #pass

if name == 'main':

host = '127.0.0.1'
sport = 9000
rport = 9001
# osc
initOSCClient(host, sport)
initOSCServer(host, rport)
TestOscApp().run()

.kv file

:

BoxLayout:

    Widget:

        Button:

            text: 'OSC'
            pos: (500, 400)

            on_press: app.send_Osc()
            sendOSCMsg: ('/%s/press', [])
            #on_release: app.send_Osc()
            #sendOSCMsg: ('activate', [3.0])

Do you think I can edit the OSC messages directly in the kv.file in order to separate every button with its assigned osc message? This is my main issue from the beginning. In fact i would like to control one of my Max patches on 3 systems, Ipad, MacbookPro and pc at the same time with the OSC protocol. And Kivy is the best on this I think. I already have a graphic plan of what I designed mostly in kv. langage. I can share the code with you if you don't mind. Thanks again for your big help.

stkflwrglator


Solution

  • The line on_press: do_root_action() in your .kv file means that when user presses the button the function do_root_action will be called. But do_root_action is not defined in your application.

    Add send_Osc method to your app:

    class TestOscApp(App):
    
        ...
    
        def send_Osc(self, *l):
            sendOSCMsg('/chaine_en_dur/', [2.0])
    

    Call send_Osc method on button press

    Button:
        text: 'OSC'
        pos: (500, 500)
        on_press: app.send_Osc()