def __init__(self, *args, **kwargs): super(ProgressWindow, self).__init__(*args, **kwargs) # Setting up progress bar self.progress_bar = QtWidgets.QProgressBar() self.progress_bar.setGeometry(10, 50, 230, 20) self.progress_bar.setMaximum(100) self.setWindowTitle("Loading") self.setFixedSize(248, 80) self.text_field = QLabel("Loading") if platform.system() == 'Darwin': self.stylesheet_path = "res/stylesheet.qss" else: self.stylesheet_path = "res/stylesheet-win-linux.qss" self.stylesheet = open(resource_path(self.stylesheet_path)).read() window_icon = QIcon() window_icon.addPixmap(QPixmap(resource_path("res/images/icon.ico")), QIcon.Normal, QIcon.Off) self.setWindowIcon(window_icon) self.progress_bar.setStyleSheet(self.stylesheet) self.layout = QVBoxLayout() self.layout.addWidget(self.text_field) self.layout.addWidget(self.progress_bar) self.setLayout(self.layout) self.threadpool = QThreadPool() self.interrupt_flag = threading.Event()
def __init__(self): super().__init__() layout = QVBoxLayout() self.progress = QProgressBar() button = QPushButton("START IT UP") button.pressed.connect(self.execute) self.status = QLabel("0 workers") layout.addWidget(self.progress) layout.addWidget(button) layout.addWidget(self.status) w = QWidget() w.setLayout(layout) # Dictionary holds the progress of current workers. self.worker_progress = {} self.setCentralWidget(w) self.show() self.threadpool = QThreadPool() print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount()) self.timer = QTimer() self.timer.setInterval(100) self.timer.timeout.connect(self.refresh_progress) self.timer.start()
def load_patient_files(self, path, progress_callback, search_complete_callback): """ Load the patient files from directory. """ # Set the interrup flag self.interrupt_flag.set() # Release the current thread, and create new threadpool self.threadpool.releaseThread() self.threadpool = QThreadPool() # Clear the interrupt flag self.interrupt_flag.clear() # Create new worker worker = Worker(DICOMDirectorySearch.get_dicom_structure, path, self.interrupt_flag, progress_callback=True) # Connect callbacks worker.signals.result.connect(search_complete_callback) worker.signals.progress.connect(progress_callback) # Start the worker self.threadpool.start(worker)
def test_worker_no_progress_callback(qtbot): """ Testing for the progress_callback parameter not being present in the called function when no progress_callback """ func_to_test = Mock() w = Worker(func_to_test, "test", 3) threadpool = QThreadPool() with qtbot.waitSignal(w.signals.finished) as blocker: threadpool.start(w) assert w.fn == func_to_test assert 'progress_callback' not in w.kwargs func_to_test.assert_called_with("test", 3)
def test_worker_result_signal(qtbot, monkeypatch): """ Testing return value of worker's called function through result signal. """ thing = FakeClass() thing.func_to_test = Mock(return_value=5, unsafe=True) w = Worker(thing.func_to_test, "test", 3) with mock.patch.object(FakeClass, 'func_result', wraps=thing.func_result) as mock_func_result: w.signals.result.connect(thing.func_result) threadpool = QThreadPool() with qtbot.waitSignal(w.signals.finished) as blocker: threadpool.start(w) thing.func_to_test.assert_called_with("test", 3) mock_func_result.assert_called_with(5)
def test_worker_progress_callback(qtbot): """ Testing for the progress_callback parameter being present in the called function when progress_callback=True """ func_to_test = Mock() w = Worker(func_to_test, "test", 3, progress_callback=True) # This starts the Worker in the threadpool and then blocks the test from progressing until the finished signal is # emitted. qtbot is a pytest fixture used to test PyQt5. threadpool = QThreadPool() with qtbot.waitSignal(w.signals.finished) as blocker: threadpool.start(w) assert w.fn == func_to_test assert w.kwargs['progress_callback'] is not None func_to_test.assert_called_with( "test", 3, progress_callback=w.kwargs['progress_callback'])
def __init__(self): super(MainWindow, self).__init__(None) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.thread_pool = QThreadPool() self.input_directory = "" self.output_directory = "" self.merger_directory: Optional[str] = None self.editor_window: Optional[ClusterEditor] = None self.__generated_images_entries: List[ClusterImageEntry] = [] self.ui.buttonInputDir.clicked.connect(self.load_input_directory) self.ui.buttonOutputDir.clicked.connect(self.load_output_directory) self.ui.buttonGenerate.clicked.connect(self.generate_handler) self.ui.buttonCheckUncheck.clicked.connect(self.select_deselect) self.ui.buttonClearGenerated.clicked.connect(self.clear_generated)
def __init__(self, *args, **kwargs): super(ProgressWindow, self).__init__(*args, **kwargs) # Setting up progress bar self.progress_bar = QtWidgets.QProgressBar() self.progress_bar.setGeometry(10, 50, 230, 20) self.progress_bar.setMaximum(100) self.setWindowTitle("Loading") self.setFixedSize(248, 80) self.text_field = QLabel("Loading") self.layout = QVBoxLayout() self.layout.addWidget(self.text_field) self.layout.addWidget(self.progress_bar) self.setLayout(self.layout) self.threadpool = QThreadPool() self.interrupt_flag = threading.Event()
def __init__(self, *args, **kwargs): super(MainWindow, self).__init__() layout = QVBoxLayout() self.progress = QProgressBar() button = QPushButton("START IT UP") button.pressed.connect(self.execute) layout.addWidget(self.progress) layout.addWidget(button) w = QWidget() w.setLayout(layout) self.setCentralWidget(w) self.show() self.threadpool = QThreadPool() print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount())
def __init__(self): """ Class initialiser function. """ self.batch_path = "" self.dvh_output_path = "" self.pyrad_output_path = "" self.clinical_data_input_path = "" self.clinical_data_output_path = "" self.processes = [] self.dicom_structure = None self.suv2roi_weights = None self.name_cleaning_options = None self.patient_files_loaded = False self.progress_window = ProgressWindow(None) self.timestamp = "" self.batch_summary = [{}, ""] # Threadpool for file loading self.threadpool = QThreadPool() self.interrupt_flag = threading.Event()
def test_worker_error_signal(qtbot): """ Testing return value of worker's called function through result signal. """ thing = FakeClass() thing.func_to_test = Mock(side_effect=ValueError()) w = Worker(thing.func_to_test, "test", 3) with mock.patch.object(FakeClass, 'func_error', wraps=thing.func_error): w.signals.error.connect(thing.func_error) threadpool = QThreadPool() with qtbot.waitSignal(w.signals.finished) as blocker: threadpool.start(w) kall = thing.func_error.call_args args, kwargs = kall thing.func_to_test.assert_called_with("test", 3) assert isinstance(args[0][1], ValueError)
def __init__(self): super().__init__() self.setWindowTitle("Hooty Light Client") self.program_started = False self.log_text_box = QPlainTextEdit(self) self.log_text_box.setReadOnly(True) self.url = self.get_url_config() self.edit_url = QLineEdit(self.url) self.run_button = QPushButton("Run Hooty!") widgy = QWidget() layout = QVBoxLayout() widgy.setLayout(layout) layout.addWidget(self.log_text_box) layout.addWidget(self.edit_url) layout.addWidget(self.run_button) self.setLayout(layout) self.setCentralWidget(widgy) self.thread_pool = QThreadPool() # Create a runner self.runner = runner.JobRunner(self.edit_url.text()) self.thread_pool.start(self.runner) self.runner.logHandler.log.signal.connect(self.write_log) # Run some actions when we press the hooty button! self.run_button.pressed.connect( lambda: self.runner.set_url(self.edit_url.text())) self.run_button.pressed.connect( lambda: self.write_url_config(self.edit_url.text())) self.run_button.pressed.connect(self.runner.clicked) self.run_button.pressed.connect(self.hooty_button_text) self.show()
def setup_ui(self, open_patient_window_instance): if platform.system() == 'Darwin': self.stylesheet_path = "res/stylesheet.qss" else: self.stylesheet_path = "res/stylesheet-win-linux.qss" window_icon = QIcon() window_icon.addPixmap(QPixmap(resource_path("res/images/icon.ico")), QIcon.Normal, QIcon.Off) open_patient_window_instance.setObjectName("OpenPatientWindowInstance") open_patient_window_instance.setWindowIcon(window_icon) open_patient_window_instance.resize(840, 530) # Create a vertical box for containing the other elements and layouts self.open_patient_window_instance_vertical_box = QVBoxLayout() self.open_patient_window_instance_vertical_box.setObjectName( "OpenPatientWindowInstanceVerticalBox") # Create a label to prompt the user to enter the path to the directory that contains the DICOM files self.open_patient_directory_prompt = QLabel() self.open_patient_directory_prompt.setObjectName( "OpenPatientDirectoryPrompt") self.open_patient_directory_prompt.setAlignment(Qt.AlignLeft) self.open_patient_window_instance_vertical_box.addWidget( self.open_patient_directory_prompt) # Create a horizontal box to hold the input box for the directory and the choose button self.open_patient_directory_input_horizontal_box = QHBoxLayout() self.open_patient_directory_input_horizontal_box.setObjectName( "OpenPatientDirectoryInputHorizontalBox") # Create a textbox to contain the path to the directory that contains the DICOM files self.open_patient_directory_input_box = UIOpenPatientWindowDragAndDropEvent( self) self.open_patient_directory_input_box.setObjectName( "OpenPatientDirectoryInputBox") self.open_patient_directory_input_box.setSizePolicy( QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)) self.open_patient_directory_input_box.returnPressed.connect( self.scan_directory_for_patient) self.open_patient_directory_input_horizontal_box.addWidget( self.open_patient_directory_input_box) # Create a choose button to open the file dialog self.open_patient_directory_choose_button = QPushButton() self.open_patient_directory_choose_button.setObjectName( "OpenPatientDirectoryChooseButton") self.open_patient_directory_choose_button.setSizePolicy( QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)) self.open_patient_directory_choose_button.resize( self.open_patient_directory_choose_button.sizeHint().width(), self.open_patient_directory_input_box.height()) self.open_patient_directory_choose_button.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.open_patient_directory_input_horizontal_box.addWidget( self.open_patient_directory_choose_button) self.open_patient_directory_choose_button.clicked.connect( self.choose_button_clicked) # Create a widget to hold the input fields self.open_patient_directory_input_widget = QWidget() self.open_patient_directory_input_horizontal_box.setStretch(0, 4) self.open_patient_directory_input_widget.setLayout( self.open_patient_directory_input_horizontal_box) self.open_patient_window_instance_vertical_box.addWidget( self.open_patient_directory_input_widget) # Create a horizontal box to hold the stop button and direction to the user on where to select the patient self.open_patient_appear_prompt_and_stop_horizontal_box = QHBoxLayout() self.open_patient_appear_prompt_and_stop_horizontal_box.setObjectName( "OpenPatientAppearPromptAndStopHorizontalBox") # Create a label to show direction on where the files will appear self.open_patient_directory_appear_prompt = QLabel() self.open_patient_directory_appear_prompt.setObjectName( "OpenPatientDirectoryAppearPrompt") self.open_patient_directory_appear_prompt.setAlignment(Qt.AlignLeft) self.open_patient_appear_prompt_and_stop_horizontal_box.addWidget( self.open_patient_directory_appear_prompt) self.open_patient_appear_prompt_and_stop_horizontal_box.addStretch(1) # Create a button to stop searching self.open_patient_window_stop_button = QPushButton() self.open_patient_window_stop_button.setObjectName( "OpenPatientWindowStopButton") self.open_patient_window_stop_button.setSizePolicy( QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)) self.open_patient_window_stop_button.resize( self.open_patient_window_stop_button.sizeHint().width(), self.open_patient_window_stop_button.sizeHint().height()) self.open_patient_window_stop_button.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.open_patient_window_stop_button.clicked.connect( self.stop_button_clicked) self.open_patient_window_stop_button.setProperty( "QPushButtonClass", "fail-button") self.open_patient_window_stop_button.setVisible( False) # Button doesn't show until a search commences self.open_patient_appear_prompt_and_stop_horizontal_box.addWidget( self.open_patient_window_stop_button) # Create a widget to hold the layout self.open_patient_appear_prompt_and_stop_widget = QWidget() self.open_patient_appear_prompt_and_stop_widget.setLayout( self.open_patient_appear_prompt_and_stop_horizontal_box) self.open_patient_window_instance_vertical_box.addWidget( self.open_patient_appear_prompt_and_stop_widget) # Create a tree view list to list out all patients in the directory selected above self.open_patient_window_patients_tree = QTreeWidget() self.open_patient_window_patients_tree.setObjectName( "OpenPatientWindowPatientsTree") self.open_patient_window_patients_tree.setSizePolicy( QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)) self.open_patient_window_patients_tree.resize( self.open_patient_window_patients_tree.sizeHint().width(), self.open_patient_window_patients_tree.sizeHint().height()) self.open_patient_window_patients_tree.setHeaderHidden(False) self.open_patient_window_patients_tree.setHeaderLabels([""]) self.open_patient_window_patients_tree.itemChanged.connect( self.tree_item_changed) self.open_patient_window_instance_vertical_box.addWidget( self.open_patient_window_patients_tree) self.last_patient = None # Create a label to show what would happen if they select the patient self.open_patient_directory_result_label = QtWidgets.QLabel() self.open_patient_directory_result_label.setObjectName( "OpenPatientDirectoryResultLabel") self.open_patient_directory_result_label.setAlignment(Qt.AlignLeft) self.open_patient_window_instance_vertical_box.addWidget( self.open_patient_directory_result_label) # Create a horizontal box to hold the Cancel and Open button self.open_patient_window_patient_open_actions_horizontal_box = QHBoxLayout( ) self.open_patient_window_patient_open_actions_horizontal_box.setObjectName( "OpenPatientWindowPatientOpenActionsHorizontalBox") self.open_patient_window_patient_open_actions_horizontal_box.addStretch( 1) # Add a button to go back/exit from the application self.open_patient_window_exit_button = QPushButton() self.open_patient_window_exit_button.setObjectName( "OpenPatientWindowExitButton") self.open_patient_window_exit_button.setSizePolicy( QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)) self.open_patient_window_exit_button.resize( self.open_patient_window_stop_button.sizeHint().width(), self.open_patient_window_stop_button.sizeHint().height()) self.open_patient_window_exit_button.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.open_patient_window_exit_button.clicked.connect( self.exit_button_clicked) self.open_patient_window_exit_button.setProperty( "QPushButtonClass", "fail-button") self.open_patient_window_patient_open_actions_horizontal_box.addWidget( self.open_patient_window_exit_button) # Add a button to confirm opening of the patient self.open_patient_window_confirm_button = QPushButton() self.open_patient_window_confirm_button.setObjectName( "OpenPatientWindowConfirmButton") self.open_patient_window_confirm_button.setSizePolicy( QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)) self.open_patient_window_confirm_button.resize( self.open_patient_window_confirm_button.sizeHint().width(), self.open_patient_window_confirm_button.sizeHint().height()) self.open_patient_window_confirm_button.setCursor( QtGui.QCursor(QtCore.Qt.PointingHandCursor)) self.open_patient_window_confirm_button.setDisabled(True) self.open_patient_window_confirm_button.clicked.connect( self.confirm_button_clicked) self.open_patient_window_confirm_button.setProperty( "QPushButtonClass", "success-button") self.open_patient_window_patient_open_actions_horizontal_box.addWidget( self.open_patient_window_confirm_button) # Create a widget to house all of the actions button for open patient window self.open_patient_window_patient_open_actions_widget = QWidget() self.open_patient_window_patient_open_actions_widget.setLayout( self.open_patient_window_patient_open_actions_horizontal_box) self.open_patient_window_instance_vertical_box.addWidget( self.open_patient_window_patient_open_actions_widget) # Set the vertical box fourth element, the tree view, to stretch out as far as possible self.open_patient_window_instance_vertical_box.setStretch( 3, 4) # Stretch the treeview out as far as possible self.open_patient_window_instance_central_widget = QWidget() self.open_patient_window_instance_central_widget.setObjectName( "OpenPatientWindowInstanceCentralWidget") self.open_patient_window_instance_central_widget.setLayout( self.open_patient_window_instance_vertical_box) # Create threadpool for multithreading self.threadpool = QThreadPool() print("Multithreading with maximum %d threads" % self.threadpool.maxThreadCount()) # Create interrupt event for stopping the directory search self.interrupt_flag = threading.Event() # Bind all texts into the buttons and labels self.retranslate_ui(open_patient_window_instance) # Set the central widget, ready for display open_patient_window_instance.setCentralWidget( self.open_patient_window_instance_central_widget) # Set the current stylesheet to the instance and connect it back to the caller through slot _stylesheet = open(resource_path(self.stylesheet_path)).read() open_patient_window_instance.setStyleSheet(_stylesheet) QtCore.QMetaObject.connectSlotsByName(open_patient_window_instance)
def __init__(self, sleep_time): super().__init__() self.thread_manager = QThreadPool() self.setCentralWidget(GameWidget(self.thread_manager, sleep_time))
def __init__(self, args: List[str]): """ At the moment the very, very long initialization of the main window, setting up everything. :param default_path: Use a user defined path as entrypoint. If it's empty, the home directory of the current user will be used. :type default_path: str """ super(tfm, self).__init__() self.setupUi(self) self.setWindowIcon(QIcon.fromTheme('system-file-manager')) self.clipboard = QApplication.clipboard() self.marked_to_cut = [] self.back_stack = stack() self.forward_stack = stack() self.config_dir = os.path.join( QStandardPaths.writableLocation( QStandardPaths().ConfigLocation), type(self).__name__) self.current_path = utility.handle_args(args) self.default_path = self.current_path self.threadpool = QThreadPool() # MAIN VIEW # # set up QFileSystemModel self.filesystem = QFileSystemModel() self.filesystem.setRootPath(self.current_path) self.filesystem.setReadOnly(False) # connect QFileSystemModel to View self.table_view.setModel(self.filesystem) self.table_view.setRootIndex( self.filesystem.index(self.current_path)) # set up header self.horizontal_header = self.table_view.horizontalHeader() self.horizontal_header.setSectionsMovable(True) # name self.horizontal_header.resizeSection(0, 200) # size self.horizontal_header.resizeSection(1, 100) # type self.horizontal_header.resizeSection(2, 100) # FS TREE # # create seperate FileSystemModel for the fs tree self.fs_tree_model = QFileSystemModel() self.fs_tree_model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot) self.fs_tree_model.setRootPath(QDir.rootPath()) # connect model to view self.fs_tree.setModel(self.fs_tree_model) # hide unneeded columns for column in range(1, self.fs_tree.header().count()): self.fs_tree.hideColumn(column) # expand root item self.fs_tree.expand(self.fs_tree_model.index(0, 0)) # BOOKMARKS # self.bookmarks = bm(path_to_bookmark_file=os.path.join(self.config_dir, 'bookmarks')) self.bookmark_view.setModel(self.bookmarks) # MOUNTS # self.udev_context = Context() self.mounts = mounts_model(context=self.udev_context) self.mounts_view.setModel(self.mounts) udev_monitor = Monitor.from_netlink(self.udev_context) udev_monitor.filter_by(subsystem='block', device_type='partition') udev_observer = MonitorObserver(udev_monitor, self.devices_changed) udev_observer.start() # STATUSBAR # # TODO: dir info self.item_info = QLabel() # self.dir_info = QLabel() self.part_info = QLabel() self.statusbar.addPermanentWidget(self.item_info) # self.statusbar.addPermanentWidget(self.dir_info) self.statusbar.addPermanentWidget(self.part_info) self.part_info.setText(utility.part_info(self.current_path)) # TOOLBAR # # initially disable back/forward navigation self.action_back.setEnabled(False) self.action_forward.setEnabled(False) # main menu self.main_menu = QMenu() self.main_menu.addAction(self.action_show_hidden) self.menu_button = QToolButton() self.menu_button.setMenu(self.main_menu) self.menu_button.setPopupMode(QToolButton().InstantPopup) self.menu_button.setDefaultAction(self.action_menu) self.toolbar.insertWidget(self.action_back, self.menu_button) # adress bar self.adressbar = QLineEdit() self.adressbar.setText(self.current_path) self.toolbar.insertWidget(self.action_go, self.adressbar) # menu for new file or directory self.new_menu = QMenu() self.new_menu.addAction(self.action_new_dir) self.new_menu.addAction(self.action_new_file) self.new_button = QToolButton() self.new_button.setMenu(self.new_menu) self.new_button.setPopupMode(QToolButton().MenuButtonPopup) self.new_button.setDefaultAction(self.action_new_dir) self.toolbar.insertWidget(self.action_back, self.new_button) self.connect_actions_to_events() self.set_shortcuts() self.set_icons() self.set_context_menus()
def run(self): pool = QThreadPool() for new_thread in self.new_thread_list: pool.start(new_thread) pool.waitForDone()
def __init__(self, base): QWidget.__init__(self) self.base = base self.setWindowIcon(QIcon('icon.ico')) self.setWindowTitle(TITLE) self.set_background_color(QColor(255, 255, 255)) self.process_header_widget = QWidget() self.process_header_layout = QHBoxLayout(self.process_header_widget) self.process_header_layout.setContentsMargins(0, 0, 0, 0) self.process_label = QLabel('Available processes:') self.github_label = QLabel( '<a href="https://github.com/darktohka/p3dephaser">GitHub</a>') self.github_label.setOpenExternalLinks(True) self.refresh_button = QPushButton('Refresh') self.refresh_button.clicked.connect(self.refresh_processes) self.refresh_button.setFixedSize(100, 23) self.multifile_widget = QWidget() self.multifile_layout = QHBoxLayout(self.multifile_widget) self.multifile_layout.setContentsMargins(0, 0, 0, 0) self.multifileLabel = QLabel('Requested multifile names:') self.multifileBox = QLineEdit(self) self.multifileBox.returnPressed.connect(self.begin_scan) self.multifile_layout.addWidget(self.multifileLabel) self.multifile_layout.addWidget(self.multifileBox) self.scan_button = QPushButton('Scan') self.scan_button.clicked.connect(self.begin_scan) self.process_list_box = QListWidget() self.process_header_layout.addWidget(self.process_label) self.process_header_layout.addStretch(1) self.process_header_layout.addWidget(self.github_label) self.process_header_layout.addWidget(self.refresh_button) self.result_table = QTableWidget() self.result_table.setColumnCount(3) self.result_table.horizontalHeader().setStretchLastSection(True) self.result_table.horizontalHeader().setSectionResizeMode( QHeaderView.ResizeMode.Stretch) for i, header in enumerate(('Process', 'Multifile', 'Password')): self.result_table.setHorizontalHeaderItem(i, QTableWidgetItem(header)) self.base_layout = QVBoxLayout(self) self.base_layout.setContentsMargins(15, 15, 15, 15) self.base_layout.addWidget(self.process_header_widget) self.base_layout.addWidget(self.process_list_box) self.base_layout.addWidget(self.multifile_widget) self.base_layout.addWidget(self.scan_button) self.base_layout.addWidget(self.result_table) self.refresh_processes() self.thread_pool = QThreadPool() self.worker = None self.process_name = None self.stop_event = threading.Event()