Kivy GUI与高速公路WAMP



我正在尝试在kivy应用程序和autobahn wamp之间进行组合。首先,我想做一个最基本的应用程序,它会显示一个标签,并在发布命令到来时更改它。

这是我的基本kivy应用程序:

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()

以下是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))

由于kivy应用程序主循环,我尝试使用线程使用autobahn.tisted.wamp应用程序,但它们没有同步

from autobahn.twisted.wamp import Application
app = Application()
@app.signal('onjoined')
def onjoined():
    kivyapp.changeLabel("realm joined!")

你能给我一个如何在它们之间组合的建议吗?因为我搜索了很多都没有结果。

您需要在激活Twisted支持的情况下运行Kivy。

以下是一个完整的示例,演示了如何使用Crossbar.io.

从Kivy使用WAMP进行实时消息传递

最新更新