def on_archiveButton_clicked(self): """ Private slot to select the archive name via a file selection dialog. """ type_ = self.typeComboBox.itemData(self.typeComboBox.currentIndex()) archive = Utilities.fromNativeSeparators(self.archiveEdit.text()) if not archive: archive = self.__projectPath if type_ == "files": archive = E5FileDialog.getExistingDirectory( self, self.tr("Select Archive Directory"), archive, E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) else: archive, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Select Archive File"), archive, self.__fileFilters, None, E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if archive: ext = QFileInfo(archive).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: archive += ex if archive: self.archiveEdit.setText(Utilities.toNativeSeparators(archive))
def on_saveButton_clicked(self): """ Private slot to save the snapshot. """ if not self.__snapshot.isNull(): while os.path.exists(self.__filename): self.__autoIncFilename() fileName, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Save Snapshot"), self.__filename, self.__outputFilter, self.__defaultFilter, E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if not fileName: return ext = QFileInfo(fileName).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fileName += ex if self.__saveImage(fileName): self.__modified = False self.__filename = fileName self.__autoIncFilename() self.__updateCaption()
def saveImage(self): """ Public method to handle the save context menu entry. """ fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Save Diagram"), "", self.tr("Portable Network Graphics (*.png);;" "Scalable Vector Graphics (*.svg)"), "", E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if fname: ext = QFileInfo(fname).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fname += ex if QFileInfo(fname).exists(): res = E5MessageBox.yesNo( self, self.tr("Save Diagram"), self.tr("<p>The file <b>{0}</b> already exists." " Overwrite it?</p>").format(fname), icon=E5MessageBox.Warning) if not res: return success = super(UMLGraphicsView, self).saveImage(fname, QFileInfo(fname).suffix().upper()) if not success: E5MessageBox.critical( self, self.tr("Save Diagram"), self.tr( """<p>The file <b>{0}</b> could not be saved.</p>"""). format(fname))
def _getFileName(self, filter): """ Protected method to get the file name of the export file from the user. @param filter the filter string to be used (string). The filter for "All Files (*)" is appended by this method. @return file name entered by the user (string) """ filter_ = filter filter_ += ";;" filter_ += QCoreApplication.translate('Exporter', "All Files (*)") fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self.editor, self.tr("Export source"), "", filter_, "", E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if fn: ext = QFileInfo(fn).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fn += ex if QFileInfo(fn).exists(): res = E5MessageBox.yesNo( self.editor, self.tr("Export source"), self.tr("<p>The file <b>{0}</b> already exists." " Overwrite it?</p>").format(fn), icon=E5MessageBox.Warning) if not res: return "" fn = Utilities.toNativeSeparators(fn) return fn
def __exportStyles(self, lexers): """ Private method to export the styles of the given lexers. @param lexers list of lexer objects for which to export the styles """ fn, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Export Highlighting Styles"), "", self.tr("Highlighting styles file (*.e4h)"), "", E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if not fn: return ext = QFileInfo(fn).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fn += ex f = QFile(fn) if f.open(QIODevice.WriteOnly): from E5XML.HighlightingStylesWriter import HighlightingStylesWriter HighlightingStylesWriter(f, lexers).writeXML() f.close() else: E5MessageBox.critical( self, self.tr("Export Highlighting Styles"), self.tr( """<p>The highlighting styles could not be exported""" """ to file <b>{0}</b>.</p><p>Reason: {1}</p>""").format( fn, f.errorString()))
def on_vcsUrlButton_clicked(self): """ Private slot to display a selection dialog. """ if self.protocolCombo.currentText() == "file://": directory = E5FileDialog.getExistingDirectory( self, self.tr("Select Repository-Directory"), self.vcsUrlEdit.text(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if directory: self.vcsUrlEdit.setText( Utilities.toNativeSeparators(directory)) else: from .SvnRepoBrowserDialog import SvnRepoBrowserDialog dlg = SvnRepoBrowserDialog(self.vcs, mode="select", parent=self) dlg.start(self.protocolCombo.currentText() + self.vcsUrlEdit.text()) if dlg.exec_() == QDialog.Accepted: url = dlg.getSelectedUrl() if url: protocol = url.split("://")[0] path = url.split("://")[1] self.protocolCombo.setCurrentIndex( self.protocolCombo.findText(protocol + "://")) self.vcsUrlEdit.setText(path)
def on_dirButton_clicked(self): """ Private slot to handle the button press for selecting the target via a selection dialog. """ if os.path.isdir(self.source): target = E5FileDialog.getExistingDirectory( self, self.tr("Select target"), self.targetEdit.text(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) else: target = E5FileDialog.getSaveFileName( self, self.tr("Select target"), self.targetEdit.text(), "", E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if target: self.targetEdit.setText(Utilities.toNativeSeparators(target))
def on_saveButton_clicked(self): """ Private slot to handle the Save button press. It saves the diff shown in the dialog to a file in the local filesystem. """ if isinstance(self.__filename, list): if len(self.__filename) > 1: fname = self.vcs.splitPathList(self.__filename)[0] else: dname, fname = self.vcs.splitPath(self.__filename[0]) if fname != '.': fname = "{0}.diff".format(self.__filename[0]) else: fname = dname else: fname = self.vcs.splitPath(self.__filename)[0] fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Save Diff"), fname, self.tr("Patch Files (*.diff)"), None, E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if not fname: return # user aborted ext = QFileInfo(fname).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fname += ex if QFileInfo(fname).exists(): res = E5MessageBox.yesNo( self, self.tr("Save Diff"), self.tr("<p>The patch file <b>{0}</b> already exists." " Overwrite it?</p>").format(fname), icon=E5MessageBox.Warning) if not res: return fname = Utilities.toNativeSeparators(fname) eol = e5App().getObject("Project").getEolString() try: f = open(fname, "w", encoding="utf-8", newline="") f.write(eol.join(self.contents2.toPlainText().splitlines())) f.write(eol) f.close() except IOError as why: E5MessageBox.critical( self, self.tr('Save Diff'), self.tr( '<p>The patch file <b>{0}</b> could not be saved.' '<br>Reason: {1}</p>') .format(fname, str(why)))
def __saveAs(self, filename=""): """ Private slot to save the diagram. @param filename name of the file to write to (string) """ if not filename: fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Save Diagram"), "", self.tr("Eric Graphics File (*.e5g);;All Files (*)"), "", E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if not fname: return ext = QFileInfo(fname).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fname += ex if QFileInfo(fname).exists(): res = E5MessageBox.yesNo( self, self.tr("Save Diagram"), self.tr("<p>The file <b>{0}</b> already exists." " Overwrite it?</p>").format(fname), icon=E5MessageBox.Warning) if not res: return filename = fname lines = [ "version: 1.0", "diagram_type: {0} ({1})".format( self.__diagramType, self.__diagramTypeString()), "scene_size: {0};{1}".format(self.scene.width(), self.scene.height()), ] persistenceData = self.builder.getPersistenceData() if persistenceData: lines.append("builder_data: {0}".format(persistenceData)) lines.extend(self.umlView.getPersistenceData()) try: f = open(filename, "w", encoding="utf-8") f.write("\n".join(lines)) f.close() except (IOError, OSError) as err: E5MessageBox.critical( self, self.tr("Save Diagram"), self.tr( """<p>The file <b>{0}</b> could not be saved.</p>""" """<p>Reason: {1}</p>""").format(filename, str(err))) return self.__fileName = filename
def on_dirSelectButton_clicked(self): """ Private slot to display a directory selection dialog. """ directory = E5FileDialog.getExistingDirectory( self, self.tr("Select directory"), self.dirCombo.currentText(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if directory: self.dirCombo.setEditText(Utilities.toNativeSeparators(directory))
def on_directoryButton_clicked(self): """ Private slot called by pressing the export directory selection button. """ dn = E5FileDialog.getExistingDirectory( self, self.tr("Export Patches"), self.directoryEdit.text(), E5FileDialog.Options(E5FileDialog.Option(0))) if dn: self.directoryEdit.setText(Utilities.toNativeSeparators(dn))
def on_iconDirectoryButton_clicked(self): """ Private slot to select an icon directory. """ dir = E5FileDialog.getExistingDirectory( None, self.tr("Select icon directory"), "", E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if dir: self.iconDirectoryEdit.setText(Utilities.toNativeSeparators(dir))
def on_exceptDirButton_clicked(self): """ Private slot to select a file to exempt from translation. """ texcept = E5FileDialog.getExistingDirectory( self, self.tr("Exempt directory from translation"), self.project.ppath, E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if texcept: self.exceptionEdit.setText(Utilities.toNativeSeparators(texcept))
def __newUiForm(self, path): """ Private slot to handle the New Form menu action for Qt-related projects. @param path full directory path for the new form file (string) """ selectedForm, ok = QInputDialog.getItem(None, self.tr("New Form"), self.tr("Select a form type:"), self.templateTypes4, 0, False) if not ok or not selectedForm: # user pressed cancel return templateIndex = self.templateTypes4.index(selectedForm) templateFile = os.path.join(getConfig('ericTemplatesDir'), self.templates4[templateIndex]) fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("New Form"), path, self.tr("Qt User-Interface Files (*.ui);;All Files (*)"), "", E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if not fname: # user aborted or didn't enter a filename return ext = QFileInfo(fname).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fname += ex if os.path.exists(fname): res = E5MessageBox.yesNo( self, self.tr("New Form"), self.tr("The file already exists! Overwrite it?"), icon=E5MessageBox.Warning) if not res: # user selected to not overwrite return try: shutil.copy(templateFile, fname) except IOError as e: E5MessageBox.critical( self, self.tr("New Form"), self.tr( "<p>The new form file <b>{0}</b> could not be created.<br>" "Problem: {1}</p>").format(fname, str(e))) return self.project.appendFile(fname) self.designerFile.emit(fname)
def on_qt4TransButton_clicked(self): """ Private slot to handle the Qt4 translations directory selection. """ dir = E5FileDialog.getExistingDirectory( self, self.tr("Select Qt4 Translations Directory"), self.qt4TransEdit.text(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if dir: self.qt4TransEdit.setText(Utilities.toNativeSeparators(dir))
def on_directoryButton_clicked(self): """ Private slot to select the shared directory via a directory selection dialog. """ directory = E5FileDialog.getExistingDirectory( self, self.tr("Shared Directory"), self.directoryEdit.text(), E5FileDialog.Options(E5FileDialog.Option(0))) if directory: self.directoryEdit.setText(Utilities.toNativeSeparators(directory))
def on_qtToolsDirButton_clicked(self): """ Private slot to handle the Qt tools directory selection. """ dir = E5FileDialog.getExistingDirectory( self, self.tr("Select Qt Tools Directory"), self.qtToolsDirEdit.text(), E5FileDialog.Options(E5FileDialog.DontUseNativeDialog)) if dir: self.qtToolsDirEdit.setText(Utilities.toNativeSeparators(dir))
def on_saveButton_clicked(self): """ Private slot to handle the Save button press. It saves the diff shown in the dialog to a file in the local filesystem. """ dname, fname = Utilities.splitPath(self.filename2) if fname != '.': fname = "{0}.diff".format(self.filename2) else: fname = dname fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Save Diff"), fname, self.tr("Patch Files (*.diff)"), None, E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if not fname: return ext = QFileInfo(fname).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fname += ex if QFileInfo(fname).exists(): res = E5MessageBox.yesNo( self, self.tr("Save Diff"), self.tr("<p>The patch file <b>{0}</b> already exists." " Overwrite it?</p>").format(fname), icon=E5MessageBox.Warning) if not res: return fname = Utilities.toNativeSeparators(fname) try: f = open(fname, "w", encoding="utf-8") txt = self.contents.toPlainText() try: f.write(txt) except UnicodeError: pass f.close() except IOError as why: E5MessageBox.critical( self, self.tr('Save Diff'), self.tr( '<p>The patch file <b>{0}</b> could not be saved.<br />' 'Reason: {1}</p>').format(fname, str(why)))
def __newToplevelDir(self): """ Private slot to handle the New toplevel directory popup menu entry. """ dname = E5FileDialog.getExistingDirectory( None, QCoreApplication.translate('Browser', "New toplevel directory"), "", E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if dname: dname = os.path.abspath(Utilities.toNativeSeparators(dname)) self.__model.addTopLevelDir(dname)
def on_dirButton_clicked(self): """ Private method used to open a directory selection dialog. """ cwd = self.ui.workdirCombo.currentText() d = E5FileDialog.getExistingDirectory( self, self.tr("Working directory"), cwd, E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if d: self.ui.workdirCombo.setEditText(Utilities.toNativeSeparators(d))
def on_flashDataPathButton_clicked(self): """ Private slot to handle the flash data path selection. """ path = E5FileDialog.getExistingDirectory( self, self.tr("Select Flash Cookies Data Path"), self.flashDataPathEdit.text(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if path: self.flashDataPathEdit.setText(Utilities.toNativeSeparators(path))
def __saveMessages(self): """ Private slot to save the contents of the messages display. """ hasText = not self.messages.document().isEmpty() if hasText: if Utilities.isWindowsPlatform(): htmlExtension = "htm" else: htmlExtension = "html" fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( self, self.tr("Save Messages"), "", self.tr( "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)") .format(htmlExtension), None, E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if fname: ext = QFileInfo(fname).suffix() if not ext: ex = selectedFilter.split("(*")[1].split(")")[0] if ex: fname += ex ext = QFileInfo(fname).suffix() if QFileInfo(fname).exists(): res = E5MessageBox.yesNo( self, self.tr("Save Messages"), self.tr("<p>The file <b>{0}</b> already exists." " Overwrite it?</p>").format(fname), icon=E5MessageBox.Warning) if not res: return fname = Utilities.toNativeSeparators(fname) try: if ext.lower() in ["htm", "html"]: txt = self.messages.toHtml() else: txt = self.messages.toPlainText() f = open(fname, "w", encoding="utf-8") f.write(txt) f.close() except IOError as err: E5MessageBox.critical( self, self.tr("Error saving Messages"), self.tr( """<p>The messages contents could not be written""" """ to <b>{0}</b></p><p>Reason: {1}</p>""") .format(fname, str(err)))
def on_projectDirButton_clicked(self): """ Private slot to display a directory selection dialog. """ directory = E5FileDialog.getExistingDirectory( self, self.tr("Select Project Directory"), self.vcsProjectDirEdit.text(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if directory: self.vcsProjectDirEdit.setText( Utilities.toNativeSeparators(directory))
def on_searchDirButton_clicked(self): """ Private slot to handle the clicked signal of the search directory selection button. """ searchDir = E5FileDialog.getExistingDirectory( None, self.tr("Select search directory"), self.searchDirEdit.text(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if searchDir: self.searchDirEdit.setText(Utilities.toNativeSeparators(searchDir))
def on_newProjectButton_clicked(self): """ Private slot to select the new project directory name via a directory selection dialog. """ directory = Utilities.fromNativeSeparators(self.newProjectEdit.text()) directory = E5FileDialog.getExistingDirectory( self, self.tr("New Project Directory"), directory, E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if directory: self.newProjectEdit.setText( Utilities.toNativeSeparators(directory))
def __saveImage(self): """ Private slot to save the selected image to disk. """ act = self.sender() index = act.data() itm = self.imagesTree.topLevelItem(index) if itm is None: return imageUrl = QUrl(itm.text(1)) if not imageUrl.host(): imageUrl.setHost(QUrl(self.siteAddressLabel.text()).host()) imageUrl.setScheme(QUrl(self.siteAddressLabel.text()).scheme()) import Helpviewer.HelpWindow cache = Helpviewer.HelpWindow.HelpWindow.networkAccessManager().cache() if cache: cacheData = cache.data(imageUrl) else: cacheData = None if not cacheData: E5MessageBox.critical( self, self.tr("Save Image"), self.tr("""This image is not available.""")) return downloadDirectory = Helpviewer.HelpWindow.HelpWindow\ .downloadManager().downloadDirectory() fn = os.path.join(downloadDirectory, os.path.basename(itm.text(1))) filename = E5FileDialog.getSaveFileName( self, self.tr("Save Image"), fn, self.tr("All Files (*)"), E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) if not filename: return f = QFile(filename) if not f.open(QFile.WriteOnly): E5MessageBox.critical( self, self.tr("Save Image"), self.tr( """<p>Cannot write to file <b>{0}</b>.</p>""") .format(filename)) return f.write(cacheData.readAll()) f.close()
def on_vcsUrlButton_clicked(self): """ Private slot to display a selection dialog. """ if self.protocolCombo.currentText() == "file://": directory = E5FileDialog.getExistingDirectory( self, self.tr("Select Repository-Directory"), self.vcsUrlEdit.text(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if directory: self.vcsUrlEdit.setText( Utilities.toNativeSeparators(directory))
def on_sourceDirectoryButton_clicked(self): """ Private slot to select the packages root directory via a directory selection dialog. """ startDir = self.sourceDirectoryEdit.text() or self.__getStartDir() sourceDirectory = E5FileDialog.getExistingDirectory( self, self.tr("Source Directory"), Utilities.fromNativeSeparators(startDir), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if sourceDirectory: self.sourceDirectoryEdit.setText( Utilities.toNativeSeparators(sourceDirectory))
def on_workspaceButton_clicked(self): """ Private slot to display a directory selection dialog. """ default = self.workspaceEdit.text() if default == "": default = Utilities.getHomeDir() directory = E5FileDialog.getExistingDirectory( self, self.tr("Select Workspace Directory"), default, E5FileDialog.Options(0)) if directory: self.workspaceEdit.setText(Utilities.toNativeSeparators(directory))
def on_downloadDirButton_clicked(self): """ Private slot to handle the directory selection via dialog. """ directory = E5FileDialog.getExistingDirectory( self, self.tr("Select plugins download directory"), self.downloadDirEdit.text(), E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) if directory: dn = Utilities.toNativeSeparators(directory) while dn.endswith(os.sep): dn = dn[:-1] self.downloadDirEdit.setText(dn)