Editor

Tue, 23 Feb 2021 17:38:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 23 Feb 2021 17:38:12 +0100
changeset 8131
f2129bb79269
parent 8130
5fe4ff181b68
child 8132
311afc776982

Editor
- added support for Cython to the code outline/navigation lists
- added support for Cython to the Typing Completers

File Browser
- added Cython support to show the file structure of these files

docs/changelog file | annotate | diff | comparison | revisions
eric6/APIs/Python3/eric6.api file | annotate | diff | comparison | revisions
eric6/Documentation/Help/source.qch file | annotate | diff | comparison | revisions
eric6/Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
eric6/Documentation/Source/eric6.QScintilla.Editor.html file | annotate | diff | comparison | revisions
eric6/Documentation/Source/eric6.UI.BrowserModel.html file | annotate | diff | comparison | revisions
eric6/QScintilla/Editor.py file | annotate | diff | comparison | revisions
eric6/QScintilla/EditorAssembly.py file | annotate | diff | comparison | revisions
eric6/QScintilla/EditorOutlineModel.py file | annotate | diff | comparison | revisions
eric6/QScintilla/TypingCompleters/CompleterPython.py file | annotate | diff | comparison | revisions
eric6/QScintilla/TypingCompleters/__init__.py file | annotate | diff | comparison | revisions
eric6/UI/BrowserModel.py file | annotate | diff | comparison | revisions
eric6/Utilities/ClassBrowsers/pyclbr.py file | annotate | diff | comparison | revisions
eric6/Utilities/ModuleParser.py file | annotate | diff | comparison | revisions
--- a/docs/changelog	Tue Feb 23 17:31:36 2021 +0100
+++ b/docs/changelog	Tue Feb 23 17:38:12 2021 +0100
@@ -5,6 +5,7 @@
 - General
   -- changed the default file format for several generated files to be based on
      JSON
+  -- added support for Cython
 - Debugger
   -- added capability to delete environment variables for the debugged script
      by adding a '-' to the variable name in the start dialog
@@ -12,9 +13,12 @@
   -- changed code to show project relative paths in the breakpoint viewer
 - Editor
   -- integrated the "Quick Search" functionality into the editor search widget
+  -- added support for Cython to the code outline/navigation lists
+  -- added support for Cython to the Typing Completers
 - File Browser
   -- added capability to show/hide hidden files (i.e. those starting with '.')
   -- added capability to create new files/directories and delete them
+  -- added Cython support to show the file structure of these files
 - Mercurial Interface
   -- added support for Mercurial 5.7
 - MicroPython
--- a/eric6/APIs/Python3/eric6.api	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/APIs/Python3/eric6.api	Tue Feb 23 17:38:12 2021 +0100
@@ -7649,6 +7649,7 @@
 eric6.QScintilla.Editor.Editor.indentLineOrSelection?4()
 eric6.QScintilla.Editor.Editor.insertDocstring?4()
 eric6.QScintilla.Editor.Editor.isClone?4(editor)
+eric6.QScintilla.Editor.Editor.isCythonFile?4()
 eric6.QScintilla.Editor.Editor.isJavascriptFile?4()
 eric6.QScintilla.Editor.Editor.isLastEditPositionAvailable?4()
 eric6.QScintilla.Editor.Editor.isMicroPythonFile?4()
@@ -7755,7 +7756,7 @@
 eric6.QScintilla.Editor.Editor.viewportEvent?4(evt)
 eric6.QScintilla.Editor.Editor.wheelEvent?4(evt)
 eric6.QScintilla.Editor.Editor.writeFile?4(fn, backup=True)
-eric6.QScintilla.Editor.Editor?1(dbs, fn="", vm=None, filetype="", editor=None, tv=None)
+eric6.QScintilla.Editor.Editor?1(dbs, fn="", vm=None, filetype="", editor=None, tv=None, parent=None)
 eric6.QScintilla.Editor.EditorAutoCompletionListID?7
 eric6.QScintilla.Editor.TemplateCompletionListID?7
 eric6.QScintilla.EditorAssembly.EditorAssembly.getEditor?4()
