Hello Spyderlib devs,

Here is my current work on adaptable ipython schema. Currently it is trying 
to mimic ipython's background scheme + syntax higlighting to that of 
Editor's schema .

It works for background and it should work if i know how to apply the sytle 
sheep without registering at pygments (as it need to do dynamically and not 
intrusively place inside pyflake folder).
Attached is the current patch , with working 
background,foreground,highlight  schema . 

I need your help how to apply syntax schema , it looks like this :


from pygments.style import Style
> from pygments.token import Keyword, Name, Comment, String, Error, Text, \
>      Number, Operator, Generic, Whitespace, Punctuation, Other, Literal
> from spyderlib.config import CONF
> from pygments.formatters import html
> section = "color_schemes"
> name = CONF.get("editor", "color_scheme_name")
> print "Color scheme name :",name
> bg = CONF.get(section,"%s/%s" % (name, "background"))
> fg = CONF.get(section,"%s/%s" % (name, "normal"))[0]
> hl = CONF.get(section,"%s/%s" % (name, "currentline"))
> built_in = CONF.get(section,"%s/%s" % (name, "builtin"))[0]
> funcs = CONF.get(section,"%s/%s" % (name, "definition"))[0]
> comm = CONF.get(section,"%s/%s" % (name, "comment"))[0]
> strs = CONF.get(section,"%s/%s" % (name, "string"))[0]
> num = CONF.get(section,"%s/%s" % (name, "number"))[0]
> kw = CONF.get(section,"%s/%s" % (name, "keyword"))[0]
> instance = CONF.get(section,"%s/%s" % (name, "instance"))[0]
> op = CONF.get(section,"%s/%s" % (name, "matched_p"))
> err = CONF.get(section,"%s/%s" % (name, "unmatched_p"))
>
> custom_style_sheet = default_custom_template%dict(
>                 bgcolor=bg, fgcolor=fg, select=hl)
> class SpyderStyle(Style):
>     """
>     This style mimics the Monokai color scheme.
>     """
>     background_color = bg
>     highlight_color = hl
>     styles = {
>         # No corresponding class for the following:
>         Text:                      fg, # class:  ''
>         Whitespace:                "",        # class: 'w'
>         Error:                     "#960050 bg:#1e0010", # class: 'err'
>         Other:                     "",        # class 'x'
>         Comment:                   comm, # class: 'c'
>         Comment.Multiline:         "",        # class: 'cm'
>         Comment.Preproc:           "",        # class: 'cp'
>         Comment.Single:            "",        # class: 'c1'
>         Comment.Special:           "",        # class: 'cs'
>         Keyword:                   kw, # class: 'k'
>         Keyword.Constant:          "",        # class: 'kc'
>         Keyword.Declaration:       "",        # class: 'kd'
>         Keyword.Namespace:         kw, # class: 'kn'
>         Keyword.Pseudo:            "",        # class: 'kp'
>         Keyword.Reserved:          "",        # class: 'kr'
>         Keyword.Type:              "",        # class: 'kt'
>         Operator:                  fg, # class: 'o'
>         Operator.Word:             "",        # class: 'ow' - like keywords
>         Punctuation:               instance, # class: 'p'
>         Name:                      fg, # class: 'n'
>         Name.Attribute:            funcs, # class: 'na' - to be revised
>        #--------snipped due to gmail's char limit-------------
>     }



I tried to apply SpyderStyle instances directly into ipython style but it 
can't work. Inspection of RichIptyhonWidget do not allow such.

Any idea how to apply it? just 1 inch away to get it done.

Thanks.

Phyo.

-- 
You received this message because you are subscribed to the Google Groups 
"spyder" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/spyderlib.
For more options, visit https://groups.google.com/groups/opt_out.
diff -r 9f23743dac6a spyderlib/plugins/ipythonconsole.py
--- a/spyderlib/plugins/ipythonconsole.py	Thu Oct 17 22:25:12 2013 +0630
+++ b/spyderlib/plugins/ipythonconsole.py	Thu Oct 17 22:46:56 2013 +0630
@@ -106,12 +106,9 @@
                                               'light_color', True)
         dark_radio = self.create_radiobutton(_("Dark background"),
                                              'dark_color', False)
