Example #1
0
    def __init__(self, parent=None):
        super().__init__()
        self.setUndoRedoEnabled(False)
        self.setCursorWidth(10)
        self.setFrameShape(0)
        self.moveCursor(QTextCursor.EndOfLine)
        self.__incomplete = False
        # History
        self._history_index = 0
        self._history = []
        self._current_command = ''
        # Console
        self._console = console.Console()
        self.setFont(settings.FONT)
        # Set highlighter and indenter for Python
        syntax = highlighter.build_highlighter(language='python')
        if syntax is not None:
            self._highlighter = Highlighter(
                self.document(),
                syntax.partition_scanner,
                syntax.scanners,
                syntax.context
            )
        #     self._highlighter = Highlighter(self.document(), syntax)
        self._indenter = indenter.load_indenter(self, lang="python")
        # Sidebar
        self.sidebar = ConsoleSideBar(self)
        self.setViewportMargins(self.sidebar.sizeHint().width(), 0, 0, 0)
        # Key operations
        self._key_operations = {
            Qt.Key_Enter: self.__manage_enter,
            Qt.Key_Return: self.__manage_enter,
            Qt.Key_Left: self.__manage_left,
            Qt.Key_Up: self.__up_pressed,
            Qt.Key_Down: self.__down_pressed,
            Qt.Key_Home: self.__manage_home,
            Qt.Key_Backspace: self.__manage_backspace
        }
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self._context_menu)

        _ToolsDock.register_widget("Interpreter", self)
Example #2
0
    def __init__(self, parent=None):
        super().__init__()
        self.setUndoRedoEnabled(False)
        self.setCursorWidth(10)
        self.setFrameShape(0)
        self.moveCursor(QTextCursor.EndOfLine)
        self.__incomplete = False
        # History
        self._history_index = 0
        self._history = []
        self._current_command = ''
        # Console
        self._console = console.Console()
        self.setFont(settings.FONT)
        # Set highlighter and indenter for Python
        syntax = highlighter.build_highlighter(language='python')
        if syntax is not None:
            self._highlighter = Highlighter(self.document(),
                                            syntax.partition_scanner,
                                            syntax.scanners, syntax.context)
        #     self._highlighter = Highlighter(self.document(), syntax)
        self._indenter = indenter.load_indenter(self, lang="python")
        # Sidebar
        self.sidebar = ConsoleSideBar(self)
        self.setViewportMargins(self.sidebar.sizeHint().width(), 0, 0, 0)
        # Key operations
        self._key_operations = {
            Qt.Key_Enter: self.__manage_enter,
            Qt.Key_Return: self.__manage_enter,
            Qt.Key_Left: self.__manage_left,
            Qt.Key_Up: self.__up_pressed,
            Qt.Key_Down: self.__down_pressed,
            Qt.Key_Home: self.__manage_home,
            Qt.Key_Backspace: self.__manage_backspace
        }
        self.setContextMenuPolicy(Qt.CustomContextMenu)
        self.customContextMenuRequested.connect(self._context_menu)

        _ToolsDock.register_widget("Interpreter", self)
Example #3
0
 def set_language(self, language):
     self.register_syntax_for(language=language)
     self._indenter = indenter.load_indenter(self, lang=language)
Example #4
0
    def __init__(self, neditable):
        QPlainTextEdit.__init__(self)
        self.setFrameStyle(0)  # Remove border
        self._neditable = neditable
        self.setMouseTracking(True)

        # Style
        self._background_color = QColor(
            resources.get_color('EditorBackground'))
        self._foreground_color = QColor(resources.get_color('Default'))
        self._selection_color = QColor(
            resources.get_color('EditorSelectionColor'))
        self._selection_background_color = QColor(
            resources.get_color('EditorSelectionBackground'))
        self.__apply_style()

        self.setCursorWidth(2)
        self._highlighter = None
        self.__visible_blocks = []
        self._last_line_position = 0
        self.__encoding = None
        self.__show_whitespaces = settings.SHOW_TABS_AND_SPACES
        self.__side_widgets = []
        # Extra Selections
        self._extra_selections = OrderedDict()
        self.__occurrences = []
        # Load indenter based on language
        self._indenter = indenter.load_indenter(self, neditable.language())
        # Set editor font before build lexer
        self.default_font = settings.FONT
        self.register_syntax_for(neditable.language())
        # Register extensions
        self.__extensions = {}
        # Brace matching
        self._brace_matching = self.register_extension(
            symbol_highlighter.SymbolHighlighter)
        self.brace_matching = settings.BRACE_MATCHING
        # Current line highlighter
        self._line_highlighter = self.register_extension(
            line_highlighter.CurrentLineHighlighter)
        self.highlight_current_line = settings.HIGHLIGHT_CURRENT_LINE
        # Right margin line
        self._margin_line = self.register_extension(margin_line.RightMargin)
        self.margin_line = settings.SHOW_MARGIN_LINE
        self.margin_line_position = settings.MARGIN_LINE
        self.margin_line_background = settings.MARGIN_LINE_BACKGROUND
        # Indentation guides
        self._indentation_guides = self.register_extension(
            indentation_guides.IndentationGuide)
        self.show_indentation_guides(settings.SHOW_INDENTATION_GUIDES)
        # Autocomplete braces
        self.__autocomplete_braces = self.register_extension(
            braces.AutocompleteBraces)
        self.autocomplete_braces(settings.AUTOCOMPLETE_BRACKETS)
        # Autocomplete quotes
        self.__autocomplete_quotes = self.register_extension(
            quotes.AutocompleteQuotes)
        self.autocomplete_quotes(settings.AUTOCOMPLETE_QUOTES)
        # Mark occurrences timer
        self._highlight_word_timer = QTimer()
        self._highlight_word_timer.setSingleShot(True)
        self._highlight_word_timer.setInterval(800)
        self._highlight_word_timer.timeout.connect(
            self.highlight_selected_word)
        # Install custom scrollbar
        self._scrollbar = scrollbar.NScrollBar(self)
        self._scrollbar.setAttribute(Qt.WA_OpaquePaintEvent, False)
        self.setVerticalScrollBar(self._scrollbar)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.additional_builtins = None
        # Set the editor after initialization
        if self._neditable is not None:
            if self._neditable.editor:
                self.setDocument(self._neditable.document)
            else:
                self._neditable.set_editor(self)
            self._neditable.checkersUpdated.connect(self._highlight_checkers)
        # Widgets on side area
        self._line_number_area = self.add_side_widget(
            line_number_area.LineNumberArea, order=2)
        self.show_line_numbers(settings.SHOW_LINE_NUMBERS)

        self._text_change_area = self.add_side_widget(
            text_change_area.TextChangeArea, order=0)
        self.show_text_changes(settings.SHOW_TEXT_CHANGES)

        self._marker_area = self.add_side_widget(marker_area.MarkerArea, 1)

        # FIXME: we need a method to initialize
        self.__set_whitespaces_flags(self.__show_whitespaces)

        self.cursorPositionChanged.connect(self._on_cursor_position_changed)
        self.cursorPositionChanged.connect(self.viewport().update)
