我想开发一个远程控制的框架来运行基于Kivy的应用程序。这个想法是使用PodSixNet(或者类似的客户端-服务器通信的网络层)来远程启动/控制/停止Kivy应用程序。这是基于运行一个外部事件循环(针对网络事件),但是我如何从Kivy的责任中获取任何Kivy应用程序的事件循环呢?在from kivy.app import App
from kivy.uix.button import Button
from 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 is sent from 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, and app events
(if there is a valid app)"""
connection.Pump()
self.Pump()
if self.current_game:
# this should run the 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()
我想运行单独的应用程序,因为他们将有不同的逻辑,以后添加新的应用程序应该没有太大的麻烦。
如果重要的话:它最终将在一个覆盆子Pi上运行(并且在Mac上进行开发)。在
编辑:潜在解决方案?
好吧,看来我可以像这样嵌套应用程序:
^{pr2}$
应该这样做吗?在