Exemplo n.º 1
0
    def __init__(self, content=None, filename=None, parent=None):
        """
        :param content: An optional string of content to pass to the editor
        :param filename: The file path where the content was read.
        :param parent: An optional parent QWidget
        """
        super(PythonFileInterpreter, self).__init__(parent)

        # layout
        self.editor = CodeEditor("AlternateCSPythonLexer", self)

        # Clear QsciScintilla key bindings that may override PyQt's bindings
        self.clear_key_binding("Ctrl+/")

        self.status = QStatusBar(self)
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.editor)
        self.layout.addWidget(self.status)
        self.setLayout(self.layout)
        self.layout.setContentsMargins(0, 0, 0, 0)
        self._setup_editor(content, filename)

        self.setAttribute(Qt.WA_DeleteOnClose, True)

        self._presenter = PythonFileInterpreterPresenter(
            self, PythonCodeExecution(content))

        self.editor.modificationChanged.connect(self.sig_editor_modified)
        self.editor.fileNameChanged.connect(self.sig_filename_modified)
        self.find_replace_dialog = None
        self.find_replace_dialog_shown = False
Exemplo n.º 2
0
    def __init__(self, font=None, content=None, filename=None,
                 parent=None):
        """
        :param font: A reference to the font to be used by the editor. If not supplied use the system default
        :param content: An optional string of content to pass to the editor
        :param filename: The file path where the content was read.
        :param parent: An optional parent QWidget
        """
        super(PythonFileInterpreter, self).__init__(parent)
        self.parent = parent

        # layout
        font = font if font is not None else QFont()
        self.editor = CodeEditor("AlternateCSPython", font, self)
        self.find_replace_dialog = None
        self.status = QStatusBar(self)
        self.layout = QVBoxLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.addWidget(self.editor)
        self.layout.addWidget(self.status)
        self.setLayout(self.layout)
        self._setup_editor(content, filename)

        self._presenter = PythonFileInterpreterPresenter(self, PythonCodeExecution(content))
        self.code_commenter = CodeCommenter(self.editor)

        self.editor.modificationChanged.connect(self.sig_editor_modified)
        self.editor.fileNameChanged.connect(self.sig_filename_modified)

        self.setAttribute(Qt.WA_DeleteOnClose, True)

        # Connect the model signals to the view's signals so they can be accessed from outside the MVP
        self._presenter.model.sig_exec_progress.connect(self.sig_progress)
        self._presenter.model.sig_exec_error.connect(self.sig_exec_error)
        self._presenter.model.sig_exec_success.connect(self.sig_exec_success)
Exemplo n.º 3
0
 def test_construction_raises_error_for_unknown_language(self):
     # self.assertRaises causes a segfault here for some reason...
     try:
         CodeEditor("MyCoolLanguage")
     except ValueError:
         pass
     except Exception as exc:
         self.fail("Expected a Value error to be raised but found a " + exc.__name__)
Exemplo n.º 4
0
 def test_get_selection_for_non_empty_selection(self):
     widget = CodeEditor(TEST_LANG)
     widget.setText("""first line
     second line
     third line
     fourth line
     """)
     selected = (0, 2, 3, 4)
     widget.setSelection(*selected)
     res = widget.getSelection()
     self.assertEqual(selected, res)
