Exemplo n.º 1
0
 def __init__(self):
     super().__init__()
     self.show_context_menu = False
     self.sh = self.modes.append(
         modes.PygmentsSH(self.document(), DiffLexer()))
     self.lines = self.panels.append(panels.LineNumberPanel(),
                                     panels.LineNumberPanel.Position.LEFT)
     self.setReadOnly(True)
     self.syntax_highlighter.color_scheme = api.ColorScheme(
         settings.color_scheme())
Exemplo n.º 2
0
 def __init__(self):
     super().__init__()
     self.show_context_menu = False
     self.sh = self.modes.append(modes.PygmentsSH(
         self.document(), DiffLexer()))
     self.lines = self.panels.append(
         panels.LineNumberPanel(), panels.LineNumberPanel.Position.LEFT)
     self.setReadOnly(True)
     self.syntax_highlighter.color_scheme = api.ColorScheme(
         settings.color_scheme())
Exemplo n.º 3
0
 def activate(self):
     self.widget = PyConsoleWidget(parent=api.window.get_main_window(),
                                   color_scheme=settings.color_scheme(),
                                   backend=pyqode_server.__file__)
     dock = api.window.add_dock_widget(self.widget, _('Python Console'),
                                       PythonManager.get_interpreter_icon(),
                                       QtCore.Qt.BottomDockWidgetArea)
     dock.hide()
     dock.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                        QtWidgets.QSizePolicy.Expanding)
     self.script_runner = api.plugins.get_script_runner()
     self.script_runner.config_refreshed.connect(self._update_interpreter)
     self._interpeter = None
     self._update_interpreter()
Exemplo n.º 4
0
 def reset(self):
     self.ui.fontComboBox.setCurrentFont(
         QtGui.QFont(settings.editor_font()))
     self.ui.spinbox_font_size.setValue(settings.editor_font_size())
     color_scheme = settings.color_scheme()
     self.ui.combo_color_schemes.setCurrentText(color_scheme)
Exemplo n.º 5
0
def color_scheme():
    """
    Returns the color scheme chosen by the usser
    """
    return settings.color_scheme()
Exemplo n.º 6
0
 def reset(self):
     self.ui.fontComboBox.setCurrentFont(QtGui.QFont(
         settings.editor_font()))
     self.ui.spinbox_font_size.setValue(settings.editor_font_size())
     color_scheme = settings.color_scheme()
     self.ui.combo_color_schemes.setCurrentText(color_scheme)
Exemplo n.º 7
0
    def open_file(self, path, line=None, column=0):
        """
        Opens a new tab in the window (and optionally goes to the
        specified line).

        :param path: path to open
        :param line: line to go to (optional).
        :param line: column to go to (optional).
        """
        if path is None:
            return
        path = os.path.normpath(path)
        if not os.path.exists(path) or os.path.isdir(path):
            return None
        self.about_to_open_tab.emit(path)
        color_scheme = settings.color_scheme()
        try:
            tab = self._ui.tabs.open_document(
                path, encoding=settings.default_encoding(),
                replace_tabs_by_spaces=settings.convert_tabs(),
                clean_trailing_whitespaces=settings.
                clean_trailing_whitespaces(),
                safe_save=settings.safe_save(),
                restore_cursor_position=settings.restore_cursor(),
                preferred_eol=settings.eol_convention(),
                autodetect_eol=settings.autodetect_eol(),
                show_whitespaces=settings.show_whitespaces(),
                color_scheme=color_scheme)
        except Exception as e:
            tab = None
            tb = traceback.format_exc()
            _logger().exception('failed to open file')
            self.notifications.add(ExceptionEvent(
                _('Failed to open file: %s') % path,
                _('An unhandled exception occured while opening file: %r') % e,
                e, tb=tb), show_balloon=False)
        else:
            _logger().debug('document opened: %s', path)

            try:
                tab.remove_action(tab.action_goto_line)
            except AttributeError:
                _logger().debug('cannot remove action goto line from editor '
                                '%r, not a CodeEdit', tab)
            else:
                assert isinstance(tab, CodeEdit)
                tab.add_action(self.project_explorer.action_goto_line)
            try:
                mode = tab.modes.get('FileWatcherMode')
            except (KeyError, AttributeError):
                _logger().debug('no file watcher on widget %r', tab)
            else:
                # enable filewatcher autoreload
                mode.auto_reload = True
            if line is not None:
                QtWidgets.qApp.processEvents()
                try:
                    TextHelper(tab).goto_line(line, column)
                except AttributeError:
                    _logger().debug('failed to go to line %d in %r' % (
                        line, tab.file.path))
        return tab
