##// END OF EJS Templates
make QtConsole Lexer configurable...
MinRK -
Show More
@@ -6,16 +6,17 b' import sys'
6 import uuid
6 import uuid
7
7
8 # System library imports
8 # System library imports
9 from pygments.lexers import PythonLexer
10 from IPython.external import qt
9 from IPython.external import qt
11 from IPython.external.qt import QtCore, QtGui
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 # Local imports
14 # Local imports
14 from IPython.core.inputsplitter import InputSplitter, IPythonInputSplitter
15 from IPython.core.inputsplitter import InputSplitter, IPythonInputSplitter
15 from IPython.core.inputtransformer import classic_prompt
16 from IPython.core.inputtransformer import classic_prompt
16 from IPython.core.oinspect import call_tip
17 from IPython.core.oinspect import call_tip
17 from IPython.qt.base_frontend_mixin import BaseFrontendMixin
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 from .bracket_matcher import BracketMatcher
20 from .bracket_matcher import BracketMatcher
20 from .call_tip_widget import CallTipWidget
21 from .call_tip_widget import CallTipWidget
21 from .completion_lexer import CompletionLexer
22 from .completion_lexer import CompletionLexer
@@ -27,8 +28,8 b' class FrontendHighlighter(PygmentsHighlighter):'
27 """ A PygmentsHighlighter that understands and ignores prompts.
28 """ A PygmentsHighlighter that understands and ignores prompts.
28 """
29 """
29
30
30 def __init__(self, frontend):
31 def __init__(self, frontend, lexer=None):
31 super(FrontendHighlighter, self).__init__(frontend._control.document())
32 super(FrontendHighlighter, self).__init__(frontend._control.document(), lexer=lexer)
32 self._current_offset = 0
33 self._current_offset = 0
33 self._frontend = frontend
34 self._frontend = frontend
34 self.highlighting_on = False
35 self.highlighting_on = False
@@ -101,6 +102,24 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
101 confirm_restart = Bool(True, config=True,
102 confirm_restart = Bool(True, config=True,
102 help="Whether to ask for user confirmation when restarting kernel")
103 help="Whether to ask for user confirmation when restarting kernel")
103
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()
122
104 # Emitted when a user visible 'execute_request' has been submitted to the
123 # Emitted when a user visible 'execute_request' has been submitted to the
105 # kernel from the FrontendWidget. Contains the code to be executed.
124 # kernel from the FrontendWidget. Contains the code to be executed.
106 executing = QtCore.Signal(object)
125 executing = QtCore.Signal(object)
@@ -141,10 +160,10 b' class FrontendWidget(HistoryConsoleWidget, BaseFrontendMixin):'
141 # FrontendWidget protected variables.
160 # FrontendWidget protected variables.
142 self._bracket_matcher = BracketMatcher(self._control)
161 self._bracket_matcher = BracketMatcher(self._control)
143 self._call_tip_widget = CallTipWidget(self._control)
162 self._call_tip_widget = CallTipWidget(self._control)
144 self._completion_lexer = CompletionLexer(PythonLexer())
163 self._completion_lexer = CompletionLexer(self.lexer)
145 self._copy_raw_action = QtGui.QAction('Copy (Raw Text)', None)
164 self._copy_raw_action = QtGui.QAction('Copy (Raw Text)', None)
146 self._hidden = False
165 self._hidden = False
147 self._highlighter = FrontendHighlighter(self)
166 self._highlighter = FrontendHighlighter(self, lexer=self.lexer)
148 self._input_splitter = self._input_splitter_class()
167 self._input_splitter = self._input_splitter_class()
149 self._kernel_manager = None
168 self._kernel_manager = None
150 self._kernel_client = None
169 self._kernel_client = None
General Comments 0
You need to be logged in to leave comments. Login now