def import_from_excel(self): msg_box = QMessageBox() msg_box.setText( "Use one of the available templates to import your collection from an Excel spreadsheet." ) msg_box.setInformativeText( "Note: do not change the filename of the template.") msg_box.setStandardButtons(QMessageBox.Open | QMessageBox.Cancel) expanded = msg_box.addButton('Create Expanded...', QMessageBox.ApplyRole) condensed = msg_box.addButton('Create Condensed...', QMessageBox.ApplyRole) msg_box.setDefaultButton(QMessageBox.Cancel) ret = msg_box.exec_() if msg_box.clickedButton() == expanded: path = QFileDialog.getExistingDirectory( self, "Select Directory for Template...") + '/' import_export.generate_sheet(path, expanded=True) elif msg_box.clickedButton() == condensed: path = QFileDialog.getExistingDirectory( self, "Select Directory for Template...") + '/' import_export.generate_sheet(path, expanded=False) elif ret == QMessageBox.Open: path = QFileDialog.getOpenFileName( self, "Select Filled-Out Template...") import_export.import_db(path[0])
def select_song_folder(self): if directory := QFileDialog.getExistingDirectory( self.dialog_anchor, "Select Folder", os.getcwd() + "/output", options=QFileDialog.ShowDirsOnly | QFileDialog.DontUseNativeDialog): direct = QDir(os.getcwd()).relativeFilePath(directory) self.song_folder = direct self.update_song_filename()
def conformDatasetToCOCO(self): '''A function that is triggered by the button labelled, Generate Dataset.''' if not self.debug: path_to_labelled = QFileDialog.getExistingDirectory( self, 'Select your labeled dataset.', os.path.abspath('../data'), QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) else: path_to_labelled = '../data/datasets/p2p3_dummy_dataset' # Check if every image in given folder trainDirExists = os.path.exists(path_to_labelled + '/train_dataset') valDirExists = os.path.exists(path_to_labelled + '/val_dataset') outputTrainDir = '../data/datasets/custom_dataset/train_dataset' outputValDir = '../data/datasets/custom_dataset/val_dataset' if trainDirExists and valDirExists: self.label_train_process = subprocess.Popen([ 'python', 'dataset/labelme2coco.py', '--labels', self._path_to_label_list, path_to_labelled + '/train_dataset', outputTrainDir ]) if not self.debug: self.label_train_process.communicate() self.label_val_process = subprocess.Popen([ 'python', 'dataset/labelme2coco.py', '--labels', self._path_to_label_list, path_to_labelled + '/val_dataset', outputValDir ]) if not self.debug: self.label_val_process.communicate() else: print('Faulty labelled dataset detected.')
def browse(self, text_input): default = os.getcwd() if text_input.text(): default = text_input.text() text = QFileDialog.getExistingDirectory(self, "Choose directory", default) # Update gui input text_input.setText(text)
def _select_symlink_dir(self): symlink_dir = QFileDialog.getExistingDirectory( self, "Select directory for Julia executable", self.field("symlink_dir") ) if not symlink_dir: return self.setField("symlink_dir", symlink_dir)
def _select_install_dir(self): install_dir = QFileDialog.getExistingDirectory( self, "Select directory for Julia packages", self.field("install_dir") ) if not install_dir: return self.setField("install_dir", install_dir)
def restore_finish(self, paths, snapshot_id): self.status_label.clear() self.setEnabled(True) if len(paths) is 0: return restore_dir = QFileDialog.getExistingDirectory() if len(restore_dir) is 0: return self.restore_dir = restore_dir self.paths = paths self.snapshot_id = snapshot_id reply = QMessageBox.information( self.window, "Start Restore?", f"You are about to restore to {restore_dir}. Continue?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply is QMessageBox.No: return if len(os.listdir(restore_dir)) is not 0: reply = QMessageBox.information( self.window, "Potential Overwrite?", f"You are restoring to a non-empty folder! BlobBackup will OVERWRITE any conflicting paths. Continue?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply is QMessageBox.No: return self.accept()
def openFolderDialog(self): options = QFileDialog.Options(QFileDialog.ShowDirsOnly) options |= QFileDialog.DontUseNativeDialog # don't use Mac/Win/Linux dialog folder = QFileDialog.getExistingDirectory(self, self.title, options=options) return folder + '/'
def _getfile(self, message, button_name): dialog = QFileDialog() self.basefoldername = dialog.getExistingDirectory() button_name.setText(message + self.basefoldername) common_prefix = self.basefoldername self._view.texture_location_button.setDisabled(False) self._model._setmdlpath(self.basefoldername)
def actionStartExperiment(self): self.updateModel() if (len(self.model().sequence_scheme.graph.nodes) == 0): # No nodes in sequence scheme, cancel operation # TODO: A better way to signal to the user that he needs to create a sequence? self.central_widget.setCurrentWidget(self.sequence_editor) return results_path = QFileDialog.getExistingDirectory( caption="Select a folder to save experiment results", options=QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) if results_path == "": return False # Action was cancelled data = self.model().export() temp_dir = QDir.tempPath() + "/nfb_studio" os.makedirs(temp_dir, exist_ok=True) timestamp = datetime.now() file_path = "{}/experiment ({:04d}-{:02d}-{:02d} {:02d}-{:02d}-{:02d}).xml".format( temp_dir, timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second) with open(file_path, "w", encoding="utf-8") as file: file.write(data) proc = Process(target=run, args=(file_path, results_path)) proc.start() self._processes.append(proc)
def get_name(self): dir_dialog = QFileDialog.getExistingDirectory(self, 'תקיית הפרויקט', self.main_dir, QFileDialog.ShowDirsOnly) if dir_dialog: self.ui.QLProject_name.setText(basename(dir_dialog)) self.ui.QLProject_name.setEnabled(False)
def _select_julia_project(self): julia_project = QFileDialog.getExistingDirectory( self, "Select Julia project (directory)", self.field("julia_project")) if not julia_project: return self.setField("julia_project", julia_project)
def exportMarkdown(self): dir = QFileDialog.getExistingDirectory(self, 'Select output folder', './doc') path = os.path.join(dir, 'summary.md') assets = os.path.join(dir, 'assets') os.makedirs(assets, exist_ok=True) line = lambda it: f"|{'|'.join(it)}|\n" with open(path, 'w', encoding='utf8') as f: f.write('## Error Summary\n\n') f.write(f'> Auto generated from {self.conf_name}.\n\n') # table title f.write(line(DiagBag.header())) f.write(line([':-:'] * len(DiagBag.header()))) # content for i in range(len(self.raw)): d = self.raw[self.ui.tblDiag.item(i, 0).text()] if int(d.pm > self.thresh) != d.ym or (d.yb is not None and argmax(d.pb) != d.yb): pic = self.solver.pid2path(d.pid) QFile.copy(pic, os.path.join(assets, os.path.split(pic)[-1])) f.write(line(self.rich(d))) self.ui.statusbar.showMessage(f'{path} saved.', 3000)
def dir_open(): selected = QFileDialog.getExistingDirectory(self, "자막 폴더 선택") for paths, subdirs, files in os.walk(selected): for file in files: if fnmatch(file, '*.smi'): name = ntpath.basename(file) Utils.insert_list(self.file_list, name, file)
def _get_saveto_path(self): path = QFileDialog.getExistingDirectory( self, 'Save files to', os.getcwd(), ) return path
def func_browse_eve(self): folder = QDir.toNativeSeparators( QFileDialog.getExistingDirectory(None, "Eve Directory", "", QFileDialog.ShowDirsOnly)) if not folder.endswith(os.sep): folder += os.sep self.ui.txt_client_path.setText(folder) self.settings['eve_path'] = folder
def selectDirAction(self): select_dir = QFileDialog.getExistingDirectory(None, "请选择输出文件夹", "") if not select_dir: QMessageBox.critical(None, "错误", "请选择文件夹") return self.ui.dirLineEdit.setText(select_dir) self.out_dir = select_dir
def directory_button_clicked(self): self.clear() dialog = QFileDialog.getExistingDirectory( None, 'Select the directory of your generated batch', 'Generated/') self.selectedDirectory = dialog for item in os.listdir(dialog): extension = item.split('.') if extension[len(extension) - 1] == 'jpg' or extension[ len(extension) - 1] == 'png' or extension[len(extension) - 1] == 'jpeg': self.ui.fileList.addItem(ListWidgetItem(item)) for file in os.listdir(dialog): self.filelistpaths.append(dialog + "/" + file) splitdirpath = dialog.split("/") self.ui.lblSelectedDirectory.setText(splitdirpath[len(splitdirpath) - 1]) self.keyPointManager.batchName = splitdirpath[len(splitdirpath) - 2] # enable/disable generated button self.ui.generateDatasetButton.setEnabled( self.selectedDirectory is not None) self.ui.fileList.sortItems() self.ui.fileList.show()
def startScan(self): try: from watchdog.observers import Observer except ImportError: msgBox = QMessageBox() msgBox.setText("The 'watchdog' package not installed") msgBox.setInformativeText( "In order to use directory scanning, install watchdog package\n pip install watchdog") msgBox.exec() return self.lastScanedFits = None fileName = QFileDialog.getExistingDirectory(None, 'Select directory') if fileName: self.setNewestFits(fileName) self.createWorkerThread() self.scanAct.setVisible(False) self.stopAct.setVisible(True) self.pauseAct.setVisible(True) self.worker_thread.start() #powinno tu być ale jest w create self.worker.setActive(True) self.activeScan = True self.worker.setFileName(fileName) self.BtnStartScan.trigger() if self.enableAutopause: self.obserwableValue.autopauseFlag = True self.showAutopauseButton()
def browse_julia_project_path(self, checked=False): """Open file browser where user can select a Julia project path.""" answer = QFileDialog.getExistingDirectory( self, "Select Julia project directory", os.path.abspath("C:\\")) if not answer: # Canceled (american-english), cancelled (british-english) return self.ui.lineEdit_julia_project_path.setText(answer)
def get_folder_name(self): try: return QFileDialog.getExistingDirectory( self, "Файловый менеджер") except Lil_error as e: QMessageBox.about( self, "Предупреждение", str(e))
def get_directory_file_dialog(self, current_path, title=_("Verzeichnis auswählen"), file_filter='(*.*)'): if not path_exists(current_path) or current_path == '': current_path = Path(KnechtSettings.app.get('current_path')) else: current_path = Path(current_path) if self.mode == 'dir': current_path = QFileDialog.getExistingDirectory( self.parent, caption=title, dir=current_path.as_posix()) if not current_path: return else: current_path, file_type = QFileDialog.getOpenFileName( self.parent, caption=title, dir=current_path.as_posix(), filter=file_filter) if not file_type: return if self.mode == 'file2dir': if Path(current_path).is_file(): current_path = Path(current_path).parent current_path = Path(current_path) self.set_path(current_path) return current_path
def select_dataset_directory(self): dirs = QFileDialog.getExistingDirectory(None, 'Select a batch', 'Datasets/') if not dirs: return path_array = dirs.split('/') self.batchName = path_array[len(path_array) - 1] print("Selected Batch: " + self.batchName) self.postures = os.listdir(dirs) self.data = [] count = 0 self.labels = [] for pose in self.postures: file_names = os.listdir(self.data_folder_path + self.batchName + '/' + pose) for file in file_names: print("Processing: " + file) self.data.append( pd.read_csv(self.data_folder_path + self.batchName + '/' + pose + "/" + file).values) for i in range(len(self.data[count])): self.labels.append(pose) count += 1 self.ui.batchNameLabel.setText(self.batchName)
def export_path_json(self): from PySide2.QtWidgets import QFileDialog file_dir = QFileDialog.getExistingDirectory(self, "Save plot .json file...", os.getcwd(), QFileDialog.ShowDirsOnly) if file_dir: self._plot_worker.export_path_json(self._layer, file_dir)
def _pick_logs_directory(self): dir_path = QFileDialog.getExistingDirectory(self, "Logs directory") if dir_path: self._logs_path_textbox.setText(dir_path) else: LOGGER.info("Picking Log directory cancelled.")
def on_browse_installation_dir(self): install_dir = str( QFileDialog.getExistingDirectory( self, "Select DCS Installation Directory")) if install_dir: self.dcs_install_dir = install_dir self.edit_dcs_install_dir.setText(install_dir)
def handle_pushButton_cmos_snr_linearity_clicked(self, checked): print("cmos_snr_linearity pushButton clicked", self) i = 0 filePath = QFileDialog.getExistingDirectory(self.ui, "选择存储路径") for root, dirs, files in os.walk(filePath): for f in files: i = i + 1 # 统计文件夹内总共有几个文件 print("i=", i) if i < 2: # 少于2个文件,无法测试线性化程度 QMessageBox.warning( self.ui, '文件太少', '文件夹内文件数目必须大于1个') return filename = [0] * i # 初始化成员为i个的一个列表 Rvalue = [0] * i GRvalue = [0] * i GBvalue = [0] * i Bvalue = [0] * i width = int(self.ui.lineEdit_cmos_snr_width.text()) height = int(self.ui.lineEdit_cmos_snr_height.text()) w_percent = int(self.ui.lineEdit_cmos_snr_w_percent.text()) / 100 h_percent = int(self.ui.lineEdit_cmos_snr_h_percent.text()) / 100 pattern = self.ui.comboBox_cmos_snr_cfa.currentText() dataformat = self.ui.comboBox_cmos_snr_dataformat.currentText() shift_bits = int(self.ui.comboBox_cmos_snr_bitshift.currentText()) WidthBorder = round((1 - w_percent) * width / 4) HeightBorder = round((1 - h_percent) * height / 4) # print("WidthBorder:", WidthBorder, HeightBorder, (width / 2 - WidthBorder), (height / 2 - HeightBorder)) i = 0 for root, dirs, files in os.walk(filePath): for f in files: filename[i] = os.path.join(root, f) # 将文件名填写到列表中 iamge = rawimage.read_plained_file(filename[i], "uint16", width, height, dataformat) R, GR, GB, B, G = rawimage.bayer_channel_separation(iamge, pattern) R = R[HeightBorder:int(height / 2 - HeightBorder), WidthBorder:int(width / 2 - WidthBorder)] GR = GR[HeightBorder:int(height / 2 - HeightBorder), WidthBorder:int(width / 2 - WidthBorder)] GB = GB[HeightBorder:int(height / 2 - HeightBorder), WidthBorder:int(width / 2 - WidthBorder)] B = B[HeightBorder:int(height / 2 - HeightBorder), WidthBorder:int(width / 2 - WidthBorder)] # print("shape:", np.shape(R)) Rvalue[i] = np.mean(R) GRvalue[i] = np.mean(GR) GBvalue[i] = np.mean(GB) Bvalue[i] = np.mean(B) print(filename[i]) i = i + 1 print("len = ", len(filename)) x = np.arange(0, i) plt.plot(x, Rvalue, "r", label="R") plt.plot(x, GRvalue, "g", label="GR") plt.plot(x, GBvalue, "c", label="GB") plt.plot(x, Bvalue, "b", label="B") plt.title("Linearity") plt.legend(loc="lower right") plt.show() self.ui.close()
def on_browse_saved_games(self): saved_game_dir = str( QFileDialog.getExistingDirectory( self, "Select DCS Saved Game Directory")) if saved_game_dir: self.saved_game_dir = saved_game_dir self.edit_saved_game_dir.setText(saved_game_dir)
def openProject(self, path=None): if not path: path = QFileDialog.getExistingDirectory( self, "Choose image directory", dir=self.lastProjectDirectory) if path: self.closeProject() self.view = View(self) self.view.previous.connect(self.onPrevious) self.view.next.connect(self.onNext) self.container.layout().addWidget(self.view) filename = Path(path) / "items.json" if filename.exists(): with io.open(filename, 'r') as f: self.items = json.load(f) else: self.items = dict() for filename in find_images(Path(path)): if filename in self.items: continue self.items[filename] = dict({"active": True}) self.refreshItems() self.files.setItemSelected(self.files.item(0), True) self.enableProjectActions(True) self.lastProjectDirectory = path self.saveProject() self.saveSettings()
def get_project_directory(self): """Asks the user to select a new project directory. If the selected directory is already a Spine Toolbox project directory, asks if overwrite is ok. Used when opening a project from an old style project file (.proj). Returns: str: Path to project directory or an empty string if operation is canceled. """ # Ask user for a new directory where to save the project answer = QFileDialog.getExistingDirectory(self._toolbox, "Select a project directory", os.path.abspath("C:\\")) if not answer: # Canceled (american-english), cancelled (british-english) return "" if not os.path.isdir(answer): # Check that it's a directory msg = "Selection is not a directory, please try again" # noinspection PyCallByClass, PyArgumentList QMessageBox.warning(self._toolbox, "Invalid selection", msg) return "" # Check if the selected directory is already a project directory and ask if overwrite is ok if os.path.isdir(os.path.join(answer, ".spinetoolbox")): msg = ( "Directory \n\n{0}\n\nalready contains a Spine Toolbox project." "\n\nWould you like to overwrite it?".format(answer) ) message_box = QMessageBox( QMessageBox.Question, "Overwrite?", msg, buttons=QMessageBox.Ok | QMessageBox.Cancel, parent=self._toolbox, ) message_box.button(QMessageBox.Ok).setText("Overwrite") msgbox_answer = message_box.exec_() if msgbox_answer != QMessageBox.Ok: return "" return answer # New project directory
def browse(self): open_dir = self.path_label.text() path = QFileDialog.getExistingDirectory( self, 'Open directory', open_dir, QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) if path: self.path_label.setText(path + '/')
def chooserootdir(self): currentdir = self.settings['RootFolder'] flags = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly newroot = QFileDialog.getExistingDirectory(None, "Open Directory", currentdir, flags) if newroot != "" and str(newroot) != currentdir: self.settings['RootFolder'] = str(newroot) filesettings.settingsToFile(self.settings, self.settings_path) self._window.rootfolder.setText(newroot) # we delete the already present downloadthread and recreate it # because otherwise it uses the old download folder. I don't know # if there's a cleaner approach del self.downloadthread self.downloadthread = DownloadThread(self.user, self.settings['RootFolder'], self) self.downloadthread.dumpuser.sig.connect(self.dumpUser) self.dumpUser()