Skip to content

Commit

Permalink
GUI - Add theme support to console
Browse files Browse the repository at this point in the history
  • Loading branch information
torzdf committed Mar 22, 2021
1 parent c830aa1 commit a49831f
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 116 deletions.
211 changes: 128 additions & 83 deletions lib/gui/.cache/themes/default.json
Original file line number Diff line number Diff line change
@@ -1,84 +1,129 @@
{
"info": "Initial default theme configuration whilst migrating from default ttk OS widgets",
"group_panel": {
"info": {
"info1": "The 'group_panel' section are any section which contains items for user input, such as the left hand options panel in the main GUI or the Settings pop-up",
"info2": "Anything which uses a 'group_panel' will use the theme specified here as default. Panels can be overriden (see below).",

"panel_background": "The background color of the main panel that holds all of the group options.",

"info_color": "The background color of the information header box at the top of each control panel",
"info_font": "The color of the font inside the information header box at the top of each control panel",
"info_border": "The color of the border around the outside of the information header box at the top of each control panel",

"header_color": "The color to use for the option group boxes header backgrounds, the group box border and for labels on options groups.",
"header_font": "The color to use for the option group boxes header font.",
"group_background": "This is the color used for the background of each group of options, as well as the background color used for any label which resides inside a group box",
"group_font": "The font color used inside each group box for labels",

"control_color": "The color of controls (e.g. Slider knob, combo pull-down arrow, scrollbar slider + arrows etc.)",
"control_active": "Selected/hovered over color of controls (e.g. Slider knob, combo pull-down arrow, scrollbar slider + arrows etc.)",
"control_disabled": "The color of controls when they are disabled (specifically scrollbars when there is no page to scroll).",

"input_color": "The background color of input boxes (e.g. text entry)",
"input_font": "The font color of input boxes (e.g. text entry)",
"button_background": "The background color of buttons",

"scrollbar_border": "Border color of scrollbar",
"scrollbar_trough": "Trough color of scrollbar"
},
"panel_background": "#CDD3D5",

"info_color": "#FFFFFF",
"info_font": "#000000",
"info_border": "#000000",

"header_color": "#176087",
"header_font": "#FFFFFF",
"group_background": "#FFFFFF",
"group_border": "#176087",
"group_font": "#000000",

"control_color": "#75929C",
"control_active": "#176087",
"control_disabled": "#CDD3D5",

"input_color": "#FFFFFF",
"input_font": "#000000",
"button_background": "#FFFFFF",

"scrollbar_border": "#176087",
"scrollbar_trough": "#CDD3D5"
},
"group_settings": {
"info": {"info1": "Override default colors for the settings pop-up. See 'group_panel' for allowable options",
"info2": "Options same as 'group_panel' with the following additions:",

"tree_select": "The color of the selected item in the left hand nav frame",
"link_color": "The color of links on pages where there are no configuration options"
},
"panel_background": "#DAD2D8",

"header_color": "#9B1D20",
"group_border": "#9B1D20",

"control_color": "#B090A8",
"control_active": "#9B1D20",
"control_disabled": "#DAD2D8",

"scrollbar_border": "#9B1D20",
"scrollbar_trough": "#DAD2D8",

"tree_select": "#9B1D20",
"link_color": "#9B1D20"
},
"console": {
"background_color": "#CDD3D5",
"foreground_color": "#000000"
},
"tooltip": {
"background_color": "#FFFFEA",
"border_color": "#FFFFEA",
"font_color": "#000000"
}
}
"info": "Initial default theme configuration whilst migrating from default ttk OS widgets",
"group_panel": {
"info": {
"info1": "The 'group_panel' section are any section which contains items for user input, such as the left hand options panel in the main GUI or the Settings pop-up",
"info2": "Anything which uses a 'group_panel' will use the theme specified here as default. Panels can be overriden (see below).",

"panel_background": "The background color of the main panel that holds all of the group options.",

"info_color": "The background color of the information header box at the top of each control panel",
"info_font": "The color of the font inside the information header box at the top of each control panel",
"info_border": "The color of the border around the outside of the information header box at the top of each control panel",

"header_color": "The color to use for the option group boxes header backgrounds, the group box border and for labels on options groups.",
"header_font": "The color to use for the option group boxes header font.",
"group_background": "This is the color used for the background of each group of options, as well as the background color used for any label which resides inside a group box",
"group_font": "The font color used inside each group box for labels",

"control_color": "The color of controls (e.g. Slider knob, combo pull-down arrow, scrollbar slider + arrows etc.)",
"control_active": "Selected/hovered over color of controls (e.g. Slider knob, combo pull-down arrow, scrollbar slider + arrows etc.)",
"control_disabled": "The color of controls when they are disabled (specifically scrollbars when there is no page to scroll).",

"input_color": "The background color of input boxes (e.g. text entry)",
"input_font": "The font color of input boxes (e.g. text entry)",
"button_background": "The background color of buttons",

"scrollbar_border": "Border color of scrollbar",
"scrollbar_trough": "Trough color of scrollbar"
},
"panel_background": "#CDD3D5",

"info_color": "#FFFFFF",
"info_font": "#000000",
"info_border": "#000000",

"header_color": "#176087",
"header_font": "#FFFFFF",
"group_background": "#FFFFFF",
"group_border": "#176087",
"group_font": "#000000",

"control_color": "#75929C",
"control_active": "#176087",
"control_disabled": "#CDD3D5",

"input_color": "#FFFFFF",
"input_font": "#000000",
"button_background": "#FFFFFF",

"scrollbar_border": "#176087",
"scrollbar_trough": "#CDD3D5"
},
"group_settings": {
"info": {
"info1": "Override default colors for the settings pop-up. See 'group_panel' for allowable options",
"info2": "Options same as 'group_panel' with the following additions:",

"tree_select": "The color of the selected item in the left hand nav frame",
"link_color": "The color of links on pages where there are no configuration options"
},
"panel_background": "#DAD2D8",

"header_color": "#9B1D20",
"group_border": "#9B1D20",

"control_color": "#B090A8",
"control_active": "#9B1D20",
"control_disabled": "#DAD2D8",

"scrollbar_border": "#9B1D20",
"scrollbar_trough": "#DAD2D8",

"tree_select": "#9B1D20",
"link_color": "#9B1D20"
},
"console": {
"info": {
"info1": "The colors of the console output box",

"background_color": "The background color of the console output",
"stdout_color": "The text color for standard print message output (non Faceswap Logging messages)",
"stderr_color": "The text color for messages that are printed to sterr (non Faceswap Logging messages)",
"info_color": "The text color for Faceswap INFO log messages",
"verbose_color": "The text color for Faceswap VERBOSE log messages",
"warning_color": "The text color for Faceswap WARNING log messages",
"critical_color": "The text color for Faceswap CRITICAL log messages",
"error_color": "The text color for Faceswap ERROR log messages",

"scrollbar_border": "The color of the overall scrollbar border",
"scrollbar_trough": "The color of the scrollbar trough",

"scrollbar_background_<state>": "The main color of the up/down buttons and the slider of the scrollbar, for active (pressed/hovered), normal and disabled (no scrollbar required)",
"scrollbar_foreground_<state>": "The foreground color for the up/down buttons of the scrollbar, for active (pressed/hovered), normal and disabled (no scrollbar required)",
"scrollbar_border_<state>": "The border color of the up/down buttons and the slider of the scrollbar, for active (pressed/hovered), normal and disabled (no scrollbar required)"
},
"background_color": "#CDD3D5",
"stdout_color": "#172c87",
"stderr_color": "#78162f",
"info_color": "#176087",
"verbose_color": "#1D9B32",
"warning_color": "#9B701D",
"critical_color": "#9B381D",
"error_color": "#9B381D",

"scrollbar_border": "#176087",
"scrollbar_trough": "#CDD3D5",
"scrollbar_background_normal": "#75929C",
"scrollbar_background_disabled": "#CDD3D5",
"scrollbar_background_active": "#176087",
"scrollbar_foreground_normal": "#CDD3D5",
"scrollbar_foreground_disabled": "#75929C",
"scrollbar_foreground_active": "#CDD3D5",
"scrollbar_border_normal": "#176087",
"scrollbar_border_disabled": "#75929C",
"scrollbar_border_active": "#176087"
},
"tooltip": {
"info": {
"info1": "The colors of the tool-tip pop ups",

"background_color": "Tool-tip background color",
"border_color": "Tool-tip border color",
"font_color": "Tool-tip font color"
},
"background_color": "#FFFFEA",
"border_color": "#FFFFEA",
"font_color": "#000000"
}
}
24 changes: 13 additions & 11 deletions lib/gui/custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,28 @@ def _build_console(self):
self._console.config(width=100,
height=6,
bg=self._theme["background_color"],
fg=self._theme["foreground_color"])
self._console.pack(side=tk.LEFT, anchor=tk.N, fill=tk.BOTH, expand=True)
fg=self._theme["stdout_color"])

