python - Kivy and external event loop -
i'd develop remote controlled framework running apps based on kivy. idea use podsixnet (or similar network layer client-server communication) remotely start/control/stop kivy apps. based on running external event loop (for network events), how take event loop of whatever kivy app want run kivy's responsibility?
from kivy.app import app kivy.uix.button import button podsixnet.connection import connection, connectionlistener class app1(app): def build(self): return button(text='hello world 1') class app2(app): def build(self): return button(text='hello world 2') class client(connectionlistener): def __init__(self, *kargs, **kwargs): connectionlistener.__init__(self, *kargs, **kwargs) self.connect((kwargs['host'], kwargs['port'])) self.current_app = app1() self.current_app.run() def network_switchgame(self, data): """gets triggered if appropriate message sent server""" if isinstance(self.current_game, app1): self.current_app.stop() self.current_app = app2() else: self.current_app.stop() self.current_app = app1() self.current_app.run() def loop(self): """this function takes care of network events, , app events (if there valid app)""" connection.pump() self.pump() if self.current_game: # should run kivy app's event loop self.current_game.events() host, port = sys.argv[1].split(":") c = client(host=host, port=int(port)) while 1: c.loop()
i'd run separate apps because have different logics, , later new apps should added without trouble. if matters: run on raspberry pi (and development on mac).
edit: potential solution?
ok, seems can nest apps this:
from kivy.app import app kivy.properties import listproperty, objectproperty, numericproperty kivy.uix.button import button kivy.clock import clock class outsideapp(app): current_app = objectproperty(none) elapsed = numericproperty(0) def build(self): clock.schedule_interval(self.update, 1.0 / 60) self.current_app = app1() self.current_app.run() return button(text='fff 1') def update(self, dt): self.elapsed += dt if self.elapsed > 3: self.elapsed = 0 if self.current_app: self.current_app.stop() if isinstance(self.current_app, app1): self.current_app = app2() else: self.current_app = app1() self.current_app.run() class app1(app): def build(self): return button(text='hello world 1') class app2(app): def build(self): return button(text='hello world 2') oa = outsideapp() oa.run()
is how should done?
Comments
Post a Comment