Show More
@@ -25,8 +25,9 b' from IPython.core.inputsplitter import IPythonInputSplitter, \\' | |||
|
25 | 25 | from IPython.core.usage import default_gui_banner |
|
26 | 26 | from IPython.utils.traitlets import Bool, Str |
|
27 | 27 | from frontend_widget import FrontendWidget |
|
28 |
from styles import (default_light_style_sheet, default_ |
|
|
29 |
default_ |
|
|
28 | from styles import (default_light_style_sheet, default_light_syntax_style, | |
|
29 | default_dark_style_sheet, default_dark_syntax_style, | |
|
30 | default_bw_style_sheet, default_bw_syntax_style) | |
|
30 | 31 | |
|
31 | 32 | #----------------------------------------------------------------------------- |
|
32 | 33 | # Constants |
@@ -329,21 +330,24 b' class IPythonWidget(FrontendWidget):' | |||
|
329 | 330 | # 'IPythonWidget' interface |
|
330 | 331 | #--------------------------------------------------------------------------- |
|
331 | 332 | |
|
332 |
def set_default_style(self, |
|
|
333 | def set_default_style(self, colors='light'): | |
|
333 | 334 | """ Sets the widget style to the class defaults. |
|
334 | 335 | |
|
335 | 336 | Parameters: |
|
336 | 337 | ----------- |
|
337 |
|
|
|
338 | colors : str, optional (default light) | |
|
338 | 339 | Whether to use the default IPython light background or dark |
|
339 | background style. | |
|
340 | background or B&W style. | |
|
340 | 341 | """ |
|
341 |
if |
|
|
342 | if colors=='light': | |
|
342 | 343 | self.style_sheet = default_light_style_sheet |
|
343 | 344 | self.syntax_style = default_light_syntax_style |
|
344 | else: | |
|
345 | elif colors=='dark': | |
|
345 | 346 | self.style_sheet = default_dark_style_sheet |
|
346 | 347 | self.syntax_style = default_dark_syntax_style |
|
348 | elif colors=='bw': | |
|
349 | self.style_sheet = default_bw_style_sheet | |
|
350 | self.syntax_style = default_bw_syntax_style | |
|
347 | 351 | |
|
348 | 352 | #--------------------------------------------------------------------------- |
|
349 | 353 | # 'IPythonWidget' protected interface |
@@ -150,13 +150,13 b' def main():' | |||
|
150 | 150 | wgroup.add_argument('--gui-completion', action='store_true', |
|
151 | 151 | help='use a GUI widget for tab completion') |
|
152 | 152 | wgroup.add_argument('--style', type=str, |
|
153 | help='specify a pygments style by name. \ | |
|
154 | Valid are: %s'%(list(get_all_styles()))) | |
|
153 | choices = list(get_all_styles()), | |
|
154 | help='specify a pygments style for by name.') | |
|
155 | 155 | wgroup.add_argument('--stylesheet', type=str, |
|
156 | 156 | help="path to a custom CSS stylesheet.") |
|
157 |
wgroup.add_argument('-- |
|
|
158 | help="use the dark style template instead of lightbg.\ | |
|
159 |
|
|
|
157 | wgroup.add_argument('--colors', type=str, | |
|
158 | help="Set the color scheme (light, dark, or bw). This is guessed\ | |
|
159 | based on the pygments style if not set.") | |
|
160 | 160 | |
|
161 | 161 | args = parser.parse_args() |
|
162 | 162 | |
@@ -197,20 +197,32 b' def main():' | |||
|
197 | 197 | |
|
198 | 198 | # configure the style: |
|
199 | 199 | if not args.pure: # only IPythonWidget supports styles |
|
200 | # parse the colors arg down to current known labels | |
|
201 | if args.colors: | |
|
202 | colors=args.colors.lower() | |
|
203 | if colors in ('lightbg', 'light'): | |
|
204 | colors='light' | |
|
205 | elif colors in ('dark', 'linux'): | |
|
206 | colors='dark' | |
|
207 | else: | |
|
208 | colors='nocolor' | |
|
209 | else: | |
|
210 | colors=None | |
|
211 | lightbg = colors != 'linux' | |
|
212 | ||
|
200 | 213 | if args.style: |
|
201 | 214 | # guess whether it's a dark style: |
|
202 | dark = args.dark or styles.dark_style(args.style) | |
|
203 | 215 | widget.syntax_style = args.style |
|
204 |
widget.style_sheet = styles.sheet_from_template(args.style, |
|
|
216 | widget.style_sheet = styles.sheet_from_template(args.style, lightbg) | |
|
205 | 217 | widget._syntax_style_changed() |
|
206 | 218 | widget._style_sheet_changed() |
|
207 |
elif |
|
|
208 |
# use default |
|
|
209 |
widget.set_default_style( |
|
|
219 | elif colors: | |
|
220 | # use a default style | |
|
221 | widget.set_default_style(colors=colors) | |
|
210 | 222 | else: |
|
211 | 223 | # this is redundant for now, but allows the widget's |
|
212 | 224 | # defaults to change |
|
213 |
widget.set_default_style( |
|
|
225 | widget.set_default_style() | |
|
214 | 226 | |
|
215 | 227 | if args.stylesheet: |
|
216 | 228 | # we got an expicit stylesheet |
@@ -43,6 +43,17 b' default_dark_style_sheet = default_dark_style_template%dict(' | |||
|
43 | 43 | bgcolor='black', fgcolor='white', select="#555") |
|
44 | 44 | default_dark_syntax_style = 'monokai' |
|
45 | 45 | |
|
46 | # The default monochrome | |
|
47 | default_bw_style_sheet = ''' | |
|
48 | QPlainTextEdit, QTextEdit { background-color: white; | |
|
49 | color: black ; | |
|
50 | selection-background-color: #cccccc} | |
|
51 | .in-prompt-number { font-weight: bold; } | |
|
52 | .out-prompt-number { font-weight: bold; } | |
|
53 | ''' | |
|
54 | default_bw_syntax_style = 'bw' | |
|
55 | ||
|
56 | ||
|
46 | 57 | def hex_to_rgb(color): |
|
47 | 58 | """Convert a hex color to rgb integer tuple.""" |
|
48 | 59 | if color.startswith('#'): |
@@ -76,7 +87,8 b' def dark_style(stylename):' | |||
|
76 | 87 | return dark_color(get_style_by_name(stylename).background_color) |
|
77 | 88 | |
|
78 | 89 | def get_colors(stylename): |
|
79 |
"""Construct the keys to be used building the base stylesheet |
|
|
90 | """Construct the keys to be used building the base stylesheet | |
|
91 | from a templatee.""" | |
|
80 | 92 | style = get_style_by_name(stylename) |
|
81 | 93 | fgcolor = style.style_for_token(Token.Text)['color'] or '' |
|
82 | 94 | if len(fgcolor) in (3,6): |
@@ -94,9 +106,14 b' def get_colors(stylename):' | |||
|
94 | 106 | fgcolor = fgcolor |
|
95 | 107 | ) |
|
96 | 108 | |
|
97 |
def sheet_from_template(name, |
|
|
109 | def sheet_from_template(name, colors='light'): | |
|
98 | 110 | """Use one of the base templates, and set bg/fg/select colors.""" |
|
99 | if lightbg: | |
|
111 | colors = colors.lower() | |
|
112 | if colors=='light': | |
|
100 | 113 | return default_light_style_template%get_colors(name) |
|
114 | elif colors=='dark': | |
|
115 | return default_dark_style_template%get_colors(name) | |
|
116 | elif colors=='nocolor': | |
|
117 | return default_bw_style_sheet | |
|
101 | 118 | else: |
|
102 | return default_dark_style_template%get_colors(name) No newline at end of file | |
|
119 | raise KeyError("No such color scheme: %s"%colors) |
General Comments 0
You need to be logged in to leave comments.
Login now