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