@@ -8947,6 +8948,7 @@
 eric6.UI.BrowserModel.BrowserFileItem.dirName?4()
 eric6.UI.BrowserModel.BrowserFileItem.fileExt?4()
 eric6.UI.BrowserModel.BrowserFileItem.fileName?4()
+eric6.UI.BrowserModel.BrowserFileItem.isCythonFile?4()
 eric6.UI.BrowserModel.BrowserFileItem.isDFile?4()
 eric6.UI.BrowserModel.BrowserFileItem.isDesignerFile?4()
 eric6.UI.BrowserModel.BrowserFileItem.isIdlFile?4()
Binary file eric6/Documentation/Help/source.qch has changed
--- a/eric6/Documentation/Help/source.qhp	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/Documentation/Help/source.qhp	Tue Feb 23 17:38:12 2021 +0100
@@ -2227,6 +2227,7 @@
       <keyword name="BrowserFileItem.dirName" id="BrowserFileItem.dirName" ref="eric6.UI.BrowserModel.html#BrowserFileItem.dirName" />
       <keyword name="BrowserFileItem.fileExt" id="BrowserFileItem.fileExt" ref="eric6.UI.BrowserModel.html#BrowserFileItem.fileExt" />
       <keyword name="BrowserFileItem.fileName" id="BrowserFileItem.fileName" ref="eric6.UI.BrowserModel.html#BrowserFileItem.fileName" />
+      <keyword name="BrowserFileItem.isCythonFile" id="BrowserFileItem.isCythonFile" ref="eric6.UI.BrowserModel.html#BrowserFileItem.isCythonFile" />
       <keyword name="BrowserFileItem.isDFile" id="BrowserFileItem.isDFile" ref="eric6.UI.BrowserModel.html#BrowserFileItem.isDFile" />
       <keyword name="BrowserFileItem.isDesignerFile" id="BrowserFileItem.isDesignerFile" ref="eric6.UI.BrowserModel.html#BrowserFileItem.isDesignerFile" />
       <keyword name="BrowserFileItem.isIdlFile" id="BrowserFileItem.isIdlFile" ref="eric6.UI.BrowserModel.html#BrowserFileItem.isIdlFile" />
@@ -5122,6 +5123,7 @@
       <keyword name="Editor.indentLineOrSelection" id="Editor.indentLineOrSelection" ref="eric6.QScintilla.Editor.html#Editor.indentLineOrSelection" />
       <keyword name="Editor.insertDocstring" id="Editor.insertDocstring" ref="eric6.QScintilla.Editor.html#Editor.insertDocstring" />
       <keyword name="Editor.isClone" id="Editor.isClone" ref="eric6.QScintilla.Editor.html#Editor.isClone" />
+      <keyword name="Editor.isCythonFile" id="Editor.isCythonFile" ref="eric6.QScintilla.Editor.html#Editor.isCythonFile" />
       <keyword name="Editor.isJavascriptFile" id="Editor.isJavascriptFile" ref="eric6.QScintilla.Editor.html#Editor.isJavascriptFile" />
       <keyword name="Editor.isLastEditPositionAvailable" id="Editor.isLastEditPositionAvailable" ref="eric6.QScintilla.Editor.html#Editor.isLastEditPositionAvailable" />
       <keyword name="Editor.isMicroPythonFile" id="Editor.isMicroPythonFile" ref="eric6.QScintilla.Editor.html#Editor.isMicroPythonFile" />
--- a/eric6/Documentation/Source/eric6.QScintilla.Editor.html	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/Documentation/Source/eric6.QScintilla.Editor.html	Tue Feb 23 17:38:12 2021 +0100
@@ -1357,6 +1357,10 @@
 <td>Public method to test, if the given editor is a clone.</td>
 </tr>
 <tr>
