From 8d8f615d1de37c16e60ef59e12e7a28c6430e3e1 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Sat, 20 Jan 2018 12:50:16 -0500 Subject: [PATCH 1/3] Issue 6235: Preserve color scheme on kernel restart --- spyder/widgets/ipythonconsole/client.py | 15 ++++++++++----- spyder/widgets/ipythonconsole/shell.py | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/spyder/widgets/ipythonconsole/client.py b/spyder/widgets/ipythonconsole/client.py index 8f7cca500c1..64fb7ea860e 100644 --- a/spyder/widgets/ipythonconsole/client.py +++ b/spyder/widgets/ipythonconsole/client.py @@ -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) @@ -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: @@ -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 @@ -478,6 +479,10 @@ def restart_kernel(self): sw.reset(clear=True) sw._append_html(_("
Restarting kernel...\n

"), 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'), diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index 31bfe060310..813fac77b66 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -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.""" From 75b94a8a8a5fe6988a8cb5ee2dd9cce684bad813 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Wed, 24 Jan 2018 15:33:24 -0500 Subject: [PATCH 2/3] Use existing set_color_scheme --- spyder/widgets/ipythonconsole/client.py | 13 ++++--------- spyder/widgets/ipythonconsole/shell.py | 17 ++++------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/spyder/widgets/ipythonconsole/client.py b/spyder/widgets/ipythonconsole/client.py index 64fb7ea860e..0738a56d866 100644 --- a/spyder/widgets/ipythonconsole/client.py +++ b/spyder/widgets/ipythonconsole/client.py @@ -232,7 +232,7 @@ def configure_shellwidget(self, give_focus=True): self.shellwidget.executed.connect(self.shellwidget.get_cwd) # To apply style - self.set_console_scheme(self.shellwidget) + self.set_color_scheme(self.shellwidget.syntax_style) # To hide the loading page self.shellwidget.sig_prompt_ready.connect(self._hide_loading_page) @@ -433,10 +433,6 @@ 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: @@ -476,13 +472,12 @@ def restart_kernel(self): before_prompt=True ) else: - sw.reset(clear=True) - sw._append_html(_("
Restarting kernel...\n

"), - 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) + self.set_color_scheme(sw.syntax_style) + sw._append_html(_("
Restarting kernel...\n

"), + before_prompt=False) else: sw._append_plain_text( _('Cannot restart a kernel not started by Spyder\n'), diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index 813fac77b66..31bfe060310 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -141,19 +141,10 @@ def set_color_scheme(self, color_scheme): self._style_sheet_changed() self._syntax_style_changed() self.reset(clear=True) - 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)) + if not dark_color: + self.silent_execute("%colors linux") + else: + self.silent_execute("%colors lightbg") def get_syspath(self): """Ask the kernel for sys.path contents.""" From 416455aaf36ba7e667a7c4a38e8cced537abd1e6 Mon Sep 17 00:00:00 2001 From: Cheryl Sabella Date: Fri, 26 Jan 2018 13:33:58 -0500 Subject: [PATCH 3/3] Fix issue with dedicated consoles --- spyder/widgets/ipythonconsole/client.py | 6 +++--- spyder/widgets/ipythonconsole/shell.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/spyder/widgets/ipythonconsole/client.py b/spyder/widgets/ipythonconsole/client.py index 0738a56d866..6365de3d66a 100644 --- a/spyder/widgets/ipythonconsole/client.py +++ b/spyder/widgets/ipythonconsole/client.py @@ -232,7 +232,7 @@ def configure_shellwidget(self, give_focus=True): self.shellwidget.executed.connect(self.shellwidget.get_cwd) # To apply style - self.set_color_scheme(self.shellwidget.syntax_style) + self.set_color_scheme(self.shellwidget.syntax_style, reset=False) # To hide the loading page self.shellwidget.sig_prompt_ready.connect(self._hide_loading_page) @@ -429,9 +429,9 @@ def set_infowidget_font(self): font = get_font(option='rich_font') self.infowidget.set_font(font) - def set_color_scheme(self, color_scheme): + def set_color_scheme(self, color_scheme, reset=True): """Set IPython color scheme.""" - self.shellwidget.set_color_scheme(color_scheme) + self.shellwidget.set_color_scheme(color_scheme, reset) def shutdown(self): """Shutdown kernel""" diff --git a/spyder/widgets/ipythonconsole/shell.py b/spyder/widgets/ipythonconsole/shell.py index 31bfe060310..43e748bb0ff 100644 --- a/spyder/widgets/ipythonconsole/shell.py +++ b/spyder/widgets/ipythonconsole/shell.py @@ -133,14 +133,15 @@ def set_bracket_matcher_color_scheme(self, color_scheme): mpcolor = bsh.get_matched_p_color() self._bracket_matcher.format.setBackground(mpcolor) - def set_color_scheme(self, color_scheme): + def set_color_scheme(self, color_scheme, reset=True): """Set color scheme of the shell.""" self.set_bracket_matcher_color_scheme(color_scheme) self.style_sheet, dark_color = create_qss_style(color_scheme) self.syntax_style = color_scheme self._style_sheet_changed() self._syntax_style_changed() - self.reset(clear=True) + if reset: + self.reset(clear=True) if not dark_color: self.silent_execute("%colors linux") else: