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)
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)
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)