Skip to content

Commit

Permalink
Merge pull request #4975 from rlaverde/split-editor
Browse files Browse the repository at this point in the history
PR: Split Editor module
  • Loading branch information
ccordoba12 authored Aug 18, 2017
2 parents 7e85cba + 96a81bb commit b5afc36
Show file tree
Hide file tree
Showing 43 changed files with 165 additions and 120 deletions.
4 changes: 2 additions & 2 deletions spyder/api/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
This module contains the code editor API.
"""

from spyder.widgets.sourcecode.api.folding import print_tree, FoldDetector
from spyder.widgets.sourcecode.api.decoration import TextDecoration
from spyder.plugins.editor.api.folding import print_tree, FoldDetector
from spyder.plugins.editor.api.decoration import TextDecoration
10 changes: 6 additions & 4 deletions spyder/api/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Mode(object):
A panel (model child class) is added to an editor by using the
PanelsManager:
- :meth:`spyder.widgets.sourcecode.CodeEditor.panels.append`
- :meth:
`spyder.plugins.editor.widgets.codeeditor.CodeEditor.panels.append`
Subclasses may/should override the following methods:
Expand All @@ -43,7 +44,7 @@ def editor(self):
**READ ONLY**
:rtype: spyder.widgets.sourcecode.CodeEditor
:rtype: spyder.plugins.editor.widgets.codeeditor.CodeEditor
"""
if self._editor is not None:
return self._editor
Expand All @@ -70,7 +71,8 @@ def enabled(self, enabled):

def __init__(self):
"""
Mode name/identifier. :class:`spyder.widgets.sourcecode.CodeEditor`
Mode name/identifier.
:class:`spyder.plugins.editor.widgets.codeeditor.CodeEditor`
uses that as the attribute key when you install a mode.
"""
self.name = self.__class__.__name__
Expand All @@ -88,7 +90,7 @@ def on_install(self, editor):
Installs the extension on the editor.
:param editor: editor widget instance
:type editor: spyder.widgets.sourcecode.CodeEditor
:type editor: spyder.plugins.editor.widgets.codeeditor.CodeEditor
.. note:: This method is called by editor when you install a Mode.
You should never call it yourself, even in a subclasss.
Expand Down
2 changes: 1 addition & 1 deletion spyder/api/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def on_install(self, editor):
method!
:param editor: editor instance
:type editor: spyder.widgets.sourcecode.CodeEditor
:type editor: spyder.plugins.editor.widgets.codeeditor.CodeEditor
"""
Mode.on_install(self, editor)
self.setParent(editor)
Expand Down
6 changes: 3 additions & 3 deletions spyder/app/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ def create_edit_action(text, tr_text, icon):

# Editor plugin
self.set_splash(_("Loading editor..."))
from spyder.plugins.editor import Editor
from spyder.plugins.editor.plugin import Editor
self.editor = Editor(self)
self.editor.register_plugin()

Expand Down Expand Up @@ -1970,7 +1970,7 @@ def get_focus_widget_properties(self):
booleans: (is_console, not_readonly, readwrite_editor)"""
widget = QApplication.focusWidget()
from spyder.widgets.shell import ShellBaseWidget
from spyder.widgets.editor import TextEditBaseWidget
from spyder.plugins.editor.widgets.editor import TextEditBaseWidget
from spyder.widgets.ipythonconsole import ControlWidget

# if focused widget isn't valid try the last focused
Expand Down Expand Up @@ -2402,7 +2402,7 @@ def global_callback(self):
widget = QApplication.focusWidget()
action = self.sender()
callback = from_qvariant(action.data(), to_text_string)
from spyder.widgets.editor import TextEditBaseWidget
from spyder.plugins.editor.widgets.editor import TextEditBaseWidget

# if focused widget isn't valid try the last focused^M
if not isinstance(widget, TextEditBaseWidget):
Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/configdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from spyder.utils import icon_manager as ima
from spyder.utils import syntaxhighlighters
from spyder.widgets.colors import ColorLayout
from spyder.widgets.sourcecode.codeeditor import CodeEditor
from spyder.plugins.editor.widgets.codeeditor import CodeEditor