Exemplo n.º 5
0
    def __init__(self,
                 font=None,
                 content=None,
                 filename=None,
                 parent=None,
                 completion_enabled=True):
        """
        :param font: A reference to the font to be used by the editor. If not supplied use the system default
        :param content: An optional string of content to pass to the editor
        :param filename: The file path where the content was read.
        :param parent: An optional parent QWidget
        :param completion_enabled: Optional parameter to control code auto-completion suggestions
        """
        super(PythonFileInterpreter, self).__init__(parent)
        self.parent = parent
        self.completion_enabled = completion_enabled
        # layout
        font = font if font is not None else QFont()
        self.editor = CodeEditor("AlternateCSPython", font, self)
        self.find_replace_dialog = None
        self.status = QStatusBar(self)
        self.layout = QVBoxLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)
        self.layout.addWidget(self.editor)
        self.layout.addWidget(self.status)
        self.setLayout(self.layout)
        self._setup_editor(content, filename)

        self._presenter = PythonFileInterpreterPresenter(
            self, PythonCodeExecution(self.editor))
        self.code_commenter = CodeCommenter(self.editor)
        if self.completion_enabled:
            self.code_completer = CodeCompleter(
                self.editor, self._presenter.model.globals_ns)

        self.editor.modificationChanged.connect(self.sig_editor_modified)
        self.editor.fileNameChanged.connect(self.sig_filename_modified)

        self.setAttribute(Qt.WA_DeleteOnClose, True)

        # Connect the model signals to the view's signals so they can be accessed from outside the MVP
        self._presenter.model.sig_exec_error.connect(self.sig_exec_error)
        self._presenter.model.sig_exec_success.connect(self.sig_exec_success)

        if self.completion_enabled:
            # Re-populate the completion API after execution success
            self._presenter.model.sig_exec_success.connect(
                self.code_completer.update_completion_api)
            # Only load the simpleapi completions if the code editor starts being modified.
            self.sig_editor_modified.connect(
                self.code_completer.add_simpleapi_to_completions_if_required)
Exemplo n.º 6
0
    def setUp(self):
        self.lines = [
            "# Mantid Repository : https://github.com/mantidproject/mantid",
            "# ",
            "# Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,",
            "#     NScD Oak Ridge National Laboratory, European Spallation Source",
            "#     & Institut Laue - Langevin",
            "# SPDX - License - Identifier: GPL - 3.0 +",
            "#  This file is part of the mantidqt package", "", "import numpy",
            "# import mantid", "do_something()"
        ]

        self.editor = CodeEditor("AlternateCSPython", QFont())
        self.editor.setText('\n'.join(self.lines))
        self.commenter = CodeCommenter(self.editor)
Exemplo n.º 7
0
    def __init__(self, content=None, filename=None, parent=None):
        """
        :param content: An optional string of content to pass to the editor
        :param filename: The file path where the content was read.
        :param parent: An optional parent QWidget
        """
        super(PythonFileInterpreter, self).__init__(parent)

        # layout
        self.editor = CodeEditor("AlternateCSPythonLexer", self)
        self.status = QStatusBar(self)
        layout = QVBoxLayout()
        layout.addWidget(self.editor)
        layout.addWidget(self.status)
        self.setLayout(layout)
        layout.setContentsMargins(0, 0, 0, 0)
        self._setup_editor(content, filename)

        self._presenter = PythonFileInterpreterPresenter(
            self, PythonCodeExecution(content))

        self.editor.modificationChanged.connect(self.sig_editor_modified)
        self.editor.fileNameChanged.connect(self.sig_filename_modified)
Exemplo n.º 8
0
 def test_get_selection_for_empty_selection(self):
     widget = CodeEditor(TEST_LANG)
     res = widget.getSelection()
     self.assertEqual((-1, -1, -1, -1), res)
Exemplo n.º 9
0
 def test_setReadOnly_to_true_sets_readonly_status(self):
     widget = CodeEditor(TEST_LANG)
     widget.setReadOnly(True)
     self.assertTrue(widget.isReadOnly())
Exemplo n.º 10
0
 def test_default_construction_yields_editable_widget(self):
     widget = CodeEditor(TEST_LANG)
     self.assertFalse(widget.isReadOnly())
Exemplo n.º 11
0
 def test_set_text_can_be_read_again(self):
     widget = CodeEditor(TEST_LANG)
     code_str = 'print "Hello World!"'
     widget.setText(code_str)
     self.assertEqual(code_str, widget.text())
Exemplo n.º 12
0
 def test_set_filename_returns_expected_string(self):
     widget = CodeEditor(TEST_LANG)
     test_filename = "myscript.py"
     widget.setFileName(test_filename)
     self.assertEqual(test_filename, widget.fileName())
Exemplo n.º 13
0
 def test_default_construction_yields_empty_filename(self):
     widget = CodeEditor(TEST_LANG)
     self.assertEqual("", widget.fileName())
Exemplo n.º 14
0
 def test_construction_accepts_Python_as_language(self):
     CodeEditor(TEST_LANG)