def loadFilename(self, filename=''): """ Loads a new XDK file into the system. :param filename | <str> :return <bool> | success """ if (not (filename and isinstance(filename, basestring))): filename = QFileDialog.getOpenFileName(self, 'Open XDK File', QDir.currentPath(), 'XDK Files (*.xdk)') if type(filename) == tuple: filename = nativestring(filename[0]) if not filename: return False if not (filename and os.path.exists(filename)): return False elif filename in self.loadedFilenames(): return False self.loadFileRequested.emit(filename) self.setCursor(Qt.WaitCursor) return True
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 pickAttachment(self): """ Prompts the user to select an attachment to add to this edit. """ filename = QFileDialog.getOpenFileName(self.window(), 'Select Attachment', '', 'All Files (*.*)') if type(filename) == tuple: filename = nativestring(filename[0]) filename = nativestring(filename) if filename: self.addAttachment(os.path.basename(filename), filename)
def pickFilepath( self ): """ Picks the image file to use for this icon path. """ filepath = QFileDialog.getOpenFileName( self, 'Select Image File', QDir.currentPath(), self.fileTypes()) if type(filepath) == tuple: filepath = nativestring(filepath[0]) if ( filepath ): self.setFilepath(filepath)
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 importProfile(self, filename=None): """ Imports the profiles from the given filename. :param filename | <str> || None """ if not filename: filename = QFileDialog.getOpenFileName(self, 'Import Perspective', '', 'XML Files (*.xml)') if type(filename) == tuple: filename = nativestring(filename[0]) if not (filename and os.path.exists(filename)): return False prof = XViewProfile.load(filename) if prof: self.addProfile(prof)
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 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 importProfile(self, filename=None): """ Imports the profiles from the given filename. :param filename | <str> || None """ if not filename: filename = QFileDialog.getOpenFileName( self, 'Import Perspective', '', 'XML Files (*.xml)') if type(filename) == tuple: filename = nativestring(filename[0]) if not (filename and os.path.exists(filename)): return False prof = XViewProfile.load(filename) if prof: self.addProfile(prof)