def on_addInstalledApiFileButton_clicked(self): """ Private slot to add an API file from the list of installed API files for the selected lexer language. """ installedAPIFiles = self.__currentAPI.installedAPIFiles() if len(installedAPIFiles) > 0: installedAPIFilesPath = QFileInfo(installedAPIFiles[0]).path() installedAPIFilesShort = QStringList() for installedAPIFile in installedAPIFiles: installedAPIFilesShort.append(QFileInfo(installedAPIFile).fileName()) file, ok = KQInputDialog.getItem( self, self.trUtf8("Add from installed APIs"), self.trUtf8("Select from the list of installed API files"), installedAPIFilesShort, 0, False, ) if ok: self.apiList.addItem( Utilities.toNativeSeparators(QFileInfo(QDir(installedAPIFilesPath), file).absoluteFilePath()) ) else: KQMessageBox.warning( self, self.trUtf8("Add from installed APIs"), self.trUtf8("""There are no APIs installed yet.""" """ Selection is not available."""), ) self.addInstalledApiFileButton.setEnabled(False)
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 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 on_namedReferenceButton_clicked(self): """ Private slot to handle the named reference toolbutton. """ # determine cursor position as length into text length = self.regexpTextEdit.textCursor().position() # only present group names that occur before the current cursor position regex = unicode(self.regexpTextEdit.toPlainText().left(length)) names = self.namedGroups(regex) if not names: KQMessageBox.information(None, self.trUtf8("Named reference"), self.trUtf8("""No named groups have been defined yet.""")) return qs = QStringList() for name in names: qs.append(name) groupName, ok = KQInputDialog.getItem(\ None, self.trUtf8("Named reference"), self.trUtf8("Select group name:"), qs, 0, True) if ok and not groupName.isEmpty(): self.__insertString("(?P=%s)" % groupName)
def __setInterval(self): """ Private slot to change the status check interval. """ interval, ok = KQInputDialog.getInt(\ None, self.trUtf8("VCS Status Monitor"), self.trUtf8("Enter monitor interval [s]"), self.project.getStatusMonitorInterval(), 0, 3600, 1) if ok: self.project.setStatusMonitorInterval(interval)
def __askForkTo(self): """ Private method to ask the user which branch of a fork to follow. """ selections = [self.trUtf8("Parent Process"), self.trUtf8("Child process")] res, ok = KQInputDialog.getItem( None, self.trUtf8("Client forking"), self.trUtf8("Select the fork branch to follow."), selections, 0, False ) if not ok or res == selections[0]: self.__sendCommand(ResponseForkTo + "parent\n") else: self.__sendCommand(ResponseForkTo + "child\n")
def on_allEolFillButton_clicked(self): """ Private method used to set the eolfill for all styles of a selected lexer. """ on = self.trUtf8("Enabled") off = self.trUtf8("Disabled") selection, ok = KQInputDialog.getItem(\ self, self.trUtf8("Fill to end of line"), self.trUtf8("Select fill to end of line for all styles"), QStringList() << on << off, 0, False) if ok: enabled = selection == on self.eolfillCheckBox.setChecked(enabled) for style in self.lexer.ind2style.values(): self.lexer.setEolFill(enabled, style)
def __sendmail(self, msg): """ Private method to actually send the message. @param msg the message to be sent (string) @return flag indicating success (boolean) """ try: server = smtplib.SMTP(str(Preferences.getUser("MailServer")), Preferences.getUser("MailServerPort")) if Preferences.getUser("MailServerUseTLS"): server.starttls() if Preferences.getUser("MailServerAuthentication"): # mail server needs authentication password = unicode(Preferences.getUser("MailServerPassword")) if not password: password, ok = KQInputDialog.getText( self, self.trUtf8("Mail Server Password"), self.trUtf8("Enter your mail server password"), QLineEdit.Password, ) if not ok: # abort return False try: server.login(unicode(Preferences.getUser("MailServerUser")), str(password)) except (smtplib.SMTPException, socket.error), e: res = KQMessageBox.critical( self, self.trUtf8("Send bug report"), self.trUtf8("""<p>Authentication failed.<br>Reason: %1</p>""").arg(str(e)), QMessageBox.StandardButtons(QMessageBox.Abort | QMessageBox.Retry), QMessageBox.Retry, ) if res == QMessageBox.Retry: return self.__sendmail(msg) else: return False QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() result = server.sendmail(unicode(Preferences.getUser("Email")), self.__toAddress, msg) server.quit() QApplication.restoreOverrideCursor()
def on_addPluginApiFileButton_clicked(self): """ Private slot to add an API file from the list of API files installed by plugins for the selected lexer language. """ pluginAPIFiles = self.pluginManager.getPluginApiFiles(self.currentApiLanguage) pluginAPIFilesDict = {} for apiFile in pluginAPIFiles: pluginAPIFilesDict[unicode(QFileInfo(apiFile).fileName())] = apiFile file, ok = KQInputDialog.getItem( self, self.trUtf8("Add from Plugin APIs"), self.trUtf8("Select from the list of API files installed by plugins"), sorted(pluginAPIFilesDict.keys()), 0, False, ) if ok: self.apiList.addItem(Utilities.toNativeSeparators(pluginAPIFilesDict[unicode(file)]))
def on_addButton_clicked(self): """ Private slot to add a new filter. """ filter, ok = KQInputDialog.getText(\ None, self.trUtf8("Add Filter"), self.trUtf8("Filter name:"), QLineEdit.Normal) if filter.isEmpty(): return ufilter = unicode(filter) if ufilter not in self.__filterMap: self.__filterMap[ufilter] = QStringList() self.filtersList.addItem(filter) itm = self.filtersList.findItems(filter, Qt.MatchCaseSensitive)[0] self.filtersList.setCurrentItem(itm)
def on_addAllowedHostButton_clicked(self): """ Private slot called to add a new allowed host. """ allowedHost, ok = KQInputDialog.getText( None, self.trUtf8("Add allowed host"), self.trUtf8("Enter the IP address of an allowed host"), QLineEdit.Normal, ) if ok and not allowedHost.isEmpty(): if QHostAddress(allowedHost).protocol() in [QAbstractSocket.IPv4Protocol, QAbstractSocket.IPv6Protocol]: self.allowedHostsList.addItem(allowedHost) else: KQMessageBox.critical( None, self.trUtf8("Add allowed host"), self.trUtf8( """<p>The entered address <b>%1</b> is not""" """ a valid IP v4 or IP v6 address. Aborting...</p>""" ).arg(allowedHost), )
def start(self, path, tags = True): """ Public slot to start the svn status command. @param path name of directory to be listed (string) @param tags flag indicating a list of tags is requested (False = branches, True = tags) """ self.errorGroup.hide() if not tags: self.setWindowTitle(self.trUtf8("Subversion Branches List")) self.activateWindow() QApplication.processEvents() dname, fname = self.vcs.splitPath(path) reposURL = self.vcs.svnGetReposName(dname) if reposURL is None: KQMessageBox.critical(None, self.trUtf8("Subversion Error"), self.trUtf8("""The URL of the project repository could not be""" """ retrieved from the working copy. The list operation will""" """ be aborted""")) self.close() return False if self.vcs.otherData["standardLayout"]: # determine the base path of the project in the repository rx_base = QRegExp('(.+)/(trunk|tags|branches).*') if not rx_base.exactMatch(reposURL): KQMessageBox.critical(None, self.trUtf8("Subversion Error"), self.trUtf8("""The URL of the project repository has an""" """ invalid format. The list operation will""" """ be aborted""")) return False reposRoot = unicode(rx_base.cap(1)) if tags: path = "%s/tags" % reposRoot else: path = "%s/branches" % reposRoot else: reposPath, ok = KQInputDialog.getText(\ self, self.trUtf8("Subversion List"), self.trUtf8("Enter the repository URL containing the tags or branches"), QLineEdit.Normal, self.vcs.svnNormalizeURL(reposURL)) if not ok: self.close() return False if reposPath.isEmpty(): KQMessageBox.critical(None, self.trUtf8("Subversion List"), self.trUtf8("""The repository URL is empty. Aborting...""")) self.close() return False path = unicode(reposPath) locker = QMutexLocker(self.vcs.vcsExecutionMutex) self.tagsList = QStringList() cwd = os.getcwd() os.chdir(dname) try: entries = self.client.list(path, recurse = False) for dirent, lock in entries: if dirent["path"] != path: name = dirent["path"].replace(path + '/', "") self.__generateItem(dirent["created_rev"].number, dirent["last_author"], formatTime(dirent["time"]), name) if self.vcs.otherData["standardLayout"]: self.tagsList.append(name) else: self.tagsList.append(path + '/' + name) if self._clientCancelCallback(): break res = True except pysvn.ClientError, e: self.__showError(e.args[0]) res = False
def start(self, path, tags, tagsList, allTagsList): """ Public slot to start the svn status command. @param path name of directory to be listed (string) @param tags flag indicating a list of tags is requested (False = branches, True = tags) @param tagsList reference to string list receiving the tags (QStringList) @param allsTagsLisr reference to string list all tags (QStringList) """ self.errorGroup.hide() self.intercept = False if not tags: self.setWindowTitle(self.trUtf8("Subversion Branches List")) self.activateWindow() self.tagsList = tagsList self.allTagsList = allTagsList dname, fname = self.vcs.splitPath(path) self.process.kill() reposURL = self.vcs.svnGetReposName(dname) if reposURL is None: KQMessageBox.critical(None, self.trUtf8("Subversion Error"), self.trUtf8("""The URL of the project repository could not be""" """ retrieved from the working copy. The list operation will""" """ be aborted""")) self.close() return args = QStringList() args.append('list') self.vcs.addArguments(args, self.vcs.options['global']) args.append('--verbose') if self.vcs.otherData["standardLayout"]: # determine the base path of the project in the repository rx_base = QRegExp('(.+)/(trunk|tags|branches).*') if not rx_base.exactMatch(reposURL): KQMessageBox.critical(None, self.trUtf8("Subversion Error"), self.trUtf8("""The URL of the project repository has an""" """ invalid format. The list operation will""" """ be aborted""")) return reposRoot = unicode(rx_base.cap(1)) if tags: args.append("%s/tags" % reposRoot) else: args.append("%s/branches" % reposRoot) self.path = None else: reposPath, ok = KQInputDialog.getText(\ self, self.trUtf8("Subversion List"), self.trUtf8("Enter the repository URL containing the tags or branches"), QLineEdit.Normal, self.vcs.svnNormalizeURL(reposURL)) if not ok: self.close() return if reposPath.isEmpty(): KQMessageBox.critical(None, self.trUtf8("Subversion List"), self.trUtf8("""The repository URL is empty. Aborting...""")) self.close() return args.append(reposPath) self.path = unicode(reposPath) self.process.setWorkingDirectory(dname) 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')) else: self.inputGroup.setEnabled(True) self.inputGroup.show()
def _vcsImport(self): """ Protected slot used to import the local project into the repository. <b>NOTE</b>: This does not necessarily make the local project a vcs controlled project. You may have to checkout the project from the repository in order to accomplish that. """ def revertChanges(): """ Local function do revert the changes made to the project object. """ self.project.pdata["VCS"] = pdata_vcs[:] self.project.pdata["VCSOPTIONS"] = copy.deepcopy(pdata_vcsoptions) self.project.pdata["VCSOTHERDATA"] = copy.deepcopy(pdata_vcsother) self.project.vcs = vcs self.project.vcsProjectHelper = vcsHelper self.project.vcsBasicHelper = vcs is None self.initMenu(self.project.vcsMenu) self.project.setDirty(True) self.project.saveProject() pdata_vcs = self.project.pdata["VCS"][:] pdata_vcsoptions = copy.deepcopy(self.project.pdata["VCSOPTIONS"]) pdata_vcsother = copy.deepcopy(self.project.pdata["VCSOTHERDATA"]) vcs = self.project.vcs vcsHelper = self.project.vcsProjectHelper vcsSystemsDict = e4App().getObject("PluginManager")\ .getPluginDisplayStrings("version_control") if not vcsSystemsDict: # no version control system found return vcsSystemsDisplay = QStringList() keys = vcsSystemsDict.keys() keys.sort() for key in keys: vcsSystemsDisplay.append(vcsSystemsDict[key]) vcsSelected, ok = KQInputDialog.getItem(\ None, self.trUtf8("Import Project"), self.trUtf8("Select version control system for the project"), vcsSystemsDisplay, 0, False) if not ok: return vcsSystem = None for vcsSystem, vcsSystemDisplay in vcsSystemsDict.items(): if vcsSystemDisplay == vcsSelected: break if vcsSystem: self.project.pdata["VCS"] = [vcsSystem] self.project.vcs = self.project.initVCS(vcsSystem) if self.project.vcs is not None: vcsdlg = self.project.vcs.vcsOptionsDialog(self.project, self.project.name, 1) if vcsdlg.exec_() == QDialog.Accepted: vcsDataDict = vcsdlg.getData() # edit VCS command options vcores = KQMessageBox.question(None, self.trUtf8("Import Project"), self.trUtf8("""Would you like to edit the VCS command options?"""), QMessageBox.StandardButtons(\ QMessageBox.No | \ QMessageBox.Yes), QMessageBox.No) if vcores == QMessageBox.Yes: codlg = vcsCommandOptionsDialog(self.project.vcs) if codlg.exec_() == QDialog.Accepted: self.project.vcs.vcsSetOptions(codlg.getOptions()) self.project.setDirty(True) self.project.vcs.vcsSetDataFromDict(vcsDataDict) self.project.saveProject() isVcsControlled = \ self.project.vcs.vcsImport(vcsDataDict, self.project.ppath)[0] if isVcsControlled: # reopen the project self.project.openProject(self.project.pfile) else: # revert the changes to the local project # because the project dir is not a VCS directory revertChanges() else: # revert the changes because user cancelled revertChanges()
def _vcsCheckout(self, export = False): """ Protected slot used to create a local project from the repository. @param export flag indicating whether an export or a checkout should be performed """ if not self.project.checkDirty(): return vcsSystemsDict = e4App().getObject("PluginManager")\ .getPluginDisplayStrings("version_control") if not vcsSystemsDict: # no version control system found return vcsSystemsDisplay = QStringList() keys = vcsSystemsDict.keys() keys.sort() for key in keys: vcsSystemsDisplay.append(vcsSystemsDict[key]) vcsSelected, ok = KQInputDialog.getItem(\ None, self.trUtf8("New Project"), self.trUtf8("Select version control system for the project"), vcsSystemsDisplay, 0, False) if not ok: return for vcsSystem, vcsSystemDisplay in vcsSystemsDict.items(): if vcsSystemDisplay == vcsSelected: break if not self.project.closeProject(): return self.project.pdata["VCS"] = [vcsSystem] self.project.vcs = self.project.initVCS(vcsSystem) if self.project.vcs is not None: vcsdlg = self.project.vcs.vcsNewProjectOptionsDialog() if vcsdlg.exec_() == QDialog.Accepted: projectdir, vcsDataDict = vcsdlg.getData() self.project.pdata["VCS"] = [vcsSystem] self.project.vcs = self.project.initVCS(vcsSystem) # edit VCS command options vcores = KQMessageBox.question(None, self.trUtf8("New Project"), self.trUtf8("""Would you like to edit the VCS command options?"""), QMessageBox.StandardButtons(\ QMessageBox.No | \ QMessageBox.Yes), QMessageBox.No) if vcores == QMessageBox.Yes: codlg = vcsCommandOptionsDialog(self.project.vcs) if codlg.exec_() == QDialog.Accepted: self.project.vcs.vcsSetOptions(codlg.getOptions()) # create the project directory if it doesn't exist already if not os.path.isdir(projectdir): try: os.makedirs(projectdir) except EnvironmentError: KQMessageBox.critical(None, self.trUtf8("Create project directory"), self.trUtf8("<p>The project directory <b>%1</b> could not" " be created.</p>").arg(projectdir)) self.project.pdata["VCS"] = ['None'] self.project.vcs = self.project.initVCS() return # create the project from the VCS self.project.vcs.vcsSetDataFromDict(vcsDataDict) if export: ok = self.project.vcs.vcsExport(vcsDataDict, projectdir) else: ok = self.project.vcs.vcsCheckout(vcsDataDict, projectdir, False) if ok: projectdir = os.path.normpath(projectdir) filters = QStringList() << "*.e4p" << "*.e4pz" << "*.e3p" << "*.e3pz" d = QDir(projectdir) plist = d.entryInfoList(filters) if len(plist): if len(plist) == 1: self.project.openProject(plist[0].absoluteFilePath()) self.project.emit(SIGNAL('newProject')) else: pfilenamelist = d.entryList(filters) pfilename, ok = KQInputDialog.getItem( None, self.trUtf8("New project from repository"), self.trUtf8("Select a project file to open."), pfilenamelist, 0, False) if ok: self.project.openProject(\ QFileInfo(d, pfilename).absoluteFilePath()) self.project.emit(SIGNAL('newProject')) if export: self.project.pdata["VCS"] = ['None'] self.project.vcs = self.project.initVCS() self.project.setDirty(True) self.project.saveProject() else: res = KQMessageBox.question(None, self.trUtf8("New project from repository"), self.trUtf8("The project retrieved from the repository" " does not contain an eric project file" " (*.e4p *.e4pz *.e3p *.e3pz)." " Create it?"), QMessageBox.StandardButtons(\ QMessageBox.No | \ QMessageBox.Yes), QMessageBox.Yes) if res == QMessageBox.Yes: self.project.ppath = projectdir self.project.opened = True from Project.PropertiesDialog import PropertiesDialog dlg = PropertiesDialog(self.project, False) if dlg.exec_() == QDialog.Accepted: dlg.storeData() self.project.initFileTypes() self.project.setDirty(True) try: ms = os.path.join(self.project.ppath, self.project.pdata["MAINSCRIPT"][0]) if os.path.exists(ms): self.project.appendFile(ms) except IndexError: ms = "" self.project.newProjectAddFiles(ms) self.project.saveProject() self.project.openProject(self.project.pfile) if not export: res = KQMessageBox.question(None, self.trUtf8("New project from repository"), self.trUtf8("Shall the project file be added to" " the repository?"), QMessageBox.StandardButtons(\ QMessageBox.No | \ QMessageBox.Yes), QMessageBox.Yes) if res == QMessageBox.Yes: self.project.vcs.vcsAdd(self.project.pfile) else: KQMessageBox.critical(None, self.trUtf8("New project from repository"), self.trUtf8("""The project could not be retrieved from""" """ the repository.""")) self.project.pdata["VCS"] = ['None'] self.project.vcs = self.project.initVCS() else: self.project.pdata["VCS"] = ['None'] self.project.vcs = self.project.initVCS()