Esempio n. 1
0
def clean(
    frame_background: str,
    text_background: str,
    normal_detail: str,
    high_detail: str,
    low_detail: str,
    normal_foreground: str,
    high_foreground: str,
    low_foreground: str,
    custom_menubar: Optional[
        int
    ] = None,  # NB! Should be 1 or 0, not True or False (Tk would convert False to "False")
) -> UiThemeSettings:

    # https://wiki.tcl.tk/37973 (Changing colors)
    # https://github.com/tcltk/tk/blob/master/library/ttk/clamTheme.tcl
    # https://github.com/tcltk/tk/blob/master/generic/ttk/ttkClamTheme.c

    return {
        ".": {
            "configure": {
                "foreground": normal_foreground,
                "background": frame_background,
                "lightcolor": frame_background,
                "darkcolor": frame_background,
                "bordercolor": frame_background,
                "selectbackground": high_detail,
                "selectforeground": high_foreground,
            },
            "map": {
                "foreground": [
                    ("disabled", low_foreground),
                    ("active", high_foreground),
                ],
                "background": [("disabled", frame_background), ("active", high_detail)],
                "selectbackground": [("!focus", low_detail)],
                "selectforeground": [("!focus", normal_foreground)],
            },
        },
        "TNotebook": {
            # https://github.com/tcltk/tk/blob/master/generic/ttk/ttkNotebook.c
            "configure": {
                "bordercolor": normal_detail,
                "tabmargins": [scale(1), 0, 0, 0],  # Margins around tab row
            }
        },
        "ButtonNotebook.TNotebook": {"configure": {"bordercolor": frame_background}},
        "AutomaticNotebook.TNotebook": {"configure": {"bordercolor": frame_background}},
        "TNotebook.Tab": {
            "configure": {"background": frame_background, "bordercolor": normal_detail},
            "map": {
                "background": [
                    ("selected", normal_detail),
                    ("!selected", "!active", frame_background),
                    ("active", "!selected", high_detail),
                ],
                "bordercolor": [
                    ("selected", frame_background),
                    ("!selected", normal_detail),
                ],
                "lightcolor": [
                    ("selected", normal_detail),
                    ("!selected", frame_background),
                ],
            },
        },
        "Treeview": {
            "configure": {
                "background": text_background,
                "borderwidth": 0,
                "relief": "flat",
            },
            "map": {
                "background": [
                    ("selected", "focus", high_detail),
                    ("selected", "!focus", low_detail),
                ],
                "foreground": [
                    ("selected", "focus", high_foreground),
                    ("selected", "!focus", normal_foreground),
                ],
            },
        },
        "Treeview.Heading": {
            # https://stackoverflow.com/questions/32051780/how-to-edit-the-style-of-a-heading-in-treeview-python-ttk
            "configure": {
                "background": normal_detail,
                "lightcolor": normal_detail,
                "borderwidth": 0,
            },
            "map": {
                "background": [("!active", normal_detail), ("active", normal_detail)]
            },
        },
        "TEntry": {
            "configure": {
                "fieldbackground": text_background,
                "lightcolor": normal_detail,
                "insertcolor": normal_foreground,
            },
            "map": {
                "background": [("readonly", text_background)],
                "bordercolor": [],
                "lightcolor": [("focus", high_detail)],
                "darkcolor": [],
            },
        },
        "TCombobox": {
            "configure": {
                "background": text_background,
                "fieldbackground": text_background,
                "selectbackground": text_background,
                "lightcolor": text_background,
                "darkcolor": text_background,
                "bordercolor": text_background,
                "arrowcolor": normal_foreground,
                "foreground": normal_foreground,
                "seleftforeground": normal_foreground,
                # "padding" : [12,2,12,2],
            },
            "map": {
                "background": [("active", text_background)],
                "fieldbackground": [],
                "selectbackground": [],
                "selectforeground": [],
                "foreground": [],
                "arrowcolor": [],
            },
        },
        "TScrollbar": {
            "configure": {
                "gripcount": 0,
                "borderwidth": 0,
                "relief": "flat",
                "darkcolor": normal_detail,
                "lightcolor": normal_detail,
                "bordercolor": text_background,
                "troughcolor": text_background,
                # arrowcolor="white"
            },
            "map": {
                "background": [
                    ("!disabled", normal_detail),
                    ("disabled", normal_detail),
                ],
                "darkcolor": [
                    ("!disabled", text_background),
                    ("disabled", text_background),
                ],
                "lightcolor": [
                    ("!disabled", text_background),
                    ("disabled", text_background),
                ],
            },
        },
        "Vertical.TScrollbar": {
            # Remove scrollbar buttons/arrows:
            "layout": [
                (
                    "Vertical.Scrollbar.trough",
                    {
                        "sticky": "ns",
                        "children": [
                            (
                                "Vertical.Scrollbar.thumb",
                                {"expand": "1", "sticky": "nswe"},
                            )
                        ],
                    },
                )
            ]
        },
        "Horizontal.TScrollbar": {
            # Remove scrollbar buttons/arrows:
            "layout": [
                (
                    "Horizontal.Scrollbar.trough",
                    {
                        "sticky": "we",
                        "children": [
                            (
                                "Horizontal.Scrollbar.thumb",
                                {"expand": "1", "sticky": "nswe"},
                            )
                        ],
                    },
                )
            ],
            "map": {
                # Make disabled Hor Scrollbar invisible
                "background": [
                    ("disabled", frame_background),
                    ("!disabled", normal_detail),
                ],
                "troughcolor": [("disabled", frame_background)],
                "bordercolor": [("disabled", frame_background)],
                "darkcolor": [("disabled", frame_background)],
                "lightcolor": [("disabled", frame_background)],
            },
        },
        "TButton": {
            "configure": {"background": normal_detail, "foreground": normal_foreground},
            "map": {
                "foreground": [
                    ("disabled", low_foreground),
                    ("alternate", high_foreground),
                ],
                "background": [("pressed", low_detail), ("active", high_detail)],
                "bordercolor": [("alternate", high_detail)],
            },
        },
        "TCheckbutton": {
            "configure": {
                "indicatorforeground": normal_foreground,
                "indicatorbackground": text_background,
            },
            "map": {
                "indicatorforeground": [
                    ("disabled", "alternate", low_foreground),
                    ("disabled", low_foreground),
                ]
            },
        },
        "TRadiobutton": {
            "configure": {
                "indicatorforeground": normal_foreground,
                "indicatorbackground": text_background,
            },
            "map": {
                "indicatorforeground": [
                    ("disabled", "alternate", low_foreground),
                    ("disabled", low_foreground),
                ]
            },
        },
        "Toolbutton": {
            "configure": {"background": frame_background},
            "map": {
                "background": [("disabled", frame_background), ("active", high_detail)]
            },
        },
        "TLabel": {"configure": {"foreground": normal_foreground}},
        "Url.TLabel": {"configure": {"foreground": high_foreground}},
        "TScale": {
            "configure": {
                "background": high_detail,
                "troughcolor": normal_detail,
                "lightcolor": high_detail,
                "darkcolor": high_detail,
                # "bordercolor" : "red",
                # "sliderlength" : 40,
                # "sliderthickness" : 60,
                "gripcount": 0,
            },
            "map": {"background": [], "troughcolor": []},
        },
        "TScale.slider": {
            "configure": {
                "background": "red",
                "troughcolor": "yellow",
                "lightcolor": "green",
                "darkcolor": "white",
                # "sliderlength" : 40,
                # "sliderthickness" : 60,
            }
        },
        "ViewBody.TFrame": {"configure": {"background": text_background}},
        "ViewToolbar.TFrame": {"configure": {"background": normal_detail}},
        "ViewToolbar.Toolbutton": {"configure": {"background": normal_detail}},
        "ViewTab.TLabel": {
            "configure": {"background": normal_detail, "padding": [5, 0]}
        },
        "ViewToolbar.TLabel": {
            "configure": {"background": normal_detail, "padding": [scale(4), 0]}
        },
        "Active.ViewTab.TLabel": {
            "configure": {
                "foreground": high_foreground,
                # "font" : "BoldTkDefaultFont",
                "background": text_background,
            }
        },
        "Inactive.ViewTab.TLabel": {
            "configure": {
                "foreground": normal_foreground,
                "font": "UnderlineTkDefaultFont",
            },
            "map": {"background": [("hover", high_detail)]},
        },
        "Text": {
            "configure": {
                "background": text_background,
                "foreground": normal_foreground,
            }
        },
        "Gutter": {
            "configure": {"background": low_detail, "foreground": low_foreground}
        },
        "Listbox": {
            "configure": {
                "background": text_background,
                "foreground": normal_foreground,
                "selectbackground": high_detail,
                "selectforeground": high_foreground,
                "disabledforeground": low_foreground,
                "highlightbackground": normal_detail,
                "highlightcolor": high_detail,
                "highlightthickness": 1,
            }
        },
        "Menubar": {
            "configure": {
                # Regular, system-provided Windows menubar doesn't allow changing colors.
                # custom=True replaces it with a custom-built menubar.
                "custom": running_on_windows()
                if custom_menubar is None
                else custom_menubar,
                "background": frame_background,
                "foreground": normal_foreground,
                "activebackground": normal_foreground,
                "activeforeground": frame_background,
                "relief": "flat",
            }
        },
        "Menu": {
            "configure": {
                "background": normal_detail,
                "foreground": high_foreground,
                "selectcolor": normal_foreground,
                #"borderwidth": 0, # Interacts badly with right-clicks in Linux
                "activebackground": normal_foreground,
                "activeforeground": frame_background,
                #"activeborderwidth": 0, # Interacts badly with right-clicks in Linux
                "relief": "flat",
            }
        },
        "CustomMenubarLabel.TLabel": {
            "configure": {"padding": [scale(10), scale(2), 0, scale(15)]}
        },
    }
