gitk: use config variables to define and load a theme

gitk uses themed tk, but has no capability to alter the theme defined
by Tk. While there are documented ways to install other themes, and
to make one the default, these methods are obscure at best. Instead,
let's offer two config variables:

- theme  this is the name of the theme to use, and must be available.
- themeloader - this is the full pathname of a tcl script that
  will load one or more themes into the Tk namespace.

By default, theme is set to the theme active when Tk is started, and
themeloader = {}.  These variables must be defined to something else to
have any user visible effect.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
main^2^2
Mark Levedahl 2025-09-22 10:36:41 -04:00
parent fe2005e723
commit 8ccb2d4a76
1 changed files with 15 additions and 1 deletions

16
gitk
View File

@ -2215,6 +2215,7 @@ proc setoptions {} {
} }


proc setttkstyle {} { proc setttkstyle {} {
global theme
eval font configure TkDefaultFont [fontflags mainfont] eval font configure TkDefaultFont [fontflags mainfont]
eval font configure TkTextFont [fontflags textfont] eval font configure TkTextFont [fontflags textfont]
eval font configure TkHeadingFont [fontflags mainfont] eval font configure TkHeadingFont [fontflags mainfont]
@ -2224,6 +2225,10 @@ proc setttkstyle {} {
eval font configure TkIconFont [fontflags uifont] eval font configure TkIconFont [fontflags uifont]
eval font configure TkMenuFont [fontflags uifont] eval font configure TkMenuFont [fontflags uifont]
eval font configure TkSmallCaptionFont [fontflags uifont] eval font configure TkSmallCaptionFont [fontflags uifont]

if {[catch {ttk::style theme use $theme} err]} {
set theme [ttk::style theme use]
}
} }


# Make a menu and submenus. # Make a menu and submenus.
@ -12618,6 +12623,9 @@ set circleoutlinecolor $fgcolor
set foundbgcolor yellow set foundbgcolor yellow
set currentsearchhitbgcolor orange set currentsearchhitbgcolor orange


set theme [ttk::style theme use]
set themeloader {}

# button for popping up context menus # button for popping up context menus
if {[tk windowingsystem] eq "aqua" && [package vcompare $::tcl_version 8.7] < 0} { if {[tk windowingsystem] eq "aqua" && [package vcompare $::tcl_version 8.7] < 0} {
set ctxbut <Button-2> set ctxbut <Button-2>
@ -12701,6 +12709,8 @@ set config_variables {
tagfgcolor tagfgcolor
tagoutlinecolor tagoutlinecolor
textfont textfont
theme
themeloader
uicolor uicolor
uifgcolor uifgcolor
uifgdisabledcolor uifgdisabledcolor
@ -12800,7 +12810,10 @@ set nullid "0000000000000000000000000000000000000000"
set nullid2 "0000000000000000000000000000000000000001" set nullid2 "0000000000000000000000000000000000000001"
set nullfile "/dev/null" set nullfile "/dev/null"


setttkstyle if {[file exists $themeloader]} {
source $themeloader
}

set appname "gitk" set appname "gitk"


set runq {} set runq {}
@ -12916,6 +12929,7 @@ if {[tk windowingsystem] eq "win32"} {
focus -force . focus -force .
} }


setttkstyle
set_gui_colors set_gui_colors


getcommits {} getcommits {}