Added capability to change the keywords of a syntax highlighter.

Sun, 28 Feb 2010 17:29:01 +0000

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 28 Feb 2010 17:29:01 +0000
changeset 131
60d355abbcd8
parent 130
fcce4cc20d95
child 132
2c870b5b485a

Added capability to change the keywords of a syntax highlighter.

Documentation/Source/eric5.Preferences.ConfigurationPages.EditorKeywordsPage.html file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/EditorKeywordsPage.py file | annotate | diff | comparison | revisions
Preferences/ConfigurationPages/EditorKeywordsPage.ui file | annotate | diff | comparison | revisions
icons/default/preferences-keywords.png file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Documentation/Source/eric5.Preferences.ConfigurationPages.EditorKeywordsPage.html	Sun Feb 28 17:29:01 2010 +0000
@@ -0,0 +1,119 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
+'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
+<html><head>
+<title>eric5.Preferences.ConfigurationPages.EditorKeywordsPage</title>
+<style>
+body {
+    background:white;
+    margin: 0em 1em 10em 1em;
+    color: black;
+}
+
+h1 { color: white; background: #4FA4FF; }
+h2 { color: white; background: #4FA4FF; }
+h3 { color: white; background: #00557F; }
+h4 { color: white; background: #00557F; }
+    
+a { color: #AA5500; }
+
+</style>
+</head>
+<body><a NAME="top" ID="top"></a>
+<h1>eric5.Preferences.ConfigurationPages.EditorKeywordsPage</h1>
+<p>
+Module implementing the editor highlighter keywords configuration page.
+</p>
+<h3>Global Attributes</h3>
+<table>
+<tr><td>None</td></tr>
+</table>
+<h3>Classes</h3>
+<table>
+<tr>
+<td><a href="#EditorKeywordsPage">EditorKeywordsPage</a></td>
+<td>Class implementing the editor highlighter keywords configuration page.</td>
+</tr>
+</table>
+<h3>Functions</h3>
+<table>
+<tr>
+<td><a href="#create">create</a></td>
+<td>Module function to create the configuration page.</td>
+</tr>
+</table>
+<hr /><hr />
+<a NAME="EditorKeywordsPage" ID="EditorKeywordsPage"></a>
+<h2>EditorKeywordsPage</h2>
+<p>
+    Class implementing the editor highlighter keywords configuration page.
+</p>
+<h3>Derived from</h3>
+ConfigurationPageBase, Ui_EditorKeywordsPage
+<h3>Class Attributes</h3>
+<table>
+<tr><td>None</td></tr>
+</table>
+<h3>Methods</h3>
+<table>
+<tr>
+<td><a href="#EditorKeywordsPage.__init__">EditorKeywordsPage</a></td>
+<td>Constructor</td>
+</tr><tr>
+<td><a href="#EditorKeywordsPage.on_languageCombo_activated">on_languageCombo_activated</a></td>
+<td>Private slot to fill the keywords edit.</td>
+</tr><tr>
+<td><a href="#EditorKeywordsPage.on_setSpinBox_valueChanged">on_setSpinBox_valueChanged</a></td>
+<td>Private slot to fill the keywords edit.</td>
+</tr><tr>
+<td><a href="#EditorKeywordsPage.save">save</a></td>
+<td>Public slot to save the editor highlighter keywords configuration.</td>
+</tr>
+</table>
+<a NAME="EditorKeywordsPage.__init__" ID="EditorKeywordsPage.__init__"></a>
+<h4>EditorKeywordsPage (Constructor)</h4>
+<b>EditorKeywordsPage</b>(<i></i>)
+<p>
+        Constructor
+</p><a NAME="EditorKeywordsPage.on_languageCombo_activated" ID="EditorKeywordsPage.on_languageCombo_activated"></a>
+<h4>EditorKeywordsPage.on_languageCombo_activated</h4>
+<b>on_languageCombo_activated</b>(<i>language</i>)
+<p>
+        Private slot to fill the keywords edit.
+</p><dl>
+<dt><i>language</i></dt>
+<dd>
+selected language (string)
+</dd>
+</dl><a NAME="EditorKeywordsPage.on_setSpinBox_valueChanged" ID="EditorKeywordsPage.on_setSpinBox_valueChanged"></a>
+<h4>EditorKeywordsPage.on_setSpinBox_valueChanged</h4>
+<b>on_setSpinBox_valueChanged</b>(<i>kwSet</i>)
+<p>
+        Private slot to fill the keywords edit.
+</p><dl>
+<dt><i>kwSet</i></dt>
+<dd>
+number of the selected keyword set (integer)
+</dd>
+</dl><a NAME="EditorKeywordsPage.save" ID="EditorKeywordsPage.save"></a>
+<h4>EditorKeywordsPage.save</h4>
+<b>save</b>(<i></i>)
+<p>
+        Public slot to save the editor highlighter keywords configuration.
+</p>
+<div align="right"><a href="#top">Up</a></div>
+<hr /><hr />
+<a NAME="create" ID="create"></a>
+<h2>create</h2>
+<b>create</b>(<i>dlg</i>)
+<p>
+    Module function to create the configuration page.
+</p><dl>
+<dt><i>dlg</i></dt>
+<dd>
+reference to the configuration dialog
+</dd>
+</dl>
+<div align="right"><a href="#top">Up</a></div>
+<hr />
+</body></html>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Preferences/ConfigurationPages/EditorKeywordsPage.py	Sun Feb 28 17:29:01 2010 +0000
@@ -0,0 +1,122 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the editor highlighter keywords configuration page.
+"""
+
+from PyQt4.QtCore import pyqtSlot
+from PyQt4.QtGui import QWidget
+
+from .ConfigurationPageBase import ConfigurationPageBase
+from .Ui_EditorKeywordsPage import Ui_EditorKeywordsPage
+
+import QScintilla.Lexers
+
+import Preferences
+
+class EditorKeywordsPage(ConfigurationPageBase, Ui_EditorKeywordsPage):
+    """
+    Class implementing the editor highlighter keywords configuration page.
+    """
+    def __init__(self):
+        """
+        Constructor
+        """
+        ConfigurationPageBase.__init__(self)
+        self.setupUi(self)
+        self.setObjectName("EditorKeywordsPage")
+        
+        # set initial values
+        self.__keywords = {
+            "" : ["", "", "", "", "", "", "", "", "", ""]
+        }
+        languages = sorted([''] + \
+                    list(QScintilla.Lexers.getSupportedLanguages().keys()))
+        for lang in languages:
+            if lang != "Guessed":
+                self.languageCombo.addItem(lang)
+        
+        for lang in languages[1:]:
+            keywords = Preferences.getEditorKeywords(lang)[:]
+            if not keywords:
+                keywords = [""]
+                lex = QScintilla.Lexers.getLexer(lang)
+                for kwSet in range(1, 10):
+                    kw = lex.keywords(kwSet)
+                    if kw is None:
+                        kw = ""
+                    keywords.append(kw)
+            self.__keywords[lang] = keywords
+        
+        self.currentLanguage = ''
+        self.currentSet = 1
+        self.on_languageCombo_activated(self.currentLanguage)
+    
+    def save(self):
+        """
+        Public slot to save the editor highlighter keywords configuration.
+        """
+        lang = self.languageCombo.currentText()
+        kwSet = self.setSpinBox.value()
+        self.__keywords[lang][kwSet] = self.keywordsEdit.toPlainText()
+        
+        for lang, keywords in self.__keywords.items():
+            Preferences.setEditorKeywords(lang, keywords)
+        
+    @pyqtSlot(str)
+    def on_languageCombo_activated(self, language):
+        """
+        Private slot to fill the keywords edit.
+        
+        @param language selected language (string)
+        """
+        if self.currentLanguage == language:
+            return
+        
+        if self.setSpinBox.value() == 1:
+            self.on_setSpinBox_valueChanged(1)
+        first, last = 10, 0
+        for kwSet in range(1, 10):
+            if self.__keywords[language][kwSet] != "":
+                first = min(first, kwSet)
+                last = max(last, kwSet)
+        self.setSpinBox.setEnabled(language != "" and first < 10)
+        self.keywordsEdit.setEnabled(language != "" and first < 10)
+        if first < 10:
+            self.setSpinBox.setMinimum(first)
+            self.setSpinBox.setMaximum(last)
+            self.setSpinBox.setValue(first)
+        else:
+            self.setSpinBox.setMinimum(0)
+            self.setSpinBox.setMaximum(0)
+            self.setSpinBox.setValue(0)
+    
+    @pyqtSlot(int)
+    def on_setSpinBox_valueChanged(self, kwSet):
+        """
+        Private slot to fill the keywords edit.
+        
+        @param kwSet number of the selected keyword set (integer)
+        """
+        language = self.languageCombo.currentText()
+        if self.currentLanguage == language and self.currentSet == kwSet:
+            return
+        
+        self.__keywords[self.currentLanguage][self.currentSet] = \
+            self.keywordsEdit.toPlainText()
+        
+        self.currentApiLanguage = language
+        self.currentSet = kwSet
+        self.keywordsEdit.setPlainText(self.__keywords[language][kwSet])
+
+def create(dlg):
+    """
+    Module function to create the configuration page.
+    
+    @param dlg reference to the configuration dialog
+    """
+    page = EditorKeywordsPage()
+    return page
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Preferences/ConfigurationPages/EditorKeywordsPage.ui	Sun Feb 28 17:29:01 2010 +0000
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>EditorKeywordsPage</class>
+ <widget class="QWidget" name="EditorKeywordsPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>462</width>
+    <height>422</height>
+   </rect>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="headerLabel">
+     <property name="text">
+      <string>&lt;b&gt;Configure syntax highlighter keywords&lt;/b&gt;</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="Line" name="line5">
+     <property name="frameShape">
+      <enum>QFrame::HLine</enum>
+     </property>
+     <property name="frameShadow">
+      <enum>QFrame::Sunken</enum>
+     </property>
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <widget class="QLabel" name="TextLabel1_3_3">
+       <property name="toolTip">
+        <string/>
+       </property>
+       <property name="text">
+        <string>Language:</string>
+       </property>
+       <property name="buddy">
+        <cstring></cstring>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QComboBox" name="languageCombo">
+       <property name="sizePolicy">
+        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
+         <horstretch>0</horstretch>
+         <verstretch>0</verstretch>
+        </sizepolicy>
+       </property>
+       <property name="toolTip">
+        <string>Select the language to be configured.</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="label">
+       <property name="text">
+        <string>Set:</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QSpinBox" name="setSpinBox">
+       <property name="minimum">
+        <number>1</number>
+       </property>
+       <property name="maximum">
+        <number>9</number>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QPlainTextEdit" name="keywordsEdit">
+     <property name="toolTip">
+      <string>Enter the keywords separated by a blank</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <tabstops>
+  <tabstop>languageCombo</tabstop>
+  <tabstop>setSpinBox</tabstop>
+  <tabstop>keywordsEdit</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
Binary file icons/default/preferences-keywords.png has changed

eric ide

mercurial