def onFromFile(self, filename=None, **kwargs): '''imports Master curve from a two-column ASCII file. The first colum will be interpreted to be the abcissas. If filename is not given, a dialog for choosing a file is presented kwargs can contain keyword arguments to pass to numpy.loadtxt() when reading each file accepted keywords and their default values are: {dtype=<type 'float'>, comments='#', delimiter=None, converters=None, skiprows=0, usecols=None, unpack=False} see help from numpy.loadtxt for more info on the kwargs''' if filename is None: filename, _ = compat.getOpenFileName(self, 'Choose input file', '', 'Ascii file (*)') if not filename: return False filename = str(filename) try: M = numpy.loadtxt(filename, **kwargs) if len(M.shape) != 2: raise Exception() x = M[:, 0] y = M[:, 1] except: self.error('Invalid input file "%s"' % filename) Qt.QMessageBox.warning( self, 'Invalid input file', 'Unknown format in selected file.\n Hint: The file must be two-column ASCII' ) return self._arrayEditor.setMaster(x, y)
def openJDraw(self): ifile, _ = compat.getOpenFileName( self, 'Load JDraw File', '', 'JDraw File (*.jdw)') if not ifile: return fileName = ifile.split("/") self._fileName = fileName[-1] self.setModel(ifile) return fileName[-1]
def onOpenSequence(self): if not self._sequenceModel.isEmpty(): if Qt.QMessageBox.question( self, "Open sequence", "Do you want to save existing sequence?", Qt.QMessageBox.Yes, Qt.QMessageBox.No) == Qt.QMessageBox.Yes: self.onSaveSequence() self.tree.clearTree() sequencesPath = self.sequencesPath() fileName, _ = compat.getOpenFileName(self, "Choose a sequence to open...", sequencesPath, "*") self.loadFile(fileName)
def onOpenSequence(self): if not self._sequenceModel.isEmpty(): if Qt.QMessageBox.question( self, "Open sequence", "Do you want to save existing sequence?", Qt.QMessageBox.Yes, Qt.QMessageBox.No) == Qt.QMessageBox.Yes: self.onSaveSequence() self.tree.clearTree() sequencesPath = self.sequencesPath() fileName, _ = compat.getOpenFileName( self, "Choose a sequence to open...", sequencesPath, "*") self.loadFile(fileName)
def loadConfigFile(self, ifile=None): """Reads a file stored by :meth:`saveConfig` and applies the settings :param ifile: (file or string) file or filename from where to read the configuration :return: (str) file name used """ import pickle if ifile is None: from taurus.external.qt import compat ifile, _ = compat.getOpenFileName(self, 'Load Configuration', '', 'Configuration File (*.pck)') if not ifile: return if not isinstance(ifile, file): ifile = open(ifile, 'r') configdict = pickle.load(ifile) self.applyConfig(configdict) return ifile.name
def loadFile(self, iniFileName=None): ''' Loads a configuration stored in a file and creates the tree. :iniFileName: (str) Name of the file. If None is given the user is prompted for a file. ''' if iniFileName is None: if self.tree.originalFile is None: path = Qt.QDir.homePath() else: path = self.tree.originalFile iniFileName, _ = compat.getOpenFileName(self, 'Select a settings file', path, 'Ini Files (*.ini)') if not iniFileName: return self.tree.loadFile(iniFileName) self.treeview.setModel(self.tree) self.setWindowTitle('TaurusConfigEditor - %s' % os.path.basename(self.tree.originalFile))
def importSettingsFile(self, fname=None): ''' loads settings (including importing all perspectives) from a given ini file. It warns before overwriting an existing perspective. :param fname: (str) name of ini file. If None given, a file dialog will be shown. ''' if fname is None: fname, _ = compat.getOpenFileName( self, 'Select a ini-format settings file', '', "Ini files (*.ini);;All files (*)") if not fname: return s = Qt.QSettings(fname, Qt.QSettings.IniFormat) # clone the perspectives found in the "factory" settings for p in self.getPerspectivesList(settings=s): self.loadPerspective(name=p, settings=s) self.savePerspective(name=p) # finally load the settings self.loadSettings(settings=s)
def openFile(self): if self.maybeSave(): fileName, _ = compat.getOpenFileName(self) if not fileName is None and file != "": self.loadFile(fileName)
def _chooseAFile(self): path, _ = compat.getOpenFileName() self.filePath.setText(path)
def openFile(self, fname=None): if fname is None: fname, _ = compat.getOpenFileName(self, 'Choose NeXus File', '') if fname: self.__nexusFile = self.__fileModel.openFile(fname)