def target_button_clicked_slot(self): '''doc''' self.target_button.setDisabled(True) select_dir = QFileDialog.getExistingDirectory() if os.path.isdir(select_dir): self.target_box.setText(select_dir) self.target_button.setDisabled(False)
def openProject(self, folderName=None): """ If no project name is supplied, it will open a file dialog so that the user can select a project file or project folder. :param folderName: Name of a folder with a project :type folderName: basestring """ fileName = "" if folderName: fileName = folderName else: fileName = QFileDialog.getExistingDirectory( self, "Open project", "", QFileDialog.ShowDirsOnly) if len(fileName) > 0: fullName = fileName + ProjectController.Instance().ProjectFile if os.path.isfile(fullName): self.multiDataWidget.transformations.clear() loaded = ProjectController.Instance().loadProject(fileName) if loaded: RegistrationShop.settings.setValue("project/lastProject", fileName) else: print "Couldn't load project:", folderName else: print "Warning: Project file does not exist" RegistrationShop.settings.remove("project/lastProject")
def append_folder_of_reports(self): fdirectoryname = QFileDialog.getExistingDirectory() all_files = os.listdir(fdirectoryname) for f in all_files: if f[0] != ".": self.append_one_report(fdirectoryname+ "/" + f) self.gprint("Appending report" + f)
def createNetwork(self): token_path = QFileDialog.getExistingDirectory(self, "Choose a directory") if not token_path: return self.settings['path'] = token_path self.load_data()
def __init__(self, parent=None): QWidget.__init__(self, parent) self.setupUi(self) self.settings = QSettings(QSettings.IniFormat, QSettings.UserScope, COMPANY, APPNAME) self.restoreGeometry(self.settings.value(self.__class__.__name__)) self.images = [] if len(sys.argv) > 1: d = QDir(path=sys.argv[1]) else: d = QDir(path=QFileDialog.getExistingDirectory()) d.setNameFilters(['*.png']) d.setFilter(QDir.Files or QDir.NoDotAndDotDot) d = QDirIterator(d) images = [] while d.hasNext(): images.append(d.next()) for i in images: print i self.images = [QImage(i) for i in images] self.images += [crop_image_from_file(i, 50)[0] for i in images]
def loadCorpus(self): corpus_path = QFileDialog.getExistingDirectory(self, "Choose a directory") if not corpus_path: return self.settings.setValue('path',corpus_path) self.setUpCorpus()
def set_folder(self): directions = "Select a folder for " + self.var_name new_value = QFileDialog.getExistingDirectory(self, directions, dir=os.path.dirname(self.full_path), options=QFileDialog.ShowDirsOnly) new_value = re.sub(self.project_root_dir, "", new_value) self.set_myvalue(new_value) if self.handler is not None: self.handler()
def fileChoosing(): global directory filePicker = QFileDialog() directory = filePicker.getExistingDirectory(parent, "Get Directory") directoryLabel.setText("Directory: " + directory) filePicker.destroy()
def extractToText(self): try: now = datetime.now().isoformat().split('T') filename='scanLog_' + now[0][0:10] + '_' + now[1][0:8] + '.txt' flags = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly folder = QFileDialog.getExistingDirectory(self._theMainWindow.theHistory.theResults, langmodule.chooseFolderToStoreText, homeDir, flags) print(filename) print(manager._resultsToPrint) path = folder + '/' + filename with open(path, 'w') as file: file.write(langmodule.userTitle + '\t\t\t' + langmodule.noOfResultsTitle + '\t\t' + langmodule.scanDateTimeTitle + '\n') # linux specific newline - not portable! file.write("----------------------------------------------------------------------------------" + '\n') # linux specific newline - not portable! for inlist in manager._resultsToPrint: file.write(inlist[0] + '\t\t\t') file.write(inlist[1] + '\t\t\t\t\t') file.write(inlist[2] + '\n') # linux specific newline - not portable! file.close() except IOError as error: print(str(error)[0:13]) if "Permission denied" in str(error): QMessageBox.critical(None, langmodule.attention, langmodule.noAccessRightsInFolder, QMessageBox.Ok | QMessageBox.Default, QMessageBox.NoButton) except Exception: QMessageBox.critical(None, langmodule.attention, langmodule.errorStoringFile, QMessageBox.Ok | QMessageBox.Default, QMessageBox.NoButton)
def chooseOntologyPath(self): """ Choose a path from the QFileDialog. """ path = self.path.text() path = QFileDialog.getExistingDirectory(self, 'Choose Directory', path) self.path.setText(path)
def on_outputLocationBrowseButton_clicked(self,): # Prompt for file name dirname = QFileDialog.getExistingDirectory(self, "Select Output Folder", self._ui.outputLocationLineEdit.text(), QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) # Returns a tuple of (filename, filetype) if dirname is not None and len(dirname) > 0: self._ui.outputLocationLineEdit.setText(dirname)
def open_directory(self, label): """Call a dialog window asking to a directory to use.""" options = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly directory = QFileDialog.getExistingDirectory(self, "Toyunda-tools", label.text(), options) if directory: label.setText(directory)
def _openFolderChoiceDialog(self): folder = QFileDialog.getExistingDirectory(self, caption=self.tr("Choose output directory")) if not folder: self.label_output.setText("<font style='color:red;'>" + self.tr("Please choose an output folder") + "</font>") else: self.label_output.setText(folder) self._output_folder = folder
def selectMasterFolder(self): self.__dataDir = QFileDialog.getExistingDirectory( self, "select master data directory", os.path.expanduser("~/")) self.__dataDirValid = True print(self.__dataDir) self.masterPathLabel.setText(self.__dataDir) self.__setInputUIEnabled(True) self.stopButton.setEnabled(False)
def browseFolder(self): path = self.parentWin._previousPath if not path: path = '' path = QFileDialog.getExistingDirectory(self, 'Select Folder', path) if path: self.parentWin._previousPath = path return path
def select_dir(self): ''' Opens a dialog box and selects a directory ''' startDir = self.loadLineEdit.text() directory = QFileDialog.getExistingDirectory(dir=startDir) if (directory): self.loadLineEdit.setText(directory)
def open_file_dialog(): dir_name = QFileDialog.getExistingDirectory(GlobalElements.MainWindow, u"Wybierz folder", GlobalElements.LoadFilesDialog.findChild(QLineEdit, "lineEditDirectory").text()) if dir_name: print("Directory changed to: " + dir_name) GlobalElements.StatusBar.showMessage(u"Zmiana folderu na " + dir_name) GlobalElements.LoadFilesDialog.findChild(QLineEdit, "lineEditDirectory").setText(dir_name)
def InvokeSingleSelectionDirectoryDialog(self): """ Prompts the user to select a single directory from a directory dialog window. """ dialog = QFileDialog() dialog.setFileMode(QFileDialog.DirectoryOnly) DirectoryName = dialog.getExistingDirectory() if len(DirectoryName) == 0: DirectoryName = None return DirectoryName
def set_output_directory(self): dir_set = False while not dir_set: dir = QFileDialog.getExistingDirectory( self, "Select Directory", ROBOCOMP_COMP_DIR, QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) if self.check_dir_is_empty(str(dir)): self._dir_line_edit.setText(dir) dir_set = True
def searchWorkspace(self): """Seach a workspace.""" path = QFileDialog.getExistingDirectory( self, self.tr('Choose a workspace for your Sci Corpus'), self.tr(self.workspace)) if path != '': self.createDir() self.workspace = os.path.abspath(path) self.ui.lineEditWorkspace.setText(os.path.abspath(path))
def _localLocationClicked(self): location = QFileDialog.getExistingDirectory( self, 'Select Image File(s) Location', self._ui.previousLocationLabel.text()) if location: self._ui.previousLocationLabel.setText(location) self._ui.localLineEdit.setText( os.path.relpath(location, self._workflow_location))
def directoryPathChooserClicked(self, textfield): """ QT Slot handles when the directory chooser is clicked. Parameter : - textfield : The QLineEdit where to output the choosen path. """ path = textfield.text() path = QFileDialog.getExistingDirectory(self, "Select Folder", path) textfield.setText(path)
def addFolder(self): folder = QFileDialog.getExistingDirectory(self, "Select folder") if len(folder): if folder not in self.config["folders"]: self.config["folders"].append(folder) fileUtils.save_config(self.config) self.browser.refreshView(self.config)
def on_publishMicProjectButton_clicked(self): """ Called when user clicks on the 'Publish project directory' button. """ projectPath = self._currentProjectObj.currentProjectPath selectedPath = QFileDialog.getExistingDirectory(self.mainWindow, "Select directory to publish", dir=projectPath) if selectedPath is None or len(selectedPath) < 1: return self.manager.addDirectoryToServer(selectedPath)
def emitFolderSelected(self): global scanPath options = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly scanPath = QFileDialog.getExistingDirectory(self._theMainWindow.theScan.theSelect, langmodule.chooseFolderToScan, '/home', options) print("scan path is: " + scanPath) if scanPath == "": scanPath=None return else: self._theMainWindow.theScan.infoLabel.setText(langmodule.scanFolderTitle) self._theMainWindow.theScan.fileToScanLabel.setText(str(scanPath)) self._theMainWindow.theScan.theSelect.close()
def select_save_dir(self): directory = QFileDialog.getExistingDirectory( None, self.tr("Select save dir"), os.path.abspath(self.edtSaveDirectory.text())) if not directory: return if directory.startswith(os.path.abspath(os.curdir)): directory = os.path.relpath(directory, '.') self.edtSaveDirectory.setText(directory)
def addFolderAction(self): folderPath = QFileDialog.getExistingDirectory(self, "Add Folder", "/") if len(folderPath): if "folders" in self.config: self.config["folders"].append(folderPath) else: self.config["folders"] = [folderPath] fileUtils.saveConfig(self.config) # refresh folder list self.folderList.refresh()
def displayDBFileBrowser(self): # Display a file browser for the user to select the database directory dbFile = str( QFileDialog.getExistingDirectory(self, "Select DB Directory")) if (not dbFile): dbFile = self.defaultDBLocation self.textBrowser_dbLocation.setText(dbFile) # Set the datamanager object dbFile based on the user's browse choice self.dm.db_filename = dbFile
def onBrowseClicked(self): """Slot. Called when the user clicks on the `browseButton` button""" # Presents the user with a native directory selector window localdir = QFileDialog.getExistingDirectory() localdir = QDir.fromNativeSeparators(localdir) if len(localdir) > 0: # If `localdir`'s value is good, store it using a `QSettings` object # and triggers a sync request. # Careful with '\' separators on Windows. localdir = QDir.toNativeSeparators(localdir) get_settings().setValue(SettingsKeys['localdir'], localdir) self.localdirEdit.setText(localdir)
def select_path_clicked(): dialog = QFileDialog() path = dialog.getExistingDirectory() config['save_folder_path'] = path config['backup_folder_path'] = os.path.join(path, "backups") config['remote_folder_path'] = os.path.join(path, "remote") if not os.path.exists(config['backup_folder_path']): os.mkdir(config['backup_folder_path']) update_save_list() save_config()
def input_out_dir(self): DataDir = os.path.dirname(__file__) outputdir = QFileDialog.getExistingDirectory(self, 'выберете дирректорию', DataDir) if not outputdir == '': self.OUT_dir = outputdir self.TXT_OUTFOLDER.setText(str(self.OUT_dir)) self.unlock_export( 2) #разблокирует экспорт, если заданы разграфка и дирректория else: return print('orthoBounds=', len(self.orthoBounds))
def open_repository(self): dir_path = QFileDialog.getExistingDirectory(self, self.tr("Open Repository")) if not dir_path: return kwargs = dict(git=self.app.workspace.git, parent=self) if self.app.workspace.git.is_git_dir(dir_path): kwargs["git_dir"] = dir_path else: kwargs["work_tree_dir"] = dir_path dialog = OpenRepositoryDialog(**kwargs) if dialog.exec_() == dialog.Accepted: with busy_cursor(): repo = Repo(work_tree_dir=dialog.work_tree_dir, git_dir=dialog.git_dir) self.app.workspace.add_repo(repo)
def open_file_dialog(self): """ Function manages the selection of files, you can recover the sender signal to change the state of the button. """ flags = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly directory = QFileDialog.getExistingDirectory( self, "Open Directory", os.getcwd(), flags) if self.sender() is self.sourceButton: self.sender().setText(directory) self.mainthread.spath = directory if self.sender() is self.doublonButton: self.sender().setText(directory) self.mainthread.dpath = directory
def on_scan_btn_clicked(self): """ The `Scan Directory` button is pressed """ path = QFileDialog.getExistingDirectory( self.base, _("Select a directory with books or " "your eReader's drive"), self.base.last_dir, QFileDialog.ShowDirsOnly) if path: self.base.last_dir = path self.base.high_list.clear() self.base.reload_highlights = True self.base.loading_thread(Scanner, path, self.base.kor_text, clear=False)
def choose_processed(self): """Prompts the user to choose the processed directory """ directory = QFileDialog.getExistingDirectory(self, "Choose the processed directory", str(self._processed)) if directory: directory = Path(directory) if directory == self._inbox: raise ValueError('The inbox directory cannot be the same as ' 'the processed directory') else: self._processed = directory print('New processed directory [{0}]'.format(self._processed)) self._controls.processed.set_link(str(self._processed.as_uri()), self._processed.name) QSettings().setValue('processed', str(self._processed))
def choose_processed(self): """Prompts the user to choose the processed directory """ directory = QFileDialog.getExistingDirectory( self, "Choose the processed directory", str(self._processed)) if directory: directory = Path(directory) if directory == self._inbox: raise ValueError('The inbox directory cannot be the same as ' 'the processed directory') else: self._processed = directory print('New processed directory [{0}]'.format(self._processed)) self._controls.processed.set_link( str(self._processed.as_uri()), self._processed.name) QSettings().setValue('processed', str(self._processed))
def exportTokens(self): export_path = QFileDialog.getExistingDirectory(self, "Choose a directory") if not export_path: return corpus_path = self.settings.value('path','') DBSession = sessionmaker(bind=self.engine) session = DBSession() qs = session.query(WordToken) print(qs) qs = qs.join(WordToken.wordtype) print(qs) qs = qs.join(WordToken.dialog) print(qs) qs = qs.filter(WordType.orth.in_(GOOD_WORDS)).order_by(Dialog.id) cur_dialog = '' for wt in qs: #if not wt.wordtype.is_word(): # continue if cur_dialog != wt.dialog.number: apath = os.path.join(corpus_path,'Processed','%sa.wav' % wt.dialog.number) bpath = os.path.join(corpus_path,'Processed','%sb.wav' % wt.dialog.number) if os.path.exists(apath): sr, a = wavfile.read(apath) else: a = None if os.path.exists(bpath): sr, b = wavfile.read(bpath) else: b = None filename = os.path.join(export_path,'%s_%s%s_%s_%d.wav' % (wt.dialog.speaker.number, wt.dialog.number, wt.dialog_part, wt.wordtype.orth, wt.id)) begin = int(wt.begin * sr) end = int(wt.end * sr) if wt.dialog_part == 'a': out = a[begin:end] else: out = b[begin:end] newsr = 16000 if newsr != sr: numt = int((wt.end - wt.begin) * 16000) out = resample(out,numt) wavfile.write(filename,sr,out)
def saveProjectAs(self): """ Opens a file dialog so that the user can select a folder in which to save the project. """ # Open file dialog fileName = QFileDialog.getExistingDirectory(self, "Select project folder", "", QFileDialog.ShowDirsOnly) if len(fileName) > 0: # TODO: check for existing project! # Set filename of project ProjectController.Instance().currentProject.folder = fileName # Call save project self.saveProject()
def create_repository(self): dir_path = QFileDialog.getExistingDirectory(self, self.tr("Create Repository")) if not dir_path: return dialog = CreateRepositoryDialog(git=self.app.workspace.git, repo_dir=dir_path, parent=self) if dialog.exec_() == dialog.Accepted: with busy_cursor(): self.app.workspace.git.init( dialog.repo_dir, bare=dialog.bare, shared=dialog.shared, template_dir=dialog.template_dir, separate_git_dir=dialog.git_dir, ) if dialog.bare: repo = Repo(work_tree_dir=None, git_dir=dialog.repo_dir) else: repo = Repo(work_tree_dir=dialog.repo_dir) self.app.workspace.add_repo(repo)
def open_folder(self): self.imagesList.clear() if not self.current_directory: self.current_directory = QFileDialog.getExistingDirectory(parent=self, caption=u'Add images from directory') folder = QDir(self.current_directory) folder.setNameFilters(['*.png']) folder.setFilter(QDir.Files or QDir.NoDotAndDotDot) dir_iterator = QDirIterator(folder, flags=QDirIterator.Subdirectories, filters=QDir.Files) images = [] while dir_iterator.hasNext(): images.append(folder.relativeFilePath(dir_iterator.next())) self.white_albatross.addImages(folder, images) self.imagesList.addItems(images)
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.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.downloadthread.dumpuser.sig.connect(self.dumpUser) self.downloadthread.course_finished.sig.connect( self.myStream_message) self.downloadthread.signal_error.sig.connect(self.myStream_message)
def select_source(self, *args): ''' Method for selecting the source directory of the sounding data that was collected ''' self.log.info('Setting the source directory') src_dir = QFileDialog.getExistingDirectory( dir = _desktop ); # Open a selection dialog self.src_dir = None if src_dir == '' else src_dir; # Update the src_dir attribute based on the value of src_dir if self.src_dir is None: # If the src_dir attribute is None self.log.warning( 'No source directory set' ); # Log a warning self.reset_values( noDialog = True ); # Reset all the values in the GUI with no confirmation dialog else: # Else self.sourcePath.setText( src_dir ); # Set the sourcePath label text self.sourcePath.show(); # Show the sourcePath label self.sourceSet.show(); # Show the sourceSet icon if self.dst_dir is not None: # If the dst_dir attribute is not None self.copyButton.setEnabled( True ); # Set the 'Copy Files' button to enabled self.reset_values(noDialog = True, noSRC = True, noDST = True); # Reset all values excluding the src AND dst directory else: self.reset_values(noDialog = True, noSRC = True); # Reset all values excluding the src directory
def open_folder(self): self.imagesList.clear() if not self.current_directory: self.current_directory = QFileDialog.getExistingDirectory( parent=self, caption=u'Add images from directory') folder = QDir(self.current_directory) folder.setNameFilters(['*.png']) folder.setFilter(QDir.Files or QDir.NoDotAndDotDot) dir_iterator = QDirIterator(folder, flags=QDirIterator.Subdirectories, filters=QDir.Files) images = [] while dir_iterator.hasNext(): images.append(folder.relativeFilePath(dir_iterator.next())) self.white_albatross.addImages(folder, images) self.imagesList.addItems(images)
def getBasePath(self): if int(cmds.about(v=1)) < 2017: import shiboken from PySide.QtGui import QFileDialog, QWidget, QDialog else: import shiboken2 as shiboken from PySide2.QtWidgets import QFileDialog, QWidget, QDialog winName = "dialog_getDirectory" mayaWin = shiboken.wrapInstance( long(maya.OpenMayaUI.MQtUtil.mainWindow()), QWidget) existing_widgets = mayaWin.findChildren(QDialog, winName) if existing_widgets: map(lambda x: x.deleteLater(), existing_widgets) dialog = QFileDialog(mayaWin) dialog.setObjectName(winName) dialog.setDirectory(os.path.splitext(cmds.file(q=1, sceneName=1))[0]) choosedFolder = dialog.getExistingDirectory() if choosedFolder: self.lineEdit.setText(choosedFolder) self.cmd_loadList()
def select_dest(self, *args): ''' Method for selecting the destination directory of the sounding data that was collected ''' self.log.info('Setting the destination directory') dst_dir = QFileDialog.getExistingDirectory( dir = _desktop); # Open a selection dialog self.dst_dir = None if dst_dir == '' else dst_dir; # Update the dst_dir attribute based on the value of dst_dir if self.dst_dir is None: # If the dst_dir attribute is None self.log.warning( 'No destination directory set' ) # Log a warning self.reset_values( noDialog = True ) # Reset all the values in the GUI with no confirmation dialog else: # Else if 'IOP' in os.path.basename( self.dst_dir ).upper(): # If an IOP directory was selected self.log.debug('Moved IOP# from directory path as it is append later'); # Log some debugging information self.dst_dir = os.path.dirname( self.dst_dir ); # Remove the IOP directory from the destination directory self.destSet.show( ); # Set the destPath label text self.destPath.setText( self.dst_dir ) # Show the destPath label self.destPath.show() # Show the destSet icon if self.src_dir is not None: # If the src_dir attribute is not None self.copyButton.setEnabled( True ); # Set the 'Copy Files' button to enabled self.reset_values(noDialog = True, noSRC = True, noDST = True); # Reset all values excluding the src AND dst directory else: self.reset_values(noDialog = True, noDST = True); # Reset all values excluding the dst directory
def _localLocationClicked(self): location = QFileDialog.getExistingDirectory(self, 'Select Image File(s) Location', self._ui.previousLocationLabel.text()) if location: self._ui.previousLocationLabel.setText(location) self._ui.localLineEdit.setText(location)
def changeDir(self): d = QFileDialog.getExistingDirectory(self, "Open Directory", 'C:\\PatientData', QFileDialog.ShowDirsOnly) self.ui.leDir.setText(d)
def _change_path(self): """Change downloads path""" self._update_path(QFileDialog.getExistingDirectory(self))
def disp_dialog(self): """ displays the dialog which select a directory for output. """ fname = QFileDialog.getExistingDirectory() Constants.CONFIG.set('directories', 'current_song', fname) self.output_cur_dir_lbl.setText( Constants.CONFIG.get('directories', 'current_song'))
def batchExemplarReduction(self): token_dir = QFileDialog.getExistingDirectory(self, "Choose a directory") if not token_dir: return
def browseFiles(self): self.dirname = QFileDialog.getExistingDirectory(self, "Select file location", options=QFileDialog.ShowDirsOnly) self.location_combobox.insertItem(0, self.dirname) self.location_combobox.setCurrentIndex(0)
def fileChoosing(self): filePicker = QFileDialog() self.directory = filePicker.getExistingDirectory(self.parent, "Get Directory") self.directoryLabel.setText("Directory: " + self.directory) filePicker.destroy()
def requestDirectory(self): self.rootdir = QFileDialog.getExistingDirectory(self, "Set Working Directory", ".", QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks) self.showAll()
def open_directory(self): filename = QFileDialog.getExistingDirectory() if len(filename) > 0: self.ui.movieLineEdit.setText(filename)
def save(self): filepath = QFileDialog.getExistingDirectory(self, 'Select .MSH', os.getcwd()) for filename in os.listdir(self.outd): shutil.copy(os.path.join(self.outd, filename), filepath) self.cancel()