Skip to content

Commit

Permalink
Issue 6235: Preserve color scheme on kernel restart
Browse files Browse the repository at this point in the history
  • Loading branch information
csabella committed Jan 25, 2018
1 parent 3d4b72f commit 8d8f615
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
15 changes: 10 additions & 5 deletions spyder/widgets/ipythonconsole/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,7 @@ def configure_shellwidget(self, give_focus=True):
self.shellwidget.executed.connect(self.shellwidget.get_cwd)

# To apply style
if not create_qss_style(self.shellwidget.syntax_style)[1]:
self.shellwidget.silent_execute("%colors linux")
else:
self.shellwidget.silent_execute("%colors lightbg")
self.set_console_scheme(self.shellwidget)

# To hide the loading page
self.shellwidget.sig_prompt_ready.connect(self._hide_loading_page)
Expand Down Expand Up @@ -436,6 +433,10 @@ def set_color_scheme(self, color_scheme):
"""Set IPython color scheme."""
self.shellwidget.set_color_scheme(color_scheme)

def set_console_scheme(self, sw):
"""Set scheme for %colors."""
sw.set_console_scheme(create_qss_style(sw.syntax_style)[1])

def shutdown(self):
"""Shutdown kernel"""
if self.get_kernel() is not None and not self.slave:
Expand All @@ -450,7 +451,7 @@ def interrupt_kernel(self):
@Slot()
def restart_kernel(self):
"""
Restart the associanted kernel
Restart the associated kernel.
Took this code from the qtconsole project
Licensed under the BSD license
Expand Down Expand Up @@ -478,6 +479,10 @@ def restart_kernel(self):
sw.reset(clear=True)
sw._append_html(_("<br>Restarting kernel...\n<hr><br>"),
before_prompt=False)
# For issue 6235. IPython was changing the setting of
# %colors on windows by assuming it was using a dark
# background. This corrects it based on the scheme.
self.set_console_scheme(sw)
else:
sw._append_plain_text(
_('Cannot restart a kernel not started by Spyder\n'),
Expand Down
17 changes: 13 additions & 4 deletions spyder/widgets/ipythonconsole/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,19 @@ def set_color_scheme(self, color_scheme):
self._style_sheet_changed()
self._syntax_style_changed()
self.reset(clear=True)
if not dark_color:
self.silent_execute("%colors linux")
else:
self.silent_execute("%colors lightbg")
self.set_console_scheme(dark_color)

def set_console_scheme(self, dark=True):
"""Apply highlight style to console.
lightbg is dark coloring for light backgrounds and linux is light
coloring for dark backgrounds.
Args:
dark: Boolean for console scheme to use.
"""
scheme = 'lightbg' if dark else 'linux'
self.silent_execute('%colors {}'.format(scheme))

def get_syspath(self):
"""Ask the kernel for sys.path contents."""
Expand Down

0 comments on commit 8d8f615

Please sign in to comment.