__version__ = "1.0"
import kivy
import plyer
kivy.require('1.0.9')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.switch import Switch
from kivy.utils import platform
from kivy.lib import osc
from kivy.clock import Clock
from kivy.properties import Property
activityport = 3001
serviceport = 3000
class switch(Switch):
def callback(self):
button.disabled = not self.active
class button(Button):
def callback(self):
plyer.vibrator.vibrate(3)
class vibrate(Widget):
pass
class ActiveApp(App):
def build(self):
if platform == 'android':
from android import AndroidService
service = AndroidService()
service.start()
self.service = service
osc.init()
oscid = osc.listen(ipAddr='127.0.0.1', port=activityport)
osc.bind(oscid, switch.callback, '~/kivyinstall/sahil/reply/step3_active')
Clock.schedule_interval(lambda *x: osc.readQueue(oscid), 0)
return vibrate()
def send(self):
osc.sendMsg('~/kivyinstall/sahil/reply/step3_active/service',[switch().property('active').get(switch()), ], port=serviceport)
if __name__ == '__main__':
ActiveApp().run()
#:kivy 1.0.9
<switch>:
on_touch_down: self.callback()
on_touch_down: app.send()
<button>:
text: "Vibrate"
size: 300,300
#on_release: self.callback()
<vibrate>:
Label:
button:
center_x: self.parent.width * 3/4
center_y: self.parent.height * 1/2
switch:
center_x: self.parent.width * 1/4
center_y: self.parent.height * 1/2
from time import sleep
from kivy.lib import osc
serviceport = 3000
def switch_callback(message, *args):
print("%s" % message)
if __name__ == '__main__':
osc.init()
oscid = osc.listen(ipAddr='127.0.0.1', port=serviceport)
osc.bind(oscid, switch_callback, '~/kivyinstall/sahil/reply/step3_active/service')
while True:
osc.readQueue(oscid)
sleep(.1)
switch().property('active').get(switch())'
This doesn't give you the active property of your switch, but instead presumably (I didn't check) of a new switch object, in which case it has the default value of False.
Also, you should give your widgets names beginning with an upper case letter, e.g. Vibrate, as kv uses this to distinguish properties from child widgets. In the case of your switch, that also means you should give it a name that doesn't clash with the kivy built in widget.
__version__ = "1.0"
import kivy
import plyer
kivy.require('1.0.9')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.switch import Switch
from kivy.utils import platform
from kivy.lib import osc
from kivy.clock import Clock
activityport = 3001
serviceport = 3000
class ActiveSwitch(Switch):
def callback(self):
VibrateButton.disabled = not self.active
class VibrateButton(Button):
def callback(self):
plyer.vibrator.vibrate(3)
class Vibrate(Widget):
switch = ActiveSwitch()
def update(self):
return self.switch.property('active').get(self.switch)
class ActiveApp(App):
def build(self):
if platform == 'android':
from android import AndroidService
service = AndroidService()
service.start()
self.service = service
osc.init()
oscid = osc.listen(ipAddr='127.0.0.1', port=activityport)
osc.bind(oscid, Vibrate.update, '~/kivyinstall/sahil/reply/step3_active')
Clock.schedule_interval(lambda *x: osc.readQueue(oscid), 0)
return Vibrate()
def send(self):
osc.sendMsg('~/kivyinstall/sahil/reply/step3_active/service',[Vibrate().update(), ], port=serviceport)
if __name__ == '__main__':
ActiveApp().run()
#:kivy 1.0.9
<ActiveSwitch>:
on_touch_down: self.callback(), app.send()
<VibrateButton>:
text: "Vibrate"
size: 300,300
#on_release: self.callback()
<Vibrate>:
switch: enable
Label:
VibrateButton:
center_x: self.parent.width * 3/4
center_y: self.parent.height * 1/2
ActiveSwitch:
id: enable
center_x: self.parent.width * 1/4
center_y: self.parent.height * 1/2
Traceback (most recent call last):
File "main.py", line 55, in <module>
ActiveApp().run()
File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 824, in run
runTouchApp()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 487, in runTouchApp
EventLoop.window.mainloop()
File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_sdl2.py", line 539, in mainloop
self._mainloop()
File "/usr/lib/python2.7/dist-packages/kivy/core/window/window_sdl2.py", line 300, in _mainloop
EventLoop.idle()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 330, in idle
self.dispatch_input()
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 315, in dispatch_input
post_dispatch_input(*pop(0))
File "/usr/lib/python2.7/dist-packages/kivy/base.py", line 221, in post_dispatch_input
listener.dispatch('on_motion', etype, me)
File "_event.pyx", line 699, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:6856)
File "/usr/lib/python2.7/dist-packages/kivy/core/window/__init__.py", line 904, in on_motion
self.dispatch('on_touch_down', me)
File "_event.pyx", line 699, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:6856)
File "/usr/lib/python2.7/dist-packages/kivy/core/window/__init__.py", line 920, in on_touch_down
if w.dispatch('on_touch_down', touch):
File "_event.pyx", line 699, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:6856)
File "/usr/lib/python2.7/dist-packages/kivy/uix/widget.py", line 382, in on_touch_down
if child.dispatch('on_touch_down', touch):
File "_event.pyx", line 695, in kivy._event.EventDispatcher.dispatch (kivy/_event.c:6815)
File "_event.pyx", line 1168, in kivy._event.EventObservers.dispatch (kivy/_event.c:11690)
File "_event.pyx", line 1052, in kivy._event.EventObservers._dispatch (kivy/_event.c:10730)
File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1465, in custom_callback
exec(__kvlang__.co_value, idmap)
File "./active.kv", line 5, in <module>
on_touch_down: self.callback(), app.send()
File "main.py", line 50, in send
osc.sendMsg('~/kivyinstall/sahil/reply/step3_active/service',[Vibrate().update(), ], port=serviceport)
File "main.py", line 31, in update
return self.switch.property('active').get(self.switch)
TypeError: Argument 'obj' has incorrect type (expected kivy._event.EventDispatcher, got kivy.weakproxy.WeakProxy)
[ERROR ] [OSC ] Error in Tuio recv()
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/kivy/lib/osc/oscAPI.py", line 229, in run
message = self.socket.recv(65535)
error: [Errno 4] Interrupted system call
kivy.require('1.0.9')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.switch import Switch
from kivy.utils import platform
from kivy.lib import osc
from kivy.clock import Clock
from kivy.properties import BooleanProperty
activityport = 3001
serviceport = 3000
class ActiveSwitch(Switch):
def callback(self):
VibrateButton.disabled = not self.active
class VibrateButton(Button):
def callback(self):
plyer.vibrator.vibrate(3)
class Vibrate(Widget):
switch = BooleanProperty(False)
def update(self):
return self.switch.active
class ActiveApp(App):
def build(self):
if platform == 'android':
from android import AndroidService
service = AndroidService()
service.start()
self.service = service
osc.init()
oscid = osc.listen(ipAddr='127.0.0.1', port=activityport)
osc.bind(oscid, Vibrate().update, '~/kivyinstall/sahil/reply/step3_active')
Clock.schedule_interval(lambda *x: osc.readQueue(oscid), 0)
return Vibrate()
def send(self):
osc.sendMsg('~/kivyinstall/sahil/reply/step3_active/service',[Vibrate().update(), ], port=serviceport)
if __name__ == '__main__':
ActiveApp().run()
#:kivy 1.0.9
<ActiveSwitch>:
on_touch_down: self.callback(), app.send()
<VibrateButton>:
text: "Vibrate"
size: 300,300
#on_release: self.callback()
<Vibrate>:
switch: enable
Label:
VibrateButton:
center_x: self.parent.width * 3/4
center_y: self.parent.height * 1/2
ActiveSwitch:
id: enable
center_x: self.parent.width * 1/4
center_y: self.parent.height * 1/2
> <mailto:kivy-users+unsub...@googlegroups.com>.
#:kivy 1.0.9
<VibrateButton>:
text: "Vibrate"
size: 300,300
<Vibrate>:
switch_active: switch_active
Label:
VibrateButton:
center_x: self.parent.width * 3/4
center_y: self.parent.height * 1/2
disabled: not switch_active.active
on_release: self.vibrate()
ActiveSwitch:
id: switch_active
on_touch_down: root.ping()
center_x: self.parent.width * 1/4
center_y: self.parent.height * 1/2
__version__ = "1.0"
import kivy
import
plyer
kivy.require('1.0.9')
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.switch import Switch
from kivy.utils import platform
from kivy.clock import Clock
from kivy.properties import BooleanProperty
from kivy.lib import osc
activityport = 3001
serviceport = 3000
def message_callback(message, *args):
print("got a message! %s" % message)
class ActiveSwitch(Switch):
pass
class VibrateButton(Button):
def vibrate(self):
plyer.vibrator.vibrate(3)
class Vibrate(Widget):
def ping(self):
osc.sendMsg('~/kivyinstall/sahil/reply/step3_active/service', [not self.switch_active.active, ], port=serviceport)
class ActiveApp(App):
def build(self):
if platform == 'android':
from android import AndroidService
service = AndroidService()
service.start()
self.service = service
osc.init()
oscid = osc.listen(ipAddr='127.0.0.1', port=activityport)
osc.bind(oscid, message_callback, '~/kivyinstall/sahil/reply/step3_active')
Clock.schedule_interval(lambda *x: osc.readQueue(oscid), 0)
return Vibrate()
if __name__ == '__main__':
ActiveApp().run()
> <mailto:kivy-users+unsub...@googlegroups.com>.