def _browse(self): options = [ QtWidgets.QFileDialog.DontResolveSymlinks, QtWidgets.QFileDialog.DontUseNativeDialog ] folders = False if folders: # browse folders specifics caption = "Browse folders to publish image sequences" file_mode = QtWidgets.QFileDialog.Directory options.append(QtWidgets.QFileDialog.ShowDirsOnly) else: # browse files specifics caption = "Browse files to publish" file_mode = QtWidgets.QFileDialog.ExistingFiles # create the dialog file_dialog = QtWidgets.QFileDialog(parent=self, caption=caption) file_dialog.setLabelText(QtWidgets.QFileDialog.Accept, "Select") file_dialog.setLabelText(QtWidgets.QFileDialog.Reject, "Cancel") file_dialog.setFileMode(file_mode) # set the appropriate options for option in options: file_dialog.setOption(option) # browse! if not file_dialog.exec_(): return # process the browsed files/folders for publishing paths = file_dialog.selectedFiles() self.drop_frame._process_paths(paths)
def loadSimulation(self, fileName=None): """Loads the simulation from ts2 file""" if not fileName: dialog = QtWidgets.QFileDialog(self) dialog.setWindowTitle('Open Simulation to edit') dialog.setNameFilters(['All supported files (*.tss *.tsg *.json)', 'TS2 simulation (*.tss)', 'TS2 saved game (*.tsg)', 'JSON file (*.json)']) dialog.setDirectory(QtCore.QDir.currentPath()) dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile) if dialog.exec_() == QtWidgets.QDialog.Accepted: fileName = str(dialog.selectedFiles()[0]) if fileName: self.statusBar().showMessage("Loading", info=True, timeout=2) self.statusBar().showBusy(True) QtWidgets.qApp.setOverrideCursor(Qt.WaitCursor) if self.editor is not None: self.simulationDisconnect() self.editor = None # TODO: This is same code used elsewhere # maybe there is a clever way to share this in utils or alike try: if zipfile.is_zipfile(fileName): with zipfile.ZipFile(fileName) as zipArchive: with zipArchive.open("simulation.json") as file: self.editor = editor.load(self, file) else: with open(fileName) as file: self.editor = editor.load(self, file) except (utils.FormatException, utils.MissingDependencyException) as err: QtWidgets.QMessageBox.critical( self, self.tr("Error while loading the simulation"), str(err), QtWidgets.QMessageBox.Ok ) self.editor = None except Exception as err: dialogs.ExceptionDialog.popupException(self, err) self.editor = None else: self.editor.fileName = fileName self.setWindowTitle( self.tr("ts2 - Editor - %s") % fileName ) self.simulationConnect() self.optionsView.resizeColumnsToContents() self.trainTypesView.resizeColumnsToContents() self.statusBar().showMessage(self.tr("Ready") + " :-)", info=True, timeout=2) self.statusBar().showBusy(False) self._dirty = False finally: QtWidgets.qApp.restoreOverrideCursor()
def showPopup(self): fileDialog = QtWidgets.QFileDialog() # Grab the name of the directory self._value, _ = fileDialog.getOpenFileNames(self) nameList = [os.path.basename(value) for value in self._value] self.lineEdit.setText(', '.join(nameList))
def showPopup(self): fileDialog = QtWidgets.QFileDialog() # Grab the name of the directory self._value = fileDialog.getExistingDirectory(self) self.lineEdit.setText(self._value)
def on_software_browse_pressed(self): self.file_dialog = QtWidgets.QFileDialog() self.file_dialog.setDirectory(self.le_software_path.text()) self.file_dialog.setFileMode(self.file_dialog.Directory) path = self.file_dialog.getExistingDirectory(self, "Find and select the folder named: {0}".format(self.software_dir)) if path: self.le_software_path.setText(path) self._on_update_versions()
def on_browse_pressed(self): self.file_dialog = QtWidgets.QFileDialog(self, directory=self.le_install_dir.text()) self.file_dialog.setFileMode(self.file_dialog.Directory) path = self.file_dialog.getExistingDirectory(self, "Choose install directory") if path == "": pass else: self.le_install_dir.setText(path)
def loadFromFile(self): '''load buttons from a json file''' sel_json = QtWidgets.QFileDialog().getOpenFileName(self,"Select a TMDataset json file", os.path.join(os.getenv('HOME'), '.nuke'), 'JSON files (*.json)')[0] if sel_json: self.data_file = sel_json self.reloadMarkers() else: print "Inviald file path"
def get_folder_path(): """Gets a folder path from the user""" file_dialog = QtWidgets.QFileDialog() file_dialog.setFileMode(QtWidgets.QFileDialog.Directory) if file_dialog.exec_(): path = str(file_dialog.selectedFiles()[0]) return path else: return None
def browse_file_path(self): dialog = QtWidgets.QFileDialog(self) dialog.setWindowTitle("Browse File") dialog.setLabelText(dialog.Accept, "Choose Path") dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) if dialog.exec_() == QtWidgets.QDialog.Accepted: file_path = dialog.selectedFiles()[0] self.set_argument_value(file_path) self.mark_as_modified()
def choose_file_path(self): file_dialog = QtGui.QFileDialog() file_dialog.setFileMode(QtGui.QFileDialog.ExistingFile) current_text = self.file_path_cbox.currentText() if current_text: caption = os.path.dirname(current_text) else: caption = '/' file_path = file_dialog.getExistingDirectory(self, 'choose directory', caption) if file_path: file_path = file_path.replace('\\', '/') if self.file_path_cbox.findText(file_path) == -1: self.file_path_cbox.addItem(str(file_path)) self.file_path_cbox.setCurrentIndex( self.file_path_cbox.findText(file_path))
def onOpenSimulation(self): #d = opendialog.OpenDialog(self) #d.openFile.connect(self.loadSimulation) #d.exec_() dialog = QtWidgets.QFileDialog(self) dialog.setWindowTitle('Open Simulation') dialog.setNameFilters([ 'All supported files (*.tss *.tsg *.json)', 'TS2 simulation (*.tss)', 'TS2 saved game (*.tsg)', 'JSON file (*.json)' ]) dialog.setDirectory(QtCore.QDir.currentPath()) dialog.setFileMode(QtWidgets.QFileDialog.ExistingFile) if dialog.exec_() == QtWidgets.QDialog.Accepted: file_full_path = str(dialog.selectedFiles()[0]) self.loadSimulation(file_full_path)
def open_file_selector(self): """ Open the file selector. """ self.file_selector = QtWidgets.QFileDialog( options=QtWidgets.QFileDialog.DontUseNativeDialog) self.file_selector.setFileMode(QtWidgets.QFileDialog.ExistingFile) authorized_files = [ "All media files (*.png *.jpg *.jpeg *.mp4 *.mov *.wmv *.obj)", "Images (*.png *.jpg *.jpeg)", "Video (*.mp4 *.mov *.wmv)", "3D (*.obj)", ] self.file_selector.setNameFilters(authorized_files) self.file_selector.setViewMode(QtWidgets.QFileDialog.Detail) if self.file_selector.exec_(): selected_file = self.file_selector.selectedFiles() self.post_path = selected_file[0] self.update_selector_btn()
def show_dialog(self): if self._dialog is not None: self._dialog.show() return dialog = QtWidgets.QFileDialog(self) if self.use_directory: result = dialog.getExistingDirectory(self, 'Choose Directory', self.current_dir) elif self.use_file: result = dialog.getOpenFileName(self, 'Choose File', self.current_dir) else: result = dialog.getOpenFileName(self, 'Choose File', self.current_dir) if result: self.field.setText(result)
def saveAsSimulation(self): """Saves the simulation to a different database""" # DEBUG # fileName = "/home/nicolas/Progs/GitHub/ts2/data/drain-save.ts2" dialog = QtWidgets.QFileDialog(self) dialog.setWindowTitle('Save Simulation') dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setNameFilters(['All supported files (*.tss *.tsg *.json)', 'TS2 simulation (*.tss)', 'TS2 saved game (*.tsg)', 'JSON file (*.json)']) dialog.setDefaultSuffix("tss") dialog.setDirectory(QtCore.QDir.currentPath()) dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) # preset the current file if self.editor.fileName is not None: dialog.selectFile(self.editor.fileName) if dialog.exec_() == QtWidgets.QDialog.Accepted: fileName = str(dialog.selectedFiles()[0]) self.editor.fileName = fileName self.saveSimulation()
def on_browse_pressed(self): self.file_dialog = QtWidgets.QFileDialog() self.file_dialog.setFileMode(self.file_dialog.Directory) path = self.file_dialog.getExistingDirectory(self, "Choose mount directory") self.le_mount_point.setText(path)
def showPopup(self): fileDialog = QtWidgets.QFileDialog() # Grab the name of the directory self._value, _ = fileDialog.getOpenFileName(self) self.lineEdit.setText(self._value)