HDPI_QT_PAGE = "http://doc.qt.io/qt-5/highdpi.html"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# (see spyder/__init__.py for details)

"""
spyder.widgets.sourcecode
=========================
spyder.plugins.editor
=====================
Source code related widgets (code editor, console) based exclusively on Qt
Editor Plugin
"""
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# (see spyder/__init__.py for details)

"""
spyder.widgets.sourcecode.api
spyder.plugins.editor.api
=========================
API to interact with some features of codeeditor
API to interact with some features of Editor and CodeEditor
"""
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
from __future__ import print_function
import sys
from spyder.utils.editor import TextBlockHelper
from spyder.plugins.editor.utils.editor import TextBlockHelper


def print_tree(editor, file=sys.stdout, print_blocks=False, return_list=False):
Expand Down
6 changes: 3 additions & 3 deletions spyder/plugins/editor.py → spyder/plugins/editor/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
from spyder.utils.introspection.manager import IntrospectionManager
from spyder.utils.qthelpers import create_action, add_actions, MENU_SEPARATOR
from spyder.widgets.findreplace import FindReplace
from spyder.widgets.editor import (EditorMainWindow, EditorSplitter,
EditorStack, Printer)
from spyder.widgets.sourcecode.codeeditor import CodeEditor
from spyder.plugins.editor.widgets.editor import (EditorMainWindow, Printer,
EditorSplitter, EditorStack,)
from spyder.plugins.editor.widgets.codeeditor import CodeEditor
from spyder.widgets.status import (CursorPositionStatus, EncodingStatus,
EOLStatus, ReadWriteStatus)
from spyder.api.plugins import SpyderPluginWidget
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# (see spyder/__init__.py for details)

"""
spyder.widgets.sourcecode.utils
=========================
spyder.plugins.editor.utils
===========================
Some utility classes and functions for CodeEditor.
"""
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def unfold_if_colapsed(self, block):
except KeyError:
pass
else:
from spyder.widgets.sourcecode.folding import FoldScope
from spyder.plugins.editor.utils.folding import FoldScope
if not block.isVisible():
block = FoldScope.find_parent_scope(block)
if TextBlockHelper.is_collapsed(block):
Expand All @@ -161,7 +161,7 @@ def selected_text(self):
def word_under_cursor(self, select_whole_word=False, text_cursor=None):
"""
Gets the word under cursor using the separators defined by
:attr:`spyder.widgets.sourcecode.CodeEditor.word_separators`.
:attr:`spyder.plugins.editor.widgets.codeeditor.CodeEditor.word_separators`.
FIXME: This is not working because CodeEditor have no attribute
word_separators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"""
import sys

from spyder.widgets.sourcecode.api.folding import FoldDetector
from spyder.utils.editor import TextBlockHelper
from spyder.plugins.editor.api.folding import FoldDetector
from spyder.plugins.editor.utils.editor import TextBlockHelper


class FoldScope(object):
Expand Down Expand Up @@ -255,9 +255,9 @@ def detect_fold_level(self, prev_block, block):

if __name__ == '__main__':
"""Print folding blocks of this file for debugging"""
from spyder.widgets.sourcecode.api.folding import print_tree
from spyder.plugins.editor.api.folding import print_tree
from spyder.utils.qthelpers import qapplication
from spyder.widgets.sourcecode.codeeditor import CodeEditor
from spyder.plugins.editor.widgets.codeeditor import CodeEditor

if len(sys.argv) > 1:
fname = sys.argv[1]
Expand Down
File renamed without changes.
30 changes: 30 additions & 0 deletions spyder/plugins/editor/utils/languages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

"""
Language utilities
"""

