-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c262abe
commit 71b8a13
Showing
10 changed files
with
1,378 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021-2023 rdbende | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
""" | ||
This was originally taken from https://github.com/rdbende/Sun-Valley-ttk-theme/ | ||
Modified it a little to make the ui smaller and more compact. | ||
""" | ||
|
||
import platform | ||
from functools import partial | ||
from pathlib import Path | ||
|
||
inited = False | ||
root = None | ||
|
||
def init_theme(func): | ||
def wrapper(*args, **kwargs): | ||
global inited | ||
global root | ||
|
||
if not inited: | ||
from tkinter import _default_root # type: ignore | ||
|
||
path = (Path(__file__).parent / "sv.tcl").resolve() | ||
|
||
try: | ||
_default_root.tk.call("source", str(path)) | ||
except AttributeError: | ||
raise RuntimeError("can't set theme, because tkinter is not initialized. " + "Please create a tkinter.Tk instance first and then set the theme.") from None | ||
else: | ||
inited = True | ||
root = _default_root | ||
|
||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
|
||
@init_theme | ||
def set_theme(theme): | ||
if theme not in {"dark", "light"}: | ||
raise RuntimeError("not a valid theme name: {}".format(theme)) | ||
|
||
root.tk.call("set_theme", theme) # type: ignore | ||
|
||
|
||
@init_theme | ||
def get_theme(): | ||
theme = root.tk.call("ttk::style", "theme", "use") # type: ignore | ||
|
||
return {"sun-valley-dark": "dark", "sun-valley-light": "light"}.get(theme, theme) | ||
|
||
|
||
@init_theme | ||
def toggle_theme(): | ||
if get_theme() == "light": | ||
use_dark_theme() | ||
else: | ||
use_light_theme() | ||
|
||
|
||
use_dark_theme = partial(set_theme, "dark") | ||
use_light_theme = partial(set_theme, "light") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package require Tk 8.6 | ||
|
||
if {[tk windowingsystem] == "win32"} { | ||
set static "" | ||
} else { | ||
set static " static" | ||
} | ||
|
||
font create SunValleyCaptionFont -family "Segoe UI Variable$static Small" -size -11 | ||
font create SunValleyBodyFont -family "Segoe UI Variable$static Text" -size -12 | ||
font create SunValleyBodyStrongFont -family "Segoe UI Variable$static Text Semibold" -size -12 | ||
font create SunValleyBodyLargeFont -family "Segoe UI Variable$static Text" -size -14 | ||
font create SunValleySubtitleFont -family "Segoe UI Variable$static Display Semibold" -size -16 | ||
font create SunValleyTitleFont -family "Segoe UI Variable$static Display Semibold" -size -24 | ||
font create SunValleyTitleLargeFont -family "Segoe UI Variable$static Display Semibold" -size -34 | ||
font create SunValleyDisplayFont -family "Segoe UI Variable$static Display Semibold" -size -48 | ||
|
||
proc config_input_font {w} { | ||
if {[ttk::style theme use] in [list "sun-valley-dark" "sun-valley-light"]} { | ||
$w configure -font SunValleyBodyFont | ||
} | ||
} | ||
|
||
proc config_menus {w} { | ||
if {[tk windowingsystem] != "aqua"} { | ||
set theme [ttk::style theme use] | ||
if {$theme == "sun-valley-dark"} { | ||
$w configure \ | ||
-relief solid \ | ||
-borderwidth 1 \ | ||
-activeborderwidth 0 \ | ||
-background "#202020" \ | ||
-activebackground "#434343" \ | ||
-activeforeground "#fafafa" \ | ||
-selectcolor "#fafafa" | ||
} elseif {$theme == "sun-valley-light"} { | ||
$w configure \ | ||
-relief solid \ | ||
-borderwidth 1 \ | ||
-activeborderwidth 0 \ | ||
-background "#ebebeb" \ | ||
-activebackground "#c4c4c4" \ | ||
-activeforeground "#1c1c1c" \ | ||
-selectcolor "#1c1c1c" | ||
} | ||
|
||
if {[[winfo toplevel $w] cget -menu] != $w} { | ||
if {$theme == "sun-valley-dark"} { | ||
$w configure -borderwidth 0 -background $ttk::theme::sv_dark::theme_colors(-bg) | ||
} elseif {$theme == "sun-valley-light"} { | ||
$w configure -borderwidth 0 -background $ttk::theme::sv_light::theme_colors(-bg) | ||
} | ||
} | ||
} | ||
} | ||
|
||
bind TEntry <<ThemeChanged>> {config_input_font %W} | ||
bind TCombobox <<ThemeChanged>> {config_input_font %W} | ||
bind TSpinbox <<ThemeChanged>> {config_input_font %W} | ||
bind Menu <<ThemeChanged>> {config_menus %W} | ||
|
||
source [file join [file dirname [info script]] theme light.tcl] | ||
source [file join [file dirname [info script]] theme dark.tcl] | ||
|
||
|
||
proc set_theme {mode} { | ||
if {$mode == "dark"} { | ||
ttk::style theme use "sun-valley-dark" | ||
|
||
ttk::style configure . \ | ||
-background $ttk::theme::sv_dark::theme_colors(-bg) \ | ||
-foreground $ttk::theme::sv_dark::theme_colors(-fg) \ | ||
-troughcolor $ttk::theme::sv_dark::theme_colors(-bg) \ | ||
-focuscolor $ttk::theme::sv_dark::theme_colors(-selbg) \ | ||
-selectbackground $ttk::theme::sv_dark::theme_colors(-selbg) \ | ||
-selectforeground $ttk::theme::sv_dark::theme_colors(-selfg) \ | ||
-insertwidth 1 \ | ||
-insertcolor $ttk::theme::sv_dark::theme_colors(-fg) \ | ||
-fieldbackground $ttk::theme::sv_dark::theme_colors(-bg) \ | ||
-borderwidth 0 \ | ||
-relief flat | ||
|
||
tk_setPalette \ | ||
background $ttk::theme::sv_dark::theme_colors(-bg) \ | ||
foreground $ttk::theme::sv_dark::theme_colors(-fg) \ | ||
highlightColor $ttk::theme::sv_dark::theme_colors(-selbg) \ | ||
selectBackground $ttk::theme::sv_dark::theme_colors(-selbg) \ | ||
selectForeground $ttk::theme::sv_dark::theme_colors(-selfg) \ | ||
activeBackground $ttk::theme::sv_dark::theme_colors(-selbg) \ | ||
activeForeground $ttk::theme::sv_dark::theme_colors(-selfg) | ||
|
||
ttk::style map . -foreground [list disabled $ttk::theme::sv_dark::theme_colors(-disfg)] | ||
|
||
option add *tearOff 0 | ||
|
||
} elseif {$mode == "light"} { | ||
ttk::style theme use "sun-valley-light" | ||
|
||
ttk::style configure . \ | ||
-background $ttk::theme::sv_light::theme_colors(-bg) \ | ||
-foreground $ttk::theme::sv_light::theme_colors(-fg) \ | ||
-troughcolor $ttk::theme::sv_light::theme_colors(-bg) \ | ||
-focuscolor $ttk::theme::sv_light::theme_colors(-selbg) \ | ||
-selectbackground $ttk::theme::sv_light::theme_colors(-selbg) \ | ||
-selectforeground $ttk::theme::sv_light::theme_colors(-selfg) \ | ||
-insertwidth 1 \ | ||
-insertcolor $ttk::theme::sv_light::theme_colors(-fg) \ | ||
-fieldbackground $ttk::theme::sv_light::theme_colors(-bg) \ | ||
-borderwidth 0 \ | ||
-relief flat | ||
|
||
tk_setPalette \ | ||
background $ttk::theme::sv_light::theme_colors(-bg) \ | ||
foreground $ttk::theme::sv_light::theme_colors(-fg) \ | ||
highlightColor $ttk::theme::sv_light::theme_colors(-selbg) \ | ||
selectBackground $ttk::theme::sv_light::theme_colors(-selbg) \ | ||
selectForeground $ttk::theme::sv_light::theme_colors(-selfg) \ | ||
activeBackground $ttk::theme::sv_light::theme_colors(-selbg) \ | ||
activeForeground $ttk::theme::sv_light::theme_colors(-selfg) | ||
|
||
ttk::style map . -foreground [list disabled $ttk::theme::sv_light::theme_colors(-disfg)] | ||
|
||
option add *tearOff 0 | ||
} | ||
} |
Oops, something went wrong.