Show More
@@ -6,6 +6,10 b'' | |||||
6 | Linux (use the xdg system). |
|
6 | Linux (use the xdg system). | |
7 | """ |
|
7 | """ | |
8 |
|
8 | |||
|
9 | #----------------------------------------------------------------------------- | |||
|
10 | # Imports | |||
|
11 | #----------------------------------------------------------------------------- | |||
|
12 | ||||
9 | # Standard library imports |
|
13 | # Standard library imports | |
10 | from collections import namedtuple |
|
14 | from collections import namedtuple | |
11 | from subprocess import Popen |
|
15 | from subprocess import Popen | |
@@ -19,18 +23,22 b' from IPython.core.usage import default_banner' | |||||
19 | from IPython.utils.traitlets import Bool, Str |
|
23 | from IPython.utils.traitlets import Bool, Str | |
20 | from frontend_widget import FrontendWidget |
|
24 | from frontend_widget import FrontendWidget | |
21 |
|
25 | |||
22 | # The default style sheet: black text on a white background. |
|
26 | #----------------------------------------------------------------------------- | |
23 | default_style_sheet = ''' |
|
27 | # Constants | |
|
28 | #----------------------------------------------------------------------------- | |||
|
29 | ||||
|
30 | # The default light style sheet: black text on a white background. | |||
|
31 | default_light_style_sheet = ''' | |||
24 | .error { color: red; } |
|
32 | .error { color: red; } | |
25 | .in-prompt { color: navy; } |
|
33 | .in-prompt { color: navy; } | |
26 | .in-prompt-number { font-weight: bold; } |
|
34 | .in-prompt-number { font-weight: bold; } | |
27 | .out-prompt { color: darkred; } |
|
35 | .out-prompt { color: darkred; } | |
28 | .out-prompt-number { font-weight: bold; } |
|
36 | .out-prompt-number { font-weight: bold; } | |
29 | ''' |
|
37 | ''' | |
30 | default_syntax_style = 'default' |
|
38 | default_light_syntax_style = 'default' | |
31 |
|
39 | |||
32 |
# |
|
40 | # The default dark style sheet: white text on a black background. | |
33 | dark_style_sheet = ''' |
|
41 | default_dark_style_sheet = ''' | |
34 | QPlainTextEdit, QTextEdit { background-color: black; color: white } |
|
42 | QPlainTextEdit, QTextEdit { background-color: black; color: white } | |
35 | QFrame { border: 1px solid grey; } |
|
43 | QFrame { border: 1px solid grey; } | |
36 | .error { color: red; } |
|
44 | .error { color: red; } | |
@@ -39,12 +47,15 b" dark_style_sheet = '''" | |||||
39 | .out-prompt { color: red; } |
|
47 | .out-prompt { color: red; } | |
40 | .out-prompt-number { color: red; font-weight: bold; } |
|
48 | .out-prompt-number { color: red; font-weight: bold; } | |
41 | ''' |
|
49 | ''' | |
42 | dark_syntax_style = 'monokai' |
|
50 | default_dark_syntax_style = 'monokai' | |
43 |
|
51 | |||
44 | # Default prompts. |
|
52 | # Default prompts. | |
45 | default_in_prompt = 'In [<span class="in-prompt-number">%i</span>]: ' |
|
53 | default_in_prompt = 'In [<span class="in-prompt-number">%i</span>]: ' | |
46 | default_out_prompt = 'Out[<span class="out-prompt-number">%i</span>]: ' |
|
54 | default_out_prompt = 'Out[<span class="out-prompt-number">%i</span>]: ' | |
47 |
|
55 | |||
|
56 | #----------------------------------------------------------------------------- | |||
|
57 | # IPythonWidget class | |||
|
58 | #----------------------------------------------------------------------------- | |||
48 |
|
59 | |||
49 | class IPythonWidget(FrontendWidget): |
|
60 | class IPythonWidget(FrontendWidget): | |
50 | """ A FrontendWidget for an IPython kernel. |
|
61 | """ A FrontendWidget for an IPython kernel. | |
@@ -71,11 +82,11 b' class IPythonWidget(FrontendWidget):' | |||||
71 | # 1. Qt: QPlainTextEdit, QFrame, QWidget, etc |
|
82 | # 1. Qt: QPlainTextEdit, QFrame, QWidget, etc | |
72 | # 2. Pygments: .c, .k, .o, etc (see PygmentsHighlighter) |
|
83 | # 2. Pygments: .c, .k, .o, etc (see PygmentsHighlighter) | |
73 | # 3. IPython: .error, .in-prompt, .out-prompt, etc |
|
84 | # 3. IPython: .error, .in-prompt, .out-prompt, etc | |
74 |
style_sheet = Str( |
|
85 | style_sheet = Str(config=True) | |
75 |
|
86 | |||
76 | # If not empty, use this Pygments style for syntax highlighting. Otherwise, |
|
87 | # If not empty, use this Pygments style for syntax highlighting. Otherwise, | |
77 | # the style sheet is queried for Pygments style information. |
|
88 | # the style sheet is queried for Pygments style information. | |
78 |
syntax_style = Str( |
|
89 | syntax_style = Str(config=True) | |
79 |
|
90 | |||
80 | # Prompts. |
|
91 | # Prompts. | |
81 | in_prompt = Str(default_in_prompt, config=True) |
|
92 | in_prompt = Str(default_in_prompt, config=True) | |
@@ -100,8 +111,11 b' class IPythonWidget(FrontendWidget):' | |||||
100 | self._previous_prompt_obj = None |
|
111 | self._previous_prompt_obj = None | |
101 |
|
112 | |||
102 | # Initialize widget styling. |
|
113 | # Initialize widget styling. | |
103 |
self. |
|
114 | if self.style_sheet: | |
104 |
self._s |
|
115 | self._style_sheet_changed() | |
|
116 | self._syntax_style_changed() | |||
|
117 | else: | |||
|
118 | self.set_default_style() | |||
105 |
|
119 | |||
106 | #--------------------------------------------------------------------------- |
|
120 | #--------------------------------------------------------------------------- | |
107 | # 'BaseFrontendMixin' abstract interface |
|
121 | # 'BaseFrontendMixin' abstract interface | |
@@ -275,6 +289,26 b' class IPythonWidget(FrontendWidget):' | |||||
275 | next_prompt['input_sep']) |
|
289 | next_prompt['input_sep']) | |
276 |
|
290 | |||
277 | #--------------------------------------------------------------------------- |
|
291 | #--------------------------------------------------------------------------- | |
|
292 | # 'IPythonWidget' interface | |||
|
293 | #--------------------------------------------------------------------------- | |||
|
294 | ||||
|
295 | def set_default_style(self, lightbg=True): | |||
|
296 | """ Sets the widget style to the class defaults. | |||
|
297 | ||||
|
298 | Parameters: | |||
|
299 | ----------- | |||
|
300 | lightbg : bool, optional (default True) | |||
|
301 | Whether to use the default IPython light background or dark | |||
|
302 | background style. | |||
|
303 | """ | |||
|
304 | if lightbg: | |||
|
305 | self.style_sheet = default_light_style_sheet | |||
|
306 | self.syntax_style = default_light_syntax_style | |||
|
307 | else: | |||
|
308 | self.style_sheet = default_dark_style_sheet | |||
|
309 | self.syntax_style = default_dark_syntax_style | |||
|
310 | ||||
|
311 | #--------------------------------------------------------------------------- | |||
278 | # 'IPythonWidget' protected interface |
|
312 | # 'IPythonWidget' protected interface | |
279 | #--------------------------------------------------------------------------- |
|
313 | #--------------------------------------------------------------------------- | |
280 |
|
314 |
General Comments 0
You need to be logged in to leave comments.
Login now