ALL_LANGUAGES = {
'Python': ('py', 'pyw', 'python', 'ipy'),
'Cython': ('pyx', 'pxi', 'pxd'),
'Enaml': ('enaml',),
'Fortran77': ('f', 'for', 'f77'),
'Fortran': ('f90', 'f95', 'f2k'),
'Idl': ('pro',),
'Diff': ('diff', 'patch', 'rej'),
'GetText': ('po', 'pot'),
'Nsis': ('nsi', 'nsh'),
'Html': ('htm', 'html'),
'Cpp': ('c', 'cc', 'cpp', 'cxx', 'h', 'hh', 'hpp', 'hxx'),
'OpenCL': ('cl',),
'Yaml': ('yaml', 'yml'),
"Markdown": ('md', ),
}

PYTHON_LIKE_LANGUAGES = ('Python', 'Cython', 'Enaml')

CELL_LANGUAGES = {'Python': ('#%%', '# %%', '# <codecell>', '# In[')}
File renamed without changes.
12 changes: 12 additions & 0 deletions spyder/plugins/editor/widgets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)

"""
spyder.plugins.editor.widgets
=============================
Editor related widgets (Editor,EditorStack, CodeEditor) based exclusively on Qt
"""
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from spyder.utils import icon_manager as ima
from spyder.widgets.calltip import CallTipWidget
from spyder.widgets.mixins import BaseEditMixin
from spyder.widgets.sourcecode.terminal import ANSIEscapeCodeHandler
from spyder.plugins.editor.utils.terminal import ANSIEscapeCodeHandler


def insert_text_to(cursor, text, fmt):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@
from spyder.utils import encoding, sourcecode
from spyder.utils.dochelpers import getobj
from spyder.utils.qthelpers import add_actions, create_action, mimedata2url
from spyder.utils.sourcecode import ALL_LANGUAGES, CELL_LANGUAGES
from spyder.plugins.editor.utils.languages import ALL_LANGUAGES, CELL_LANGUAGES
from spyder.plugins.outlineexplorer.languages import PythonCFM
from spyder.widgets.sourcecode.base import TextEditBaseWidget
from spyder.widgets.sourcecode.kill_ring import QtKillRing
from spyder.plugins.editor.widgets.base import TextEditBaseWidget
from spyder.plugins.editor.utils.kill_ring import QtKillRing
from spyder.widgets.panels.linenumber import LineNumberArea
from spyder.widgets.panels.edgeline import EdgeLine
from spyder.widgets.panels.indentationguides import IndentationGuide
from spyder.widgets.panels.scrollflag import ScrollFlagArea
from spyder.widgets.panels.manager import PanelsManager
from spyder.widgets.panels.codefolding import FoldingPanel
from spyder.widgets.sourcecode.folding import IndentFoldDetector
from spyder.widgets.sourcecode.utils.decoration import TextDecorationsManager
from spyder.plugins.editor.utils.folding import IndentFoldDetector
from spyder.plugins.editor.utils.decoration import TextDecorationsManager
from spyder.api.panel import Panel

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
from spyder.plugins.outlineexplorer.editor import OutlineExplorerProxyEditor
from spyder.widgets.fileswitcher import FileSwitcher
from spyder.widgets.findreplace import FindReplace
from spyder.widgets.sourcecode import codeeditor
from spyder.widgets.sourcecode.base import TextEditBaseWidget # analysis:ignore
from spyder.widgets.sourcecode.codeeditor import Printer # analysis:ignore
from spyder.widgets.sourcecode.codeeditor import get_file_language
from spyder.plugins.editor.widgets import codeeditor
from spyder.plugins.editor.widgets.base import TextEditBaseWidget # analysis:ignore
from spyder.plugins.editor.widgets.codeeditor import Printer # analysis:ignore
from spyder.plugins.editor.widgets.codeeditor import get_file_language
from spyder.widgets.status import (CursorPositionStatus, EncodingStatus,
EOLStatus, ReadWriteStatus)
from spyder.widgets.tabs import BaseTabs
Expand Down Expand Up @@ -2748,11 +2748,13 @@ def test():

