namespace eval ttk::theme::gtkTtk { variable PreviewInterp {} variable System variable StyleToRc proc loadLibraries {args} { if {![initialiseLibrary required]} {return} package require platform set libs {gdk gdk_pixbuf glib gobject gtk} switch -glob [::platform::generic] { *_64 { set paths { /usr/lib64 /usr/lib /opt/gnome/lib /usr/openwin/lib /usr/lib/x86_64-linux-gnu } } default { set paths { /usr/lib /opt/gnome/lib /usr/openwin/lib } } } set ext [info sharedlibextension] switch $::tcl_platform(platform) { windows { set sep \; set prefixes {{} lib} set names {-win32-2.0* -2.0* 20* -win32* * {}} } unix { set sep : set prefixes {lib} set names {-x11-2.0 -2.0 20 -x11 {}} lappend libs gdk_pixbuf_xlib } default {} } if {[info exists ::env(LD_LIBRARY_PATH)]} { foreach path [split $::env(LD_LIBRARY_PATH) $sep] { set path [string trim $path] if {[string length $path] && [file isdirectory $path]} { lappend paths $path } } } if {[info exists ::env(ProgramFiles)]} { foreach path [glob -nocomplain -dir $::env(ProgramFiles) *gtk*] { set path $path/bin if {[file isdirectory $path]} { lappend paths [file normalize $path] } } } set loaded 0 foreach lib $libs { set found 0 foreach name $names { foreach prefix $prefixes { foreach path $paths { if {$found} {break} if {![file isdirectory $path]} {continue} foreach file [glob -nocomplain -dir $path -type f \ ${prefix}${lib}${name}$ext] { if {$found} {break} if {[file exists $file]} { if {[catch {initialiseLibrary $lib $file} symbol]} { puts " => ERROR while initialising library $lib from $file : $symbol" } else { incr loaded; set found 1 break } };# if {[file exists $file]} };# foreach file ... };# foreach prefix $prefixes };# foreach name $names } } if {$loaded != [llength $libs]} { error "Not all symbols loaded!" } };# loadLibraries proc getSystemInfo {} { global env variable System set System(HOME) {} foreach var {HOME} { if {[info exists env($var)]} { set System($var) [file normalize $env($var)] break } } set System(GTK_RC_FILES) {} if {[info exists env(GTK_RC_FILES)]} { set System(GTK_RC_FILES) [file normalize $env(GTK_RC_FILES)] } elseif {[info exists env(HOME)]} { foreach rc [glob -nocomplain -dir $System(HOME) -type f .gtkrc*] { lappend System(GTK_RC_FILES) $rc } set System(GTK_RC_FILES) [lsort -dictionary $System(GTK_RC_FILES)] } set System(TEMP) {} foreach var {TEMP TMP temp tmp} { if {[info exists env($var)]} { set System(TEMP) [file normalize $env($var)] break } } if {![string length $System(TEMP)]} { foreach dir {/tmp} { if {[file isdirectory $dir] && [file writable $dir]} { set System(TEMP) $dir; break } } } set System(DEFAULT_FILES) [gtkDirectory default_files] };# getSystemInfo ## availableStyles_AsReturned: # Returns the available styles... proc availableStyles_AsReturned {} { variable StyleToRc variable System set styles {} foreach dir [list $System(HOME)/.themes [gtkDirectory theme]] { foreach theme [glob -nocomplain -type d -directory $dir *] { if {[file exists $theme/gtk-2.0/gtkrc]} { set style [file tail $theme] lappend styles $style set StyleToRc($style) [file normalize $theme/gtk-2.0/gtkrc] } } } return $styles };# availableStyles_AsReturned proc updateLayouts {} { ## Variable "theme" should be defined by the C part of the extension. variable theme variable GtkHScrollbar variable GtkVScrollbar if {![info exists theme]} {return} ttk::style theme use gtkTtk # puts "============================================================" # puts "Current Gtk Theme: [currentThemeName] ($theme)" # puts "Tab alignment: [getStyleHint -SH_TabBar_Alignment]" # puts "Tab base overlap: [getPixelMetric -PM_TabBarBaseOverlap]" # puts "Tab overlap: [getPixelMetric -PM_TabBarTabOverlap]" # foreach sc {SC_ScrollBarAddLine SC_ScrollBarSubLine # SC_ScrollBarAddPage SC_ScrollBarSubPage # SC_ScrollBarFirst SC_ScrollBarLast # SC_ScrollBarSlider SC_ScrollBarGroove} { # foreach {x y w h} [getSubControlMetrics -$sc] {break} # puts "$sc: x=$x, y=$y, w=$w, h=$h" # } ## ## Update the scrollbars layouts, according to information retrieved from ## the GTK style in use... ## ## has-backward-stepper: Display the standard backward arrow ## button. ## has-forward-stepper: Display the standard forward arrow ## button. ## has-secondary-backward-stepper: Display a second backward arrow button ## on the opposite end of the scrollbar. ## has-secondary-forward-stepper: Display a second forward arrow button ## on the opposite end of the scrollbar. foreach widget {GtkHScrollbar GtkVScrollbar} { foreach p {has-backward-stepper has-forward-stepper has-secondary-backward-stepper has-secondary-forward-stepper trough-under-steppers trough-side-details} { set ${widget}($p) [widgetStyleProperty $widget $p boolean] } foreach p {arrow-displacement-x arrow-displacement-y slider-width stepper-size stepper-spacing trough-border} { set ${widget}($p) [widgetStyleProperty $widget $p integer] } } # parray GtkHScrollbar # puts "============================================================" ## ## Dynamically create the scrollbars layouts... ## set Horizontal.Scrollbar.trough [list] if {$GtkHScrollbar(has-backward-stepper)} { lappend Horizontal.Scrollbar.trough \ Horizontal.Scrollbar.leftarrow -side left } if {$GtkHScrollbar(has-forward-stepper)} { lappend Horizontal.Scrollbar.trough \ Horizontal.Scrollbar.rightarrow -side right } if {$GtkHScrollbar(has-secondary-backward-stepper)} { lappend Horizontal.Scrollbar.trough \ Horizontal.Scrollbar.leftarrow -side right } if {$GtkHScrollbar(has-secondary-forward-stepper)} { lappend Horizontal.Scrollbar.trough \ Horizontal.Scrollbar.rightarrow -side left } lappend Horizontal.Scrollbar.trough \ Horizontal.Scrollbar.thumb -side left -expand true -sticky we ttk::style layout Horizontal.TScrollbar [list \ Horizontal.Scrollbar.trough -children ${Horizontal.Scrollbar.trough}] set Vertical.Scrollbar.trough [list] if {$GtkVScrollbar(has-backward-stepper)} { lappend Vertical.Scrollbar.trough \ Vertical.Scrollbar.uparrow -side top } if {$GtkVScrollbar(has-forward-stepper)} { lappend Vertical.Scrollbar.trough \ Vertical.Scrollbar.downarrow -side bottom } if {$GtkVScrollbar(has-secondary-backward-stepper)} { lappend Vertical.Scrollbar.trough \ Vertical.Scrollbar.uparrow -side bottom } if {$GtkVScrollbar(has-secondary-forward-stepper)} { lappend Vertical.Scrollbar.trough \ Vertical.Scrollbar.downarrow -side top } lappend Vertical.Scrollbar.trough \ Vertical.Scrollbar.thumb -side top -expand true -sticky ns ttk::style layout Vertical.TScrollbar \ [list Vertical.Scrollbar.trough -children ${Vertical.Scrollbar.trough}] }; # updateLayouts proc updateStyles {} { syncTkClassicPaletteAndFonts # puts [currentThemeColourKeys] ttk::style theme settings gtkTtk { ttk::style configure . \ -background [currentThemeColour bg(NORMAL)] \ -foreground [currentThemeColour fg(NORMAL)] \ -selectforeground [currentThemeColour fg(SELECTED)] \ -selectbackground [currentThemeColour bg(SELECTED)] \ -font TkDefaultFont \ ; # Configuration of the ttk::Treeview ttk::style map Treeview -foreground [list \ active [currentThemeColour fg(ACTIVE)] \ disabled [currentThemeColour fg(INSENSITIVE)] \ focus [currentThemeColour fg(PRELIGHT)] \ pressed [currentThemeColour fg(ACTIVE)] \ selected [currentThemeColour fg(SELECTED)] \ ] -background [list \ active [currentThemeColour bg(ACTIVE)] \ disabled [currentThemeColour bg(INSENSITIVE)] \ pressed [currentThemeColour bg(ACTIVE)] \ selected [currentThemeColour bg(SELECTED)] \ ] ttk::style map Treeview.Heading -foreground [list \ pressed [currentThemeColour bg(PRELIGHT)] \ ] -background [list \ pressed [currentThemeColour fg(PRELIGHT)] \ ] set tv_rowh [expr {[font metrics TkDefaultFont -linespace] + [spx 8]}] ttk::style configure Treeview.Heading -relief raised \ -font TkHeadingFont \ -background [currentThemeColour bg(ACTIVE)] \ -padding [list [spx 8] [spx 3] [spx 8] [spx 3]] ttk::style configure Treeview.Item \ -indicatormargins [list [spx 2] [spx 2] [spx 4] [spx 2]] \ -indicatorsize [spx 9] ttk::style configure Treeview \ -font TkDefaultFont \ -fieldbackground [currentThemeColour bg(INSENSITIVE)] \ -rowheight $tv_rowh set base_bg [ttk::style lookup . -background] set base_fg [ttk::style lookup . -foreground] set text_fg [ttk::style lookup Treeview -foreground] set select_bg [ttk::style lookup . -selectbackground] set select_fg [ttk::style lookup . -selectforeground] option add *Menu.Background $base_bg option add *Menu.Foreground $base_fg option add *Menu.activeBackground $select_bg option add *Menu.activeForeground $select_fg option add *Menu.selectColor $text_fg ttk::style configure TButton -font TkDefaultFont -anchor center -width -11 -padding [list [spx 9] [spx 3] [spx 9] [spx 3]] ttk::style configure TLabel -font TkDefaultFont ttk::style configure TCheckbutton -font TkDefaultFont -padding [list [spx 5] [spx 3] [spx 5] [spx 3]] ttk::style configure TCombobox -font TkTextFont -padding [list [spx 6] [spx 3] [spx 6] [spx 3]] ttk::style configure TEntry -font TkTextFont -padding [list [spx 6] [spx 3] [spx 6] [spx 3]] ttk::style configure TSpinbox -font TkTextFont -padding [list [spx 6] [spx 3] [spx 6] [spx 3]] ttk::style configure TLabelframe -background [currentThemeColour bg(NORMAL)] -labeloutside false -padding [spx 6] ttk::style configure TLabelframe.Label -font TkHeadingFont ttk::style configure TMenubutton -font TkDefaultFont -width -11 -padding [list [spx 8] [spx 3] [spx 8] [spx 3]] ## ## Notebook widget properties: ## tab-pos: Which side of the notebook holds the tabs ## tab-border: Width of the border around the tab labels ## tab-hborder: Width of the horizontal border of tab labels ## tab-vborder: Width of the vertical border of tab labels ## homogeneous: Whether tabs should have homogeneous sizes ## tab-overlap: Size of tab overlap area ## tab-curvature: Size of tab curvature ## arrow-spacing: Scroll arrow spacing ## set tab_overlap [widgetStyleProperty GtkNotebook tab-overlap integer] set tab_curvature [widgetStyleProperty GtkNotebook tab-curvature integer] set homogeneous [widgetProperty GtkNotebook homogeneous boolean] set tab_pos [gtkEnum GtkPositionType \ [widgetProperty GtkNotebook tab-pos integer]] set tab_base_overlap 0 switch -exact $tab_pos { GTK_POS_TOP {set tabposition nw} GTK_POS_BOTTOM {set tabposition sw} GTK_POS_LEFT {set tabposition nw} GTK_POS_RIGHT {set tabposition ne} default {set tabposition nw} } ttk::style configure TNotebook -tabmargins \ [list $tab_overlap 0 $tab_overlap $tab_base_overlap] \ -tabposition $tabposition ttk::style configure TNotebook.Tab -font TkDefaultFont -padding [list [spx 10] [spx 3] [spx 10] [spx 3]] ttk::style map TNotebook.Tab -expand [list selected \ [list $tab_overlap 0 $tab_overlap $tab_base_overlap]] ttk::style configure TRadiobutton -font TkDefaultFont -padding [list [spx 5] [spx 3] [spx 5] [spx 3]] ttk::style configure Toolbutton -font TkDefaultFont -anchor center -padding [list [spx 6] [spx 3] [spx 6] [spx 3]] ttk::style configure TPaned -background [currentThemeColour bg(NORMAL)] ttk::style configure Horizontal.Sash -background [currentThemeColour \ bg(NORMAL)] ttk::style configure Vertical.Sash -background [currentThemeColour \ bg(NORMAL)] };# ttk::style theme settings gtkTtk # puts "\nPixel Metric Information:" # foreach pm {PM_TabBarTabOverlap PM_TabBarTabHSpace # PM_TabBarTabVSpace PM_TabBarBaseHeight # PM_TabBarBaseOverlap PM_TabBarTabShiftHorizontal # PM_TabBarTabShiftVertical PM_TabBarScrollButtonWidth # PM_DefaultFrameWidth} { # puts "$pm: [getPixelMetric -$pm]" # } };# updateStyles ## updateColourPalette: # This procedure will be called from gtkTtk core each time a message is # received from KDE to change the palette used. proc updateColourPalette {} { return # puts >>updateColourPalette foreach filename [kdeLocate_kdeglobals] { if {[file exists $filename]} { set file [open $filename] while {[gets $file line] != -1} { set line [string trim $line] switch -glob $line { contrast=* { if {![info exists options(-contrast)]} { set options(-contrast) [string range $line 9 end] } } background=* { if {![info exists options(-background)]} { set options(-background) [kdeGetColourHex $line] } } foreground=* { if {![info exists options(-foreground)]} { set options(-foreground) [kdeGetColourHex $line] } } buttonBackground=* { if {![info exists options(-buttonBackground)]} { set options(-buttonBackground) [kdeGetColourHex $line] } } buttonForeground=* { if {![info exists options(-buttonForeground)]} { set options(-buttonForeground) [kdeGetColourHex $line] } } selectBackground=* { if {![info exists options(-selectBackground)]} { set options(-selectBackground) [kdeGetColourHex $line] } } selectForeground=* { if {![info exists options(-selectForeground)]} { set options(-selectForeground) [kdeGetColourHex $line] } } windowBackground=* { if {![info exists options(-windowBackground)]} { set options(-windowBackground) [kdeGetColourHex $line] } } windowForeground=* { if {![info exists options(-windowForeground)]} { set options(-windowForeground) [kdeGetColourHex $line] } } linkColor=* { if {![info exists options(-linkColor)]} { set options(-linkColor) [kdeGetColourHex $line] } } visitedLinkColor=* { if {![info exists options(-visitedLinkColor)]} { set options(-visitedLinkColor) [kdeGetColourHex $line] } } } } close $file } } if {[info exists options]} { eval setPalette [array get options] } };# updateColourPalette ## kdeStyleChangeNotification: # This procedure will be called from gtkTtk core each time a message is # received from KDE to change the style used. proc kdeStyleChangeNotification {} { return # puts >>kdeStyleChangeNotification ## This method will be called each time a ClientMessage is received from ## KDE KIPC... ## Our Job is: ## a) To get the current style from KDE, and ## b) Apply it. foreach filename [kdeLocate_kdeglobals] { if {[file exists $filename]} { set file [open $filename] while {[gets $file line] != -1} { set line [string trim $line] if {[string match widgetStyle*=* $line]} { # We have found the style! set index [string first = $line]; incr index set style [string range $line $index end] if {[string length $style]} { close $file applyStyle $style return } } } close $file } } };# kdeStyleChangeNotification ## applyStyle: # This procedure can be used to apply any available GTK+ style. # Ths "style" parameter must be a string from the style names returned by # ttk::theme::gtkTtk::availableStyles. proc applyStyle {style} { variable StyleToRc variable System if {![info exists StyleToRc($style)]} { error "unknown GTK style: \"$style\"" } ## ## In order to force a style update, we need to create an rc file, and force ## GTK to load it... ## set rc [file normalize $System(TEMP)/gtkrc.gtkTtk-[pid]] set fd [open $rc w] puts $fd {# -- THEME AUTO-WRITTEN DO NOT EDIT} puts $fd "include \"$StyleToRc($style)\"" puts $fd "include \"$System(HOME)/.gtkrc.mine\"" puts $fd {# -- THEME AUTO-WRITTEN DO NOT EDIT} close $fd ## ## Set it as the default file... ## set default_files [gtkDirectory default_files] gtkDirectory default_files [list $rc] gtk_method gtk_rc_reparse_all_for_settings gtk_method gtk_rc_reset_styles #gtkDirectory default_files $default_files puts $StyleToRc($style) updateColourPalette updateStyles updateLayouts event generate {} <> file delete -force $rc };# applyStyle ## kdePaletteChangeNotification: # This procedure will be called from gtkTtk core each time a message is # received from KDE to change the palette used. proc kdePaletteChangeNotification {} { return # puts >>kdePaletteChangeNotification kdeStyleChangeNotification };# kdePaletteChangeNotification proc kdeGetColourHex {line} { set index [string first = $line]; incr index set value [string range $line $index end] foreach {r g b} [split $value ,] {break} return [format #%02X%02X%02X $r $g $b] };# kdeGetColourHex ## createThemeConfigurationPanel: # This method will create a configuration panel for the gtkTtk theme in the # provided frame widget. proc createThemeConfigurationPanel {dlgFrame} { ## The first element in our panel, is a combobox, with all the available ## GTK+ styles. ttk::labelframe $dlgFrame.style_selection -text "GTK+ Style:" ttk::combobox $dlgFrame.style_selection.style -state readonly $dlgFrame.style_selection.style set [currentThemeName] bind $dlgFrame.style_selection.style <> \ {%W set [ttk::theme::gtkTtk::currentThemeName]} bind $dlgFrame.style_selection.style \ {%W configure -values [ttk::theme::gtkTtk::availableStyles]} ttk::button $dlgFrame.style_selection.apply -text Apply -command \ "ttk::theme::gtkTtk::applyStyle \[$dlgFrame.style_selection.style get\]" grid $dlgFrame.style_selection.style $dlgFrame.style_selection.apply \ -padx 2 -sticky snew grid columnconfigure $dlgFrame.style_selection 0 -weight 1 pack $dlgFrame.style_selection -fill x -expand 0 -padx 2 -pady 2 ## The second element of our panel, is a preview area. Since tile does not ## allow us to use a different theme for some widgets, we start a new wish ## session through a pipe, and we embed its window in our dialog. Then, we ## instrument this second wish through the pipe... ttk::labelframe $dlgFrame.preview -text "Preview:" variable PreviewInterp if {[string length $PreviewInterp]} { frame $dlgFrame.preview.container pack [label $dlgFrame.preview.container.lbl \ -text {Preview Unavailable!}] -fill both -expand 1 } else { frame $dlgFrame.preview.container -container 1 -height 250 -width 400 ## Create a slave interpreter, and load gtkTtk. Widgets in this interp ## may be of a different widget style! set PreviewInterp [interp create] interp eval $PreviewInterp {package require Tk} interp eval $PreviewInterp " wm withdraw . set auto_path \{$::auto_path\} if {[catch {package require Ttk}]} { package require tile } ttk::setTheme gtkTtk # package require ttk::theme::gtkTtk ttk::theme::gtkTtk::applyStyle \{[currentThemeName]\} toplevel .widgets -height 250 -width 400 \ -use [winfo id $dlgFrame.preview.container] ttk::theme::gtkTtk::selectStyleDlg_previewWidgets .widgets " bind $dlgFrame.preview.container \ "ttk::theme::gtkTtk::destroyThemeConfigurationPanel" bind $dlgFrame.style_selection.style <> \ {ttk::theme::gtkTtk::updateThemeConfigurationPanel [%W get]} } pack $dlgFrame.preview.container -padx 0 -pady 0 -fill both -expand 1 pack $dlgFrame.preview -fill both -expand 1 -padx 2 -pady 2 };# createThemeConfigurationPanel proc destroyThemeConfigurationPanel {} { variable PreviewInterp interp delete $PreviewInterp set PreviewInterp {} };# destroyThemeConfigurationPanel proc updateThemeConfigurationPanel {style} { variable PreviewInterp interp eval $PreviewInterp "ttk::theme::gtkTtk::applyStyle \{$style\}" };# updateThemeConfigurationPanel proc selectStyleDlg_previewWidgets {{win {}}} { ## Create a notebook widget... ttk::notebook $win.nb -padding 6 set tab1 [ttk::frame $win.nb.tab1] $win.nb add $tab1 -text "Tab 1" -underline 4 -sticky news set tab2 [ttk::frame $win.nb.tab2] $win.nb add $tab2 -text "Tab 2" -underline 4 -sticky news set tab3 [ttk::frame $win.nb.tab3] $win.nb add $tab3 -text "Tab 3" -underline 4 -sticky news set tab4 [ttk::frame $win.nb.tab4] $win.nb add $tab4 -text "Tab 4" -underline 4 -sticky news ## Fill tab1... ##################### ttk::panedwindow $tab1.panedwindow -orient horizontal ## Add a set of radiobuttons to the left... ttk::labelframe $tab1.panedwindow.buttons -text " Button Group " ttk::radiobutton $tab1.panedwindow.buttons.b1 -text "Radio button" \ -variable ttk::theme::gtkTtk::temp(selectionVariable) -value 1 ttk::radiobutton $tab1.panedwindow.buttons.b2 -text "Radio button" \ -variable ttk::theme::gtkTtk::temp(selectionVariable) -value 2 ttk::radiobutton $tab1.panedwindow.buttons.b3 -text "Radio button" \ -variable ttk::theme::gtkTtk::temp(selectionVariable) -value 3 ttk::separator $tab1.panedwindow.buttons.sep -orient horizontal ttk::checkbutton $tab1.panedwindow.buttons.b4 -text "Checkbox" $tab1.panedwindow.buttons.b4 state selected set ttk::theme::gtkTtk::temp(selectionVariable) 1 grid $tab1.panedwindow.buttons.b1 -sticky snew -padx 2 -pady 2 grid $tab1.panedwindow.buttons.b2 -sticky snew -padx 2 -pady 2 grid $tab1.panedwindow.buttons.b3 -sticky snew -padx 2 -pady 2 grid $tab1.panedwindow.buttons.sep -sticky snew -padx 2 -pady 2 grid $tab1.panedwindow.buttons.b4 -sticky snew -padx 2 -pady 2 grid columnconfigure $tab1.panedwindow.buttons 0 -weight 1 $tab1.panedwindow add $tab1.panedwindow.buttons ## Add a set of other widgets (like progress, combo, scale, etc). ttk::frame $tab1.panedwindow.widgets ttk::progressbar $tab1.panedwindow.widgets.progress -orient horizontal \ -maximum 100 -variable ttk::theme::gtkTtk::temp(progress) grid $tab1.panedwindow.widgets.progress -sticky snew -padx 2 -pady 2 ttk::scale $tab1.panedwindow.widgets.scale -orient horizontal -from 0 \ -to 100 -variable ttk::theme::gtkTtk::temp(progress) set ttk::theme::gtkTtk::temp(progress) 70 grid $tab1.panedwindow.widgets.scale -sticky snew -padx 2 -pady 2 ttk::entry $tab1.panedwindow.widgets.entry -textvariable \ ttk::theme::gtkTtk::temp(entry) set ttk::theme::gtkTtk::temp(entry) {Entry Widget} grid $tab1.panedwindow.widgets.entry -sticky snew -padx 2 -pady 2 ttk::button $tab1.panedwindow.widgets.button -text Button grid $tab1.panedwindow.widgets.button -sticky snew -padx 2 -pady 2 ttk::combobox $tab1.panedwindow.widgets.combo -values \ {{Selection 1} {Selection 2} {Selection 3} {Selection 4}} $tab1.panedwindow.widgets.combo set {Selection 1} grid $tab1.panedwindow.widgets.combo -sticky snew -padx 2 -pady 2 grid columnconfigure $tab1.panedwindow.widgets 0 -weight 1 $tab1.panedwindow add $tab1.panedwindow.widgets grid $tab1.panedwindow -padx 2 -pady 2 -sticky snew ttk::sizegrip $tab1.sg ttk::scrollbar $tab1.hsb -orient horizontal grid $tab1.hsb $tab1.sg -padx 2 -pady 2 -sticky snew ttk::scrollbar $tab1.vsb -orient vertical grid $tab1.vsb -row 0 -column 1 -padx 2 -pady 2 -sticky snew grid columnconfigure $tab1 0 -weight 1 grid rowconfigure $tab1 0 -weight 1 ## Fill tab2... ##################### ttk::panedwindow $tab2.panedwindow -orient vertical ttk::label $tab2.panedwindow.label -text {Label Widget} $tab2.panedwindow add $tab2.panedwindow.label ttk::treeview $tab2.panedwindow.tree -height 4 $tab2.panedwindow add $tab2.panedwindow.tree grid $tab2.panedwindow -padx 2 -pady 2 -sticky snew grid columnconfigure $tab2 0 -weight 1 grid rowconfigure $tab2 0 -weight 1 pack $win.nb -fill both -expand 1 };# selectStyleDlg_previewWidgets proc availableStyles {} { return [lsort -dictionary [availableStyles_AsReturned]] };# availableStyles ## Test the theme configuration panel... if {0 && ![info exists ::testConfigurationPanel]} { toplevel .themeConfPanel wm withdraw .themeConfPanel wm title .themeConfPanel "GtkTtk Configuration Panel..." frame .themeConfPanel.page createThemeConfigurationPanel .themeConfPanel.page update pack .themeConfPanel.page -fill both -expand 1 wm deiconify .themeConfPanel } proc getStyleColourInformation {} { foreach colour {fg_color bg_color base_color text_color selected_bg_color selected_fg_color tooltip_bg_color tooltip_fg_color} { catch {set C($colour) [currentThemeColour $colour]} e } foreach prefix {fg bg base text} { foreach state {NORMAL PRELIGHT ACTIVE SELECTED INSENSITIVE} { set colour ${prefix}($state) catch {set C($colour) [currentThemeColour $colour]} e } } return [array get C] };# getStyleColourInformation variable prevClassicPalette if {![info exists prevClassicPalette]} { array set prevClassicPalette {} } variable prevClassicGeom if {![info exists prevClassicGeom]} { array set prevClassicGeom {} } proc getDpiAndScale {} { set home [expr {[info exists ::env(HOME)] ? $::env(HOME) : "/home/user"}] set xres [file join $home .Xresources] if {![file readable $xres] && [file readable /etc/skel/.Xresources]} { set xres /etc/skel/.Xresources } set xft_dpi "" set base_sz "" if {[file readable $xres]} { set fd [open $xres r] set data [read $fd] close $fd foreach line [split $data "\n"] { set line [string trim $line] if {$line eq "" || [string match "!*" $line] || [string match "#*" $line]} { continue } if {[regexp {^Xft\.dpi\s*:\s*([0-9]+(?:\.[0-9]+)?)} $line -> v]} { set xft_dpi $v } elseif {[regexp {^theme\.baseFontSize\s*:\s*([0-9]+)} $line -> v]} { set base_sz $v } } } if {$xft_dpi eq "" || $xft_dpi <= 0} { set sw [winfo screenwidth .] set mm [winfo screenmmwidth .] if {$mm > 0 && $sw > 0} { set dpi [expr {double($sw) * 25.4 / double($mm)}] } else { set dpi 96.0 } } else { set dpi [expr {double($xft_dpi)}] } if {$dpi < 72.0} { set dpi 72.0 } catch {tk scaling [expr {$dpi / 72.0}]} set scale "" if {[info exists ::env(GTKTTK_SCALE)] && [string is double -strict $::env(GTKTTK_SCALE)] && $::env(GTKTTK_SCALE) > 0} { set scale [expr {double($::env(GTKTTK_SCALE))}] if {$scale < 0.5} { set scale 0.5 } if {$scale > 8.0} { set scale 8.0 } } elseif {[info exists ::env(GDK_SCALE)] && [string is double -strict $::env(GDK_SCALE)] && $::env(GDK_SCALE) > 0} { set scale [expr {double($::env(GDK_SCALE))}] if {[info exists ::env(GDK_DPI_SCALE)] && [string is double -strict $::env(GDK_DPI_SCALE)] && $::env(GDK_DPI_SCALE) > 0} { set scale [expr {$scale * double($::env(GDK_DPI_SCALE))}] } if {$scale < 1.0} { set scale 1.0 } if {$scale > 4.0} { set scale 4.0 } } elseif {[info exists ::env(QT_SCALE_FACTOR)] && [string is double -strict $::env(QT_SCALE_FACTOR)] && $::env(QT_SCALE_FACTOR) > 0} { set scale [expr {double($::env(QT_SCALE_FACTOR))}] if {$scale < 1.0} { set scale 1.0 } if {$scale > 4.0} { set scale 4.0 } } else { set scale [expr {$dpi / 96.0}] if {$scale < 1.0} { set scale 1.0 } if {$scale > 4.0} { set scale 4.0 } } return [list $dpi $scale $base_sz] };# getDpiAndScale proc spx {px} { if {$px <= 0} { return 0 } lassign [getDpiAndScale] dpi scale base_sz set v [expr {int(round(double($px) * $scale))}] return [expr {$v < 1 ? 1 : $v}] };# spx proc syncTkClassicPaletteAndFonts {} { variable prevClassicPalette variable prevClassicGeom variable scaledNamedFonts lassign [getDpiAndScale] dpi scale base_sz array set nextPal [list \ base_bg [currentThemeColour bg(NORMAL)] \ base_fg [currentThemeColour fg(NORMAL)] \ active_bg [currentThemeColour bg(PRELIGHT)] \ active_fg [currentThemeColour fg(PRELIGHT)] \ select_bg [currentThemeColour bg(SELECTED)] \ select_fg [currentThemeColour fg(SELECTED)] \ entry_bg [currentThemeColour base(NORMAL)] \ entry_fg [currentThemeColour text(NORMAL)] \ dis_fg [currentThemeColour fg(INSENSITIVE)] \ ] set base_bg $nextPal(base_bg) set base_fg $nextPal(base_fg) set active_bg $nextPal(active_bg) set active_fg $nextPal(active_fg) set select_bg $nextPal(select_bg) set select_fg $nextPal(select_fg) set entry_bg $nextPal(entry_bg) set entry_fg $nextPal(entry_fg) set dis_fg $nextPal(dis_fg) array set nextGeom [list \ btn_padx [spx 10] \ btn_pady [spx 4] \ chk_padx [spx 6] \ chk_pady [spx 4] \ rad_padx [spx 6] \ rad_pady [spx 4] \ mb_padx [spx 8] \ mb_pady [spx 4] \ sb_width [spx 15] \ sc_width [spx 14] \ sc_len [spx 24] \ bw_px [spx 1] \ ] set queue [list .] while {[llength $queue] > 0} { set w [lindex $queue 0] set queue [lrange $queue 1 end] if {![winfo exists $w]} { continue } foreach child [winfo children $w] { lappend queue $child } if {![catch {$w cget -style}]} { continue } set cls [winfo class $w] if {$cls in {Entry Text Listbox Canvas Spinbox}} { set w_bg_role entry_bg set w_fg_role entry_fg } else { set w_bg_role base_bg set w_fg_role base_fg } foreach {opt role} [list \ -background $w_bg_role \ -foreground $w_fg_role \ -activebackground active_bg \ -activeforeground active_fg \ -selectbackground select_bg \ -selectforeground select_fg \ -disabledforeground dis_fg \ -highlightbackground base_bg \ -highlightcolor select_bg \ -insertbackground $w_fg_role \ -troughcolor active_bg] { if {![info exists nextPal($role)] || $nextPal($role) eq ""} { continue } if {[catch {$w configure $opt} cfg] == 0 && [llength $cfg] == 5} { set def_val [lindex $cfg 3] set cur_val [lindex $cfg 4] set matched 0 if {$cur_val eq $def_val} { set matched 1 } elseif {[catch {winfo rgb . $cur_val} cur_rgb] == 0 && \ [catch {winfo rgb . $def_val} def_rgb] == 0 && \ $cur_rgb eq $def_rgb} { set matched 1 } elseif {[info exists prevClassicPalette($role)] && $prevClassicPalette($role) ne ""} { set prev_val $prevClassicPalette($role) if {$cur_val eq $prev_val} { set matched 1 } elseif {[catch {winfo rgb . $cur_val} cur_rgb] == 0 && \ [catch {winfo rgb . $prev_val} prev_rgb] == 0 && \ $cur_rgb eq $prev_rgb} { set matched 1 } } if {$matched} { catch {$w configure $opt $nextPal($role)} } } } set gpairs {} switch -exact $cls { Button { set gpairs [list -padx btn_padx -pady btn_pady] } Checkbutton { set gpairs [list -padx chk_padx -pady chk_pady] } Radiobutton { set gpairs [list -padx rad_padx -pady rad_pady] } Menubutton { set gpairs [list -padx mb_padx -pady mb_pady] } Scrollbar { set gpairs [list -width sb_width] } Scale { set gpairs [list -width sc_width -sliderlength sc_len] } } foreach {opt grole} $gpairs { if {[catch {$w configure $opt} cfg] == 0 && [llength $cfg] == 5} { set def_val [lindex $cfg 3] set cur_val [lindex $cfg 4] set matched 0 if {$cur_val eq $def_val} { set matched 1 } elseif {[catch {winfo pixels $w $cur_val} cur_px] == 0 && \ [catch {winfo pixels $w $def_val} def_px] == 0 && \ $cur_px == $def_px} { set matched 1 } elseif {[info exists prevClassicGeom($grole)] && $prevClassicGeom($grole) ne ""} { set pval $prevClassicGeom($grole) if {$cur_val eq $pval} { set matched 1 } elseif {[catch {winfo pixels $w $cur_val} cur_px] == 0 && \ [catch {winfo pixels $w $pval} prev_px] == 0 && \ $cur_px == $prev_px} { set matched 1 } } if {$matched} { catch {$w configure $opt $nextGeom($grole)} } } } } array set prevClassicPalette [array get nextPal] array set prevClassicGeom [array get nextGeom] foreach {pat val} [list \ *borderWidth $nextGeom(bw_px) \ *Button.padX $nextGeom(btn_padx) \ *Button.padY $nextGeom(btn_pady) \ *Checkbutton.padX $nextGeom(chk_padx) \ *Checkbutton.padY $nextGeom(chk_pady) \ *Radiobutton.padX $nextGeom(rad_padx) \ *Radiobutton.padY $nextGeom(rad_pady) \ *Menubutton.padX $nextGeom(mb_padx) \ *Menubutton.padY $nextGeom(mb_pady) \ *Scrollbar.width $nextGeom(sb_width) \ *Scale.width $nextGeom(sc_width) \ *Scale.sliderLength $nextGeom(sc_len) \ *background $base_bg \ *foreground $base_fg \ *activeBackground $active_bg \ *activeForeground $active_fg \ *selectBackground $select_bg \ *selectForeground $select_fg \ *disabledForeground $dis_fg \ *highlightBackground $base_bg \ *highlightColor $select_bg \ *troughColor $active_bg \ *insertBackground $entry_fg \ *Entry.background $entry_bg \ *Entry.foreground $entry_fg \ *Text.background $entry_bg \ *Text.foreground $entry_fg \ *Listbox.background $entry_bg \ *Listbox.foreground $entry_fg \ *Canvas.background $entry_bg \ *Menu.background $base_bg \ *Menu.foreground $base_fg \ *Menu.activeBackground $select_bg \ *Menu.activeForeground $select_fg \ *Menu.selectColor $entry_fg \ *Font TkDefaultFont \ *font TkDefaultFont \ *Entry.font TkTextFont \ *Spinbox.font TkTextFont \ *Text.font TkFixedFont \ *Listbox.font TkDefaultFont \ *TCombobox*Listbox.font TkTextFont \ *Menu.font TkMenuFont] { catch {option add $pat $val widgetDefault} } set fam "Fira Code" catch { set cur_fam [font configure TkDefaultFont -family] if {$cur_fam ne ""} { set fam $cur_fam } } set rc_pt 10 if {![catch {set font_spec [settingsProperty gtk-font-name string]}] && $font_spec ne ""} { set parts [split [string trim $font_spec]] if {[llength $parts] >= 2 && [string is double -strict [lindex $parts end]]} { set rc_pt [lindex $parts end] set fam [join [lrange $parts 0 end-1] " "] } elseif {[llength $parts] >= 1} { set fam [join $parts " "] } } if {[string is integer -strict $base_sz] && $base_sz >= 10} { set px_main [expr {int(round(($base_sz + 10) * ($scale / 1.88)))}] } elseif {$rc_pt <= 12 && $scale > 1.3} { set px_main [expr {int(round($rc_pt * ($dpi / 72.0) * ($scale * 0.85)))}] } else { set px_main [expr {int(round($rc_pt * ($dpi / 72.0)))}] } if {$px_main < 10} { set px_main 10 } set px_head [expr {$px_main + 4}] set px_small [expr {$px_main - 5}] if {$px_small < 10} { set px_small 10 } foreach tkfont {TkDefaultFont TkTextFont TkFixedFont TkMenuFont TkIconFont} { catch {font configure $tkfont -family $fam -size [expr {-$px_main}]} } foreach tkfont {TkHeadingFont TkCaptionFont} { catch {font configure $tkfont -family $fam -size [expr {-$px_head}] -weight bold} } foreach tkfont {TkSmallCaptionFont TkTooltipFont} { catch {font configure $tkfont -family $fam -size [expr {-$px_small}]} } scaleExistingAppFonts };# syncTkClassicPaletteAndFonts proc ptToScaledPx {pt factor} { set px [expr {int(round(double($pt) * $factor))}] return [expr {$px < 10 ? 10 : $px}] };# ptToScaledPx proc scaleExistingAppFonts {} { variable scaledNamedFonts lassign [getDpiAndScale] dpi scale base_sz if {$scale <= 1.3} { return } set builtins { TkDefaultFont TkTextFont TkFixedFont TkMenuFont TkHeadingFont TkCaptionFont TkSmallCaptionFont TkIconFont TkTooltipFont } set factor [expr {($dpi / 72.0) * ($scale * 0.85)}] foreach fn [font names] { if {$fn in $builtins} { continue } set sz "" if {[catch {set sz [font configure $fn -size]}]} { continue } if {[string is integer -strict $sz] && $sz > 0 && $sz <= 32} { set scaledNamedFonts($fn) $sz catch {font configure $fn -size [expr {-[ptToScaledPx $sz $factor]}]} } } set knownFonts [font names] set queue [list .] while {[llength $queue] > 0} { set w [lindex $queue 0] set queue [lrange $queue 1 end] if {![winfo exists $w]} { continue } foreach child [winfo children $w] { lappend queue $child } if {[catch {set wf [$w cget -font]}]} { continue } if {$wf eq "" || ($wf in $knownFonts)} { continue } if {[regexp {(?:^|\s|-size\s+)-[0-9]+} $wf]} { continue } set new_wf "" if {![catch {set n [llength $wf]}]} { if {$n >= 2 && [expr {$n % 2 == 0}] && [string match -* [lindex $wf 0]]} { set idx [lsearch -exact $wf -size] if {$idx >= 0 && ($idx + 1) < $n} { set pt [lindex $wf [expr {$idx + 1}]] if {[string is double -strict $pt] && $pt > 0 && $pt <= 32} { set px [ptToScaledPx $pt $factor] set new_wf [lreplace $wf [expr {$idx + 1}] [expr {$idx + 1}] [expr {-$px}]] } } } elseif {$n >= 2 && [string is double -strict [lindex $wf 1]]} { set pt [lindex $wf 1] if {$pt > 0 && $pt <= 32} { set px [ptToScaledPx $pt $factor] set new_wf [lreplace $wf 1 1 [expr {-$px}]] } } } if {$new_wf ne ""} { catch {$w configure -font $new_wf} } } };# scaleExistingAppFonts proc syncGtkRcSettings {} { set home [expr {[info exists ::env(HOME)] ? $::env(HOME) : "/home/user"}] set rcfile [file join $home .gtkrc-2.0] if {![file readable $rcfile] && [file readable /etc/skel/.gtkrc-2.0]} { set rcfile /etc/skel/.gtkrc-2.0 } if {[file readable $rcfile]} { set fd [open $rcfile r] set data [read $fd] close $fd set tname "" set fname "" foreach line [split $data "\n"] { set line [string trim $line] if {[regexp {^gtk-theme-name\s*=\s*"?([^"]+)"?} $line -> m]} { set tname [string trim $m] } elseif {[regexp {^gtk-font-name\s*=\s*"?([^"]+)"?} $line -> m]} { set fname [string trim $m] } } gtkDirectory default_files [list $rcfile] if {$tname ne ""} { set themeRc [file join $home .themes $tname gtk-2.0 gtkrc] if {![file readable $themeRc] && [file readable [file join /etc/skel .themes $tname gtk-2.0 gtkrc]]} { set themeRc [file join /etc/skel .themes $tname gtk-2.0 gtkrc] } if {[file readable $themeRc]} { gtkDirectory default_files [list $themeRc $rcfile] } catch {setSettingsString gtk-theme-name $tname} variable theme $tname } if {$fname ne ""} { catch {setSettingsString gtk-font-name $fname} } catch {gtk_method gtk_rc_reparse_all_for_settings} catch {gtk_method gtk_rc_reset_styles} } };# syncGtkRcSettings proc reloadCurrentGtkTheme {} { getSystemInfo availableStyles_AsReturned syncGtkRcSettings if {[ttk::style theme use] eq "gtkTtk"} { updateLayouts updateStyles event generate . <> } };# reloadCurrentGtkTheme ## Update layouts on load... proc init {} { getSystemInfo availableStyles_AsReturned syncGtkRcSettings updateLayouts updateStyles catch {after idle ::ttk::theme::gtkTtk::scaleExistingAppFonts} };# init }