##// END OF EJS Templates
make QtConsole Lexer configurable...
MinRK -
Show More
@@ -6,16 +6,17 b' import sys'
6 6 import uuid
7 7
8 8 # System library imports
9 from pygments.lexers import PythonLexer
10 9 from IPython.external import qt
11 10 from IPython.external.qt import QtCore, QtGui
11 from IPython.utils import py3compat
12 from IPython.utils.importstring import import_item
12 13
13 14 # Local imports
14 15 from IPython.core.inputsplitter import InputSplitter, IPythonInputSplitter
15 16 from IPython.core.inputtransformer import classic_prompt
16 17 from IPython.core.oinspect import call_tip
17 18 from IPython.qt.base_frontend_mixin import BaseFrontendMixin
18 from IPython.utils.traitlets import Bool, Instance, Unicode
19 from IPython.utils.traitlets import Any, Bool, Instance, Unicode, DottedObjectName
19 20 from .bracket_matcher import BracketMatcher
20 21 from .call_tip_widget import CallTipWidget
21 22 from .completion_lexer import CompletionLexer
@@ -27,8 +28,8 b' class FrontendHighlighter(PygmentsHighlighter):'
27 28 """ A PygmentsHighlighter that understands and ignores prompts.
28 29 """
29 30
30 def __init__(self, frontend):
31 super(FrontendHighlighter, self).__init__(frontend._control.document())
31 def __init__(self, frontend, lexer=None):
32 super(FrontendHighlighter, self).__init__(frontend._control.document(), lexer=lexer)
32 33 self._current_offset = 0
33 34 self._frontend = frontend
34 35 self.highlighting_on = False
@@ -100,6 +101,24 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
100 101
101 102 confirm_restart = Bool(True, config=True,
102 103 help="Whether to ask for user confirmation when restarting kernel")
104
105 lexer_class = DottedObjectName(config=True,
106 help="The pygments lexer class to use."
107 )
108 def _lexer_class_changed(self, name, old, new):
109 lexer_class = import_item(new)
110 self.lexer = lexer_class()
111
112 def _lexer_class_default(self):
113 if py3compat.PY3:
114 return 'pygments.lexers.Python3Lexer'
115 else:
116 return 'pygments.lexers.PythonLexer'
117
118 lexer = Any()
119 def _lexer_default(self):
120 lexer_class = import_item(self.lexer_class)
121 return lexer_class()
103 122
104 123 # Emitted when a user visible 'execute_request' has been submitted to the
105 124 # kernel from the FrontendWidget. Contains the code to be executed.
@@ -141,10 +160,10 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
141 160 # FrontendWidget protected variables.
142 161 self._bracket_matcher = BracketMatcher(self._control)
143 162 self._call_tip_widget = CallTipWidget(self._control)
144 self._completion_lexer = CompletionLexer(PythonLexer())
163 self._completion_lexer = CompletionLexer(self.lexer)
145 164 self._copy_raw_action = QtGui.QAction('Copy (Raw Text)', None)
146 165 self._hidden = False
147 self._highlighter = FrontendHighlighter(self)
166 self._highlighter = FrontendHighlighter(self, lexer=self.lexer)
148 167 self._input_splitter = self._input_splitter_class()
149 168 self._kernel_manager = None
150 169 self._kernel_client = None
General Comments 0
You need to be logged in to leave comments. Login now