Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add color schemes to IPython console #916

Closed
spyder-bot opened this issue Feb 17, 2015 · 24 comments
Closed

Add color schemes to IPython console #916

spyder-bot opened this issue Feb 17, 2015 · 24 comments

Comments

@spyder-bot
Copy link
Collaborator

From [email protected] on 2012-01-22T23:45:51Z

I wonder if Spyder can provide color scheme options for the IPython windows (as well as the Console windows)... I use black background on the main editor and the object inspector. And the white background of IPython and Console looks a bit annoying... Attached is how it looks on my computer.

Attachment: spyder-color.jpg

Original issue: http://code.google.com/p/spyderlib/issues/detail?id=916

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-01-23T06:46:45Z

Hi,

It's not possible to define a color scheme for the IPython console but you can go to

Tools > Preferences > Console > Display

and look for the section called "Background color". In there deselect the option called

"Light background (white color)"

and next time you open a new console, you'll see it has a dark background with a predefined color scheme

@spyder-bot
Copy link
Collaborator Author

From [email protected] on 2012-09-19T15:10:35Z

Seconded. IPython follows the colour scheme of the separate terminal I use (Console2 on Windows), but it does not follow Spyder's colour scheme. I would not call it a defect, though, but an enhancement request.

@spyder-bot
Copy link
Collaborator Author

From [email protected] on 2012-09-20T16:20:37Z

Ipython's qtconsole uses pygments for syntax highlighting. Perhaps spyder could convert its color scheme to pygments when embedding the ipython qtconsole.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2012-09-21T09:36:45Z

Yes, this is now possible but only for IPython. We'll try to add it for 2.2.

Summary: Add color schemes for IPython plugin
Status: Accepted
Labels: Cat-IPythonConsole MS-v2.2

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-02-11T09:00:14Z

Blocking: spyderlib:1053

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-03-12T08:55:52Z

issue #1300 has been merged into this issue.

@spyder-bot
Copy link
Collaborator Author

From [email protected] on 2013-04-29T14:41:22Z

Labels: -MS-v2.2 MS-v2.3

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-07-12T18:09:37Z

Labels: -MS-v2.3 MS-v2.4

@spyder-bot
Copy link
Collaborator Author

From [email protected] on 2013-09-06T09:42:50Z

I'd be interested in this as well. Any update on the Ipython color schemes, or at least a dark backgorund? Also, looks like issue #1520 should be merged into here...
Cheers!

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2013-09-16T11:56:47Z

I have done it and contributing to spyder! Too bad it seems that google-code remove serverside cloning (Forking) so i have to attach a patch.

It will automatically try to match with current background and foreground color set in your code background.

diff -r 4f523daf4159 spyderlib/widgets/ipython.py
--- a/spyderlib/widgets/ipython.py Mon Sep 16 01:15:50 2013 -0500
+++ b/spyderlib/widgets/ipython.py Tue Sep 17 01:21:14 2013 +0630
@@ -11,8 +11,11 @@

IPython imports

try: # 1.0
from IPython.qt.console.rich_ipython_widget import RichIPythonWidget

  • from IPython.qt.console import styles
    except ImportError: # 0.13
    from IPython.frontend.qt.console.rich_ipython_widget import RichIPythonWidget
  • from IPython.frontend.qt.console import styles

Qt imports