Example #5
0
    def __init__(self, neditable):
        super().__init__()
        self.setFrameStyle(QFrame.NoFrame)
        self._neditable = neditable
        self.setMouseTracking(True)
        self.__encoding = None
        self._last_line_position = 0
        # List of word separators
        # Can be used by code completion and the link emulator
        self.word_separators = [",", ".", ":", "[", "]", "(", ")", "{", "}"]
        # Extra Selections
        self._extra_selections = OrderedDict()
        self.__link_cursor = QTextCursor()
        # Load indenter based on language
        self._indenter = indenter.load_indenter(self, neditable.language())
        # Set editor font before build lexer
        self.set_font(settings.FONT)
        # Register extensions
        self.__extensions = {}
        # Brace matching
        self._brace_matching = self.register_extension(
            symbol_highlighter.SymbolHighlighter)
        self.brace_matching = settings.BRACE_MATCHING
        # Current line highlighter
        self._line_highlighter = self.register_extension(
            line_highlighter.CurrentLineHighlighter)
        self.highlight_current_line = settings.HIGHLIGHT_CURRENT_LINE
        # Right margin line
        self._margin_line = self.register_extension(margin_line.RightMargin)
        self.margin_line = settings.SHOW_MARGIN_LINE
        self.margin_line_position = settings.MARGIN_LINE
        self.margin_line_background = settings.MARGIN_LINE_BACKGROUND
        # Indentation guides
        self._indentation_guides = self.register_extension(
            indentation_guides.IndentationGuide)
        self.show_indentation_guides(settings.SHOW_INDENTATION_GUIDES)
        # Autocomplete braces
        self.__autocomplete_braces = self.register_extension(
            braces.AutocompleteBraces)
        self.autocomplete_braces(settings.AUTOCOMPLETE_BRACKETS)
        # Autocomplete quotes
        self.__autocomplete_quotes = self.register_extension(
            quotes.AutocompleteQuotes)
        self.autocomplete_quotes(settings.AUTOCOMPLETE_QUOTES)
        # Highlight word under cursor
        self.__word_occurrences = []
        self._highlight_word_timer = QTimer()
        self._highlight_word_timer.setSingleShot(True)
        self._highlight_word_timer.setInterval(1000)
        self._highlight_word_timer.timeout.connect(
            self.highlight_selected_word)
        # Install custom scrollbar
        self._scrollbar = scrollbar.NScrollBar(self)
        self._scrollbar.setAttribute(Qt.WA_OpaquePaintEvent, False)
        self.setVerticalScrollBar(self._scrollbar)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.additional_builtins = None
        # Set the editor after initialization
        if self._neditable is not None:
            if self._neditable.editor:
                self.setDocument(self._neditable.document)
            else:
                self._neditable.set_editor(self)
            self._neditable.checkersUpdated.connect(self._highlight_checkers)
        # self.register_syntax_for(language=neditable.language())
        # Widgets on side area
        self.side_widgets = manager.SideWidgetManager(self)
        # Mark text changes
        self._text_change_widget = self.side_widgets.add(
            text_change_widget.TextChangeWidget)
        self.show_text_changes(settings.SHOW_TEXT_CHANGES)
        # Breakpoints/bookmarks widget
        self._marker_area = self.side_widgets.add(marker_widget.MarkerWidget)
        # Line number widget
        self._line_number_widget = self.side_widgets.add(
            line_number_widget.LineNumberWidget)
        self.show_line_numbers(settings.SHOW_LINE_NUMBERS)
        # Code folding
        self.side_widgets.add(code_folding.CodeFoldingWidget)

        # FIXME: we need a method to initialize
        # self.__set_whitespaces_flags(self.__show_whitespaces)
        self.cursorPositionChanged.connect(self._on_cursor_position_changed)
        self.blockCountChanged.connect(self.update)
Example #6
0
    def __init__(self, neditable):
        QPlainTextEdit.__init__(self)
        self.setFrameStyle(0)  # Remove border
        self._neditable = neditable
        self.setMouseTracking(True)
        # Style
        self._background_color = QColor(
            resources.get_color('EditorBackground'))
        self._foreground_color = QColor(resources.get_color('Default'))
        self._selection_color = QColor(
            resources.get_color('EditorSelectionColor'))
        self._selection_background_color = QColor(
            resources.get_color('EditorSelectionBackground'))
        self.__apply_style()

        self._init_settings()
        self._highlighter = None
        self.__visible_blocks = []
        self._last_line_position = 0
        self.__encoding = None
        self.__show_whitespaces = settings.SHOW_TABS_AND_SPACES
        self.__side_widgets = []
        # Extra Selections
        self._extra_selections = OrderedDict()
        self._current_line_selection = None
        self.__checker_extra_selections = []
        self.__occurrences = []
        # Load indenter based on language
        self._indenter = indenter.load_indenter(self, neditable.language())
        # Set editor font before build lexer
        self.set_font(settings.FONT)
        self.register_syntax_for(neditable.language())
        # Register all editor extension
        self.initialize_extensions()
        # FIXME: based on lang
        self.enable_extension('indentation_guides',
                              settings.SHOW_INDENTATION_GUIDE)
        self.enable_extension('margin_line', settings.SHOW_MARGIN_LINE)
        self.enable_extension('line_highlighter', True)
        self.enable_extension('symbol_highlighter', True)
        self.enable_extension('quotes', True)
        self.enable_extension('braces', True)
        # self._symbol_completer = symbol_completer.SymbolCompleter(self)

        # Mark occurrences timer
        self._highlight_word_timer = QTimer()
        self._highlight_word_timer.setSingleShot(True)
        self._highlight_word_timer.setInterval(800)
        self._highlight_word_timer.timeout.connect(
            self.highlight_selected_word)
        # Install custom scrollbar
        self._scrollbar = scrollbar.NScrollBar(self)
        self._scrollbar.setAttribute(Qt.WA_OpaquePaintEvent, False)
        self.setVerticalScrollBar(self._scrollbar)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.additional_builtins = None
        # Set the editor after initialization
        if self._neditable is not None:
            if self._neditable.editor:
                self.setDocument(self._neditable.document)
            else:
                self._neditable.set_editor(self)
            self._neditable.checkersUpdated.connect(self._highlight_checkers)
        # Widgets on side area
        self._line_number_area = None
        if settings.SHOW_LINE_NUMBERS:
            self._line_number_area = self.add_side_widget(
                line_number_area.LineNumberArea, 2)
        self._lint_area = None
        # if settings.SHOW_LINT_AREA:
        #    self._lint_area = self.add_side_widget(lint_area.LintArea, 3)
        self._marker_area = None
        # if settings.SHOW_MARK_AREA:
        #    self._marker_area = self.add_side_widget(marker_area.MarkerArea, 1)
        self._text_change_area = None
        if settings.SHOW_TEXT_CHANGE_AREA:
            self._text_change_area = self.add_side_widget(
                text_change_area.TextChangeArea, 0)
        # FIXME: we need a method to initialize
        self.__set_whitespaces_flags(self.__show_whitespaces)

        self.cursorPositionChanged.connect(self._on_cursor_position_changed)
        self.cursorPositionChanged.connect(self.viewport().update)
