summaryrefslogtreecommitdiffstats
path: root/library/ttk
diff options
context:
space:
mode:
authorjenglish <jenglish@flightlab.com>2006-12-13 17:06:31 (GMT)
committerjenglish <jenglish@flightlab.com>2006-12-13 17:06:31 (GMT)
commit94acb8d71c38b7e493d498a69816f77b520f49f1 (patch)
tree5750b2c23f77580621592431250ee7f66a508fd7 /library/ttk
parentb7c21ec7f3c632eb27c460678d7382bf05eb1d38 (diff)
downloadtk-94acb8d71c38b7e493d498a69816f77b520f49f1.zip
tk-94acb8d71c38b7e493d498a69816f77b520f49f1.tar.gz
tk-94acb8d71c38b7e493d498a69816f77b520f49f1.tar.bz2
Try to straighten out theme loading and selection logic.
Diffstat (limited to 'library/ttk')
-rw-r--r--library/ttk/clamTheme.tcl66
-rw-r--r--library/ttk/defaults.tcl71
-rw-r--r--library/ttk/ttk.tcl73
3 files changed, 116 insertions, 94 deletions
diff --git a/library/ttk/clamTheme.tcl b/library/ttk/clamTheme.tcl
index abf979f..9061006 100644
--- a/library/ttk/clamTheme.tcl
+++ b/library/ttk/clamTheme.tcl
@@ -1,16 +1,14 @@
#
-# $Id: clamTheme.tcl,v 1.2 2006/11/24 18:04:14 jenglish Exp $
+# $Id: clamTheme.tcl,v 1.3 2006/12/13 17:06:32 jenglish Exp $
#
-# Ttk widget set: "Clam" theme
+# "Clam" theme.
#
# Inspired by the XFCE family of Gnome themes.
#
namespace eval ttk::theme::clam {
-
- package provide ttk::theme::clam 0.0.1
-
- variable colors ; array set colors {
+ variable colors
+ array set colors {
-disabledfg "#999999"
-frame "#dcdad5"
@@ -23,10 +21,9 @@ namespace eval ttk::theme::clam {
-selectfg "#ffffff"
}
- namespace import -force ::ttk::style
- style theme settings clam {
+ ttk::style theme settings clam {
- style configure "." \
+ ttk::style configure "." \
-background $colors(-frame) \
-foreground black \
-bordercolor $colors(-darkest) \
@@ -39,7 +36,7 @@ namespace eval ttk::theme::clam {
-font TkDefaultFont \
;
- style map "." \
+ ttk::style map "." \
-background [list disabled $colors(-frame) \
active $colors(-lighter)] \
-foreground [list disabled $colors(-disabledfg)] \
@@ -48,8 +45,8 @@ namespace eval ttk::theme::clam {
;
# -selectbackground [list !focus "#847d73"]
- style configure TButton -width -11 -padding 5 -relief raised
- style map TButton \
+ ttk::style configure TButton -width -11 -padding 5 -relief raised
+ ttk::style map TButton \
-background [list \
disabled $colors(-frame) \
pressed $colors(-darker) \
@@ -59,42 +56,47 @@ namespace eval ttk::theme::clam {
-bordercolor [list alternate "#000000"] \
;
- style configure Toolbutton -padding 2 -relief flat
- style map Toolbutton \
- -relief {disabled flat selected sunken pressed sunken active raised} \
- -background [list disabled $colors(-frame) \
- pressed $colors(-darker) \
- active $colors(-lighter)] \
+ ttk::style configure Toolbutton -padding 2 -relief flat
+ ttk::style map Toolbutton \
+ -relief [list \
+ disabled flat \
+ selected sunken \
+ pressed sunken \
+ active raised] \
+ -background [list \
+ disabled $colors(-frame) \
+ pressed $colors(-darker) \
+ active $colors(-lighter)] \
-lightcolor [list pressed $colors(-darker)] \
-darkcolor [list pressed $colors(-darker)] \
;
- style configure TCheckbutton \
+ ttk::style configure TCheckbutton \
-indicatorbackground "#ffffff" \
-indicatormargin {1 1 4 1} \
-padding 2 ;
- style configure TRadiobutton \
+ ttk::style configure TRadiobutton \
-indicatorbackground "#ffffff" \
-indicatormargin {1 1 4 1} \
-padding 2 ;
- style map TCheckbutton -indicatorbackground \
+ ttk::style map TCheckbutton -indicatorbackground \
[list disabled $colors(-frame) pressed $colors(-frame)]
- style map TRadiobutton -indicatorbackground \
+ ttk::style map TRadiobutton -indicatorbackground \
[list disabled $colors(-frame) pressed $colors(-frame)]
- style configure TMenubutton \
+ ttk::style configure TMenubutton \
-width -11 -padding 5 -relief raised -anchor w
- style configure TEntry -padding 1 -insertwidth 1
- style map TEntry \
+ ttk::style configure TEntry -padding 1 -insertwidth 1
+ ttk::style map TEntry \
-background [list readonly $colors(-frame)] \
-bordercolor [list focus $colors(-selectbg)] \
-lightcolor [list focus "#6f9dc6"] \
-darkcolor [list focus "#6f9dc6"] \
;
- style configure TCombobox -padding 1 -insertwidth 1
- style map TCombobox \
+ ttk::style configure TCombobox -padding 1 -insertwidth 1
+ ttk::style map TCombobox \
-background [list active $colors(-lighter) \
pressed $colors(-lighter)] \
-fieldbackground [list {readonly focus} $colors(-selectbg) \
@@ -102,19 +104,19 @@ namespace eval ttk::theme::clam {
-foreground [list {readonly focus} $colors(-selectfg)] \
;
- style configure TNotebook.Tab -padding {6 2 6 2}
- style map TNotebook.Tab \
+ ttk::style configure TNotebook.Tab -padding {6 2 6 2}
+ ttk::style map TNotebook.Tab \
-padding [list selected {6 4 6 2}] \
-background [list selected $colors(-frame) {} $colors(-darker)] \
-lightcolor [list selected $colors(-lighter) {} $colors(-dark)] \
;
- style configure TLabelframe \
+ ttk::style configure TLabelframe \
-labeloutside true -labelmargins {0 0 0 4} \
-borderwidth 2 -relief raised
- style configure TProgressbar -background $colors(-frame)
+ ttk::style configure TProgressbar -background $colors(-frame)
- style configure Sash -sashthickness 6 -gripcount 10
+ ttk::style configure Sash -sashthickness 6 -gripcount 10
}
}
diff --git a/library/ttk/defaults.tcl b/library/ttk/defaults.tcl
index be7d7f3..0869fd3 100644
--- a/library/ttk/defaults.tcl
+++ b/library/ttk/defaults.tcl
@@ -1,13 +1,10 @@
#
-# $Id: defaults.tcl,v 1.2 2006/11/24 18:04:14 jenglish Exp $
+# $Id: defaults.tcl,v 1.3 2006/12/13 17:06:32 jenglish Exp $
#
-# Ttk widget set: Default theme
+# Settings for default theme.
#
-namespace eval ttk {
- # XXX do we want to separate Tk version from theme version?
- package provide ttk::theme::default $::tk_version
-
+namespace eval ttk::theme::default {
variable colors
array set colors {
-frame "#d9d9d9"
@@ -19,9 +16,9 @@ namespace eval ttk {
-indicator "#4a6984"
}
- style theme settings default {
+ ttk::style theme settings default {
- style configure "." \
+ ttk::style configure "." \
-borderwidth 1 \
-background $colors(-frame) \
-foreground black \
@@ -34,52 +31,59 @@ namespace eval ttk {
-indicatordiameter 10 \
;
- style map "." -background \
+ ttk::style map "." -background \
[list disabled $colors(-frame) active $colors(-activebg)]
- style map "." -foreground \
+ ttk::style map "." -foreground \
[list disabled $colors(-disabledfg)]
- style configure TButton \
+ ttk::style configure TButton \
-padding "3 3" -width -9 -relief raised -shiftrelief 1
- style map TButton -relief [list {!disabled pressed} sunken]
+ ttk::style map TButton -relief [list {!disabled pressed} sunken]
- style configure TCheckbutton \
+ ttk::style configure TCheckbutton \
-indicatorcolor "#ffffff" -indicatorrelief sunken -padding 1
- style map TCheckbutton -indicatorcolor \
+ ttk::style map TCheckbutton -indicatorcolor \
[list pressed $colors(-activebg) selected $colors(-indicator)]
- style configure TRadiobutton \
+ ttk::style configure TRadiobutton \
-indicatorcolor "#ffffff" -indicatorrelief sunken -padding 1
- style map TRadiobutton -indicatorcolor \
+ ttk::style map TRadiobutton -indicatorcolor \
[list pressed $colors(-activebg) selected $colors(-indicator)]
- style configure TMenubutton \
+ ttk::style configure TMenubutton \
-relief raised -padding "10 3" -anchor w
- style configure TEntry -relief sunken -fieldbackground white -padding 1
- style map TEntry -fieldbackground \
+ ttk::style configure TEntry \
+ -relief sunken -fieldbackground white -padding 1
+ ttk::style map TEntry -fieldbackground \
[list readonly $colors(-frame) disabled $colors(-frame)]
- style configure TCombobox -arrowsize 12 -padding 1
- style map TCombobox -fieldbackground \
+ ttk::style configure TCombobox -arrowsize 12 -padding 1
+ ttk::style map TCombobox -fieldbackground \
[list readonly $colors(-frame) disabled $colors(-frame)]
- style configure TLabelframe -relief groove -borderwidth 2
+ ttk::style configure TLabelframe \
+ -relief groove -borderwidth 2
- style configure TScrollbar -width 12 -arrowsize 12
- style map TScrollbar -arrowcolor [list disabled $colors(-disabledfg)]
+ ttk::style configure TScrollbar \
+ -width 12 -arrowsize 12
+ ttk::style map TScrollbar \
+ -arrowcolor [list disabled $colors(-disabledfg)]
- style configure TScale -sliderrelief raised
- style configure TProgressbar -background $colors(-selectbg)
+ ttk::style configure TScale \
+ -sliderrelief raised
+ ttk::style configure TProgressbar \
+ -background $colors(-selectbg)
- style configure TNotebook.Tab \
+ ttk::style configure TNotebook.Tab \
-padding {4 2} -background $colors(-darker)
- style map TNotebook.Tab -background [list selected $colors(-frame)]
+ ttk::style map TNotebook.Tab \
+ -background [list selected $colors(-frame)]
#
# Toolbar buttons:
#
- style layout Toolbutton {
+ ttk::style layout Toolbutton {
Toolbutton.border -children {
Toolbutton.padding -children {
Toolbutton.label
@@ -87,10 +91,11 @@ namespace eval ttk {
}
}
- style configure Toolbutton -padding 2 -relief flat
- style map Toolbutton -relief \
- {disabled flat selected sunken pressed sunken active raised}
- style map Toolbutton -background \
+ ttk::style configure Toolbutton \
+ -padding 2 -relief flat
+ ttk::style map Toolbutton -relief \
+ [list disabled flat selected sunken pressed sunken active raised]
+ ttk::style map Toolbutton -background \
[list pressed $colors(-darker) active $colors(-activebg)]
}
}
diff --git a/library/ttk/ttk.tcl b/library/ttk/ttk.tcl
index 5c1b5b2..37a96bc 100644
--- a/library/ttk/ttk.tcl
+++ b/library/ttk/ttk.tcl
@@ -1,5 +1,5 @@
#
-# $Id: ttk.tcl,v 1.3 2006/12/13 05:36:38 jenglish Exp $
+# $Id: ttk.tcl,v 1.4 2006/12/13 17:06:32 jenglish Exp $
#
# Ttk widget set initialization script.
#
@@ -114,44 +114,59 @@ source [file join $::ttk::library dialog.tcl]
bind TLabelframe <<Invoke>> { tk::TabToWindow [tk_focusNext %W] }
bind TLabel <<Invoke>> { tk::TabToWindow [tk_focusNext %W] }
-### Load themes.
+### Load settings for built-in themes:
#
-source [file join $::ttk::library defaults.tcl]
-source [file join $::ttk::library classicTheme.tcl]
-source [file join $::ttk::library altTheme.tcl]
-source [file join $::ttk::library clamTheme.tcl]
+proc ttk::LoadThemes {} {
+ variable library
+
+ # "default" always present:
+ uplevel #0 [list source [file join $library defaults.tcl]]
+
+ set builtinThemes [style theme names]
+ foreach {theme script} {
+ classic classicTheme.tcl
+ alt altTheme.tcl
+ clam clamTheme.tcl
+ winnative winTheme.tcl
+ xpnative xpTheme.tcl
+ aqua aquaTheme.tcl
+ } {
+ if {[lsearch -exact $builtinThemes $theme] >= 0} {
+ uplevel #0 [list source [file join $library $script]]
+ }
+ }
+}
+
+ttk::LoadThemes; rename ::ttk::LoadThemes {}
-### Choose platform-specific default theme.
+### Select platform-specific default theme:
#
-# Notes:
-# + xpnative takes precedence over winnative if available.
+# Notes:
+# + On OSX, aqua theme is the default
+# + On Windows, xpnative takes precedence over winnative if available.
# + On X11, users can use the X resource database to
-# specify a preferred theme (*TkTheme: themeName)
+# specify a preferred theme (*TkTheme: themeName);
+# otherwise "default" is used.
#
-set ::ttk::defaultTheme "default"
+proc ttk::DefaultTheme {} {
+ set preferred [list aqua xpnative winnative]
-if {[package provide ttk::theme::winnative] != {}} {
- source [file join $::ttk::library winTheme.tcl]
- set ::ttk::defaultTheme "winnative"
-}
-if {[package provide ttk::theme::xpnative] != {}} {
- source [file join $::ttk::library xpTheme.tcl]
- set ::ttk::defaultTheme "xpnative"
-}
-if {[package provide ttk::theme::aqua] != {}} {
- source [file join $::ttk::library aquaTheme.tcl]
- set ::ttk::defaultTheme "aqua"
-}
+ set userTheme [option get . tkTheme TkTheme]
+ if {$userTheme != {} && ![catch {
+ uplevel #0 [list package require ttk::theme::$userTheme]
+ }]} {
+ return $userTheme
+ }
-set ::ttk::userTheme [option get . tkTheme TkTheme]
-if {$::ttk::userTheme != {}} {
- if {($::ttk::userTheme in [::ttk::style theme names])
- || ![catch {package require ttk::theme::$ttk::userTheme}]} {
- set ::ttk::defaultTheme $::ttk::userTheme
+ foreach theme $preferred {
+ if {[package provide ttk::theme::$theme] != ""} {
+ return $theme
+ }
}
+ return "default"
}
-::ttk::setTheme $::ttk::defaultTheme
+ttk::setTheme [ttk::DefaultTheme] ; rename ttk::DefaultTheme {}
#*EOF*