scrollbar = ttk.Scrollbar(self, command=self._console.yview)
scrollbar.pack(side=tk.LEFT, fill="y")
scrollbar = ttk.Scrollbar(self,
command=self._console.yview,
style="Console.Vertical.TScrollbar")
self._console.configure(yscrollcommand=scrollbar.set)

scrollbar.pack(side=tk.RIGHT, fill="y")
self._console.pack(side=tk.LEFT, anchor=tk.N, fill=tk.BOTH, expand=True)
self._redirect_console()
logger.debug("Built console")

def _add_tags(self):
""" Add tags to text widget to color based on output """
logger.debug("Adding text color tags")
self._console.tag_config("default", foreground="#1E1E1E")
self._console.tag_config("stderr", foreground="#E25056")
self._console.tag_config("info", foreground="#2B445E")
self._console.tag_config("verbose", foreground="#008140")
self._console.tag_config("warning", foreground="#F77B00")
self._console.tag_config("critical", foreground="red")
self._console.tag_config("error", foreground="red")
self._console.tag_config("default", foreground=self._theme["stdout_color"])
self._console.tag_config("stderr", foreground=self._theme["stderr_color"])
self._console.tag_config("info", foreground=self._theme["info_color"])
self._console.tag_config("verbose", foreground=self._theme["verbose_color"])
self._console.tag_config("warning", foreground=self._theme["warning_color"])
self._console.tag_config("critical", foreground=self._theme["critical_color"])
self._console.tag_config("error", foreground=self._theme["error_color"])

