def exportProfile(self, profile, filename=None): """ Exports this toolbar to the given filename. :param profile | <XViewProfile> filename | <str> || None """ if not filename: filename = QFileDialog.getSaveFileName(self, 'Export Profile', '', 'XML Files (*.xml)') if type(filename) == tuple: filename = nativestring(filename[0]) if not filename: return False profile.save(filename) return True
def accept(self): """ Prompts the user for the filepath to save and then saves the image. """ filetypes = 'PNG Files (*.png);;JPG Files (*.jpg);;All Files (*.*)' filename = QFileDialog.getSaveFileName(None, 'Save Snapshot', self.filepath(), filetypes) if type(filename) == tuple: filename = filename[0] filename = nativestring(filename) if not filename: self.reject() else: self.setFilepath(filename) self.save()
def saveAs( self, filename = '' ): """ Saves the current document to the inputed filename. If no filename \ is supplied, then the user will be prompted to supply a filename. :param filename | <str> :return <bool> | success """ if ( not (filename and isinstance(filename, basestring)) ): langTypes = XLanguage.pluginFileTypes() filename = QFileDialog.getSaveFileName( None, 'Save File As...', QDir.currentPath(), langTypes) if type(filename) == tuple: filename = nativestring(filename[0]) if ( not filename ): return False docfile = QFile(filename) if ( not docfile.open(QFile.WriteOnly) ): logger.warning('Could not open %s for writing.' % filename) return False success = self.write(docfile) docfile.close() if success: filename = nativestring(filename) self._filename = filename self.setModified(False) # set the language lang = XLanguage.byFileType(os.path.splitext(filename)[1]) if ( lang != self.language() ): self.setLanguage(lang) return success
def pickFilepath( self ): """ Prompts the user to select a filepath from the system based on the \ current filepath mode. """ mode = self.filepathMode() filepath = '' filepaths = [] curr_dir = nativestring(self._filepathEdit.text()) if ( not curr_dir ): curr_dir = QDir.currentPath() if mode == XFilepathEdit.Mode.SaveFile: filepath = QFileDialog.getSaveFileName( self, self.windowTitle(), curr_dir, self.filepathTypes() ) elif mode == XFilepathEdit.Mode.OpenFile: filepath = QFileDialog.getOpenFileName( self, self.windowTitle(), curr_dir, self.filepathTypes() ) elif mode == XFilepathEdit.Mode.OpenFiles: filepaths = QFileDialog.getOpenFileNames( self, self.windowTitle(), curr_dir, self.filepathTypes() ) else: filepath = QFileDialog.getExistingDirectory( self, self.windowTitle(), curr_dir ) if filepath: if type(filepath) == tuple: filepath = filepath[0] self.setFilepath(nativestring(filepath)) elif filepaths: self.setFilepaths(map(str, filepaths))
def exportProfile(self, profile, filename=None): """ Exports this toolbar to the given filename. :param profile | <XViewProfile> filename | <str> || None """ if not filename: filename = QFileDialog.getSaveFileName(self, 'Export Profile', '', 'XML Files (*.xml)') if type(filename) == tuple: filename = nativestring(filename[0]) if not filename: return False profile.save(filename) return True
def saveAs(self, filename=''): """ Saves the current document to the inputed filename. If no filename \ is supplied, then the user will be prompted to supply a filename. :param filename | <str> :return <bool> | success """ if (not (filename and isinstance(filename, basestring))): langTypes = XLanguage.pluginFileTypes() filename = QFileDialog.getSaveFileName(None, 'Save File As...', QDir.currentPath(), langTypes) if type(filename) == tuple: filename = nativestring(filename[0]) if (not filename): return False docfile = QFile(filename) if (not docfile.open(QFile.WriteOnly)): logger.warning('Could not open %s for writing.' % filename) return False success = self.write(docfile) docfile.close() if success: filename = nativestring(filename) self._filename = filename self.setModified(False) # set the language lang = XLanguage.byFileType(os.path.splitext(filename)[1]) if (lang != self.language()): self.setLanguage(lang) return success