def _setup_modes(self, color_scheme): self.cursor_history = self.modes.append(modes.CursorHistoryMode()) self.extended_selection_mode = self.modes.append( modes.ExtendedSelectionMode()) self.case_converter = self.modes.append(modes.CaseConverterMode()) self.auto_complete = self.modes.append(modes.AutoCompleteMode()) self.outline_mode = self.modes.append(modes.OutlineMode(get_outline)) self.add_separator() self.goto_def_mode = self.modes.append(cobmodes.GoToDefinitionMode()) self.code_completion_mode = self.modes.append( modes.CodeCompletionMode()) self.code_completion_mode.trigger_symbols[:] = [] self.file_watcher = self.modes.append(modes.FileWatcherMode()) self.auto_indent_mode = self.modes.append( cobmodes.CobolAutoIndentMode()) self.caret_line_mode = self.modes.append( modes.CaretLineHighlighterMode()) self.zoom_mode = self.modes.append(modes.ZoomMode()) self.indenter_mode = self.modes.append(cobmodes.IndenterMode()) self.auto_indent_mode = self.modes.append(modes.AutoIndentMode()) self.modes.append( cobmodes.CobolSyntaxHighlighter( self.document(), color_scheme=api.ColorScheme(color_scheme))) self.syntax_highlighter.fold_detector = CobolFoldDetector() self.margins = self.modes.append(cobmodes.MarginsMode()) self.comments_mode = self.modes.append(cobmodes.CommentsMode()) self.offset_calculator = self.modes.append( cobmodes.OffsetCalculatorMode()) self.occurences_highlighter_mode = self.modes.append( modes.OccurrencesHighlighterMode()) self.occurences_highlighter_mode.case_sensitive = False self.backspace_mode = self.modes.append(cobmodes.SmartBackSpaceMode())
def test_key_pressed(): # " -> "" editor = CodeEdit() editor.modes.append(modes.AutoCompleteMode()) editor.setPlainText('', '', 'utf-8') QTest.keyPress(editor, '"') assert editor.toPlainText() == '""' editor.clear() # if a " already exists, cursor should just move after " and a new " should # not be inserted editor.setPlainText('"', 'text/x-python', 'utf-8') TextHelper(editor).goto_line(0, 0) QTest.keyPress(editor, '"') assert editor.toPlainText() == '"' editor.clear() # if a ) already exists, cursor should just move after ) and a new ) should # not be inserted editor.setPlainText(')', 'text/x-python', 'utf-8') TextHelper(editor).goto_line(0, 0) QTest.keyPress(editor, ')') QTest.qWait(1000) assert editor.toPlainText() == ')' # ] should be inserted ")" -> "])" TextHelper(editor).goto_line(0, 0) QTest.keyPress(editor, ']') QTest.qWait(1000) assert editor.toPlainText() == '])'
def _enable_lsp_modes(self): if cfg.lsp_code_completion and self.supports_completions: self._enable_mode(modes.CodeCompletionMode()) self._enable_mode(modes.AutoCompleteMode()) # These modes consume key presses that are used by the completion # modes, and should therefore be moved to the end. self._move_mode_to_end('AutoIndentMode') self._move_mode_to_end('SmartBackSpaceMode') if cfg.lsp_calltips and self.supports_calltips: self._enable_mode(lsp_modes.CalltipsMode()) # The diagnostics mode also does some bookkeeping that is generally # required for LSP support. Therefore it's always installed, but only # shows the actual diagnostics if the show_diagnostics keyword is True. diagnostics_mode = lsp_modes.DiagnosticsMode( show_diagnostics=cfg.lsp_diagnostics and self.supports_diagnostics) diagnostics_mode.set_ignore_rules([ ir.strip() for ir in cfg.lsp_diagnostics_ignore.split(u';') if ir.strip() ]) diagnostics_mode.server_status_changed.connect( self._on_server_status_changed) self._enable_mode(diagnostics_mode) if cfg.lsp_diagnostics and self.supports_diagnostics: self._enable_panel(panels.CheckerPanel(), panels.GlobalCheckerPanel.Position.LEFT) self._enable_panel(panels.GlobalCheckerPanel(), panels.GlobalCheckerPanel.Position.RIGHT) if cfg.lsp_symbols and self.supports_symbols: self._enable_mode( lsp_modes.SymbolsMode( cfg.lsp_symbols_kind.split(';') if isinstance( cfg.lsp_symbols_kind, basestring) else []))
def __init__(self, parent=None, server_script=server.__file__, interpreter=sys.executable, args=None, create_default_actions=True, color_scheme='qt'): super(GenericCodeEdit, self).__init__(parent, create_default_actions) from pyqode.core import panels from pyqode.core import modes self.backend.start(server_script, interpreter, args) # append panels self.panels.append(panels.FoldingPanel()) self.panels.append(panels.LineNumberPanel()) self.panels.append(panels.SearchAndReplacePanel(), Panel.Position.BOTTOM) self.panels.append(panels.EncodingPanel(), Panel.Position.TOP) # append modes self.modes.append(modes.AutoCompleteMode()) self.add_separator() self.modes.append(modes.CaseConverterMode()) self.modes.append(modes.FileWatcherMode()) self.modes.append(modes.CaretLineHighlighterMode()) self.modes.append(modes.RightMarginMode()) self.modes.append(modes.PygmentsSyntaxHighlighter( self.document(), color_scheme=ColorScheme(color_scheme))) self.modes.append(modes.ZoomMode()) self.modes.append(modes.CodeCompletionMode()) self.modes.append(modes.AutoIndentMode()) self.modes.append(modes.IndenterMode()) self.modes.append(modes.SymbolMatcherMode()) self.modes.append(modes.OccurrencesHighlighterMode()) self.modes.append(modes.SmartBackSpaceMode()) self.modes.append(modes.ExtendedSelectionMode()) self.syntax_highlighter.fold_detector = IndentFoldDetector()
def configure_modes_and_panels(self): # Modes self.modes.append(modes.IndenterMode()) self.modes.append(modes.AutoIndentMode()) self.modes.append(modes.AutoCompleteMode()) self.modes.append(CommentsMode()) # Panels self.panels.append(LineNumberPanel(), api.Panel.Position.LEFT) self.panels.append(panels.SearchAndReplacePanel(), api.Panel.Position.BOTTOM)
def __init__(self, parent=None, server_script=None, interpreter=sys.executable, args=None, create_default_actions=True, color_scheme='qt', reuse_backend=False): super(GenericCodeEdit, self).__init__(parent, create_default_actions) from pyqode.core import panels from pyqode.core import modes if server_script is None: server_script = GenericCodeEdit.DEFAULT_SERVER self.backend.start(server_script, interpreter, args, reuse=reuse_backend) # append panels self.panels.append(panels.LineNumberPanel()) self.panels.append(panels.SearchAndReplacePanel(), Panel.Position.BOTTOM) self.panels.append(panels.FoldingPanel()) # append modes self.modes.append(modes.CursorHistoryMode()) self.modes.append(modes.AutoCompleteMode()) self.modes.append(modes.ExtendedSelectionMode()) self.modes.append(modes.CaseConverterMode()) self.modes.append(modes.FileWatcherMode()) self.modes.append(modes.CaretLineHighlighterMode()) self.modes.append(modes.RightMarginMode()) self.modes.append( modes.PygmentsSyntaxHighlighter( self.document(), color_scheme=ColorScheme(color_scheme))) self.modes.append(modes.ZoomMode()) self.modes.append(modes.CodeCompletionMode()) self.modes.append(modes.AutoIndentMode()) self.modes.append(modes.IndenterMode()) self.modes.append(modes.SymbolMatcherMode()) self.modes.append(modes.OccurrencesHighlighterMode()) self.modes.append(modes.SmartBackSpaceMode()) self.panels.append(panels.EncodingPanel(), Panel.Position.TOP) self.panels.append(panels.ReadOnlyPanel(), Panel.Position.TOP)
def setup_editor(code_edit): # append panels p = panels.FoldingPanel(highlight_caret_scope=True) code_edit.panels.append(p) p.show() p = panels.LineNumberPanel() code_edit.panels.append(p) p.show() p = panels.MarkerPanel() code_edit.panels.append(p) p.show() p = panels.CheckerPanel() code_edit.panels.append(p) p.show() p = panels.SearchAndReplacePanel() code_edit.panels.append(p, p.Position.BOTTOM) p.show() p = panels.GlobalCheckerPanel() code_edit.panels.append(p, p.Position.RIGHT) p.show() # append modes code_edit.modes.append(modes.AutoCompleteMode()) code_edit.modes.append(modes.CaseConverterMode()) code_edit.modes.append(modes.FileWatcherMode()) code_edit.modes.append(modes.CaretLineHighlighterMode()) code_edit.modes.append(modes.RightMarginMode()) code_edit.modes.append( modes.PygmentsSyntaxHighlighter(code_edit.document())) code_edit.modes.append(modes.ZoomMode()) code_edit.modes.append(modes.CodeCompletionMode()) code_edit.modes.append(modes.AutoIndentMode()) code_edit.modes.append(modes.IndenterMode()) code_edit.modes.append(modes.SymbolMatcherMode()) code_edit.modes.append(modes.WordClickMode()) code_edit.modes.get(modes.FileWatcherMode).auto_reload = True code_edit.syntax_highlighter.fold_detector = IndentFoldDetector() code_edit.modes.append(modes.SmartBackSpaceMode()) code_edit.modes.append(modes.ExtendedSelectionMode()) code_edit.modes.append(modes.OccurrencesHighlighterMode())
def __init__(self, parent=None, server_script=server.__file__, interpreter=sys.executable, args=None, create_default_actions=True, color_scheme='qt', reuse_backend=False): from pyqode.core import panels from pyqode.core import modes super(TextCodeEdit, self).__init__(parent, create_default_actions) self.backend.start(server_script, interpreter, args, reuse=reuse_backend) # append panels self.panels.append(panels.SearchAndReplacePanel(), Panel.Position.BOTTOM) self.panels.append(panels.FoldingPanel()) self.panels.append(panels.LineNumberPanel()) # append modes self.modes.append(modes.AutoCompleteMode()) self.modes.append(modes.ExtendedSelectionMode()) self.modes.append(modes.CaseConverterMode()) self.modes.append(modes.FileWatcherMode()) self.modes.append(modes.CaretLineHighlighterMode()) self.modes.append(modes.RightMarginMode()) self.modes.append( TextCodeEdit.TextSH(self.document(), ColorScheme(color_scheme))) self.modes.append(modes.ZoomMode()) self.modes.append(modes.OccurrencesHighlighterMode()) self.modes.append(modes.CodeCompletionMode()) self.modes.append(modes.AutoIndentMode()) self.modes.append(modes.IndenterMode()) self.modes.append(modes.SymbolMatcherMode()) self.panels.append(panels.EncodingPanel(), Panel.Position.TOP)
def __init__(self, args): QMainWindow.__init__(self) self.setupUi(self) self.moderat = args['moderat'] self.client = args['client'] self.module_id = args['module_id'] self.alias = args['alias'] self.ip_address = args['ip_address'] self.p2p = args['p2p'] title_prefix = self.alias if len(self.alias) > 0 else self.ip_address self.setWindowTitle(u'[{}] {}'.format( title_prefix, self.moderat.MString('MSCRIPTING_TITLE'))) # init idle self.editor = api.CodeEdit() #self.editor.setStyleSheet('border: 0px; padding: 0px; background: #34495e;') # start the backend as soon as possible self.editor.backend.start(server.__file__) # append some modes and panels self.editor.modes.append(modes.CodeCompletionMode()) self.editor.modes.append(modes.AutoIndentMode()) self.editor.modes.append(modes.AutoCompleteMode()) self.editor.modes.append(modes.IndenterMode()) self.editor.modes.append(modes.ExtendedSelectionMode()) self.editor.modes.append(modes.SymbolMatcherMode()) self.editor.modes.append(modes.ZoomMode()) self.editor.modes.append(modes.LineHighlighterMode()) self.editor.modes.append( modes.PygmentsSyntaxHighlighter(self.editor.document())) sh = self.editor.modes.append(modes.PygmentsSH(self.editor.document())) sh.fold_detector = api.IndentFoldDetector() self.editor.modes.get( modes.PygmentsSyntaxHighlighter).pygments_style = 'monokai' self.editor.panels.append(panels.SearchAndReplacePanel(), api.Panel.Position.BOTTOM) self.editor.panels.append(panels.CheckerPanel()) self.editor.panels.append(panels.LineNumberPanel()) self.editor.panels.append(panels.MarkerPanel()) self.editor.panels.append(panels.EncodingPanel()) self.editor.panels.append(panels.FoldingPanel()) self.editor.panels.append(panels.ReadOnlyPanel()) self.output = Output(self.editor, self.moderat) self.splitter = QSplitter() self.splitter.setOrientation(Qt.Vertical) self.splitter.addWidget(self.editor) self.splitter.addWidget(self.output) self.setCentralWidget(self.splitter) # self.runButton.clicked.connect(self.run_script) # self.testButton.clicked.connect(self.run_test) # self.openButton.clicked.connect(self.from_file) # self.pluginsListButton.clicked.connect(self.open_list) # self.addPluginButton.clicked.connect(self.insert_plugin) # self.saveButton.clicked.connect(self.save_plugin) # self.pluginSearchLine.returnPressed.connect(self.insert_plugin) # self.clearButton.clicked.connect(self.clear_script) # self.pinButton.clicked.connect(self.always_top) # Autocompleter self.completer = QCompleter(self.moderat.plugins.keys()) self.completer.setCompletionMode(QCompleter.PopupCompletion) self.completer.setCaseSensitivity(Qt.CaseInsensitive) self.completer.popup().setStyleSheet('''background-color: #273747; color: #c9f5f7; border: 1px solid #243342; border-top: none;''') self.addTools()