def select_output_dir(self): self.output_dir_path = QFileDialog.getExistingDirectory( None, self.select_output_dir_title, "C:/") if self.output_dir_path == '' or not os.path.exists( self.output_dir_path): return self.txtOutputDir.setText(self.output_dir_path)
def load_input_directory(self) -> None: """ Open a popup to select the directory where is located source images. """ in_dir = QFileDialog.getExistingDirectory(self) if len(in_dir) == 0: return self.input_directory = in_dir self.clear_image_entries() self.clear_preview_image() # self.ui.labelInDir.setText(f"Loaded: {self.input_directory}") src_layout = self.source_layout() first = True for entry in sorted(os.scandir(self.input_directory), key=lambda x: x.name): if not Tat.is_image(entry.path): continue qim = load_image(entry.path) ime = CheckableImageEntry(src_layout.parent(), qim, entry.name, entry.path) ime.mouse_pressed.connect(self.image_entry_click_handler) self.add_source_image_entry(ime) if first: self.set_preview_image(qim, ime) first = False if len(self.output_directory) != 0: self.ui.buttonGenerate.setEnabled(True)
def move_copy_dialog(self, copy): """dialog for copy or move a file Args: copy (boolean): True to copy, False to move """ if copy: libelle = "Move to" else: libelle = "Copy to" if not self.index == -1: directory = QFileDialog.getExistingDirectory( self, libelle, self.images[self.index], QFileDialog.ShowDirsOnly | QFileDialog.DontUseNativeDialog) if directory: file = os.path.join(directory, os.path.basename(self.images[self.index])) if not os.path.isfile(file): self.move_copy_file(self.images[self.index], file, copy) else: dialog = ImageDialog(self.images[self.index], file) result = dialog.exec_() if result == QDialog.Accepted: self.move_copy_file(self.images[self.index], file, copy) elif result == 3: # renamme self.move_copy_file( self.images[self.index], os.path.join( directory, os.path.basename( dialog.edit_file_name.text())), copy)
def folderselect(self): print("click") print(self.dir_path) self.dir_path = QFileDialog.getExistingDirectory() self.folderbutton.setStatusTip(self.dir_path) print(self.dir_path) self.fileboxlist()
def slot_edit_load_folder(self): dir = QFileDialog.getExistingDirectory( self, 'Folder in which the save states are stored by mGBA', self.ui.lineEditLoadFolder.text()) print(dir) if dir is not None: self.ui.lineEditLoadFolder.setText(dir)
def getInputDir(self): dir = QFileDialog.getExistingDirectory(None, "Select folder", self.userDesktop) if dir: path = dir.replace("/", "\\") self.InputLineEdit.setText(path)
def getOuputDir(self): dir = QFileDialog.getExistingDirectory(None, "Select save folder location", self.userDesktop) if dir: path = dir.replace("/", "\\") self.OutputLineEdit.setText(path)
def changeFolder(self, button): fname = QFileDialog.getExistingDirectory(self, 'Open f', '/home') if fname: # Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system. # On Windows, toNativeSeparators("c:/winnt/system32") returns # "c:\winnt\system32". fname = QDir.toNativeSeparators(fname) if os.path.isdir(fname): self.download_folder_lineEdit.setText(fname)
def tempDownloadPushButtonClicked(self, button): download_path_temp = str( self.persepolis_setting.value('settings/download_path_temp')) fname = QFileDialog.getExistingDirectory(self, 'Open f', download_path_temp) if fname: self.temp_download_lineEdit.setText(fname) self.persepolis_setting.setValue('settings/download_path_temp', str(fname))
def setDirectory(self): """ Choose the directory. """ file_dialog = QFileDialog(self) file_dialog.setFileMode(QFileDialog.Directory) self.directory = file_dialog.getExistingDirectory(self, "Open Directory", "", QFileDialog.ShowDirsOnly) if self.directory: self.dir_line_edit.setText(self.directory) # Set the max value of progress bar equal to max number of files in the directory. num_of_files = len([name for name in os.listdir(self.directory)]) self.progress_bar.setRange(0, num_of_files)
def browseFolderPathSlot(self): """ Called when the user presses the Browse button :return: None """ directory: str = QFileDialog.getExistingDirectory() if os.path.exists(directory) and os.path.isdir(directory): self.path = directory # Set text to input as directory path self.ui.lineEdit.setText(directory) self.archive_name = f'{os.path.basename(directory)}.zip' self.debugPrint(f'Set directory: {directory}') else: self.debugPrint('The directory is not exist!')
def load_output_directory(self) -> None: """ Open a popup to select the directory where to generate the clusters and layers. """ out_dir = QFileDialog.getExistingDirectory(self) if len(out_dir) == 0: return self.output_directory = out_dir self.merger_directory = os.path.join(self.output_directory, "merged") Path(self.merger_directory).mkdir(exist_ok=True) # self.ui.labelOutDir.setText(f"Loaded: {self.output_directory}") if len(self.input_directory) != 0: self.ui.buttonGenerate.setEnabled(True)
def _select_models_path(self): print('Selecting models path... ', end='', flush=True) settings = QSettings() models_path = QFileDialog.getExistingDirectory( parent=self, caption='Select models directory', dir=QStandardPaths.standardLocations( QStandardPaths.AppDataLocation).pop(), ) if models_path != '': settings.setValue(self._models_path_key, str(models_path)) self._models_path = Path(models_path) print(models_path) else: print('canceled')
def downloadFolderPushButtonClicked(self, button): download_path = str( self.persepolis_setting.value('settings/download_path')) fname = QFileDialog.getExistingDirectory(self, 'Select a directory', download_path) if fname: # Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system. # On Windows, toNativeSeparators("c:/winnt/system32") returns # "c:\winnt\system32". fname = QDir.toNativeSeparators(fname) self.download_folder_lineEdit.setText(fname) self.persepolis_setting.setValue('settings/download_path', str(fname))
def GenerateImage(self): self.statusBar().showMessage('Generating image...') self._createProgressBar() if self.config["save_route"] is None: self.config["save_route"] = THISDIR save_to_route = QFileDialog.getExistingDirectory(self, "Where to save the image", self.config["save_route"], QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) if self.config["save_route"] != save_to_route: temp_file = open(THISDIR + "\\config\\config.json", "r", encoding="utf-8") fp_teams = json.loads(temp_file.read()) fp_teams["save_route"] = save_to_route fp_teams["image_route"] = self.bg_image new_file = open(THISDIR + "\\config\\config.json", "w+", encoding="utf-8") new_file.write(json.dumps(fp_teams, indent=4)) new_file.close() self.background = Image.open(THISDIR + "\\images\\mat.png") self.table_border = Image.open(THISDIR + "\\images\\table_border.png") self.tech_lines = Image.open(THISDIR + "\\images\\technical_lines.png") self.thread = QThread() east_id = self.SearchTeamID(self.cloth_east, True) south_id = self.SearchTeamID(self.cloth_south, True) west_id = self.SearchTeamID(self.cloth_west, True) north_id = self.SearchTeamID(self.cloth_north, True) self.worker = GenerateImageThread(self.background, self.table_border, east_id, south_id, west_id, north_id, self.technical_lines.isChecked(), save_to_route, self.bg_image) self.worker.moveToThread(self.thread) self.thread.started.connect(self.worker.run) self.worker.update_progress.connect(self.UpdateStatus) self.worker.finished.connect(self.thread.quit) self.worker.finished.connect(self.worker.deleteLater) self.thread.finished.connect(self.thread.deleteLater) self.thread.finished.connect(self.GeneratedDialog) self.thread.start()
class Path_selector(QWidget): def __init__(self, type): super().__init__() if not (type == 'file' or type == 'folder'): raise Exception( "invalid type when initializing Path_selector class instance") self.type = type self.label = QLabel(f"Select a {type}", self) self.input = QLineEdit(self) self.button = QPushButton(f"Select {type}", self) self.button.clicked.connect(self.navigate_for_path) self.layout = QHBoxLayout(self) self.layout.addWidget(self.label) self.layout.addWidget(self.input) self.layout.addWidget(self.button) self.resize(500, 200) def navigate_for_path(self): self.dialog = QFileDialog(self) path = "" if self.type == 'file': self.dialog.setFileMode(QFileDialog.ExistingFile) self.dialog.setNameFilter("Text files (*.txt)") self.dialog.exec() path = self.dialog.selectedFiles()[0] #path = self.dialog.getOpenFileName(self)[0] elif self.type == 'folder': path = self.dialog.getExistingDirectory(self) print(path) self.input.setText(path) return def get_path(self): return self.input.text()
def eventFilter(self, source: QLineEdit, event: Union[QDropEvent, QMouseEvent, QDragEnterEvent]): if event.type() == QEvent.DragEnter: event.accept() elif event.type() == QEvent.Drop: # 任何拖放事件 都先清空原来的内容 source.clear() md = event.mimeData() # type: QMimeData if md.hasUrls() and len(md.urls()) == 1: path = md.urls()[0].toLocalFile() if os.path.exists(path): source.setText(path) self.update_name.emit(path) return True elif event.type() == QEvent.MouseButtonDblClick: # 选择本地headers.json文件 filePath = QFileDialog.getExistingDirectory( None, "select save dir", './') if filePath and os.path.exists(filePath): source.clear() source.setText(filePath) self.update_name.emit(filePath) return True return super(SaveDirQLineEdit, self).eventFilter(source, event)
def select_image_path(self): self.image_path = QFileDialog.getExistingDirectory(parent=self, caption="Select the folder containing the images of interest.", options=QFileDialog.ShowDirsOnly)
def onClickFileSearch(self): fileSearch = QFileDialog.getExistingDirectory(self, "Select a Directory...", "C:/Users") self.userFilepath.setText(fileSearch)
def open_encrypt_files_dialog(key: Key, progress_title='正在处理', caption_files='选择需要加密的文件', caption_output_dir='选择输出目录', file_filter='All Files (*);;Text Files (*.txt)', parent=None): file_list, _ = QFileDialog.getOpenFileNames(parent, caption=caption_files, filter=file_filter) if len(file_list) == 0: return dir_path = QFileDialog.getExistingDirectory(None, caption_output_dir, "C:/") if dir_path == '' or not os.path.exists(dir_path): return pd = QProgressDialog(parent) pd.setMinimumDuration(1000) pd.setAutoClose(True) pd.setAutoReset(False) pd.setLabelText('正在处理') pd.setCancelButtonText('取消') pd.setRange(0, len(file_list)) pd.setValue(0) pd.setWindowModality(Qt.WindowModal) pd.show() try: for index, file_path in enumerate(file_list): if pd.wasCanceled(): break pd.setLabelText('正在处理 {}/{}'.format(str(index + 1), len(file_list))) if os.path.exists(file_path): p, n = os.path.split(file_path) file_content = read_file(file_path) if not is_encrypt_data(file_content): encrypt_content = encrypt_data(key.key, file_content) output_file = os.path.join(dir_path, n) write_file(output_file, encrypt_content) pd.setValue(pd.value() + 1) if not pd.wasCanceled(): QMessageBox.information(pd, '处理完成', '加密完成') else: QMessageBox.information(pd, '已经终止', '用户取消') except Exception as e: pass QMessageBox.critical(pd, '处理失败', str(e)) pd.close()
def source_dir_dialog(self): selected_dir = QFileDialog.getExistingDirectory(self.parent(), 'Select a source directory', options=QFileDialog.ShowDirsOnly) self.source_dir.setText(selected_dir)
def repoPath(self): tmp = QFileDialog.getExistingDirectory(self, "Open config", os.getcwd()) self.ui.path.setText(tmp)
def edit_repo_location(self): dir = QFileDialog.getExistingDirectory( self, 'Location of the repository', self.ui.lineEditRepoLocation.text()) if dir is not None: self.ui.lineEditRepoLocation.setText(dir)
def folderOpenDialog(parent: Optional[QWidget], title: str, folder: str = '') -> Path: path = QFileDialog.getExistingDirectory(parent, title, folder, QFileDialog.ShowDirsOnly) return Path(path) if path else None
def target_dir_dialog(self): selected_dir = QFileDialog.getExistingDirectory(self.parent(), 'Select a target directory', options=QFileDialog.ShowDirsOnly) self.target_dir.setText(selected_dir)
def slot_edit_save_folder(self): dir = QFileDialog.getExistingDirectory( self, 'Folder in which all save states should be copied', self.ui.lineEditSaveFolder.text()) if dir is not None: self.ui.lineEditSaveFolder.setText(dir)
def open_dialog(self): self.output_dir.setText( QFileDialog.getExistingDirectory( options=QFileDialog.ShowDirsOnly))