##// END OF EJS Templates
added --colors flag to ipythonqt
MinRK -
Show More
@@ -25,8 +25,9 b' from IPython.core.inputsplitter import IPythonInputSplitter, \\'
25 from IPython.core.usage import default_gui_banner
25 from IPython.core.usage import default_gui_banner
26 from IPython.utils.traitlets import Bool, Str
26 from IPython.utils.traitlets import Bool, Str
27 from frontend_widget import FrontendWidget
27 from frontend_widget import FrontendWidget
28 from styles import (default_light_style_sheet, default_dark_style_sheet,
28 from styles import (default_light_style_sheet, default_light_syntax_style,
29 default_light_syntax_style, default_dark_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 # Constants
33 # Constants
@@ -329,21 +330,24 b' class IPythonWidget(FrontendWidget):'
329 # 'IPythonWidget' interface
330 # 'IPythonWidget' interface
330 #---------------------------------------------------------------------------
331 #---------------------------------------------------------------------------
331
332
332 def set_default_style(self, lightbg=True):
333 def set_default_style(self, colors='light'):
333 """ Sets the widget style to the class defaults.
334 """ Sets the widget style to the class defaults.
334
335
335 Parameters:
336 Parameters:
336 -----------
337 -----------
337 lightbg : bool, optional (default True)
338 colors : str, optional (default light)
338 Whether to use the default IPython light background or dark
339 Whether to use the default IPython light background or dark
339 background style.
340 background or B&W style.
340 """
341 """
341 if lightbg:
342 if colors=='light':
342 self.style_sheet = default_light_style_sheet
343 self.style_sheet = default_light_style_sheet
343 self.syntax_style = default_light_syntax_style
344 self.syntax_style = default_light_syntax_style
344 else:
345 elif colors=='dark':
345 self.style_sheet = default_dark_style_sheet
346 self.style_sheet = default_dark_style_sheet
346 self.syntax_style = default_dark_syntax_style
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 # 'IPythonWidget' protected interface
353 # 'IPythonWidget' protected interface
@@ -150,13 +150,13 b' def main():'
150 wgroup.add_argument('--gui-completion', action='store_true',
150 wgroup.add_argument('--gui-completion', action='store_true',
151 help='use a GUI widget for tab completion')
151 help='use a GUI widget for tab completion')
152 wgroup.add_argument('--style', type=str,
152 wgroup.add_argument('--style', type=str,
153 help='specify a pygments style by name. \
153 choices = list(get_all_styles()),
154 Valid are: %s'%(list(get_all_styles())))
154 help='specify a pygments style for by name.')
155 wgroup.add_argument('--stylesheet', type=str,
155 wgroup.add_argument('--stylesheet', type=str,
156 help="path to a custom CSS stylesheet.")
156 help="path to a custom CSS stylesheet.")
157 wgroup.add_argument('--dark', action='store_true',
157 wgroup.add_argument('--colors', type=str,
158 help="use the dark style template instead of lightbg.\
158 help="Set the color scheme (light, dark, or bw). This is guessed\
159 If --style is not specified, the default dark style is used.")
159 based on the pygments style if not set.")
160
160
161 args = parser.parse_args()
161 args = parser.parse_args()
162
162
@@ -197,20 +197,32 b' def main():'
197
197
198 # configure the style:
198 # configure the style:
199 if not args.pure: # only IPythonWidget supports styles
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 if args.style:
213 if args.style:
201 # guess whether it's a dark style:
214 # guess whether it's a dark style:
202 dark = args.dark or styles.dark_style(args.style)
203 widget.syntax_style = args.style
215 widget.syntax_style = args.style
204 widget.style_sheet = styles.sheet_from_template(args.style, not dark)
216 widget.style_sheet = styles.sheet_from_template(args.style, lightbg)
205 widget._syntax_style_changed()
217 widget._syntax_style_changed()
206 widget._style_sheet_changed()
218 widget._style_sheet_changed()
207 elif args.dark:
219 elif colors:
208 # use default dark style
220 # use a default style
209 widget.set_default_style(lightbg=False)
221 widget.set_default_style(colors=colors)
210 else:
222 else:
211 # this is redundant for now, but allows the widget's
223 # this is redundant for now, but allows the widget's
212 # defaults to change
224 # defaults to change
213 widget.set_default_style(lightbg=True)
225 widget.set_default_style()
214
226
215 if args.stylesheet:
227 if args.stylesheet:
216 # we got an expicit stylesheet
228 # we got an expicit stylesheet
@@ -43,6 +43,17 b' default_dark_style_sheet = default_dark_style_template%dict('
43 bgcolor='black', fgcolor='white', select="#555")
43 bgcolor='black', fgcolor='white', select="#555")
44 default_dark_syntax_style = 'monokai'
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 def hex_to_rgb(color):
57 def hex_to_rgb(color):
47 """Convert a hex color to rgb integer tuple."""
58 """Convert a hex color to rgb integer tuple."""
48 if color.startswith('#'):
59 if color.startswith('#'):
@@ -76,7 +87,8 b' def dark_style(stylename):'
76 return dark_color(get_style_by_name(stylename).background_color)
87 return dark_color(get_style_by_name(stylename).background_color)
77
88
78 def get_colors(stylename):
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 style = get_style_by_name(stylename)
92 style = get_style_by_name(stylename)
81 fgcolor = style.style_for_token(Token.Text)['color'] or ''
93 fgcolor = style.style_for_token(Token.Text)['color'] or ''
82 if len(fgcolor) in (3,6):
94 if len(fgcolor) in (3,6):
@@ -94,9 +106,14 b' def get_colors(stylename):'
94 fgcolor = fgcolor
106 fgcolor = fgcolor
95 )
107 )
96
108
97 def sheet_from_template(name, lightbg=True):
109 def sheet_from_template(name, colors='light'):
98 """Use one of the base templates, and set bg/fg/select colors."""
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 return default_light_style_template%get_colors(name)
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 else:
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