import time
t0 = time.time()
test.load(osp.join(spyder_dir, "widgets", "editor.py"))
test.load(osp.join(spyder_dir, "plugins", "editor", "widgets",
"editor.py"))
test.load(osp.join(spyder_dir, "plugins", "explorer", "widgets.py"))
test.load(osp.join(spyder_dir, "plugins", "variableexplorer", "widgets",
"viewers", "collections.py"))
test.load(osp.join(spyder_dir, "widgets", "sourcecode", "codeeditor.py"))
test.load(osp.join(spyder_dir, "plugins", "editor", "widgets",
"codeeditor.py"))
print("Elapsed time: %.3f s" % (time.time()-t0)) # spyder: test-skip

sys.exit(app.exec_())
Expand Down
File renamed without changes.
41 changes: 41 additions & 0 deletions spyder/plugins/editor/widgets/tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
#
# Copyright © Spyder Project Contributors
# Licensed under the terms of the MIT License
#

"""
Testing utilities to be used with pytest.
"""

try:
from unittest.mock import Mock
except ImportError:
from mock import Mock # Python 2

# Third party imports
import pytest

# Local imports
from spyder.plugins.editor.widgets.editor import EditorStack
from spyder.widgets.findreplace import FindReplace


@pytest.fixture
def setup_editor(qtbot):
"""
Set up EditorStack with CodeEditor containing some Python code.
The cursor is at the empty line below the code.
Returns tuple with EditorStack and CodeEditor.
"""
text = ('a = 1\n'
'print(a)\n'
'\n'
'x = 2') # a newline is added at end
editorStack = EditorStack(None, [])
editorStack.set_introspector(Mock())
editorStack.set_find_widget(FindReplace(editorStack))
editorStack.set_io_actions(Mock(), Mock(), Mock(), Mock())
finfo = editorStack.new('foo.py', 'utf-8', text)
qtbot.addWidget(editorStack)
return editorStack, finfo.editor
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Local imports
from spyder.utils.qthelpers import qapplication
from spyder.widgets.sourcecode.codeeditor import CodeEditor
from spyder.plugins.editor.widgets.codeeditor import CodeEditor


# --- Fixtures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Local imports
from spyder.utils.qthelpers import qapplication
from spyder.py3compat import to_text_string
from spyder.widgets.sourcecode.codeeditor import CodeEditor
from spyder.plugins.editor.widgets.codeeditor import CodeEditor


# --- Fixtures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from qtpy.QtCore import Qt

# Local imports
from spyder.utils.fixtures import setup_editor
from spyder.widgets.editor import EditorStack
from spyder.plugins.editor.widgets.tests.fixtures import setup_editor
from spyder.plugins.editor.widgets.editor import EditorStack
from spyder.widgets.findreplace import FindReplace

# Qt Test Fixtures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

# Local imports
from spyder.utils.qthelpers import qapplication
from spyder.widgets.sourcecode.codeeditor import CodeEditor
from spyder.widgets.sourcecode.api.folding import print_tree
from spyder.plugins.editor.widgets.codeeditor import CodeEditor
from spyder.plugins.editor.api.folding import print_tree


# --- Fixtures
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Local imports
from spyder.utils.qthelpers import qapplication
from spyder.widgets.sourcecode.codeeditor import CodeEditor
from spyder.plugins.editor.widgets.codeeditor import CodeEditor
from spyder.widgets.panels.linenumber import LineNumberArea
from spyder.widgets.panels.edgeline import EdgeLine
from spyder.widgets.panels.scrollflag import ScrollFlagArea
Expand Down
2 changes: 1 addition & 1 deletion spyder/plugins/help/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from spyder.widgets.browser import FrameWebView
from spyder.widgets.comboboxes import EditableComboBox
from spyder.widgets.findreplace import FindReplace
from spyder.widgets.sourcecode import codeeditor
from spyder.plugins.editor.widgets import codeeditor


class ObjectComboBox(EditableComboBox):
Expand Down
Loading

0 comments on commit b5afc36

Please sign in to comment.