def on_browse(self, *_): dialog = QFileDialog(self) dialog.setFileMode(QFileDialog.DirectoryOnly) dialog.setViewMode(QFileDialog.Detail) dialog.setDirectory(self.le_output.text()) if dialog.exec_(): self.le_output.setText(dialog.selectedFiles()[0])
def _add(self): dialog = QFileDialog(self) dialog.setFileMode(QFileDialog.ExistingFiles) dialog.setViewMode(QFileDialog.Detail) fileNames = dialog.selectedFiles() if dialog.exec_() else [] for fileName in fileNames: layer = Layer() layer.load_file(fileName, None) self.list.add_layer(layer)
def cmdSfoglia_click(self): """Evento che gestisce il tasto per sfogliare il percorso""" dialog = QFileDialog(self) dialog.setFileMode(QFileDialog.AnyFile) dialog.setNameFilter("SQLite db (*.db)") dialog.setViewMode(QFileDialog.Detail) if dialog.exec_(): fileNames = dialog.selectedFiles() self.myWidget.txtPercorso.setText(fileNames[0]) self.InitTable()
def cmdSfoglia_click(self): """Evento che gestisce il tasto per sfogliare il percorso""" dialog = QFileDialog(self) dialog.setFileMode(QFileDialog.AnyFile) dialog.setNameFilter("SQLite db (*.db)") dialog.setViewMode(QFileDialog.Detail) if dialog.exec_(): fileNames = dialog.selectedFiles() self.myWidget.txtPercorso.setText( fileNames[0] ) self.InitTable()
def _create_control ( self, parent ): # If the caller provided a default path instead of a default directory # and filename, split the path into it directory and filename # components. if ((len( self.default_path ) != 0) and (len( self.default_directory ) == 0) and (len( self.default_filename ) == 0)): default_directory, default_filename = \ os.path.split( self.default_path ) else: default_directory = self.default_directory default_filename = self.default_filename # Convert the filter: keep = True filters = [] for f in self.wildcard.split( '|' ): if keep and f: filters.append( f ) keep = not keep # Set the default directory: if not default_directory: default_directory = QDir.currentPath() dlg = QFileDialog( parent, self.title, default_directory ) dlg.setViewMode( QFileDialog.Detail ) dlg.selectFile( default_filename ) dlg.setFilters( filters ) if self.wildcard_index < filters.count(): dlg.selectFilter( filters[ self.wildcard_index ] ) if self.action == 'open': dlg.setAcceptMode( QFileDialog.AcceptOpen ) dlg.setFileMode( QFileDialog.ExistingFile ) elif self.action == 'open files': dlg.setAcceptMode( QFileDialog.AcceptOpen ) dlg.setFileMode( QFileDialog.ExistingFiles ) else: dlg.setAcceptMode( QFileDialog.AcceptSave ) dlg.setFileMode( QFileDialog.AnyFile ) return dlg
def importF(self): fileBrowser = QFileDialog() fileBrowser.setFileMode(QFileDialog.Directory) fileBrowser.setViewMode(QFileDialog.Detail) fileBrowser.setOption(QFileDialog.ShowDirsOnly, True) if fileBrowser.exec_(): dir = fileBrowser.selectedFiles() else: print "Cancelled" return print "Copying data from " + str(dir[0]) files = os.listdir(str(dir[0])) copyOn = True print files for file in files: copyOn = True if file.endswith(".json"): if os.path.exists( os.path.join(json_reader.buildPath("data"), file)): if popup( "File " + file[:len(file) - 5] + " already exists. Overwrite?", "Warning"): os.remove(json_reader.buildPath("data/" + file)) else: copyOn = False if copyOn: print "Copying valid file " + file copy(os.path.join(str(dir[0]), file), json_reader.buildPath("data")) if "_link" not in file: try: #Ugly AF json_reader.readOne(file[:len(file) - 5]) json_reader.writeCharNames(file[:len(file) - 5]) except: print "Not a Character" try: json_reader.readP(file[:len(file) - 5]) json_reader.writePerNames(file[:len(file) - 5]) except Exception as e: print "Not a Persona" print e print "Successfully copied files" popup("Files imported successfully!", "Information")
def export(self): fileBrowser = QFileDialog() fileBrowser.setFileMode(QFileDialog.Directory) fileBrowser.setViewMode(QFileDialog.Detail) fileBrowser.setOption(QFileDialog.ShowDirsOnly, True) if fileBrowser.exec_(): dir = fileBrowser.selectedFiles() else: print "Cancelled" return print "Copying data to " + str(dir[0]) + "/exportdata" try: copytree(json_reader.buildPath("data"), str(dir[0]) + "/exportdata") except Exception as e: print e popup( "Error in copying files. There is a file in the selected directory that has the same name as a Story Creator file.\n\nFiles are copied to " + str(dir[0]) + "/exportdata" + ". Please ensure this directory does not already exist.", "Critical") return print "Successfully copied files" popup("Files exported successfully!", "Information")