def __printPreviewImage(self): """ Private slot to handle the Print Preview menu action. """ from PyQt4.QtGui import QPrintPreviewDialog if self.mainWidget is None: KQMessageBox.critical(None, self.trUtf8("Print Preview"), self.trUtf8("""There is no UI file loaded.""")) return settings = Preferences.Prefs.settings printer = KdeQt.KQPrinter.KQPrinter(mode = QPrinter.HighResolution) printer.setFullPage(True) if not KdeQt.isKDE(): printer.setPrinterName(settings.value("UIPreviewer/printername").toString()) printer.setPageSize( QPrinter.PageSize(settings.value("UIPreviewer/pagesize").toInt()[0])) printer.setPageOrder( QPrinter.PageOrder(settings.value("UIPreviewer/pageorder").toInt()[0])) printer.setOrientation( QPrinter.Orientation(settings.value("UIPreviewer/orientation").toInt()[0])) printer.setColorMode( QPrinter.ColorMode(settings.value("UIPreviewer/colormode").toInt()[0])) preview = QPrintPreviewDialog(printer, self) self.connect(preview, SIGNAL("paintRequested(QPrinter*)"), self.__print) preview.exec_()
def on_newButton_clicked(self): """ Private slot to create a new toolbar. """ name, ok = KQInputDialog.getText(\ self, self.trUtf8("New Toolbar"), self.trUtf8("Toolbar Name:"), QLineEdit.Normal) if ok and not name.isEmpty(): if self.toolbarComboBox.findText(name) != -1: # toolbar with this name already exists KQMessageBox.critical(self, self.trUtf8("New Toolbar"), self.trUtf8("""A toolbar with the name <b>%1</b> already exists.""")\ .arg(name), QMessageBox.StandardButtons(\ QMessageBox.Abort)) return tbItem = E4ToolBarItem(None, [], False) tbItem.title = name tbItem.isChanged = True self.__toolbarItems[id(tbItem)] = tbItem self.__toolBarItemToWidgetActionID[id(tbItem)] = [] self.toolbarComboBox.addItem(name, QVariant(long(id(tbItem)))) self.toolbarComboBox.model().sort(0) self.toolbarComboBox.setCurrentIndex(self.toolbarComboBox.findText(name))
def __importStyles(self, lexers): """ Private method to import the styles of the given lexers. @param lexers dictionary of lexer objects for which to import the styles """ fn = KQFileDialog.getOpenFileName(\ self, self.trUtf8("Import Highlighting Styles"), QString(), self.trUtf8("eric4 highlighting styles file (*.e4h)"), None) if fn.isEmpty(): return fn = unicode(fn) try: f = open(fn, "rb") try: line = f.readline() dtdLine = f.readline() finally: f.close() except IOError, err: KQMessageBox.critical(self, self.trUtf8("Import Highlighting Styles"), self.trUtf8("""<p>The highlighting styles could not be read""" """ from file <b>%1</b>.</p><p>Reason: %2</p>""")\ .arg(fn)\ .arg(str(err)) ) return
def on_validateButton_clicked(self): """ Private slot to validate the entered regexp. """ regex = self.regexpLineEdit.text() if not regex.isEmpty(): re = QRegExp(regex) if self.caseSensitiveCheckBox.isChecked(): re.setCaseSensitivity(Qt.CaseSensitive) else: re.setCaseSensitivity(Qt.CaseInsensitive) re.setMinimal(self.minimalCheckBox.isChecked()) if self.wildcardCheckBox.isChecked(): re.setPatternSyntax(QRegExp.Wildcard) else: re.setPatternSyntax(QRegExp.RegExp) if re.isValid(): KQMessageBox.information(None, self.trUtf8(""), self.trUtf8("""The regular expression is valid.""")) else: KQMessageBox.critical(None, self.trUtf8("Error"), self.trUtf8("""Invalid regular expression: %1""") .arg(re.errorString())) return else: KQMessageBox.critical(None, self.trUtf8("Error"), self.trUtf8("""A regular expression must be given."""))
def on_renameButton_clicked(self): """ Private slot to rename a custom toolbar. """ oldName = self.toolbarComboBox.currentText() newName, ok = KQInputDialog.getText(\ self, self.trUtf8("Rename Toolbar"), self.trUtf8("New Toolbar Name:"), QLineEdit.Normal, oldName) if ok and not newName.isEmpty(): if oldName == newName: return if self.toolbarComboBox.findText(newName) != -1: # toolbar with this name already exists KQMessageBox.critical(self, self.trUtf8("Rename Toolbar"), self.trUtf8("""A toolbar with the name <b>%1</b> already exists.""")\ .arg(newName), QMessageBox.StandardButtons(\ QMessageBox.Abort)) return index = self.toolbarComboBox.currentIndex() self.toolbarComboBox.setItemText(index, newName) tbItem = \ self.__toolbarItems[self.toolbarComboBox.itemData(index).toULongLong()[0]] tbItem.title = newName tbItem.isChanged = True
def __checkPluginsDownloadDirectory(self): """ Private slot to check for the existance of the plugins download directory. """ downloadDir = unicode(Preferences.getPluginManager("DownloadPath")) if not downloadDir: downloadDir = self.__defaultDownloadDir if not os.path.exists(downloadDir): try: os.mkdir(downloadDir, 0755) except (OSError, IOError), err: # try again with (possibly) new default downloadDir = self.__defaultDownloadDir if not os.path.exists(downloadDir): try: os.mkdir(downloadDir, 0755) except (OSError, IOError), err: KQMessageBox.critical(self.__ui, self.trUtf8("Plugin Manager Error"), self.trUtf8("""<p>The plugin download directory <b>%1</b> """ """could not be created. Please configure it """ """via the configuration dialog.</p>""" """<p>Reason: %2</p>""")\ .arg(downloadDir).arg(str(err))) downloadDir = ""
def __generateTSFileDone(self, exitCode, exitStatus): """ Private slot to handle the finished signal of the pylupdate process. @param exitCode exit code of the process (integer) @param exitStatus exit status of the process (QProcess.ExitStatus) """ if exitStatus == QProcess.NormalExit and exitCode == 0: KQMessageBox.information(None, self.trUtf8("Translation file generation"), self.trUtf8("The generation of the translation files (*.ts)" " was successful.")) else: KQMessageBox.critical(None, self.trUtf8("Translation file generation"), self.trUtf8("The generation of the translation files (*.ts) has failed.")) proc = self.sender() for index in range(len(self.__pylupdateProcesses)): if proc == self.__pylupdateProcesses[index][0]: try: os.remove(self.__pylupdateProcesses[index][1]) except EnvironmentError: pass del self.__pylupdateProcesses[index] break if not self.__pylupdateProcesses: # all done self.pylupdateProcRunning = False
def startSynchronizedProcess(self, proc, program, arguments, workingDir = None): """ Public method to start a synchroneous process This method starts a process and waits for its end while still serving the Qt event loop. @param proc process to start (QProcess) @param program path of the executable to start (string or QString) @param arguments list of arguments for the process (QStringList) @param workingDir working directory for the process (string or QString) @return flag indicating normal exit (boolean) """ if proc is None: return if workingDir: proc.setWorkingDirectory(workingDir) proc.start(program, arguments) procStarted = proc.waitForStarted() if not procStarted: KQMessageBox.critical(None, self.trUtf8('Process Generation Error'), self.trUtf8( 'The process %1 could not be started. ' 'Ensure, that it is in the search path.' ).arg(program)) return False else: while proc.state() == QProcess.Running: QApplication.processEvents() QThread.msleep(300) QApplication.processEvents() return (proc.exitStatus() == QProcess.NormalExit) and (proc.exitCode() == 0)
def on_changeButton_clicked(self): """ Private slot to change an entry. """ row = self.groupsList.currentRow() if row < 0: return groupName = self.nameEdit.text() if groupName.isEmpty(): KQMessageBox.critical(self, self.trUtf8("Add tool group entry"), self.trUtf8("You have to give a name for the group to add.")) return if len(self.groupsList.findItems(groupName, Qt.MatchFlags(Qt.MatchExactly))): KQMessageBox.critical(self, self.trUtf8("Add tool group entry"), self.trUtf8("An entry for the group name %1 already exists.")\ .arg(groupName)) return self.toolGroups[row][0] = unicode(groupName) self.groupsList.currentItem().setText(groupName)
def start(self, pfn, fn=None): """ Public slot to start the calculation of the profile data. @param pfn basename of the profiling file (string) @param fn file to display the profiling data for (string) """ self.basename = os.path.splitext(pfn)[0] fname = "%s.profile" % self.basename if not os.path.exists(fname): KQMessageBox.warning(None, self.trUtf8("Profile Results"), self.trUtf8("""<p>There is no profiling data""" """ available for <b>%1</b>.</p>""") .arg(pfn)) self.close() return try: f = open(fname, 'rb') self.stats = pickle.load(f) f.close() except (EnvironmentError, pickle.PickleError, EOFError): KQMessageBox.critical(None, self.trUtf8("Loading Profiling Data"), self.trUtf8("""<p>The profiling data could not be""" """ read from file <b>%1</b>.</p>""") .arg(fname)) self.close() return self.file = fn self.__populateLists() self.__finish()
def __writeXMLMultiProject(self, fn = None): """ Private method to write the multi project data to an XML file. @param fn the filename of the multi project file (string) """ try: if fn.lower().endswith("e4mz"): try: import gzip except ImportError: KQMessageBox.critical(None, self.trUtf8("Save multiproject file"), self.trUtf8("""Compressed multiproject files not supported.""" """ The compression library is missing.""")) return False f = gzip.open(fn, "wb") else: f = open(fn, "wb") MultiProjectWriter(self, f, os.path.splitext(os.path.basename(fn))[0])\ .writeXML() f.close() except IOError: KQMessageBox.critical(None, self.trUtf8("Save multiproject file"), self.trUtf8("<p>The multiproject file <b>%1</b> could not be " "written.</p>").arg(fn)) return False return True
def exportShortcuts(fn): """ Module function to export the keyboard shortcuts for the defined QActions. @param fn filename of the export file (string) @return flag indicating success """ try: if fn.lower().endswith("e4kz"): try: import gzip except ImportError: KQMessageBox.critical(None, QApplication.translate("Shortcuts", "Export Keyboard Shortcuts"), QApplication.translate("Shortcuts", """Compressed keyboard shortcut files""" """ not supported. The compression library is missing.""")) return 0 f = gzip.open(fn, "wb") else: f = open(fn, "wb") ShortcutsWriter(f).writeXML() f.close() return True except IOError: return False
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 type(self.filename) is types.ListType: if len(self.filename) > 1: fname = self.vcs.splitPathList(self.filename)[0] else: dname, fname = self.vcs.splitPath(self.filename[0]) if fname != '.': fname = "%s.diff" % self.filename[0] else: fname = dname else: fname = self.vcs.splitPath(self.filename)[0] selectedFilter = QString("") fname = KQFileDialog.getSaveFileName(\ self, self.trUtf8("Save Diff"), fname, self.trUtf8("Patch Files (*.diff)"), selectedFilter, QFileDialog.Options(QFileDialog.DontConfirmOverwrite)) if fname.isEmpty(): return ext = QFileInfo(fname).suffix() if ext.isEmpty(): ex = selectedFilter.section('(*',1,1).section(')',0,0) if not ex.isEmpty(): fname.append(ex) if QFileInfo(fname).exists(): res = KQMessageBox.warning(self, self.trUtf8("Save Diff"), self.trUtf8("<p>The patch file <b>%1</b> already exists.</p>") .arg(fname), QMessageBox.StandardButtons(\ QMessageBox.Abort | \ QMessageBox.Save), QMessageBox.Abort) if res != QMessageBox.Save: return fname = unicode(Utilities.toNativeSeparators(fname)) try: f = open(fname, "wb") f.write(unicode(self.contents.toPlainText())) f.close() except IOError, why: KQMessageBox.critical(self, self.trUtf8('Save Diff'), self.trUtf8('<p>The patch file <b>%1</b> could not be saved.' '<br>Reason: %2</p>') .arg(unicode(fname)).arg(str(why)))
def startProcess(self, args, workingDir=None, setLanguage=False): """ Public slot used to start the process. @param args list of arguments for the process (QStringList) @param workingDir working directory for the process (string or QString) @param setLanguage flag indicating to set the language to "C" (boolean) @return flag indicating a successful start of the process """ self.errorGroup.hide() self.normal = False self.intercept = False self.__hasAddOrDelete = False self.proc = QProcess() if setLanguage: env = QProcessEnvironment.systemEnvironment() env.insert("LANG", "C") self.proc.setProcessEnvironment(env) nargs = QStringList() lastWasPwd = False for arg in args: if lastWasPwd: lastWasPwd = True continue nargs.append(arg) if arg == QString("--password"): lastWasPwd = True nargs.append("*****") self.resultbox.append(nargs.join(" ")) self.resultbox.append("") self.connect(self.proc, SIGNAL("finished(int, QProcess::ExitStatus)"), self.__procFinished) self.connect(self.proc, SIGNAL("readyReadStandardOutput()"), self.__readStdout) self.connect(self.proc, SIGNAL("readyReadStandardError()"), self.__readStderr) if workingDir: self.proc.setWorkingDirectory(workingDir) self.proc.start("svn", args) procStarted = self.proc.waitForStarted() if not procStarted: self.buttonBox.setFocus() self.inputGroup.setEnabled(False) self.inputGroup.hide() KQMessageBox.critical( None, self.trUtf8("Process Generation Error"), self.trUtf8("The process %1 could not be started. " "Ensure, that it is in the search path.").arg( "svn" ), ) else: self.inputGroup.setEnabled(True) self.inputGroup.show() return procStarted
def on_deleteButton_clicked(self): """ Private slot to delete the selected search engines. """ if self.enginesTable.model().rowCount() == 1: KQMessageBox.critical(self, self.trUtf8("Delete selected engines"), self.trUtf8("""You must have at least one search engine.""")) self.enginesTable.removeSelected()
def __generatePythonCode(self): """ Private slot to generate Python code as requested by the user. """ # init some variables sourceImpl = [] appendAtIndex = -1 indentStr = " " slotsCode = [] if self.__module is None: # new file try: if self.project.getProjectLanguage() == "Python3": tmplName = os.path.join(getConfig('ericCodeTemplatesDir'), "impl_pyqt.py3.tmpl") else: if self.project.getProjectType() == "PySide": tmplName = os.path.join(getConfig('ericCodeTemplatesDir'), "impl_pyside.py.tmpl") else: tmplName = os.path.join(getConfig('ericCodeTemplatesDir'), "impl_pyqt.py.tmpl") tmplFile = open(tmplName, 'rb') template = tmplFile.read() tmplFile.close() except IOError, why: KQMessageBox.critical(self, self.trUtf8("Code Generation"), self.trUtf8("""<p>Could not open the code template file "%1".</p>""" """<p>Reason: %2</p>""")\ .arg(tmplName)\ .arg(str(why)), QMessageBox.StandardButtons(\ QMessageBox.Ok)) return objName = self.__objectName() if not objName.isEmpty(): template = template\ .replace("$FORMFILE$", os.path.splitext(os.path.basename(self.formFile))[0])\ .replace("$FORMCLASS$", unicode(objName))\ .replace("$CLASSNAME$", unicode(self.classNameCombo.currentText()))\ .replace("$SUPERCLASS$", unicode(self.__className())) sourceImpl = template.splitlines(True) appendAtIndex = -1 # determine indent string for line in sourceImpl: if line.lstrip().startswith("def __init__"): indentStr = line.replace(line.lstrip(), "") break
def on_diffButton_clicked(self): """ Private slot to handle the Compare button press. """ self.filename1 = unicode(Utilities.toNativeSeparators(self.file1Edit.text())) try: filemtime1 = time.ctime(os.stat(self.filename1).st_mtime) except IOError: filemtime1 = "" try: f1 = open(self.filename1, "rb") lines1 = f1.readlines() f1.close() except IOError: KQMessageBox.critical(self, self.trUtf8("Compare Files"), self.trUtf8("""<p>The file <b>%1</b> could not be read.</p>""") .arg(self.filename1)) return self.filename2 = unicode(Utilities.toNativeSeparators(self.file2Edit.text())) try: filemtime2 = time.ctime(os.stat(self.filename2).st_mtime) except IOError: filemtime2 = "" try: f2 = open(self.filename2, "rb") lines2 = f2.readlines() f2.close() except IOError: KQMessageBox.critical(self, self.trUtf8("Compare Files"), self.trUtf8("""<p>The file <b>%1</b> could not be read.</p>""") .arg(self.filename2)) return self.contents.clear() self.saveButton.setEnabled(False) if self.unifiedRadioButton.isChecked(): self.__generateUnifiedDiff(lines1, lines2, self.filename1, self.filename2, filemtime1, filemtime2) else: self.__generateContextDiff(lines1, lines2, self.filename1, self.filename2, filemtime1, filemtime2) tc = self.contents.textCursor() tc.movePosition(QTextCursor.Start) self.contents.setTextCursor(tc) self.contents.ensureCursorVisible() self.saveButton.setEnabled(True)
def __copyImageToClipboard(self): """ Private slot to handle the Copy Image menu action. """ if self.mainWidget is None: KQMessageBox.critical(None, self.trUtf8("Save Image"), self.trUtf8("""There is no UI file loaded.""")) return cb = QApplication.clipboard() cb.setPixmap(QPixmap.grabWidget(self.mainWidget)) self.__updateChildren(self.lastStyle)
def start(self, path): """ Public slot to populate the data. @param path directory name to show change lists for (string) """ self.changeListsDict = {} self.filesLabel.setText(self.trUtf8("Files (relative to %1):").arg(path)) self.errorGroup.hide() self.intercept = False self.path = path self.currentChangelist = "" self.process = QProcess() self.process.finished.connect(self.__procFinished) self.process.readyReadStandardOutput.connect(self.__readStdout) self.process.readyReadStandardError.connect(self.__readStderr) args = [] args.append('status') self.vcs.addArguments(args, self.vcs.options['global']) self.vcs.addArguments(args, self.vcs.options['status']) if '--verbose' not in self.vcs.options['global'] and \ '--verbose' not in self.vcs.options['status']: args.append('--verbose') if isinstance(path, list): self.dname, fnames = self.vcs.splitPathList(path) self.vcs.addArguments(args, fnames) else: self.dname, fname = self.vcs.splitPath(path) args.append(fname) self.process.setWorkingDirectory(self.dname) self.process.start('svn', args) procStarted = self.process.waitForStarted() if not procStarted: self.inputGroup.setEnabled(False) self.inputGroup.hide() KQMessageBox.critical(self, self.trUtf8('Process Generation Error'), self.trUtf8( 'The process %1 could not be started. ' 'Ensure, that it is in the search path.' ).arg('svn')) else: self.inputGroup.setEnabled(True) self.inputGroup.show()
def __getLogEntries(self, startRev = None): """ Private method to retrieve log entries from the repository. @param startRev revision number to start from (integer, string or QString) """ self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) QApplication.processEvents() QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() self.intercept = False self.process.kill() self.buf = QStringList() self.cancelled = False self.errors.clear() args = QStringList() args.append('log') self.vcs.addArguments(args, self.vcs.options['global']) self.vcs.addArguments(args, self.vcs.options['log']) args.append('--verbose') args.append('--limit') args.append('%d' % self.limitSpinBox.value()) if startRev is not None: args.append('--revision') args.append('%s:0' % startRev) if self.stopCheckBox.isChecked(): args.append('--stop-on-copy') args.append(self.fname) self.process.setWorkingDirectory(self.dname) self.inputGroup.setEnabled(True) self.inputGroup.show() self.process.start('svn', args) procStarted = self.process.waitForStarted() if not procStarted: self.inputGroup.setEnabled(False) self.inputGroup.hide() KQMessageBox.critical(None, self.trUtf8('Process Generation Error'), self.trUtf8( 'The process %1 could not be started. ' 'Ensure, that it is in the search path.' ).arg('svn'))
def start(self, args, fn): """ Public slot to start the ericapi command. @param args commandline arguments for ericapi program (QStringList) @param fn filename or dirname to be processed by ericapi program @return flag indicating the successful start of the process """ self.errorGroup.hide() self.filename = unicode(fn) if os.path.isdir(self.filename): dname = os.path.abspath(self.filename) fname = "." if os.path.exists(os.path.join(dname, "__init__.py")): fname = os.path.basename(dname) dname = os.path.dirname(dname) else: dname = os.path.dirname(self.filename) fname = os.path.basename(self.filename) self.contents.clear() self.errors.clear() program = args[0] del args[0] args.append(fname) self.process = QProcess() self.process.setWorkingDirectory(dname) self.connect(self.process, SIGNAL('readyReadStandardOutput()'), self.__readStdout) self.connect(self.process, SIGNAL('readyReadStandardError()'), self.__readStderr) self.connect(self.process, SIGNAL('finished(int, QProcess::ExitStatus)'), self.__finish) self.setWindowTitle(self.trUtf8('%1 - %2').arg(self.cmdname).arg(self.filename)) self.process.start(program, args) procStarted = self.process.waitForStarted() if not procStarted: KQMessageBox.critical(None, self.trUtf8('Process Generation Error'), self.trUtf8( 'The process %1 could not be started. ' 'Ensure, that it is in the search path.' ).arg(program)) return procStarted
def on_testButton_clicked(self): """ Private slot to test the mail server login data. """ QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() try: server = smtplib.SMTP(str(self.mailServerEdit.text()), self.portSpin.value(), timeout=10) if self.useTlsCheckBox.isChecked(): server.starttls() try: server.login(unicode(self.mailUserEdit.text()), unicode(self.mailPasswordEdit.text())) QApplication.restoreOverrideCursor() KQMessageBox.information(self, self.trUtf8("Login Test"), self.trUtf8("""The login test succeeded.""")) except (smtplib.SMTPException, socket.error) as e: QApplication.restoreOverrideCursor() if isinstance(e, smtplib.SMTPResponseException): errorStr = e.smtp_error.decode() elif isinstance(e, socket.timeout): errorStr = str(e) elif isinstance(e, socket.error): errorStr = e[1] else: errorStr = str(e) KQMessageBox.critical(self, self.trUtf8("Login Test"), self.trUtf8("""<p>The login test failed.<br>Reason: %1</p>""") .arg(errorStr)) server.quit() except (smtplib.SMTPException, socket.error) as e: QApplication.restoreOverrideCursor() if isinstance(e, smtplib.SMTPResponseException): errorStr = e.smtp_error.decode() elif isinstance(e, socket.timeout): errorStr = str(e) elif isinstance(e, socket.error): errorStr = e[1] else: errorStr = str(e) KQMessageBox.critical(self, self.trUtf8("Login Test"), self.trUtf8("""<p>The login test failed.<br>Reason: %1</p>""") .arg(errorStr))
def __className(self): """ Private method to get the class name of the dialog. @return class name (QSting) """ try: dlg = uic.loadUi(self.formFile) return dlg.metaObject().className() except (AttributeError, ImportError), err: KQMessageBox.critical(self, self.trUtf8("uic error"), self.trUtf8("""<p>There was an error loading the form <b>%1</b>.</p>""" """<p>%2</p>""").arg(self.formFile).arg(str(err)), QMessageBox.StandardButtons(\ QMessageBox.Ok)) return QString()
def exportBookmarks(self): """ Public method to export the bookmarks. """ fileName = KQFileDialog.getSaveFileName(\ None, self.trUtf8("Export Bookmarks"), "eric4_bookmarks.xbel", self.trUtf8("XBEL bookmarks").append(" (*.xbel *.xml)")) if fileName.isEmpty(): return writer = XbelWriter() if not writer.write(fileName, self.__bookmarkRootNode): KQMessageBox.critical(None, self.trUtf8("Exporting Bookmarks"), self.trUtf8("""Error exporting bookmarks to <b>%1</b>.""")\ .arg(fileName))
def __handle(self): """ Private method to handle the wizards action """ editor = e4App().getObject("ViewManager").activeWindow() if editor == None: KQMessageBox.critical(None, self.trUtf8('No current editor'), self.trUtf8('Please open or create a file first.')) else: code, ok = self.__callForm(editor) if ok: line, index = editor.getCursorPosition() # It should be done on this way to allow undo editor.beginUndoAction() editor.insertAt(code, line, index) editor.endUndoAction()
def on_addButton_clicked(self): """ Private slot to add a new search engine. """ fileNames = KQFileDialog.getOpenFileNames(\ self, self.trUtf8("Add search engine"), QString(), self.trUtf8("OpenSearch (*.xml);;All Files (*)"), None) osm = self.__mw.openSearchManager() for fileName in fileNames: if not osm.addEngine(fileName): KQMessageBox.critical(self, self.trUtf8("Add search engine"), self.trUtf8("""%1 is not a valid OpenSearch 1.1 description or""" """ is already on your list.""").arg(fileName))
def __repoRoot(self, url): """ Private method to get the repository root using the svn info command. @param url the repository URL to browser (string or QString) @return repository root (string) """ ioEncoding = str(Preferences.getSystem("IOEncoding")) repoRoot = None process = QProcess() args = QStringList() args.append('info') self.vcs.addArguments(args, self.vcs.options['global']) args.append('--xml') args.append(url) process.start('svn', args) procStarted = process.waitForStarted() if procStarted: finished = process.waitForFinished(30000) if finished: if process.exitCode() == 0: output = unicode(process.readAllStandardOutput(), ioEncoding, 'replace') for line in output.splitlines(): line = line.strip() if line.startswith('<root>'): repoRoot = line.replace('<root>', '').replace('</root>', '') break else: error = QString(process.readAllStandardError()) self.errors.insertPlainText(error) self.errors.ensureCursorVisible() else: QApplication.restoreOverrideCursor() KQMessageBox.critical(None, self.trUtf8('Process Generation Error'), self.trUtf8( 'The process %1 could not be started. ' 'Ensure, that it is in the search path.' ).arg('svn')) return repoRoot
def on_executableButton_clicked(self): """ Private slot to handle the executable selection via a file selection dialog. """ execfile = KQFileDialog.getOpenFileName(\ self, self.trUtf8("Select executable"), self.executableEdit.text(), QString()) if not execfile.isEmpty(): execfile = unicode(Utilities.toNativeSeparators(execfile)) if not Utilities.isinpath(execfile): KQMessageBox.critical(self, self.trUtf8("Select executable"), self.trUtf8("The selected file is not an executable." " Please choose an executable filename.")) return self.executableEdit.setText(execfile)
def __importConfigurationPage(self, name): """ Private method to import a configuration page module. @param name name of the configuration page module (string) @return reference to the configuration page module """ modName = "Preferences.ConfigurationPages.%s" % name try: mod = __import__(modName) components = modName.split('.') for comp in components[1:]: mod = getattr(mod, comp) return mod except ImportError: KQMessageBox.critical(None, self.trUtf8("Configuration Page Error"), self.trUtf8("""<p>The configuration page <b>%1</b>""" """ could not be loaded.</p>""").arg(name)) return None
def on_addButton_clicked(self): """ Private slot to add a new entry. """ groupName = self.nameEdit.text() if groupName.isEmpty(): KQMessageBox.critical(self, self.trUtf8("Add tool group entry"), self.trUtf8("You have to give a name for the group to add.")) return if len(self.groupsList.findItems(groupName, Qt.MatchFlags(Qt.MatchExactly))): KQMessageBox.critical(self, self.trUtf8("Add tool group entry"), self.trUtf8("An entry for the group name %1 already exists.")\ .arg(groupName)) return self.groupsList.addItem(unicode(groupName)) self.toolGroups.append([unicode(groupName), []])