python kivy事件_Kivy和外部事件循环

我想开发一个远程控制的框架来运行基于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}$

应该这样做吗?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值