+<td><a href="#Editor.isCythonFile">isCythonFile</a></td>
+<td>Public method to return a flag indicating a Cython file.</td>
+</tr>
+<tr>
 <td><a href="#Editor.isJavascriptFile">isJavascriptFile</a></td>
 <td>Public method to return a flag indicating a Javascript file.</td>
 </tr>
@@ -1741,39 +1745,42 @@
 
 <a NAME="Editor.__init__" ID="Editor.__init__"></a>
 <h4>Editor (Constructor)</h4>
-<b>Editor</b>(<i>dbs, fn="", vm=None, filetype="", editor=None, tv=None</i>)
+<b>Editor</b>(<i>dbs, fn="", vm=None, filetype="", editor=None, tv=None, parent=None</i>)
 
 <p>
         Constructor
 </p>
 <dl>
 
-<dt><i>dbs</i></dt>
+<dt><i>dbs</i> (DebugServer)</dt>
 <dd>
 reference to the debug server object
 </dd>
-<dt><i>fn</i></dt>
-<dd>
-name of the file to be opened (string). If it is None,
-                a new (empty) editor is opened
-</dd>
-<dt><i>vm</i></dt>
+<dt><i>fn</i> (str)</dt>
+<dd>
+name of the file to be opened. If it is None, a new (empty)
+            editor is opened.
+</dd>
+<dt><i>vm</i> (ViewManager)</dt>
 <dd>
 reference to the view manager object
-            (ViewManager.ViewManager)
-</dd>
-<dt><i>filetype</i></dt>
-<dd>
-type of the source file (string)
-</dd>
-<dt><i>editor</i></dt>
+</dd>
+<dt><i>filetype</i> (str)</dt>
+<dd>
+type of the source file
+</dd>
+<dt><i>editor</i> (Editor)</dt>
 <dd>
 reference to an Editor object, if this is a cloned view
 </dd>
-<dt><i>tv</i></dt>
+<dt><i>tv</i> (TaskViewer)</dt>
 <dd>
 reference to the task viewer object
 </dd>
+<dt><i>parent</i> (QWidget)</dt>
+<dd>
+reference to the parent widget
+</dd>
 </dl>
 <dl>
 
@@ -5633,6 +5640,25 @@
 bool
 </dd>
 </dl>
+<a NAME="Editor.isCythonFile" ID="Editor.isCythonFile"></a>
+<h4>Editor.isCythonFile</h4>
+<b>isCythonFile</b>(<i></i>)
+
+<p>
+        Public method to return a flag indicating a Cython file.
+</p>
+<dl>
+<dt>Return:</dt>
+<dd>
+flag indicating a Cython file
+</dd>
+</dl>
+<dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl>
 <a NAME="Editor.isJavascriptFile" ID="Editor.isJavascriptFile"></a>
 <h4>Editor.isJavascriptFile</h4>
 <b>isJavascriptFile</b>(<i></i>)
--- a/eric6/Documentation/Source/eric6.UI.BrowserModel.html	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/Documentation/Source/eric6.UI.BrowserModel.html	Tue Feb 23 17:38:12 2021 +0100
@@ -904,6 +904,10 @@
 <td>Public method returning the filename.</td>
 </tr>
 <tr>
+<td><a href="#BrowserFileItem.isCythonFile">isCythonFile</a></td>
+<td>Public method to check, if this file is a Cython file.</td>
+</tr>
+<tr>
 <td><a href="#BrowserFileItem.isDFile">isDFile</a></td>
 <td>Public method to check, if this file is a D file.</td>
 </tr>
@@ -1043,6 +1047,25 @@
 filename (string)
 </dd>
 </dl>