def _redirect_console(self):
""" Redirect stdout/stderr to console Text Box """
Expand Down
64 changes: 42 additions & 22 deletions lib/gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,15 @@ def _set_styles(self):
font=(self._font[0], self._font[1] + 4, "bold"))
self._style.configure("SPanel.Header2.TLabel",
font=(self._font[0], self._font[1] + 2, "bold"))
# Console
theme = self._user_theme["console"]
console_sbar = {area: tuple(theme[f"scrollbar_{area}_{state}"]
for state in ("normal", "disabled", "active"))
for area in ("background", "foreground", "border")}
self._get_custom_scrollbar("Console",
console_sbar,
theme["scrollbar_trough"],
theme["scrollbar_border"])

def _config_settings_group(self):
""" Configures the style of the control panel entry boxes. Used for inputting Faceswap
Expand All @@ -1159,7 +1168,19 @@ def _config_settings_group(self):
self._group_panel_widgets(panel_type, theme)
self._group_panel_infoheader(panel_type, theme)
self._config_settings_group_slider(panel_type, theme)
self._config_settings_group_scrollbar(panel_type, theme)
sbar_theme = dict(background=(theme["control_color"],
theme["control_disabled"],
theme["control_active"]),
foreground=(theme["control_disabled"],
theme["control_color"],
theme["control_disabled"]),
border=(theme["header_color"],
theme["control_color"],
theme["header_color"]))
self._get_custom_scrollbar(panel_type,
sbar_theme,
theme["scrollbar_trough"],
theme["scrollbar_border"])
self._config_settings_group_combobox(panel_type, theme)

def _group_panel_infoheader(self, key, theme):
Expand Down Expand Up @@ -1259,42 +1280,41 @@ def _config_settings_group_slider(self, key, theme):
groovewidth=4,
troughcolor=self._user_theme["group_panel"]["group_background"])

def _config_settings_group_scrollbar(self, key, theme):
def _get_custom_scrollbar(self, key, theme, trough, border):
""" Create a custom scroll bar widget so we can control the colors.
Parameters
----------
key: str
The section that the slider will belong to
theme: dict
The user configuration theme options
The theme options for a scroll bar. The dict should contain the keys: `background`,
`foreground`, `border`, with each item containing a tuple of the colors for the states
`normal`, `disabled` and `active` respectively
trough: str
The hex code for the scrollbar trough color
border: str
The hex code for the scrollbar border color
"""
logger.debug("Creating scrollbar: (key: %s, theme: %s, trough: %s, border: %s)",
key, theme, trough, border)
images = dict()
backgrounds = dict(normal=theme["control_color"],
disabled=theme["control_disabled"],
active=theme["control_active"])
foregrounds = dict(normal=theme["control_disabled"],
disabled=theme["control_color"],
active=theme["control_disabled"])
borders = dict(normal=theme["header_color"],
disabled=theme["control_color"],
active=theme["header_color"])

for state in ("normal", "disabled", "active"):
for idx, state in enumerate(("normal", "disabled", "active")):
# Create arrow and slider widgets for each state
img_args = ((16, 16), backgrounds[state])
img_args = ((16, 16), theme["background"][idx])
for dir_ in ("up", "down"):
images[f"img_{dir_}_{state}"] = self._images.get_image(
*img_args,
foreground=foregrounds[state],
foreground=theme["foreground"][idx],
pattern="arrow",
direction=dir_,
thickness=4,
border_width=1,
border_color=borders[state])
images[f"img_thumb_{state}"] = self._images.get_image(*img_args,
border_width=1,
border_color=borders[state])
border_color=theme["border"][idx])
images[f"img_thumb_{state}"] = self._images.get_image(
*img_args,
border_width=1,
border_color=theme["border"][idx])

for element in ("thumb", "uparrow", "downarrow"):
# Create the elements with the new images
Expand Down Expand Up @@ -1322,8 +1342,8 @@ def _config_settings_group_scrollbar(self, key, theme):
]
})])
self._style.configure(f"{key}.Vertical.TScrollbar",
troughcolor=theme["scrollbar_trough"],
bordercolor=theme["scrollbar_border"],
troughcolor=trough,
bordercolor=border,
troughrelief=tk.SOLID,
troughborderwidth=1)

Expand Down

0 comments on commit a49831f

Please sign in to comment.