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

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

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

        如何在一個進程中多次啟動 pyqt GUI?

        How can I launch pyqt GUI multiple times consequtively in a process?(如何在一個進程中多次啟動 pyqt GUI?)
          <bdo id='jHKE3'></bdo><ul id='jHKE3'></ul>

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

            <tfoot id='jHKE3'></tfoot>

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

                    <tbody id='jHKE3'></tbody>
                • <legend id='jHKE3'><style id='jHKE3'><dir id='jHKE3'><q id='jHKE3'></q></dir></style></legend>

                • 本文介紹了如何在一個進程中多次啟動 pyqt GUI?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  如何構建代碼以在一個進程中連續(xù)多次運行 pyqt GUI?

                  How can I architect code to run a pyqt GUI multiple times consecutively in a process?

                  (特別是 pyqtgraph,如果相關的話)

                  (pyqtgraph specifically, if that is relevant)

                  在測量設備上執(zhí)行長時間運行的數(shù)據(jù)捕獲的 python 腳本(一個大的 for 循環(huán)).在每次捕獲迭代期間,都會出現(xiàn)一個新的 GUI,并向用戶顯示來自測量設備的實時數(shù)據(jù),同時主捕獲代碼正在運行.

                  A python script that performs long running data capture on measurement equipment (a big for loop). During each capture iteration a new GUI appear and displays live data from the measurement equipment to the user, while the main capture code is running.

                  我想做這樣的事情:

                  for setting in settings:
                    measurement_equipment.start(setting)
                    gui = LiveDataStreamGUI(measurement_equipment)
                    gui.display()
                    measurement_equipment.capture_data(300) #may take hours
                    gui.close()
                  

                  主要問題

                  我希望數(shù)據(jù)捕獲代碼成為主線程.然而 pyqt 似乎不允許這種架構,因為它的 app.exec_() 是一個阻塞調用,允許每個進程只創(chuàng)建一次 GUI(例如,在 gui.display() 以上).

                  The main issue

                  I'd like the data capture code to be the main thread. However pyqt doesn't seems to allow this architecture, as its app.exec_() is a blocking call, allowing a GUI to be created only once per process (e.g., in gui.display() above).

                  推薦答案

                  應用程序是一個可執(zhí)行進程,它運行在一個或多個前臺線程上,每個前臺線程也可以啟動后臺線程來執(zhí)行并行操作或操作而不阻塞調用線程.應用程序將在所有前臺線程結束后終止,因此,您至少需要一個前臺線程,在您的情況下,該線程是在您調用 app.exec_() 語句時創(chuàng)建的.在 GUI 應用程序中,這是您應該創(chuàng)建和顯示主窗口和任何其他 UI 小部件的 UI 線程.當所有小部件都關閉時,Qt 將自動終止您的應用程序進程.

                  An application is an executable process that runs on one or more foreground threads each of which can also start background threads to perform parallel operations or operations without blocking the calling thread. An application will terminate after all foreground threads have ended, therefore, you need at least one foreground thread which in your case is created when you call the app.exec_() statement. In a GUI application, this is the UI thread where you should create and display the main window and any other UI widget. Qt will automatically terminate your application process when all widgets are closed.

                  恕我直言,您應該盡量遵循上述正常流程,工作流程可能如下:

                  IMHO, you should try to follow the normal flow described above as much as possible, the workflow could be as follows:

                  啟動應用程序 > 創(chuàng)建主窗口 > 為每個計算啟動一個后臺線程 > 將進度發(fā)送到 UI 線程 > 每次計算完成后在窗口中顯示結果 > 關閉所有窗口 > 結束應用程序

                  Start Application > Create main window > Start a background thread for each calculation > Send progress to UI thread > Show results in a window after each calculation is finished > Close all windows > End application

                  另外,您應該使用 ThreadPool 來確保不會耗盡資源.

                  Also, you should use ThreadPool to make sure you don't run out of resources.

                  這是一個完整的例子:

                  import sys
                  import time
                  import PyQt5
                  
                  from PyQt5 import QtCore, QtWidgets
                  from PyQt5.QtCore import QRunnable, pyqtSignal, QObject
                  from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QDialog
                  
                  
                  class CaptureDataTaskStatus(QObject):
                      progress = pyqtSignal(int, int)  # This signal is used to report progress to the UI thread.
                      captureDataFinished = pyqtSignal(dict)  # Assuming your result is a dict, this can be a class, a number, etc..
                  
                  
                  class CaptureDataTask(QRunnable):
                      def __init__(self, num_measurements):
                          super().__init__()
                  
                          self.num_measurements = num_measurements
                          self.status = CaptureDataTaskStatus()
                  
                      def run(self):
                          for i in range(0, self.num_measurements):
                              # Report progress
                              self.status.progress.emit(i + 1, self.num_measurements)
                              # Make your equipment measurement here
                              time.sleep(0.1) # Wait for some time to mimic a long action
                  
                          # At the end you will have a result, for example
                          result = {'a': 1, 'b': 2, 'c': 3}
                  
                          # Send it to the UI thread
                          self.status.captureDataFinished.emit(result)
                  
                  
                  class ResultWindow(QWidget):
                      def __init__(self, result):
                          super().__init__()
                  
                          # Display your result using widgets...
                          self.result = result
                  
                          # For this example I will just print the dict values to the console
                          print('a: {}'.format(result['a']))
                          print('b: {}'.format(result['b']))
                          print('c: {}'.format(result['c']))
                  
                  
                  class MainWindow(QMainWindow):
                      def __init__(self, *args, **kwargs):
                          super(MainWindow, self).__init__(*args, **kwargs)
                  
                          self.result_windows = []
                  
                          self.thread_pool = QtCore.QThreadPool().globalInstance()
                  
                          # Change the following to suit your needs (I just put 1 here so you can see each task opening a window while the others are still running)
                          self.thread_pool.setMaxThreadCount(1)
                  
                          # You could also start by clicking a button, menu, etc..
                          self.start_capturing_data()
                  
                      def start_capturing_data(self):
                          # Here you start data capture tasks as needed (I just start 3 as an example)
                          for setting in range(0, 3):
                              capture_data_task = CaptureDataTask(300)
                              capture_data_task.status.progress.connect(self.capture_data_progress)
                              capture_data_task.status.captureDataFinished.connect(self.capture_data_finished)
                              self.thread_pool.globalInstance().start(capture_data_task)
                  
                  
                      def capture_data_progress(self, current, total):
                          # Update progress bar, label etc... for this example I will just print them to the console
                          print('Current: {}'.format(current))
                          print('Total: {}'.format(total))
                  
                      def capture_data_finished(self, result):
                          result_window = ResultWindow(result)
                          self.result_windows.append(result_window)
                          result_window.show()
                  
                  
                  class App(QApplication):
                      """Main application wrapper, loads and shows the main window"""
                  
                      def __init__(self, sys_argv):
                          super().__init__(sys_argv)
                  
                          self.main_window = MainWindow()
                          self.main_window.show()
                  
                  
                  if __name__ == '__main__':
                      app = App(sys.argv)   
                      sys.exit(app.exec_())
                  

                  這篇關于如何在一個進程中多次啟動 pyqt GUI?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數(shù)有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                  <i id='Q7u6p'><tr id='Q7u6p'><dt id='Q7u6p'><q id='Q7u6p'><span id='Q7u6p'><b id='Q7u6p'><form id='Q7u6p'><ins id='Q7u6p'></ins><ul id='Q7u6p'></ul><sub id='Q7u6p'></sub></form><legend id='Q7u6p'></legend><bdo id='Q7u6p'><pre id='Q7u6p'><center id='Q7u6p'></center></pre></bdo></b><th id='Q7u6p'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Q7u6p'><tfoot id='Q7u6p'></tfoot><dl id='Q7u6p'><fieldset id='Q7u6p'></fieldset></dl></div>
                  • <bdo id='Q7u6p'></bdo><ul id='Q7u6p'></ul>

                      <tbody id='Q7u6p'></tbody>
                    1. <small id='Q7u6p'></small><noframes id='Q7u6p'>

                        • <legend id='Q7u6p'><style id='Q7u6p'><dir id='Q7u6p'><q id='Q7u6p'></q></dir></style></legend>
                          <tfoot id='Q7u6p'></tfoot>

                          1. 主站蜘蛛池模板: 天天综合国产 | 国产高清在线观看 | 在线91| 国产一区亚洲 | 国产精品久久久久久久久久软件 | 久久久久久九九九九九九 | 婷婷在线免费 | 国产精品久久久久久久久久妇女 | 一区二区成人在线 | 免费在线性爱视频 | 日韩欧美一级片 | 亚洲va欧美va人人爽午夜 | 国产成人精品久久 | 日韩在线中文 | 天堂免费看片 | 91精品国产综合久久久动漫日韩 | 91免费看片 | 99久久久久久久久 | 国产成人麻豆免费观看 | 亚洲一区二区av | 国产精品视频区 | 免费在线观看av网址 | 成人小视频在线观看 | 国产精品久久久久久久久久三级 | 午夜视频免费网站 | 国产成年人小视频 | 中文字幕日韩欧美 | 久久久久国产精品 | 97伦理电影网 | 精品乱码一区二区 | 91中文视频| 亚洲视频 欧美视频 | 日本成人中文字幕在线观看 | 欧美一区二区三区在线观看 | 播放一级黄色片 | 天天操狠狠操 | 日本一区二区三区在线观看 | 国产1区2区| 国产精品视频一区二区三区四蜜臂 | 一区二区精品视频 | 香蕉一区 |