Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
appearance.tcl
Go to the documentation of this file.
1 # Copyright (C) 2018 Uwe Klimmek
2 #
3 # This file is part of SCID (Shane's Chess Information Database).
4 #
5 # SCID is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation.
8 #
9 # SCID is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with SCID. If not, see <http://www.gnu.org/licenses/>.
16 
17 namespace eval ::appearance {}
18 
19 proc ::appearance::applyMenuBarColor { menu docked_nb } {
20  if { ! [info exists ::menuColor(background)] && \
21  ! [info exists ::menuBarColor(background)] } { return}
22 
23  if { $docked_nb eq ""} {
24  set varname ::menuBarColor(background)
25  } else {
26  set varname ::menuColor(background)
27  }
28  if { [info exists $varname] } {
29  $menu configure -background [set $varname]
30  } else {
31  lassign [lrange [$menu configure -background] 3 end] default currCol
32  if { $default ne $currCol } {
33  $menu configure -background $default
34  }
35  }
36 }
37 
38 proc ::appearance::chooseMenuColor {col_var} {
39  set col [ tk_chooseColor -initialcolor [set $col_var] -title "Scid"]
40  if { $col != "" } {
41  set $col_var $col
43  }
44  raiseWin .menuOptions
45  focus .menuOptions.f.bg
46 }
47 
48 proc ::appearance::setNewMenuColors { m configure_cmd } {
49  $m configure {*}$configure_cmd
50  foreach child [winfo children $m] {
51  setNewMenuColors $child $configure_cmd
52  }
53 }
54 
55 proc ::appearance::updateMenuColors {} {
56  foreach {col value} [array get ::menuDialog_] {
57  lappend configure_cmd "-[string tolower $col]"
58  lappend configure_cmd $value
59  }
60  set toplevel_wins [::win::getWindows]
61  lappend toplevel_wins "."
62  foreach wnd $toplevel_wins {
63  lassign [::win::getMenu $wnd] menu
64  if {$menu ne ""} {
65  setNewMenuColors $menu $configure_cmd
66 
67  lassign [::win::isDocked $wnd] docked_nb
68  applyMenuBarColor $menu $docked_nb
69  }
70  }
71 }
72 
73 proc ::appearance::setMenuColors {} {
74  foreach {col value} [array get ::menuDialog_] {
75  if { $value ne $::menuDialogDefault_($col) } {
76  set ::menuColor($col) $value
77  } else {
78  unset -nocomplain ::menuColor($col)
79  }
80  option add *Menu.$col $value
81  }
82  foreach {col value} [array get ::menuBarDialog_] {
83  if { $value ne $::menuDialogDefault_($col) } {
84  set ::menuBarColor($col) $value
85  } else {
86  unset -nocomplain ::menuBarColor($col)
87  }
88  }
89 
91 
92  set w .menuOptions
93  catch {grab release $w}
94  destroy $w
95 }
96 
97 proc ::appearance::defaultColors {} {
98  foreach col { background foreground activeBackground activeForeground selectColor disabledForeground } {
99  set config [.menu configure -[string tolower $col]]
100  set ::menuDialogDefault_($col) [lindex $config 3]
101  set ::menuDialog_($col) $::menuDialogDefault_($col)
102  }
103  set ::menuBarDialog_(background) $::menuDialogDefault_(background)
104 }
105 
106 # Menu Color Config
107 #
108 # Dialog window for configuring Menu colors
109 proc ::appearance::menuConfigDialog {} {
111  foreach {col value} [array get ::menuColor] {
112  set ::menuDialog_($col) $value
113  }
114  foreach {col value} [array get ::menuBarColor] {
115  set ::menuBarDialog_($col) $value
116  }
117 
118  set w .menuOptions
120  wm title $w "Scid: [tr OptionsMenuColor]"
121 
122  ttk::label $w.status -text ""
123  pack [ttk::frame $w.b] -side bottom -fill x
124  pack [ttk::frame $w.f] \
125  -side top -fill x
126 
127  set f $w.f
128  set r 0
129 
130  ttk::label $f.mainmenu -text "Menu bar Menu"
131  if { ! $::windowsOS && ! $::macOS} {
132  ttk::button $f.mbg -text $::tr(MenuColorBackground) -command { ::appearance::chooseMenuColor ::menuBarDialog_(background) }
133  grid $f.mainmenu -row $r -column 0 -columnspan 3 -padx 4 -sticky e
134  grid $f.mbg -row $r -column 4 -padx 4
135  incr r
136  }
137  ttk::label $f.menuline0 -text "Disabled"
138  grid $f.menuline0 -row $r -column 2 -padx 4
139  ttk::button $f.dfg -text $::tr(MenuColorForeground) -command { ::appearance::chooseMenuColor ::menuDialog_(disabledForeground) }
140  grid $f.dfg -row $r -column 3 -padx 4
141  incr r
142  ttk::button $f.sel -text $::tr(MenuColorSelect) -command { ::appearance::chooseMenuColor ::menuDialog_(selectColor) }
143  grid $f.sel -row $r -column 0 -padx 4
144  ttk::label $f.select -text "x"
145  grid $f.select -row $r -column 1
146  ttk::label $f.menuline1 -text "Menu1"
147  grid $f.menuline1 -row $r -column 2 -padx 4
148  ttk::button $f.fg -text $::tr(MenuColorForeground) -command { ::appearance::chooseMenuColor ::menuDialog_(foreground) }
149  grid $f.fg -row $r -column 3 -padx 4 -pady 5
150  ttk::button $f.bg -text $::tr(MenuColorBackground) -command { ::appearance::chooseMenuColor ::menuDialog_(background) }
151  grid $f.bg -row $r -column 4 -padx 4
152  incr r
153  ttk::label $f.menuline2 -text "Menu2"
154  grid $f.menuline2 -row $r -column 2 -padx 4
155  ttk::button $f.afg -text $::tr(MenuColorForeground) -command { ::appearance::chooseMenuColor ::menuDialog_(activeForeground) }
156  grid $f.afg -row $r -column 3 -padx 4
157  ttk::button $f.abg -text $::tr(MenuColorBackground) -command { ::appearance::chooseMenuColor ::menuDialog_(activeBackground) }
158  grid $f.abg -row $r -column 4 -padx 4 -pady 5
159  incr r
161  ttk::button $w.b.help -image tb_help -command {grab release .menuOptions; helpWindow Appearance }
162  ::utils::tooltip::Set $w.b.help $::tr(Help)
163  dialogbutton $w.b.ok -text OK -command ::appearance::setMenuColors
164  dialogbutton $w.b.reset -text $::tr(Defaults) -command {
165  ::appearance::defaultColors
166  ::appearance::setMenuColors
167  }
168  dialogbutton $w.b.cancel -text $::tr(Cancel) -command "::win::closeWindow $w"
169  packdlgbuttons $w.b.cancel $w.b.ok $w.b.reset $w.b.help
170  bind $w <Return> [list $w.b.ok invoke]
171  bind $w <Escape> [list $w.b.cancel invoke]
172  bind $w.f <Destroy> { unset ::menuDialog_ }
173  bind $w <F1> { grab release .menuOptions; helpWindow Appearance }
176  wm resizable $w 0 0
177  raiseWin $w
178  grab $w
179  focus $w.f.bg
180 }
181 
182 proc ::appearance::Refresh {} {
183  global menuDialog_
184  set w .menuOptions
185  $w.f.menuline0 configure -background $menuDialog_(background) -foreground $menuDialog_(disabledForeground)
186  $w.f.menuline1 configure -background $menuDialog_(background) -foreground $menuDialog_(foreground)
187  $w.f.menuline2 configure -background $menuDialog_(activeBackground) -foreground $menuDialog_(activeForeground)
188  $w.f.select configure -foreground $menuDialog_(selectColor)
189  $w.f.mainmenu configure -background $::menuBarDialog_(background) -foreground $menuDialog_(foreground)
190 }