from spyderlib.qt.QtGui import QTextEdit, QKeySequence, QShortcut
@@ -24,6 +27,34 @@
from spyderlib.utils import programs
from spyderlib.widgets.mixins import (BaseEditMixin, InspectObjectMixin,
TracebackLinksMixin)
+section = "color_schemes"
+names = CONF.get("color_schemes", "names", [])
+bg = "%s/%s" % (name, "background")
+fg = "%s/%s" % (name, "normal")
+hl = "%s/%s" % (name, "currentline")
+current_bg= CONF.get(section, bg, default=None)
+current_fg= CONF.get(section, fg, default=None)
+current_hl= CONF.get(section, hl, default=None)
+
+
+default_dark_style_template = '''

  • QPlainTextEdit, QTextEdit { background-color: %(bgcolor)s;

  •        color: %(fgcolor)s ;
    
  •        selection-background-color: %(select)s}
    
  • QFrame { border: 1px solid grey; }

  • .error { color: red; }

  • .in-prompt { color: lime; }

  • .in-prompt-number { color: lime; font-weight: bold; }

  • .out-prompt { color: red; }

  • .out-prompt-number { color: red; font-weight: bold; }

  • .inverted { background-color: %(fgcolor)s ; color:%(bgcolor)s;}
    +'''
    +custom_style_sheet = default_dark_style_template%dict(

  •            bgcolor=current_source_bg, fgcolor=current_fg, select=current_hl)
    

    +custom_syntax_style = 'monokai'
    +
    +
    +

    class IPythonControlWidget(TracebackLinksMixin, InspectObjectMixin, QTextEdit,
    @@ -143,6 +174,32 @@

     \# To restart the Spyder kernel in case it dies
     self.custom_restart = True
    
  •    self.set_default_style()
    
  • def set_default_style(self, colors='custom'):

  •    """ Sets the widget style to the class defaults.
    
  •    Parameters:
    

  •    colors : str, optional (default lightbg)
    
  •        Whether to use the default IPython light background or dark
    
  •        background or B&W style.
    
  •    """
    
  •    colors = colors.lower()
    
  •    if colors=='lightbg':
    
  •        self.style_sheet = styles.default_light_style_sheet
    
  •        self.syntax_style = styles.default_light_syntax_style
    
  •    elif colors=='linux':
    
  •        self.style_sheet = styles.default_dark_style_sheet
    
  •        self.syntax_style = styles.default_dark_syntax_style
    
  •    elif colors=='nocolor':
    
  •        self.style_sheet = styles.default_bw_style_sheet
    
  •        self.syntax_style = styles.default_bw_syntax_style
    
  •    elif colors=='custom':
    
  •       self.style_sheet = custom_style_sheet
    
  •       self.syntax_style = custom_syntax_style
    
  •    else:
    
  •        raise KeyError("No such color scheme: %s"%colors)
    

    #---- Public API ----------------------------------------------------------
    def set_ipyclient(self, ipyclient):

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2013-09-16T12:01:43Z

patch attached , pasting here looks ugly.
Spyder guys , don't you want to move this awesome project from shitty google-code hosting? Google no longer cares about googlecode anymore , time to move to Bitbucket I know you guys love mercurial like the rest of python devs. Github is awesome but we love HG!

Attachment: custom_ipython_sytlesheet.patch

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2013-09-22T10:32:59Z

Thanks a lot phyo for the patch! You are proposing something much more ambitious just using a dark background, it's meant to use our own color schemes. That requires more work and that's why I'm leaving it for 2.3.

I didn't notice GoogleCode eliminated the option to do server-side clones. It's really time to move to BitBucket, you're absolutely right! I'll try to do it in the next couple of weeks.

Labels: -MS-v2.4 MS-v2.3

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2013-09-23T07:00:58Z

You welcome ccordoba12!

You are proposing something much more ambitious just using a dark background, it's meant to use our own color schemes. That requires more work and that's why I'm leaving it for 2.3.

Yep , my patch does it. It reads the config of currently active color schema and applies it to ipython directly.

I didn't notice GoogleCode eliminated the option to do server-side clones.
Yeah man , i was looking for any kind of announcement of the removal but i found none. Damn , what happened to our respected tech giant..

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2013-10-03T11:35:43Z

I am working onwards automatic coloring of ipython , including ipython's syntax.
I am stuck how to apply CSS scheme for ipython console syntax coloring, attached is the code.

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2013-10-03T11:38:43Z

Forget to attach code:
I doing it in a separated module.

Attachment: ipython_styles.py

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2014-01-23T09:57:25Z

Working now , Pull Request submitted for it @ Bitbucket.

@spyder-bot
Copy link
Collaborator Author

From ccordoba12 on 2014-05-04T14:59:12Z

Hope to this finished someday :)

Labels: -MS-v2.3 MS-v2.4

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2014-05-05T00:53:20Z

Sorry , I am in a rush to complete a project by end of this month .

@spyder-bot
Copy link
Collaborator Author

From phyo.arkarlwin on 2014-06-24T16:46:11Z

Pull request submitted.

@goanpeca
Copy link
Member

@v3ss0n?

@ccordoba12
Copy link
Member

He implemented this feature on Bitbucket, but his pull request was a bit messy. We'd need to port it here.

I pretend to do that for beta2.

@goanpeca
Copy link
Member

👍

@goanpeca
Copy link
Member

What is the plan?

To keep the global Coloring Scheme and for all Consoles (ipython included) add the option to select the coloring scheme with a checkbox, to use the same as the editor? (to avoid repetition?)

@goanpeca
Copy link
Member

Just adding comments to include the bitbucket code

https://bitbucket.org/spyder-ide/spyderlib/pull-requests/19/finally-working-adaptable-ipython-color/diff

@ccordoba12 is this something that cannot be done until you finish your kernel and stuff work, or is this something that can be done in parallel?

@ccordoba12 ccordoba12 modified the milestones: v3.0, v3.0beta4 Jan 27, 2016
@ccordoba12 ccordoba12 modified the milestones: v3.0beta4, v3.1 Apr 25, 2016
@ccordoba12 ccordoba12 modified the milestones: v3.1, v3.2 Oct 1, 2016
@ccordoba12 ccordoba12 changed the title Add color schemes for IPython plugin Add color schemes for IPython console Oct 1, 2016
@ccordoba12 ccordoba12 changed the title Add color schemes for IPython console Add color schemes to IPython console Oct 1, 2016
@ccordoba12 ccordoba12 modified the milestones: v3.2, v3.1 Jan 5, 2017
@ccordoba12 ccordoba12 modified the milestones: v3.2, v3.3 Feb 14, 2017
@dalthviz dalthviz modified the milestones: v3.2, v4.0beta2 Jun 2, 2017
@dalthviz dalthviz self-assigned this Jun 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants