久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <tfoot id='vuCeR'></tfoot>

      1. <small id='vuCeR'></small><noframes id='vuCeR'>

        <i id='vuCeR'><tr id='vuCeR'><dt id='vuCeR'><q id='vuCeR'><span id='vuCeR'><b id='vuCeR'><form id='vuCeR'><ins id='vuCeR'></ins><ul id='vuCeR'></ul><sub id='vuCeR'></sub></form><legend id='vuCeR'></legend><bdo id='vuCeR'><pre id='vuCeR'><center id='vuCeR'></center></pre></bdo></b><th id='vuCeR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vuCeR'><tfoot id='vuCeR'></tfoot><dl id='vuCeR'><fieldset id='vuCeR'></fieldset></dl></div>
      2. <legend id='vuCeR'><style id='vuCeR'><dir id='vuCeR'><q id='vuCeR'></q></dir></style></legend>
          <bdo id='vuCeR'></bdo><ul id='vuCeR'></ul>

        暫停 python 腳本,直到事件發(fā)生而不掛起/阻塞

        Pause a python script until an event occurs without hanging/blocking the GUI(暫停 python 腳本,直到事件發(fā)生而不掛起/阻塞 GUI)
          <bdo id='LUdA0'></bdo><ul id='LUdA0'></ul>
              <tbody id='LUdA0'></tbody>
            <tfoot id='LUdA0'></tfoot>
          1. <legend id='LUdA0'><style id='LUdA0'><dir id='LUdA0'><q id='LUdA0'></q></dir></style></legend>

            <small id='LUdA0'></small><noframes id='LUdA0'>

              <i id='LUdA0'><tr id='LUdA0'><dt id='LUdA0'><q id='LUdA0'><span id='LUdA0'><b id='LUdA0'><form id='LUdA0'><ins id='LUdA0'></ins><ul id='LUdA0'></ul><sub id='LUdA0'></sub></form><legend id='LUdA0'></legend><bdo id='LUdA0'><pre id='LUdA0'><center id='LUdA0'></center></pre></bdo></b><th id='LUdA0'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LUdA0'><tfoot id='LUdA0'></tfoot><dl id='LUdA0'><fieldset id='LUdA0'></fieldset></dl></div>
                  本文介紹了暫停 python 腳本,直到事件發(fā)生而不掛起/阻塞 GUI的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  嘗試使用 Kivy 從 PyQt 遷移,我什至無法想象解決方案.

                  Trying to migrate from PyQt with Kivy and I cant even imagine a solution for this.

                  我有數(shù)千行代碼使用 Qt 的對話進行文本輸入.也就是說,當?shù)竭_他們的代碼行時,他們會停止"腳本,直到按下確定"按鈕,這樣他們就可以返回文本輸入.

                  I have thousands of lines of code that use Qt's dialogues for text input. That is, when their line of code is reached, they 'stop' the script until the "ok" button is pressed, so they can return the text input.

                  Kivy 沒有該功能,因此理想情況下,當程序需要用戶輸入時,確定"按鈕會調用下一個功能來運行.

                  Kivy doesnt have that functionality, so ideally, when the program needs user input, the "ok" button would call for the next function to run.

                  因此,我必須將所有當前對 PyQt 函數(shù)的調用替換為一個函數(shù),該函數(shù)會停止正在運行的腳本,啟動一個有效的響應式對話,然后在它有請求的文本輸入時恢復原始對話.所以問題是:

                  Therefore I must replace all the current calls to a PyQt function with a function that stops the running script, launches a working responsive dialogue, then resumes the original when it has the text input it requested. So the question is:

                  有沒有辦法在函數(shù)完成之前停止正在運行的腳本,不掛起 GUI?

                  Is there a way to stop a running script until a function finishes, without hanging the GUI?

                  我已經試過了:

                  • 線程:

                  即使我在新線程中開始文本輸入:

                  Even if I start the text input in a new thread:

                  t = threading.Thread(target=TextInput.waiter)
                  

                  調用此類線程的函數(shù)將在調用文本輸入后立即返回.如果我使用此代碼:

                  the function that calls such thread will return just after calling the text input. If I use this code:

                  t.start()
                  t.join()
                  

                  主腳本將停止,但也會掛起文本輸入 GUI.

                  The main script will stop, but also hangs the text input GUI.

                  • While/Sleep:等待文本輸入變量包含有效結果.但這會阻止 Kivy 中正在進行的文本輸入 GUI

                  • While/Sleep: Waiting for the text input variable to contain a valid result. But this blocks the ongoing textinput GUI in Kivy

                  破解 raw_input:目前正在考慮嘗試一些破解,這將允許我停止腳本,然后反饋由 kivy 文本輸入彈出窗口找到的輸入.

                  Hacking raw_input: Currently thinking into try some hack with that, that would allow me to stop the script, then feed back the input found by the kivy text input popup.

                  非常歡迎任何指點,感謝閱讀.

                  Any pointers would be really welcome, thanks for reading.

                  推薦答案

                  你不能只是暫停正在運行的腳本.相反,您需要將程序重構為事件驅動(因為 Kivy 是事件驅動的 GUI).

                  You can't just pause the running script. Instead, you'll need to refactor your program to be event-driven (as Kivy is an event-driven GUI).

                  這是一個簡單的示例函數(shù):

                  Here's a simple example function:

                  def myfunc():
                      # do some stuff here
                      # now we need some input...
                      val = qt_input_dialogue()
                      # do some more stuff here
                  

                  重構:

                  class MyPopup(Popup):
                      value = StringProperty() # bind this to a TextInput or something
                  
                  def myfunc1():
                      # do some stuff here
                      p = MyPopupClass()
                      p.bind(on_dismiss=lambda *_: myfunc2(p.value))
                      p.open()
                  
                  def myfunc2(val):
                      # do some more stuff here
                  


                  如果你愿意使用 Twisted,你可以使用 Deferreds 和 inlineCallbacks 使這更容易.


                  If you're willing to use Twisted, you can make this even easier using Deferreds and inlineCallbacks.

                  from kivy.support import install_twisted_reactor
                  install_twisted_reactor()
                  
                  from twisted.internet import defer
                  
                  Builder.load_string('''
                  <MyPopup>:
                      BoxLayout:
                          orientation: 'vertical'
                          TextInput:
                              id: text_input
                          BoxLayout:
                              orientation: 'horizontal'
                              Button:
                                  text: 'OK'
                                  on_press: root.okfn(text_input.text)
                  ''')
                  
                  class MyPopup(Popup):
                      def show(self, *args):
                          d = defer.Deferred()
                          self.okfn = d.callback
                          self.open(*args)
                          return d
                  
                  @defer.inlineCallbacks
                  def myfunc():
                      # do some stuff here
                      val = yield MyPopup().show()
                      # do some more stuff here
                  

                  這樣,您只需將 QT 輸入對話的調用替換為 yield MyPopup().show().

                  This way, you can just replace the calls to QT input dialogues with yield MyPopup().show().

                  這篇關于暫停 python 腳本,直到事件發(fā)生而不掛起/阻塞 GUI的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)

                    <tfoot id='IBFyZ'></tfoot>
                      <tbody id='IBFyZ'></tbody>

                    1. <legend id='IBFyZ'><style id='IBFyZ'><dir id='IBFyZ'><q id='IBFyZ'></q></dir></style></legend>
                      • <bdo id='IBFyZ'></bdo><ul id='IBFyZ'></ul>
                        <i id='IBFyZ'><tr id='IBFyZ'><dt id='IBFyZ'><q id='IBFyZ'><span id='IBFyZ'><b id='IBFyZ'><form id='IBFyZ'><ins id='IBFyZ'></ins><ul id='IBFyZ'></ul><sub id='IBFyZ'></sub></form><legend id='IBFyZ'></legend><bdo id='IBFyZ'><pre id='IBFyZ'><center id='IBFyZ'></center></pre></bdo></b><th id='IBFyZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='IBFyZ'><tfoot id='IBFyZ'></tfoot><dl id='IBFyZ'><fieldset id='IBFyZ'></fieldset></dl></div>

                        <small id='IBFyZ'></small><noframes id='IBFyZ'>

                            主站蜘蛛池模板: 精品伊人久久 | 日韩欧美国产精品一区 | 精品香蕉一区二区三区 | 全免费a级毛片免费看视频免 | 久久久123| 久久精彩 | 成人精品免费视频 | 久久精品青青大伊人av | 午夜精品一区二区三区在线播放 | 亚洲精品在线播放 | avtt国产 | 欧美精品一区二区三区蜜桃视频 | 2020天天操 | 岛国二区| 国产成人精品视频在线观看 | 欧美日韩国产一区二区三区 | 91天堂网 | 人人艹人人 | 午夜精品久久久久久久久久久久 | 性色av一区二区三区 | 一片毛片| 国产精品久久a | 中文字幕在线观看视频网站 | 中文字幕第一页在线 | 欧美日韩在线播放 | 欧美精品一区二区三区在线 | 日韩欧美在线视频观看 | 国产高清在线精品一区二区三区 | 国产成人亚洲精品自产在线 | 黄色网址免费看 | 天天干视频网 | 精品一区二区三区在线观看 | 国产精品色婷婷久久58 | 亚洲乱码一区二区三区在线观看 | 免费av毛片 | 中文字幕日韩av | h网站在线观看 | 成人午夜视频在线观看 | 成人免费视频在线观看 | 久久1区| 欧美成人a∨高清免费观看 老司机午夜性大片 |