簡體   English   中英

Kivy GUI與高速公路WAMP

[英]Kivy GUI with 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))

我嘗試使用Threads來使用autobahn.twisted.wamp應用程序,因為它是kivy應用程序主循環,但它們未同步

from autobahn.twisted.wamp import Application

app = Application()

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

因為我搜索了很多但沒有結果,所以您能給出如何結合它們的建議嗎?

您需要在激活Twisted支持的情況下運行Kivy。

這是一個完整的示例 ,該示例演示如何使用WAMP從Kivy使用Crossbar.io進行實時消息傳遞。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM