[英]Kivy GUI with autobahn WAMP
And I am trying to combine between kivy application and autobahn wamp. 而且我正在尝试将kivy应用程序和高速公路沼泽结合起来。 For start I want to make the most basic app which will show a label and change it when a publish command will come. 首先,我想制作最基本的应用程序,该应用程序将显示标签,并在发布命令到来时对其进行更改。
This is my basic kivy App: 这是我的基本猕猴桃应用程序:
class MyFrontendComponent(App):
def build(self):
root = self.setup_gui()
return root
def setup_gui(self):
self.label = Label(text='connecting...\n')
self.layout = BoxLayout(orientation='vertical')
self.layout.add_widget(self.label)
return self.layout
def changeLabel(self, text):
self.label.text = text
if __name__ == '__main__':
# Run the kivy app
kivyapp = MyFrontendComponent()
kivyapp.run()
And here is how autobahn Wamp should be implemented according to: http://autobahn.ws/python/wamp/programming.html 这是根据以下方式实施高速公路Wamp的方法: http : //autobahn.ws/python/wamp/programming.html
from autobahn.twisted.wamp import ApplicationSession
from twisted.internet.defer import inlineCallbacks
class MyComponent(ApplicationSession):
@inlineCallbacks
def onJoin(self, details):
print("session ready")
def oncounter(count):
print("event received: {0}", count)
try:
yield self.subscribe(oncounter, u'com.myapp.oncounter')
print("subscribed to topic")
except Exception as e:
print("could not subscribe to topic: {0}".format(e))
I have tried to use the autobahn.twisted.wamp Application using Threads because of the kivy app main loop but they are not getting syncronized 我尝试使用Threads来使用autobahn.twisted.wamp应用程序,因为它是kivy应用程序主循环,但它们未同步
from autobahn.twisted.wamp import Application
app = Application()
@app.signal('onjoined')
def onjoined():
kivyapp.changeLabel("realm joined!")
Can you give an advice of how to combine between them because I search a lot with no results. 因为我搜索了很多但没有结果,所以您能给出如何结合它们的建议吗?
You need to run Kivy with Twisted support activated . 您需要在激活Twisted支持的情况下运行Kivy。
Here is a complete example that demonstrates how to use WAMP for real-time messaging from Kivy using Crossbar.io . 这是一个完整的示例 ,该示例演示如何使用WAMP从Kivy使用Crossbar.io进行实时消息传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.