【问题标题】:Kivy GUI with autobahn WAMP带有高速公路 WAMP 的 Kivy GUI
【发布时间】:2015-03-06 17:07:41
【问题描述】:

我正在尝试将 kivy 应用程序和高速公路 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.twisted.wamp 应用程序,但它们没有得到同步

from autobahn.twisted.wamp import Application

app = Application()

@app.signal('onjoined')
def onjoined():
    kivyapp.changeLabel("realm joined!")

您能否就如何将它们结合起来给出一个建议,因为我搜索了很多都没有结果。

【问题讨论】:

    标签: python kivy autobahn


    【解决方案1】:

    您需要使用Twisted support activated 运行 Kivy。

    这是一个complete example,它演示了如何使用WAMP 使用Crossbar.io 从 Kivy 进行实时消息传递。

    【讨论】:

    • 谢谢,这是我要找的。你知道我需要为 Android 的 buildozer 指定哪些要求吗?目前我指定了 kivy、twisted、autobahn 和 openssl,但应用程序在我的设备中不断崩溃
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多