久久久久久久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的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

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

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

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

                  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 沒(méi)有該功能,因此理想情況下,當(dāng)程序需要用戶輸入時(shí),確定"按鈕會(huì)調(diào)用下一個(gè)功能來(lái)運(yùn)行.

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

                  因此,我必須將所有當(dāng)前對(duì) PyQt 函數(shù)的調(diào)用替換為一個(gè)函數(shù),該函數(shù)會(huì)停止正在運(yùn)行的腳本,啟動(dòng)一個(gè)有效的響應(yīng)式對(duì)話,然后在它有請(qǐng)求的文本輸入時(shí)恢復(fù)原始對(duì)話.所以問(wèn)題是:

                  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:

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

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

                  我已經(jīng)試過(guò)了:

                  • 線程:

                  即使我在新線程中開(kāi)始文本輸入:

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

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

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

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

                  t.start()
                  t.join()
                  

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

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

                  • While/Sleep:等待文本輸入變量包含有效結(jié)果.但這會(huì)阻止 Kivy 中正在進(jìn)行的文本輸入 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.

                  非常歡迎任何指點(diǎn),感謝閱讀.

                  Any pointers would be really welcome, thanks for reading.

                  推薦答案

                  你不能只是暫停正在運(yùn)行的腳本.相反,您需要將程序重構(gòu)為事件驅(qū)動(dòng)(因?yàn)?Kivy 是事件驅(qū)動(dòng)的 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).

                  這是一個(gè)簡(jiǎn)單的示例函數(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
                  

                  重構(gòu):

                  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 輸入對(duì)話的調(diào)用替換為 yield MyPopup().show().

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

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

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

                  相關(guān)文檔推薦

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

                    <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'>

                            主站蜘蛛池模板: 国产在线精品一区二区 | 亚洲字幕在线观看 | 国产麻豆一区二区三区 | 国产伦精品一区二区三毛 | 毛片毛片毛片毛片毛片 | 狠狠干2020 | 日本大香伊一区二区三区 | 国产精品网址 | 99re6在线视频 | 亚洲成人在线网 | 91精品国产综合久久婷婷香蕉 | 51ⅴ精品国产91久久久久久 | 自拍偷拍中文字幕 | 999久久久久久久久6666 | 国产精品视频导航 | 91精品国产综合久久婷婷香蕉 | 国产激情在线观看 | 亚洲欧洲小视频 | 欧美中文字幕一区二区 | 秋霞av国产精品一区 | 在线视频国产一区 | 久久噜噜噜精品国产亚洲综合 | 一a一片一级一片啪啪 | 国产精品黄色 | 亚洲精品一区二区网址 | 久久一区| 天天操夜夜操 | 国产精品精品视频一区二区三区 | 日本不卡视频在线播放 | 国产精品欧美一区二区三区不卡 | 美女131mm久久爽爽免费 | 国产1区2区在线观看 | 韩日免费视频 | 午夜看看| 91精品国产色综合久久 | 一区精品国产欧美在线 | 中日av | 亚洲欧美一区二区三区在线 | 亚洲成人网在线观看 | 色综网| 一区二区免费在线视频 |