##// END OF EJS Templates
color settings from ipythonqt propagate down to the ZMQInteractiveShell in the Kernel
MinRK -
Show More
@@ -330,24 +330,27 b' class IPythonWidget(FrontendWidget):'
330 330 # 'IPythonWidget' interface
331 331 #---------------------------------------------------------------------------
332 332
333 def set_default_style(self, colors='light'):
333 def set_default_style(self, colors='lightbg'):
334 334 """ Sets the widget style to the class defaults.
335 335
336 336 Parameters:
337 337 -----------
338 colors : str, optional (default light)
338 colors : str, optional (default lightbg)
339 339 Whether to use the default IPython light background or dark
340 340 background or B&W style.
341 341 """
342 if colors=='light':
342 colors = colors.lower()
343 if colors=='lightbg':
343 344 self.style_sheet = default_light_style_sheet
344 345 self.syntax_style = default_light_syntax_style
345 elif colors=='dark':
346 elif colors=='linux':
346 347 self.style_sheet = default_dark_style_sheet
347 348 self.syntax_style = default_dark_syntax_style
348 elif colors=='bw':
349 elif colors=='nocolor':
349 350 self.style_sheet = default_bw_style_sheet
350 351 self.syntax_style = default_bw_syntax_style
352 else:
353 raise KeyError("No such color scheme: %s"%colors)
351 354
352 355 #---------------------------------------------------------------------------
353 356 # 'IPythonWidget' protected interface
@@ -155,11 +155,30 b' def main():'
155 155 wgroup.add_argument('--stylesheet', type=str,
156 156 help="path to a custom CSS stylesheet.")
157 157 wgroup.add_argument('--colors', type=str,
158 help="Set the color scheme (light, dark, or bw). This is guessed\
158 help="Set the color scheme (LightBG,Linux,NoColor). This is guessed\
159 159 based on the pygments style if not set.")
160 160
161 161 args = parser.parse_args()
162 162
163 # parse the colors arg down to current known labels
164 if args.colors:
165 colors=args.colors.lower()
166 if colors in ('lightbg', 'light'):
167 colors='lightbg'
168 elif colors in ('dark', 'linux'):
169 colors='linux'
170 else:
171 colors='nocolor'
172 elif args.style:
173 if args.style=='bw':
174 colors='nocolor'
175 elif styles.dark_style(args.style):
176 colors='linux'
177 else:
178 colors='lightbg'
179 else:
180 colors=None
181
163 182 # Don't let Qt or ZMQ swallow KeyboardInterupts.
164 183 import signal
165 184 signal.signal(signal.SIGINT, signal.SIG_DFL)
@@ -172,13 +191,15 b' def main():'
172 191 if not args.existing:
173 192 # if not args.ip in LOCAL_IPS+ALL_ALIAS:
174 193 # raise ValueError("Must bind a local ip, such as: %s"%LOCAL_IPS)
175
194
176 195 kwargs = dict(ip=args.ip)
177 196 if args.pure:
178 197 kwargs['ipython']=False
179 elif args.pylab:
180 kwargs['pylab']=args.pylab
181
198 else:
199 kwargs['colors']=colors
200 if args.pylab:
201 kwargs['pylab']=args.pylab
202
182 203 kernel_manager.start_kernel(**kwargs)
183 204 kernel_manager.start_channels()
184 205
@@ -197,23 +218,9 b' def main():'
197 218
198 219 # configure the style:
199 220 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
213 221 if args.style:
214 # guess whether it's a dark style:
215 222 widget.syntax_style = args.style
216 widget.style_sheet = styles.sheet_from_template(args.style, lightbg)
223 widget.style_sheet = styles.sheet_from_template(args.style, colors)
217 224 widget._syntax_style_changed()
218 225 widget._style_sheet_changed()
219 226 elif colors:
@@ -106,12 +106,12 b' def get_colors(stylename):'
106 106 fgcolor = fgcolor
107 107 )
108 108
109 def sheet_from_template(name, colors='light'):
109 def sheet_from_template(name, colors='lightbg'):
110 110 """Use one of the base templates, and set bg/fg/select colors."""
111 111 colors = colors.lower()
112 if colors=='light':
112 if colors=='lightbg':
113 113 return default_light_style_template%get_colors(name)
114 elif colors=='dark':
114 elif colors=='linux':
115 115 return default_dark_style_template%get_colors(name)
116 116 elif colors=='nocolor':
117 117 return default_bw_style_sheet
@@ -535,7 +535,7 b' class GTKKernel(Kernel):'
535 535 #-----------------------------------------------------------------------------
536 536
537 537 def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,
538 independent=False, pylab=False):
538 independent=False, pylab=False, colors=None):
539 539 """Launches a localhost kernel, binding to the specified ports.
540 540
541 541 Parameters
@@ -566,6 +566,9 b' def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,'
566 566 string is passed, matplotlib will use the specified backend. Otherwise,
567 567 matplotlib's default backend will be used.
568 568
569 colors : None or string, optional (default None)
570 If not None, specify the color scheme. One of (NoColor, LightBG, Linux)
571
569 572 Returns
570 573 -------
571 574 A tuple of form:
@@ -581,6 +584,9 b' def launch_kernel(ip=None, xrep_port=0, pub_port=0, req_port=0, hb_port=0,'
581 584 extra_arguments.append('--ip')
582 585 if isinstance(ip, basestring):
583 586 extra_arguments.append(ip)
587 if colors is not None:
588 extra_arguments.append('--colors')
589 extra_arguments.append(colors)
584 590 return base_launch_kernel('from IPython.zmq.ipkernel import main; main()',
585 591 xrep_port, pub_port, req_port, hb_port,
586 592 independent, extra_arguments)
@@ -595,6 +601,10 b' def main():'
595 601 "Pre-load matplotlib and numpy for interactive use. If GUI is not \
596 602 given, the GUI backend is matplotlib's, otherwise use one of: \
597 603 ['tk', 'gtk', 'qt', 'wx', 'inline'].")
604 parser.add_argument('--colors',
605 type=str, dest='colors',
606 help="Set the color scheme (NoColor, Linux, and LightBG).",
607 metavar='ZMQInteractiveShell.colors')
598 608 namespace = parser.parse_args()
599 609
600 610 kernel_class = Kernel
@@ -616,6 +626,8 b" given, the GUI backend is matplotlib's, otherwise use one of: \\"
616 626 if kernel_class is None:
617 627 raise ValueError('GUI is not supported: %r' % gui)
618 628 pylabtools.activate_matplotlib(backend)
629 if namespace.colors:
630 ZMQInteractiveShell.colors=namespace.colors
619 631
620 632 kernel = make_kernel(namespace, kernel_class, OutStream)
621 633
General Comments 0
You need to be logged in to leave comments. Login now