Esempio n. 2
0
def pix():
    MAIN_BACKGROUND = "#ededed"

    res_dir = os.path.join(os.path.dirname(__file__), "res")
    scrollbar_button_settings = {}
    for direction, element_name in [
        ("up", "Vertical.Scrollbar.uparrow"),
        ("down", "Vertical.Scrollbar.downarrow"),
        ("left", "Horizontal.Scrollbar.leftarrow"),
        ("right", "Horizontal.Scrollbar.rightarrow"),
    ]:
        # load the image
        img_name = "scrollbar-button-" + direction
        for suffix in ["", "-insens"]:
            get_workbench().get_image(
                os.path.join(res_dir, img_name + suffix + ".png"), img_name + suffix
            )

        scrollbar_button_settings[element_name] = {
            "element create": (
                "image",
                img_name,
                ("!disabled", img_name),
                ("disabled", img_name + "-insens"),
            )
        }

    settings = {
        ".": {"configure": {"background": MAIN_BACKGROUND}},
        "Toolbutton": {
            "configure": {"borderwidth": 1},
            "map": {
                "relief": [("disabled", "flat"), ("hover", "groove"), ("!hover", "flat")],
                "background": [
                    ("disabled", MAIN_BACKGROUND),
                    ("!hover", MAIN_BACKGROUND),
                    ("hover", "#ffffff"),
                ],
            },
        },
        "Treeview.Heading": {
            "configure": {
                "background": "#f0f0f0",
                "foreground": "#808080",
                "relief": "flat",
                "borderwidth": 1,
            },
            "map": {"foreground": [("active", "black")]},
        },
        "TNotebook.Tab": {
            "map": {"background": [("!selected", "#d0d0d0"), ("selected", MAIN_BACKGROUND)]}
        },
        "ButtonNotebook.TNotebook.Tab": {
            "map": {
                "background": [("!selected", "#d0d0d0"), ("selected", MAIN_BACKGROUND)],
                "padding": [
                    ("selected", [scale(4), scale(2), scale(4), scale(3)]),
                    ("!selected", [scale(4), scale(2), scale(4), scale(3)]),
                ],
            }
        },
        "TScrollbar": {
            "configure": {
                "gripcount": 0,
                "borderwidth": 0,
                "padding": scale(1),
                "relief": "solid",
                "background": "#9e9e9e",
                "darkcolor": "#d6d6d6",
                "lightcolor": "#d6d6d6",
                "bordercolor": "#d6d6d6",
                "troughcolor": "#d6d6d6",
                "arrowsize": scale(1),
                "arrowcolor": "gray",
            },
            "map": {"background": [], "darkcolor": [], "lightcolor": []},
        },
        # Padding allows twaking thumb width
        "Vertical.TScrollbar": {
            "layout": [
                (
                    "Vertical.Scrollbar.trough",
                    {
                        "sticky": "ns",
                        "children": [
                            ("Vertical.Scrollbar.uparrow", {"side": "top", "sticky": ""}),
                            ("Vertical.Scrollbar.downarrow", {"side": "bottom", "sticky": ""}),
                            (
                                "Vertical.Scrollbar.padding",
                                {
                                    "sticky": "nswe",
                                    "children": [
                                        (
                                            "Vertical.Scrollbar.thumb",
                                            {"expand": 1, "sticky": "nswe"},
                                        )
                                    ],
                                },
                            ),
                        ],
                    },
                )
            ]
        },
        "Horizontal.TScrollbar": {
            "layout": [
                (
                    "Horizontal.Scrollbar.trough",
                    {
                        "sticky": "we",
                        "children": [
                            ("Horizontal.Scrollbar.leftarrow", {"side": "left", "sticky": ""}),
                            ("Horizontal.Scrollbar.rightarrow", {"side": "right", "sticky": ""}),
                            (
                                "Horizontal.Scrollbar.padding",
                                {
                                    "sticky": "nswe",
                                    "children": [
                                        (
                                            "Horizontal.Scrollbar.thumb",
                                            {"expand": 1, "sticky": "nswe"},
                                        )
                                    ],
                                },
                            ),
                        ],
                    },
                )
            ],
            "map": {
                # Make disabled Hor Scrollbar invisible
                "background": [("disabled", "#d6d6d6")],
                "troughcolor": [("disabled", "#d6d6d6")],
                "bordercolor": [("disabled", "#d6d6d6")],
                "darkcolor": [("disabled", "#d6d6d6")],
                "lightcolor": [("disabled", "#d6d6d6")],
            },
        },
        "TCombobox": {"configure": {"arrowsize": scale(10)}},
        "Menubar": {
            "configure": {
                "background": MAIN_BACKGROUND,
                "relief": "flat",
                "activebackground": "#ffffff",
                "activeborderwidth": 0,
            }
        },
        "Menu": {
            "configure": {
                "background": "#ffffff",
                "relief": "flat",
                "borderwidth": 1,
                "activeborderwidth": 0,
                # "activebackground" : bg, # updated below
                # "activeforeground" : fg,
            }
        },
        "Tooltip": {
            "configure": {
                "background": "#808080",
                "foreground": "#ffffff",
                "borderwidth": 0,
                "padx": 10,
                "pady": 10,
            }
        },
        "OPTIONS": {"configure": {"icons_in_menus": False, "shortcuts_in_tooltips": False}},
    }

    settings.update(scrollbar_button_settings)

    # try to refine settings according to system configuration
    """Note that fonts are set globally, 
    ie. all themes will later inherit these"""
    update_fonts()

    for path in [GLOBAL_CONFIGURATION_PATH, CONFIGURATION_PATH]:
        if os.path.exists(path):
            with open(path) as fp:
                for line in fp:
                    if "sGtk/ColorScheme" in line:
                        if "selected_bg_color" in line:
                            bgr = re.search(r"selected_bg_color:#([0-9a-fA-F]*)", line, re.M).group(
                                1
                            )  # @UndefinedVariable
                            settings["Menu"]["configure"]["activebackground"] = (
                                "#" + bgr[0:2] + bgr[4:6] + bgr[8:10]
                            )
                        if "selected_fg_color" in line:
                            fgr = re.search(r"selected_fg_color:#([0-9a-fA-F]*)", line, re.M).group(
                                1
                            )  # @UndefinedVariable
                            settings["Menu"]["configure"]["activeforeground"] = (
                                "#" + fgr[0:2] + fgr[4:6] + fgr[8:10]
                            )

    return settings