我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用PyQt5.QtWidgets.QProgressDialog()。
def prompt_extractor(self, item): extractor = extractors[item.data(Qt.UserRole)] inputs = [] if not assert_installed(self.view, **extractor.get('depends', {})): return if not extractor.get('pick_url', False): files, mime = QFileDialog.getOpenFileNames() for path in files: inputs.append((path, Path(path).stem)) else: text, good = QInputDialog.getText(self.view, ' ', 'Input an URL:') if text: url = urlparse(text) inputs.append((url.geturl(), url.netloc)) if inputs: wait = QProgressDialog('Extracting .proto structures...', None, 0, 0) wait.setWindowTitle(' ') self.set_view(wait) self.worker = Worker(inputs, extractor) self.worker.progress.connect(self.extraction_progress) self.worker.finished.connect(self.extraction_done) self.worker.start()
def progress_start(title: str = '', length: int = 100, label: str = ''): MainUiProgress.progress = QProgressDialog() MainUiProgress.progress.setWindowFlags(Qt.FramelessWindowHint) MainUiProgress.progress.setWindowFlags(Qt.WindowTitleHint) MainUiProgress.progress.setMinimumWidth(400) from PyQt5.QtWidgets import QPushButton # QString() seems to be deprecated in v5 # PyQt does not support setCancelButton(0) as it expects a QPushButton instance # Get your shit together, Qt ! MainUiProgress.progress.findChild(QPushButton).hide() MainUiProgress.progress.setMinimumDuration(1) MainUiProgress.progress.setWindowModality(Qt.ApplicationModal) MainUiProgress.progress.setCancelButtonText('') MainUiProgress.progress.setWindowIcon(QIcon(':/ico/app.ico')) MainUiProgress.progress.setWindowTitle(title) MainUiProgress.progress.setLabelText(label) MainUiProgress.progress.setMaximum(length) MainUiProgress.progress.show()
def progressBar(cmd): MainWindow = QtWidgets.QWidget() progress = QtWidgets.QProgressDialog("Please Wait!", "Cancel", 0, 100, MainWindow) progress.setWindowModality(QtCore.Qt.WindowModal) progress.setAutoReset(True) progress.setAutoClose(True) progress.setMinimum(0) progress.setMaximum(100) progress.resize(500,100) progress.setWindowTitle("Loading, Please Wait! (Cloudflare Protection)") progress.show() progress.setValue(0) #content = cmd #print content #content = ccurl(cmd,"") content = subprocess.check_output(cmd) progress.setValue(100) progress.hide() #print content return content
def spawn_window(parent, node, iface_name): driver = node.can_driver if not slcan_cli.CLIInterface.is_backend_supported(driver): mbox = QMessageBox(parent) mbox.setWindowTitle('Unsupported CAN Backend') mbox.setText('CAN Adapter Control Panel cannot be used with the current CAN backend.') mbox.setInformativeText('The current backend is %r.' % type(driver).__name__) mbox.setIcon(QMessageBox.Information) mbox.setStandardButtons(QMessageBox.Ok) mbox.show() # Not exec() because we don't want it to block! return progress_dialog = QProgressDialog(parent) progress_dialog.setWindowTitle('CAN Adapter Control Panel Initialization') progress_dialog.setLabelText('Detecting CAN adapter capabilities...') progress_dialog.setMinimumDuration(800) progress_dialog.setCancelButton(None) progress_dialog.setRange(0, 0) progress_dialog.show() def supported_callback(supported): progress_dialog.close() if not supported: mbox = QMessageBox(parent) mbox.setWindowTitle('Incompatible CAN Adapter') mbox.setText('CAN Adapter Control Panel cannot be used with the connected adapter.') mbox.setInformativeText('Connected SLCAN adapter does not support CLI extensions.') mbox.setIcon(QMessageBox.Information) mbox.setStandardButtons(QMessageBox.Ok) mbox.show() # Not exec() because we don't want it to block! return slcp = slcan_cli.ControlPanelWindow(parent, slcan_iface, iface_name) slcp.show() slcan_iface = slcan_cli.CLIInterface(driver) slcan_iface.check_is_interface_supported(supported_callback)
def accept(self, project=None): """Runs some basic verification before calling QDialog accept().""" # Case where project object is passed to accept() (when creating new project) if isinstance(project, prj.GravityProject): self.log.debug("Opening new project: {}".format(project.name)) elif not self.project_path: self.log.error("No valid project selected.") else: try: project = prj.AirborneProject.load(self.project_path) except FileNotFoundError: self.log.error("Project could not be loaded from path: {}".format(self.project_path)) return self.update_recent_files(self.recent_file, {project.name: project.projectdir}) # Show a progress dialog for loading the project (as we generate plots upon load) progress = QtWidgets.QProgressDialog("Loading Project", "Cancel", 0, len(project), self) progress.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.FramelessWindowHint | QtCore.Qt.CustomizeWindowHint) progress.setModal(True) progress.setMinimumDuration(0) progress.setCancelButton(None) # Remove the cancel button. Possibly add a slot that has load() check and cancel progress.setValue(1) # Set an initial value to show the dialog main_window = MainWindow(project) main_window.status.connect(progress.setLabelText) main_window.progress.connect(progress.setValue) main_window.load() progress.close() # This isn't necessary if the min/max is set correctly, but just in case. super().accept() return main_window
def on_action_export_wav_triggered(self): path = self.loaded_path if path: with self.catcher.more: project = self.exportable_project() slug = project.name.lower().replace(' ', '-') timestamp = now().strftime('%Y%m%d%H%M%S') bpm = project.initial_bpm / (project.initial_tpl / 6) filename = '{}-{}-{}bpm-{}.wav'.format(path, slug, bpm, timestamp) freq = 44100 size = freq channels = 2 data_type = float32 p = BufferedProcess(freq=freq, size=size, channels=channels, data_type=data_type) slot = Slot(project, process=p) length = slot.get_song_length_frames() output = np.zeros((length, 2), data_type) position = 0 slot.play_from_beginning() dialog = QProgressDialog('Writing WAV to {}'.format(filename), 'Cancel', 0, length, self) dialog.setWindowModality(Qt.WindowModal) dialog.forceShow() cancelled = False while position < length: if dialog.wasCanceled(): cancelled = True break buffer = p.fill_buffer() end_pos = min(position + freq, length) copy_size = end_pos - position output[position:end_pos] = buffer[:copy_size] position = end_pos dialog.setValue(position) if not cancelled: wavfile.write(filename, freq, output) print('Exported project to {}'.format(filename)) else: print('Cancelled export') p.deinit() p.kill() dialog.close()
def function(self): params = self.getGuiParams() searchdir = params['searchDirectoryLineEdit'] searchstring = params['searchStringLineEdit'] to_csv = params['outputFileNameLineEdit'] try: lookupfile = params['metadataFilesLineEdit'] except: lookupfile = None ave = bool(params['averagesradioButton']) progressbar = QtWidgets.QProgressDialog() io_ccam_pds.ccam_batch(searchdir, searchstring=searchstring, to_csv=Basics.outpath + '/' + to_csv, lookupfile=lookupfile, ave=ave, progressbar=progressbar) self.do_get_data(Basics.outpath + '/' + to_csv, 'ChemCam')