Example #7
0
    def __init__(self, neditable):
        super().__init__()
        self.setFrameStyle(QFrame.NoFrame)
        self._neditable = neditable
        self.allow_word_wrap(False)
        self.setMouseTracking(True)
        self.setCursorWidth(2)
        self.__encoding = None
        self._highlighter = None
        self._last_line_position = 0
        # Extra Selections
        self._extra_selections = ExtraSelectionManager(self)
        # Load indenter based on language
        self._indenter = indenter.load_indenter(self, neditable.language())
        # Widgets on side area
        self.side_widgets = manager.SideWidgetManager(self)

        self.__link_pressed = False

        # Set editor font before build lexer
        self.set_font(settings.FONT)
        # Register extensions
        self.__extensions = {}
        # Brace matching
        self._brace_matching = self.register_extension(
            symbol_highlighter.SymbolHighlighter)
        self.brace_matching = settings.BRACE_MATCHING
        # Current line highlighter
        self._line_highlighter = self.register_extension(
            line_highlighter.CurrentLineHighlighter)
        self.highlight_current_line = settings.HIGHLIGHT_CURRENT_LINE
        # Right margin line
        self._margin_line = self.register_extension(margin_line.RightMargin)
        self.margin_line = settings.SHOW_MARGIN_LINE
        self.margin_line_position = settings.MARGIN_LINE
        self.margin_line_background = settings.MARGIN_LINE_BACKGROUND
        # Indentation guides
        self._indentation_guides = self.register_extension(
            indentation_guides.IndentationGuide)
        self.show_indentation_guides(settings.SHOW_INDENTATION_GUIDES)
        # Autocomplete braces
        self.__autocomplete_braces = self.register_extension(
            braces.AutocompleteBraces)
        self.autocomplete_braces(settings.AUTOCOMPLETE_BRACKETS)
        # Autocomplete quotes
        self.__autocomplete_quotes = self.register_extension(
            quotes.AutocompleteQuotes)
        self.autocomplete_quotes(settings.AUTOCOMPLETE_QUOTES)
        # Calltips
        # self.register_extension(calltip.CallTips)
        # Highlight word under cursor
        self.__word_occurrences = []
        self._highlight_word_timer = QTimer()
        self._highlight_word_timer.setSingleShot(True)
        self._highlight_word_timer.setInterval(1000)
        self._highlight_word_timer.timeout.connect(
            self.highlight_selected_word)
        # Install custom scrollbar
        self._scrollbar = scrollbar.NScrollBar(self)
        self._scrollbar.setAttribute(Qt.WA_OpaquePaintEvent, False)
        self.setVerticalScrollBar(self._scrollbar)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.additional_builtins = None
        # Set the editor after initialization
        if self._neditable is not None:
            if self._neditable.editor:
                self.setDocument(self._neditable.document)
            else:
                self._neditable.set_editor(self)
            self._neditable.checkersUpdated.connect(self._highlight_checkers)

        self.cursorPositionChanged.connect(self._on_cursor_position_changed)
        self.blockCountChanged.connect(self.update)

        # Mark text changes
        self._text_change_widget = self.side_widgets.add(
            text_change_widget.TextChangeWidget)
        self.show_text_changes(settings.SHOW_TEXT_CHANGES)
        # Breakpoints/bookmarks widget
        self._marker_area = self.side_widgets.add(
            marker_widget.MarkerWidget)
        # Line number widget
        self._line_number_widget = self.side_widgets.add(
            line_number_widget.LineNumberWidget)
        self.show_line_numbers(settings.SHOW_LINE_NUMBERS)
        # Code folding
        self.side_widgets.add(code_folding.CodeFoldingWidget)

        from ninja_ide.gui.editor import intellisense_assistant as ia
        self._iassistant = None
        intellisense = IDE.get_service("intellisense")
        if intellisense is not None:
            if intellisense.provider_services(self._neditable.language()):
                self._iassistant = ia.IntelliSenseAssistant(self)