+<a NAME="BrowserFileItem.isCythonFile" ID="BrowserFileItem.isCythonFile"></a>
+<h4>BrowserFileItem.isCythonFile</h4>
+<b>isCythonFile</b>(<i></i>)
+
+<p>
+        Public method to check, if this file is a Cython file.
+</p>
+<dl>
+<dt>Return:</dt>
+<dd>
+flag indicating a Cython file
+</dd>
+</dl>
+<dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
+</dl>
 <a NAME="BrowserFileItem.isDFile" ID="BrowserFileItem.isDFile"></a>
 <h4>BrowserFileItem.isDFile</h4>
 <b>isDFile</b>(<i></i>)
@@ -1176,7 +1199,13 @@
 <dl>
 <dt>Return:</dt>
 <dd>
-flag indicating a Python file (boolean)
+flag indicating a Python3 file
+</dd>
+</dl>
+<dl>
+<dt>Return Type:</dt>
+<dd>
+bool
 </dd>
 </dl>
 <a NAME="BrowserFileItem.isResourcesFile" ID="BrowserFileItem.isResourcesFile"></a>
--- a/eric6/QScintilla/Editor.py	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/QScintilla/Editor.py	Tue Feb 23 17:38:12 2021 +0100
@@ -171,21 +171,29 @@
     }
     
     def __init__(self, dbs, fn="", vm=None,
-                 filetype="", editor=None, tv=None):
+                 filetype="", editor=None, tv=None,
+                 parent=None):
         """
         Constructor
         
         @param dbs reference to the debug server object
-        @param fn name of the file to be opened (string). If it is None,
-                a new (empty) editor is opened
+        @type DebugServer
+        @param fn name of the file to be opened. If it is None, a new (empty)
+            editor is opened.
+        @type str
         @param vm reference to the view manager object
-            (ViewManager.ViewManager)
-        @param filetype type of the source file (string)
+        @type ViewManager
+        @param filetype type of the source file
+        @type str
         @param editor reference to an Editor object, if this is a cloned view
+        @type Editor
         @param tv reference to the task viewer object
+        @type TaskViewer
+        @param parent reference to the parent widget
+        @type QWidget
         @exception OSError raised to indicate an issue accessing the file
         """
-        super(Editor, self).__init__()
+        super(Editor, self).__init__(parent)
         self.setAttribute(Qt.WA_KeyCompression)
         self.setUtf8(True)
         
@@ -1761,7 +1769,7 @@
                 pyVer = Utilities.determinePythonVersion(
                     filename, self.text(0), self)
                 language = "Python{0}".format(pyVer)