Exemplo n.º 8
0
    def _apply_editor_preferences(self, editor, set_color_scheme=True):
        if not isinstance(editor, CodeEdit):
            return
        editor.show_whitespaces = settings.show_whitespaces()
        if set_color_scheme:
            editor.syntax_highlighter.color_scheme = ColorScheme(
                settings.color_scheme())
        editor.font_size = settings.editor_font_size()
        editor.font_name = settings.editor_font()
        if settings.dark_theme() or settings.is_dark_color_scheme():
            self._setup_dark_editor(editor)
        else:
            self._setup_native_editor(editor)
        editor.tab_length = settings.tab_length()
        editor.use_spaces_instead_of_tabs = \
            settings.use_spaces_instead_of_tabs()
        editor.setCenterOnScroll(settings.center_on_scroll())
        editor.file.replace_tabs_by_spaces = settings.convert_tabs()
        editor.file.safe_save = settings.safe_save()
        editor.file.clean_trailing_whitespaces = \
            settings.clean_trailing_whitespaces()
        editor.file.restore_cursor = settings.restore_cursor()
        editor.file.preferred_eol = settings.eol_convention()
        editor.file.autodetect_eol = settings.autodetect_eol()
        editor.setLineWrapMode(
            editor.WidgetWidth if settings.text_wrapping() else
            editor.NoWrap)
        try:
            mode = editor.modes.get(modes.RightMarginMode)
        except KeyError:
            _logger().debug('no RightMarginMode on widget %r', editor)
        else:
            if 'cobol' not in editor.__class__.__name__.lower():
                mode.position = settings.margin_position()
                mode.enabled = settings.right_margin()

        try:
            mode = editor.modes.get(modes.CodeCompletionMode)
        except KeyError:
            _logger().debug('no CodeCompletionMode on widget %r', editor)
        else:
            mode.filter_mode = settings.cc_filter_mode()
            mode.trigger_length = settings.cc_trigger_len()
            mode.case_sensitive = settings.cc_case_sensitive()
            mode.show_tooltips = settings.cc_show_tooltips()

        try:
            mode = editor.modes.get(modes.CaretLineHighlighterMode)
        except KeyError:
            _logger().debug('no CaretLineHighlighterMode on widget %r', editor)
        else:
            mode.enabled = settings.highlight_caret_line()

        try:
            mode = editor.modes.get(modes.SymbolMatcherMode)
        except KeyError:
            _logger().debug('no SymbolMatcherMode on widget %r', editor)
        else:
            mode.enabled = settings.highlight_parentheses()

        try:
            mode = editor.modes.get(modes.SmartBackSpaceMode)
        except KeyError:
            _logger().debug('no SmartBackSpaceMode on widget %r', editor)
        else:
            mode.enabled = settings.backspace_unindents()

        # those modes are typically subclasses
        available_modes = editor.modes.keys()
        for name in available_modes:
            if 'autocomplete' in name.lower():
                mode = editor.modes.get(name)
                mode.enabled = settings.auto_complete()
                break
        for name in available_modes:
            if 'autoindent' in name.lower():
                mode = editor.modes.get(name)
                mode.enabled = settings.auto_indent()
                break
        try:
            panel = editor.panels.get(panels.LineNumberPanel)
        except KeyError:
            _logger().debug('no LineNumberPanel on widget %r', editor)
        else:
            panel.setVisible(settings.show_line_numbers_panel())

        try:
            panel = editor.panels.get(panels.CheckerPanel)
        except KeyError:
            _logger().debug('no CheckerPanel on widget %r', editor)
        else:
            panel.setVisible(settings.show_errors_panel())

        try:
            panel = editor.panels.get(panels.GlobalCheckerPanel)
        except KeyError:
            _logger().debug('no GlobalCheckerPanel on widget %r', editor)
        else:
            panel.setVisible(settings.show_global_panel())

        try:
            panel = editor.panels.get(panels.FoldingPanel)
        except KeyError:
            _logger().debug('no FoldingPanel on widget %r', editor)
        else:
            panel.highlight_caret_scope = settings.highlight_caret_scope()
            panel.setVisible(settings.show_folding_panel())

        self._apply_editor_shortcuts(editor)
        self._apply_editor_plugin_preferences(editor)
Exemplo n.º 9
0
 def apply_preferences(self):
     self.widget.font_name = settings.editor_font()
     self.widget.font_size = settings.editor_font_size()
     self.widget.syntax_highlighter.color_scheme = ColorScheme(settings.color_scheme())
     self.widget.update_terminal_colors()
Exemplo n.º 10
0
 def activate(self):
     self.widget = PyConsoleWidget(parent=api.window.get_main_window(), color_scheme=settings.color_scheme(),
                                   backend=pyqode_server.__file__)
     dock = api.window.add_dock_widget(self.widget, _('Python Console'),
                                       PythonManager.get_interpreter_icon(), QtCore.Qt.BottomDockWidgetArea)
     dock.hide()
     dock.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
                        QtWidgets.QSizePolicy.Expanding)
     self.script_runner = api.plugins.get_script_runner()
     self.script_runner.config_refreshed.connect(self._update_interpreter)
     self._interpeter = None
     self._update_interpreter()
Exemplo n.º 11
0
 def apply_preferences(self):
     self.widget.font_name = settings.editor_font()
     self.widget.font_size = settings.editor_font_size()
     self.widget.syntax_highlighter.color_scheme = ColorScheme(
         settings.color_scheme())
     self.widget.update_terminal_colors()
Exemplo n.º 12
0
def color_scheme():
    """
    Returns the color scheme chosen by the usser
    """
    return settings.color_scheme()