Example #8
0
    def __init__(self, neditable):
        super().__init__()
        self.setFrameStyle(QFrame.NoFrame)
        self._neditable = neditable
        self.allow_word_wrap(False)
        self.setMouseTracking(True)
        self.setCursorWidth(2)
        self.__encoding = None
        self._highlighter = None
        self._last_line_position = 0
        # Extra Selections
        self._extra_selections = ExtraSelectionManager(self)
        # Load indenter based on language
        self._indenter = indenter.load_indenter(self, neditable.language())
        # Widgets on side area
        self.side_widgets = manager.SideWidgetManager(self)

        self.__link_pressed = False

        # Set editor font before build lexer
        self.set_font(settings.FONT)
        # Register extensions
        self.__extensions = {}
        # Brace matching
        self._brace_matching = self.register_extension(
            symbol_highlighter.SymbolHighlighter)
        self.brace_matching = settings.BRACE_MATCHING
        # Current line highlighter
        self._line_highlighter = self.register_extension(
            line_highlighter.CurrentLineHighlighter)
        self.highlight_current_line = settings.HIGHLIGHT_CURRENT_LINE
        # Right margin line
        self._margin_line = self.register_extension(margin_line.RightMargin)
        self.margin_line = settings.SHOW_MARGIN_LINE
        self.margin_line_position = settings.MARGIN_LINE
        self.margin_line_background = settings.MARGIN_LINE_BACKGROUND
        # Indentation guides
        self._indentation_guides = self.register_extension(
            indentation_guides.IndentationGuide)
        self.show_indentation_guides(settings.SHOW_INDENTATION_GUIDES)
        # Autocomplete braces
        self.__autocomplete_braces = self.register_extension(
            braces.AutocompleteBraces)
        self.autocomplete_braces(settings.AUTOCOMPLETE_BRACKETS)
        # Autocomplete quotes
        self.__autocomplete_quotes = self.register_extension(
            quotes.AutocompleteQuotes)
        self.autocomplete_quotes(settings.AUTOCOMPLETE_QUOTES)
        # Calltips
        # self.register_extension(calltip.CallTips)
        # Highlight word under cursor
        self.__word_occurrences = []
        self._highlight_word_timer = QTimer()
        self._highlight_word_timer.setSingleShot(True)
        self._highlight_word_timer.setInterval(1000)
        self._highlight_word_timer.timeout.connect(
            self.highlight_selected_word)
        # Install custom scrollbar
        self._scrollbar = scrollbar.NScrollBar(self)
        self._scrollbar.setAttribute(Qt.WA_OpaquePaintEvent, False)
        self.setVerticalScrollBar(self._scrollbar)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.additional_builtins = None
        # Set the editor after initialization
        if self._neditable is not None:
            if self._neditable.editor:
                self.setDocument(self._neditable.document)
            else:
                self._neditable.set_editor(self)
            self._neditable.checkersUpdated.connect(self._highlight_checkers)

        self.cursorPositionChanged.connect(self._on_cursor_position_changed)
        self.blockCountChanged.connect(self.update)

        # Mark text changes
        self._text_change_widget = self.side_widgets.add(
            text_change_widget.TextChangeWidget)
        self.show_text_changes(settings.SHOW_TEXT_CHANGES)
        # Breakpoints/bookmarks widget
        self._marker_area = self.side_widgets.add(
            marker_widget.MarkerWidget)
        # Line number widget
        self._line_number_widget = self.side_widgets.add(
            line_number_widget.LineNumberWidget)
        self.show_line_numbers(settings.SHOW_LINE_NUMBERS)
        # Code folding
        self.side_widgets.add(code_folding.CodeFoldingWidget)

        from ninja_ide.gui.editor import intellisense_assistant as ia
        self._iassistant = None
        intellisense = IDE.get_service("intellisense")
        if intellisense is not None:
            if intellisense.provider_services(self._neditable.language()):
                self._iassistant = ia.IntelliSenseAssistant(self)