-        adapt_radio = self.create_radiobutton(_("Adapt Scheme"),
-                                             'adapt_color', False)
         bg_layout = QVBoxLayout()
         bg_layout.addWidget(light_radio)
         bg_layout.addWidget(dark_radio)
-        bg_layout.addWidget(adapt_radio)
         bg_group.setLayout(bg_layout)
 
         # Source Code Group
diff -r 9f23743dac6a spyderlib/widgets/ipython.py
--- a/spyderlib/widgets/ipython.py	Thu Oct 17 22:25:12 2013 +0630
+++ b/spyderlib/widgets/ipython.py	Thu Oct 17 22:46:56 2013 +0630
@@ -18,65 +18,14 @@
 from spyderlib.qt.QtGui import (QTextEdit, QKeySequence, QShortcut, QWidget,
                                 QMenu, QHBoxLayout, QToolButton, QVBoxLayout,
                                 QMessageBox)
-from spyderlib.qt.QtCore import SIGNAL, Qt, QUrl
+from spyderlib.qt.QtCore import SIGNAL, Qt
 from spyderlib.utils.qthelpers import restore_keyevent
 
 # 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
-
-# Local imports
-from spyderlib.baseconfig import (get_conf_path, get_image_path,
-                                  get_module_source_path, _)
-from spyderlib.config import CONF
-from spyderlib.utils.qthelpers import (get_std_icon, create_toolbutton,
-                                       add_actions, create_action, get_icon)
-from spyderlib.utils import programs
-from spyderlib.widgets.mixins import (BaseEditMixin, InspectObjectMixin,
-                                      SaveHistoryMixin, TracebackLinksMixin)
-from spyderlib.widgets.browser import WebView
-
-#-----------------------------------------------------------------------------
-# Templates
-#-----------------------------------------------------------------------------
-# Using the same css file from the Object Inspector (because we are
-# sharing the same rules)
-OI_UTILS_PATH = get_module_source_path('spyderlib', osp.join('utils',
-                                                             'inspector'))
-CSS_PATH = osp.join(OI_UTILS_PATH, 'static', 'css')
-
-BLANK = \
-r"""<html>
-<head>
-  <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
-</head>
-</html>
-  <link rel="stylesheet" href="file:///${css_path}/default.css" type="text/css"/>
-</head>
-<body>
-  <div class="loading">
-    <img src="file:///${loading_img}"/>&nbsp;&nbsp;${message}
-  </div>
-</body>
-</html>
-"""
-
-KERNEL_ERROR = \
-r"""<html>
-<head>
-    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-    <link rel="stylesheet" href="file:///${css_path}/default.css" type="text/css"/>
-</head>
-<body>
-  <div id="warning">${message}</div>
-  <div class="metadata"><p><tt>${error}</tt></p></div>
-</body>
-</html>
-"""
 
 # Local imports
 from spyderlib.baseconfig import (get_conf_path, get_image_path,
@@ -132,39 +81,6 @@
 </body>
 </html>
 """
-import traceback
-try:
-    #section = "color_schemes"
-    #name = CONF.get("editor", "color_scheme_name", [])
-    #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)
-    ##QPlainTextEdit, QTextEdit { background-color: %(bgcolor)s;
-
-
-    #default_custom_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_custom_template%dict(
-                    #bgcolor=current_bg, fgcolor=current_fg, select=current_hl)
-    from spyderlib.widgets.ipython_styles import custom_style_sheet
-except:
-    print traceback.format_exc()
-    custom_style_sheet = styles.default_dark_style_sheet
-custom_syntax_style = 'monokai'
 
 #-----------------------------------------------------------------------------
 # Control widgets
@@ -289,30 +205,7 @@
         
         # To restart the Spyder kernel in case it dies
         self.custom_restart = True
-    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 = 'monokai'
-        else:
-            raise KeyError("No such color scheme: %s"%colors)
     #---- Public API ----------------------------------------------------------
     def set_ipyclient(self, ipyclient):
         """Bind this IPython widget to an IPython client widget
@@ -373,9 +266,6 @@
     def set_background_color(self):
         lightbg_o = CONF.get('ipython_console', 'light_color', True)
         if not lightbg_o:
-            if CONF.get('ipython_console', 'adapt_color', True):
-                self.set_default_style(colors='custom')
-            else:
                 self.set_default_style(colors='linux')
 
     #---- IPython private methods ---------------------------------------------
@@ -637,39 +527,6 @@
             self.namespacebrowser.refresh_table()
     
     #------ Private API -------------------------------------------------------
-    def _show_rich_help(self, text):
-        """Use our Object Inspector to show IPython help texts in rich mode"""
-        from spyderlib.utils.inspector import sphinxify as spx
-        
-        context = spx.generate_context(name='', argspec='', note='',
-                                       math=False)
-        html_text = spx.sphinxify(text, context)
-        inspector = self.get_control().inspector
-        inspector.switch_to_rich_text()
-        inspector.set_rich_text_html(html_text,
-                                     QUrl.fromLocalFile(spx.CSS_PATH))
-    
-    def _show_plain_help(self, text):
-        """Use our Object Inspector to show IPython help texts in plain mode"""
-        inspector = self.get_control().inspector
-        inspector.switch_to_plain_text()
-        inspector.set_plain_text(text, is_code=False)
-    
-    def _show_intro(self):
-        """Show intro to IPython help"""
-        from IPython.core.usage import interactive_usage
-        self._show_rich_help(interactive_usage)
-    
-    def _show_guiref(self):
-        """Show qtconsole help"""
-        from IPython.core.usage import gui_reference
-        self._show_rich_help(gui_reference)
-    
-    def _show_quickref(self):
-        """Show IPython Cheat Sheet"""
-        from IPython.core.usage import quick_reference
-        self._show_plain_help(quick_reference)
-    
     def _create_loading_page(self):
         loading_template = Template(LOADING)
         loading_img = get_image_path('loading.gif')
diff -r 9f23743dac6a spyderlib/widgets/ipython_styles.py
--- a/spyderlib/widgets/ipython_styles.py	Thu Oct 17 22:25:12 2013 +0630
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,165 +0,0 @@
-from pygments.style import Style
-from pygments.token import Keyword, Name, Comment, String, Error, Text, \
-     Number, Operator, Generic, Whitespace, Punctuation, Other, Literal
-from spyderlib.config import CONF
-from pygments.formatters import html
-#section = "color_schemes"
-#name = CONF.get("editor", "color_scheme_name", [])
-#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)
-##QPlainTextEdit, QTextEdit { background-color: %(bgcolor)s;
-
-
-#default_custom_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_custom_template%dict(
-                #bgcolor=current_bg, fgcolor=current_fg, select=current_hl)
-#custom_syntax_style = 'monokai'
-
-
-section = "color_schemes"
-name = CONF.get("editor", "color_scheme_name")
-print "Color scheme name :",name
-bg = CONF.get(section,"%s/%s" % (name, "background"))
-fg = CONF.get(section,"%s/%s" % (name, "normal"))[0]
-hl = CONF.get(section,"%s/%s" % (name, "currentline"))
-built_in = CONF.get(section,"%s/%s" % (name, "builtin"))[0]
-funcs = CONF.get(section,"%s/%s" % (name, "definition"))[0]
-comm = CONF.get(section,"%s/%s" % (name, "comment"))[0]
-strs = CONF.get(section,"%s/%s" % (name, "string"))[0]
-num = CONF.get(section,"%s/%s" % (name, "number"))[0]
-kw = CONF.get(section,"%s/%s" % (name, "keyword"))[0]
-instance = CONF.get(section,"%s/%s" % (name, "instance"))[0]
-op = CONF.get(section,"%s/%s" % (name, "matched_p"))
-err = CONF.get(section,"%s/%s" % (name, "unmatched_p"))
-
-#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_custom_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_custom_template%dict(
-                bgcolor=bg, fgcolor=fg, select=hl)
-
-class SpyderStyle(Style):
-    """
-    This style mimics the Monokai color scheme.
-    """
-
-    background_color = bg
-    highlight_color = hl
-
-    styles = {
-        # No corresponding class for the following:
-        Text:                      fg, # class:  ''
-        Whitespace:                "",        # class: 'w'
-        Error:                     "#960050 bg:#1e0010", # class: 'err'
-        Other:                     "",        # class 'x'
-
-        Comment:                   comm, # class: 'c'
-        Comment.Multiline:         "",        # class: 'cm'
-        Comment.Preproc:           "",        # class: 'cp'
-        Comment.Single:            "",        # class: 'c1'
-        Comment.Special:           "",        # class: 'cs'
-
-        Keyword:                   kw, # class: 'k'
-        Keyword.Constant:          "",        # class: 'kc'
-        Keyword.Declaration:       "",        # class: 'kd'
-        Keyword.Namespace:         kw, # class: 'kn'
-        Keyword.Pseudo:            "",        # class: 'kp'
-        Keyword.Reserved:          "",        # class: 'kr'
-        Keyword.Type:              "",        # class: 'kt'
-
-        Operator:                  fg, # class: 'o'
-        Operator.Word:             "",        # class: 'ow' - like keywords
-
-        Punctuation:               instance, # class: 'p'
-
-        Name:                      fg, # class: 'n'
-        Name.Attribute:            funcs, # class: 'na' - to be revised
-        Name.Builtin:              "",        # class: 'nb'
-        Name.Builtin.Pseudo:       "",        # class: 'bp'
-        Name.Class:                funcs, # class: 'nc' - to be revised
-        Name.Constant:             fg, # class: 'no' - to be revised
-        Name.Decorator:            funcs, # class: 'nd' - to be revised
-        Name.Entity:               "",        # class: 'ni'
-        Name.Exception:            funcs, # class: 'ne'
-        Name.Function:             funcs, # class: 'nf'
-        Name.Property:             "",        # class: 'py'
-        Name.Label:                "",        # class: 'nl'
-        Name.Namespace:            "",        # class: 'nn' - to be revised
-        Name.Other:                fg, # class: 'nx'
-        Name.Tag:                  kw, # class: 'nt' - like a keyword
-        Name.Variable:             "",        # class: 'nv' - to be revised
-        Name.Variable.Class:       "",        # class: 'vc' - to be revised
-        Name.Variable.Global:      "",        # class: 'vg' - to be revised
-        Name.Variable.Instance:    "",        # class: 'vi' - to be revised
-
-        Number:                    num, # class: 'm'
-        Number.Float:              "",        # class: 'mf'
-        Number.Hex:                "",        # class: 'mh'
-        Number.Integer:            "",        # class: 'mi'
-        Number.Integer.Long:       "",        # class: 'il'
-        Number.Oct:                "",        # class: 'mo'
-
-        Literal:                   num, # class: 'l'
-        Literal.Date:              num, # class: 'ld'
-
-        String:                    strs, # class: 's'
-        String.Backtick:           "",        # class: 'sb'
-        String.Char:               "",        # class: 'sc'
-        String.Doc:                "",        # class: 'sd' - like a comment
-        String.Double:             "",        # class: 's2'
-        String.Escape:             num, # class: 'se'
-        String.Heredoc:            "",        # class: 'sh'
-        String.Interpol:           "",        # class: 'si'
-        String.Other:              "",        # class: 'sx'
-        String.Regex:              "",        # class: 'sr'
-        String.Single:             "",        # class: 's1'
-        String.Symbol:             "",        # class: 'ss'
-
-        Generic:                   "",        # class: 'g'
-        Generic.Deleted:           "",        # class: 'gd',
-        Generic.Emph:              "italic",  # class: 'ge'
-        Generic.Error:             "",        # class: 'gr'
-        Generic.Heading:           "",        # class: 'gh'
-        Generic.Inserted:          "",        # class: 'gi'
-        Generic.Output:            "",        # class: 'go'
-        Generic.Prompt:            "",        # class: 'gp'
-        Generic.Strong:            "bold",    # class: 'gs'
-        Generic.Subheading:        "",        # class: 'gu'
-        Generic.Traceback:         "",        # class: 'gt'
-    }
-
-
-custom_style_sheet = custom_style_sheet
-custom_syntax_style = html.HtmlFormatter(style=SpyderStyle).get_style_defs()
\ No newline at end of file

Reply via email to