-            if language in ['Python3', 'MicroPython', 'Ruby',
+            if language in ['Python3', 'MicroPython', 'Cython', 'Ruby',
                             'JavaScript', 'YAML', 'JSON']:
                 self.filetype = language
             else:
@@ -2102,6 +2110,18 @@
             return True
         
         return False
+    
+    def isCythonFile(self):
+        """
+        Public method to return a flag indicating a Cython file.
+        
+        @return flag indicating a Cython file
+        @rtype bool
+        """
+        if self.filetype == "Cython":
+            return True
+        
+        return False
 
     def isRubyFile(self):
         """
--- a/eric6/QScintilla/EditorAssembly.py	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/QScintilla/EditorAssembly.py	Tue Feb 23 17:38:12 2021 +0100
@@ -53,7 +53,7 @@
         
         self.__showOutline = Preferences.getEditor("ShowSourceOutline")
         
-        self.__editor = Editor(dbs, fn, vm, filetype, editor, tv)
+        self.__editor = Editor(dbs, fn, vm, filetype, editor, tv, parent=self)
         self.__buttonsWidget = EditorButtonsWidget(self.__editor, self)
         self.__globalsCombo = QComboBox()
         self.__globalsCombo.setDuplicatesEnabled(True)
--- a/eric6/QScintilla/EditorOutlineModel.py	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/QScintilla/EditorOutlineModel.py	Tue Feb 23 17:38:12 2021 +0100
@@ -25,7 +25,8 @@
     Class implementing the editor outline model.
     """
     SupportedLanguages = (
-        "IDL", "JavaScript", "Protocol", "Python3", "MicroPython", "Ruby",
+        "IDL", "JavaScript", "Protocol", "Python3", "MicroPython", "Cython",
+        "Ruby",
     )
     
     def __init__(self, editor, populate=True):
@@ -81,7 +82,7 @@
                 dictionary = jsclbr.scan(
                     self.__editor.text(), self.__filename, self.__module)
                 jsclbr._modules.clear()
-            elif language in ("Python3", "MicroPython"):
+            elif language in ("Python3", "MicroPython", "Cython"):
                 from Utilities.ClassBrowsers import pyclbr
                 dictionary = pyclbr.scan(
                     self.__editor.text(), self.__filename, self.__module)
--- a/eric6/QScintilla/TypingCompleters/CompleterPython.py	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/QScintilla/TypingCompleters/CompleterPython.py	Tue Feb 23 17:38:12 2021 +0100
@@ -30,10 +30,14 @@
         """
         super(CompleterPython, self).__init__(editor, parent)
         
-        self.__defRX = re.compile(r"^[ \t]*def \w+\(")
-        self.__defSelfRX = re.compile(r"^[ \t]*def \w+\([ \t]*self[ \t]*[,)]")
-        self.__defClsRX = re.compile(r"^[ \t]*def \w+\([ \t]*cls[ \t]*[,)]")
-        self.__classRX = re.compile(r"^[ \t]*class \w+\(")
+        self.__defRX = re.compile(
+            r"^[ \t]*(def|cdef|cpdef) \w+\(")
+        self.__defSelfRX = re.compile(
+            r"^[ \t]*(def|cdef|cpdef) \w+\([ \t]*self[ \t]*[,)]")
+        self.__defClsRX = re.compile(
+            r"^[ \t]*(def|cdef|cpdef) \w+\([ \t]*cls[ \t]*[,)]")
+        self.__classRX = re.compile(
+            r"^[ \t]*(cdef[ \t]+)?class \w+\(")
         self.__importRX = re.compile(r"^[ \t]*from [\w.]+ ")
         self.__classmethodRX = re.compile(r"^[ \t]*@classmethod")
         self.__staticmethodRX = re.compile(r"^[ \t]*@staticmethod")
--- a/eric6/QScintilla/TypingCompleters/__init__.py	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/QScintilla/TypingCompleters/__init__.py	Tue Feb 23 17:38:12 2021 +0100
@@ -18,7 +18,7 @@
     @return reference to the instanciated lexer object (QsciLexer)
     """
     try:
-        if language in ["Python", "Python3", "MicroPython"]:
+        if language in ["Python", "Python3", "MicroPython", "Cython"]:
             from .CompleterPython import CompleterPython
             return CompleterPython(editor, parent)
         elif language == "Ruby":
--- a/eric6/UI/BrowserModel.py	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/UI/BrowserModel.py	Tue Feb 23 17:38:12 2021 +0100
@@ -621,7 +621,7 @@
         try:
             dictionary = Utilities.ClassBrowsers.readmodule(
                 moduleName, [parentItem.dirName()],
-                parentItem.isPython3File())
+                parentItem.isPython3File() or parentItem.isCythonFile())
         except ImportError:
             return
         
@@ -1160,6 +1160,11 @@
             self._populated = False
             self._lazyPopulation = True
             self._moduleName = os.path.basename(finfo)
+        elif self.isCythonFile():
+            pixName = "lexerCython"
+            self._populated = False
+            self._lazyPopulation = True
+            self._moduleName = os.path.basename(finfo)
         elif self.isRubyFile():
             pixName = "fileRuby"
             self._populated = False
@@ -1270,13 +1275,26 @@
         """
         Public method to check, if this file is a Python3 script.
         
-        @return flag indicating a Python file (boolean)
+        @return flag indicating a Python3 file
+        @rtype bool
         """
         return (
             self.fileext in Preferences.getPython("Python3Extensions") or
             (self.fileext == "" and self.sourceLanguage == "Python3")
         )
     
+    def isCythonFile(self):
+        """
+        Public method to check, if this file is a Cython file.
+        
+        @return flag indicating a Cython file
+        @rtype bool
+        """
+        return (
+            self.fileext in (".pyx", ".pxd", ".pxi") or
+            (self.fileext == "" and self.sourceLanguage == "Cython")
+        )
+    
     def isRubyFile(self):
         """
         Public method to check, if this file is a Ruby script.
--- a/eric6/Utilities/ClassBrowsers/pyclbr.py	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/Utilities/ClassBrowsers/pyclbr.py	Tue Feb 23 17:38:12 2021 +0100
@@ -64,7 +64,7 @@
 |   (?P<Method>
         ^
         (?P<MethodIndent> [ \t]* )
-        (?: async [ \t]+ )? def [ \t]+
+        (?: async [ \t]+ )? (?: cdef | cpdef | def) [ \t]+
         (?P<MethodName> \w+ )
         (?: [ \t]* \[ (?: plain | html ) \] )?
         [ \t]* \(
@@ -77,6 +77,7 @@
 |   (?P<Class>
         ^
         (?P<ClassIndent> [ \t]* )
+        (?: cdef [ \t]+ )?
         class [ \t]+
         (?P<ClassName> \w+ )
         [ \t]*
@@ -112,7 +113,7 @@
     )
 
 |   (?P<Import>
-        ^ [ \t]* (?: import | from [ \t]+ \. [ \t]+ import ) [ \t]+
+        ^ [ \t]* (?: c? import | from [ \t]+ \. [ \t]+ c? import ) [ \t]+
         (?P<ImportList> (?: [^#;\\\n]* (?: \\\n )* )* )
     )
 
@@ -125,7 +126,7 @@
             )*
         )
         [ \t]+
-        import [ \t]+
+        c? import [ \t]+
         (?P<ImportFromList>
             (?: \( \s* .*? \s* \) )
             |
--- a/eric6/Utilities/ModuleParser.py	Tue Feb 23 17:31:36 2021 +0100
+++ b/eric6/Utilities/ModuleParser.py	Tue Feb 23 17:38:12 2021 +0100
@@ -37,6 +37,7 @@
     "Python": PY_SOURCE,
     "Python3": PY_SOURCE,
     "MicroPython": PY_SOURCE,
+    "Cython": PY_SOURCE,
     "Ruby": RB_SOURCE,
 }
 
@@ -134,7 +135,7 @@
         )?
         ^
         (?P<MethodIndent> [ \t]* )
-        (?: async [ \t]+ )? def [ \t]+
+        (?: async [ \t]+ )? (?: cdef | cpdef | def) [ \t]+
         (?P<MethodName> \w+ )
         (?: [ \t]* \[ (?: plain | html ) \] )?
         [ \t]* \(
@@ -147,6 +148,7 @@
 |   (?P<Class>
         ^
         (?P<ClassIndent> [ \t]* )
+        (?: cdef [ \t]+ )?
         class [ \t]+
         (?P<ClassName> \w+ )
         [ \t]*
@@ -175,7 +177,7 @@
     )
 
 |   (?P<Import>
-        ^ [ \t]* (?: import | from [ \t]+ \. [ \t]+ import ) [ \t]+
+        ^ [ \t]* (?: c? import | from [ \t]+ \. [ \t]+ c? import ) [ \t]+
         (?P<ImportList> (?: [^#;\\\n]* (?: \\\n )* )* )
     )
 
@@ -188,7 +190,7 @@
             )*
         )
         [ \t]+
-        import [ \t]+
+        c? import [ \t]+
         (?P<ImportFromList>
             (?: \( \s* .*? \s* \) )
             |

eric ide

mercurial