Beispiel #1
0
def create_qss_style(color_scheme):
    """Returns a QSS stylesheet with Spyder color scheme settings.

    The stylesheet can contain classes for:
        Qt: QPlainTextEdit, QFrame, QWidget, etc
       Pygments: .c, .k, .o, etc. (see PygmentsHighlighter)
        IPython: .error, .in-prompt, .out-prompt, etc
    """

    def give_font_weight(is_bold):
        if is_bold:
            return 'bold'
        else:
            return 'normal'

    def give_font_style(is_italic):
        if is_italic:
            return 'italic'
        else:
            return 'normal'

    color_scheme = get_color_scheme(color_scheme)
    fon_c, fon_fw, fon_fs = color_scheme['normal']
    font_color =  fon_c
    if dark_color(font_color):
        in_prompt_color = 'navy'
        out_prompt_color = 'darkred'
    else:
        in_prompt_color = 'lime'
        out_prompt_color = 'red'
    background_color = color_scheme['background']
    error_color = 'red'
    in_prompt_number_font_weight = 'bold'
    out_prompt_number_font_weight = 'bold'
    inverted_background_color = font_color
    inverted_font_color = background_color

    sheet = """QPlainTextEdit, QTextEdit, ControlWidget {{
                                          color: {} ;
                                          background-color: {};
                                         }}
              .error {{ color: {}; }}
              .in-prompt {{ color: {}; }}
              .in-prompt-number {{ color: {}; font-weight: {}; }}
              .out-prompt {{ color: {}; }}
              .out-prompt-number {{ color: {}; font-weight: {}; }}
              .inverted {{ color: {}; background-color: {}; }}
              """

    sheet_formatted = sheet.format(font_color, background_color,
                                   error_color,
                                   in_prompt_color, in_prompt_color,
                                   in_prompt_number_font_weight,
                                   out_prompt_color, out_prompt_color,
                                   out_prompt_number_font_weight,
                                   inverted_background_color,
                                   inverted_font_color)

    return (sheet_formatted, dark_color(font_color))
Beispiel #2
0
def create_qss_style(color_scheme):
    """Returns a QSS stylesheet with Spyder color scheme settings.

    The stylesheet can contain classes for:
        Qt: QPlainTextEdit, QFrame, QWidget, etc
       Pygments: .c, .k, .o, etc. (see PygmentsHighlighter)
        IPython: .error, .in-prompt, .out-prompt, etc
    """
    def give_font_weight(is_bold):
        if is_bold:
            return 'bold'
        else:
            return 'normal'

    def give_font_style(is_italic):
        if is_italic:
            return 'italic'
        else:
            return 'normal'

    color_scheme = get_color_scheme(color_scheme)
    fon_c, fon_fw, fon_fs = color_scheme['normal']
    font_color = fon_c
    if dark_color(font_color):
        in_prompt_color = 'navy'
        out_prompt_color = 'darkred'
    else:
        in_prompt_color = 'lime'
        out_prompt_color = 'red'
    background_color = color_scheme['background']
    selection_background_color = '#ccc'
    error_color = 'red'
    in_prompt_number_font_weight = 'bold'
    out_prompt_number_font_weight = 'bold'
    inverted_background_color = font_color
    inverted_font_color = background_color

    sheet = """QPlainTextEdit, QTextEdit, ControlWidget {{
                                          color: {} ;
                                          background-color: {};
                                          selection-background-color: {}
                                         }}
              .error {{ color: {}; }}
              .in-prompt {{ color: {}; }}
              .in-prompt-number {{ color: {}; font-weight: {}; }}
              .out-prompt {{ color: {}; }}
              .out-prompt-number {{ color: {}; font-weight: {}; }}
              .inverted {{ color: {}; background-color: {}; }}
              """

    sheet_formatted = sheet.format(
        font_color, background_color, selection_background_color, error_color,
        in_prompt_color, in_prompt_color, in_prompt_number_font_weight,
        out_prompt_color, out_prompt_color, out_prompt_number_font_weight,
        inverted_background_color, inverted_font_color)

    return (sheet_formatted, dark_color(font_color))
Beispiel #3
0
    def set_color_scheme(self, foreground_color, background_color):
        """Set color scheme (foreground and background)."""
        if dark_color(foreground_color):
            self.default_foreground_color = 30
        else:
            self.default_foreground_color = 37

        if dark_color(background_color):
            self.default_background_color = 47
        else:
            self.default_background_color = 40
Beispiel #4
0
    def set_color_scheme(self, foreground_color, background_color):
        """Set color scheme (foreground and background)."""
        if dark_color(foreground_color):
            self.default_foreground_color = 30
        else:
            self.default_foreground_color = 37

        if dark_color(background_color):
            self.default_background_color = 47
        else:
            self.default_background_color = 40
Beispiel #5
0
    def is_dark_interface(self):
        """
        Check if our interface is dark independently from our config
        system.

        We need to do this because when applying settings we can't
        detect correctly the current theme.
        """
        return dark_color(QStylePalette.COLOR_BACKGROUND_1)
Beispiel #6
0
def is_dark_font_color(color_scheme):
    """Check if the font color used in the color scheme is dark."""
    color_scheme = get_color_scheme(color_scheme)
    font_color, fon_fw, fon_fs = color_scheme['normal']
    return dark_color(font_color)
Beispiel #7
0
def is_dark_font_color(color_scheme):
    """Check if the font color used in the color scheme is dark."""
    color_scheme = get_color_scheme(color_scheme)
    font_color, fon_fw, fon_fs = color_scheme['normal']
    return dark_color(font_color)
Beispiel #8
0
 def test_dark_color(self):
     self.assertTrue(dark_color('#000000'))  # black
     self.assertTrue(not dark_color('#ffff66'))  # bright yellow
     self.assertTrue(dark_color('#80807f'))  # < 50% gray
     self.assertTrue(not dark_color('#808080'))  # = 50% gray
Beispiel #9
0
 def test_dark_color(self):
     self.assertTrue(dark_color('#000000'))  # black
     self.assertTrue(not dark_color('#ffff66'))  # bright yellow
     self.assertTrue(dark_color('#80807f'))  # < 50% gray
     self.assertTrue(not dark_color('#808080'))  # = 50% gray