36 package require Tcl 8.5
37 package require Tk 8.5
38 if {$tcl_version == 8.5} {
catch {
package require img::png}}
40 set scidVersion [
sc_info version]
41 set scidVersionDate [
sc_info version date]
42 set scidVersionExpected "4.7.0"
46 if {[
string compare $::scidVersion $::scidVersionExpected]} {
48 set msg "This is Scid version $::scidVersion, but the scid GUI (tcl/tk code)\n"
49 append msg "has the version number $scidVersionExpected.\n"
50 tk_messageBox -type ok -icon error -title "Scid: Version Error" -message $msg
57 if {$tcl_platform(platform) == "windows"} {
set windowsOS 1}
59 if {$tcl_platform(platform) == "unix"} {
set unixOS 1}
61 if {![
catch {tk windowingsystem} wsystem] && $wsystem == "aqua"} {
set macOS 1}
64 global scidExeDir scidUserDir scidConfigDir scidDataDir scidLogDir scidShareDir scidImgDir scidTclDir
65 global scidBooksDir scidBasesDir ecoFile
69 set scidExecutable [
info nameofexecutable]
70 if {[
file type $scidExecutable] == "link"} {
71 set scidExeDir [
file dirname [
file readlink $scidExecutable]]
72 if {[
file pathtype $scidExeDir] == "relative"} {
73 set scidExeDir [
file dirname [
file join [
file dirname $scidExecutable]\
74 [
file readlink $scidExecutable]]]
77 set scidExeDir [
file dirname $scidExecutable]
83 set scidUserDir $scidExeDir
85 regexp {(\d+\.\d+).*} $::scidVersion -> version
86 set scidUserDir [
file nativename "~/.scid$version"]
91 set scidConfigDir [
file nativename [
file join $scidUserDir "config"]]
92 set scidDataDir [
file nativename [
file join $scidUserDir "data"]]
93 set scidLogDir [
file nativename [
file join $scidUserDir "log"]]
97 set scidShareDir [
file normalize [
file join $scidExeDir "../share/scid"]]
98 if {! [
file isdirectory $::scidShareDir]} {
99 set scidShareDir $::scidExeDir
101 set scidTclDir [
file nativename [
file join $scidShareDir "tcl"]]
102 if {! [
file isdirectory $scidTclDir]} {
103 set scidTclDir [
file dirname [
info script]]
104 set scidShareDir [
file normalize "$scidTclDir/../"]
106 set scidImgDir [
file nativename [
file join $scidShareDir "img"]]
109 set scidBooksDir [
file nativename [
file join $scidShareDir "books"]]
110 set scidBasesDir [
file nativename [
file join $scidShareDir "bases"]]
111 set ecoFile [
file nativename [
file join $scidShareDir "scid.eco"]]
113 proc moveOldConfigFiles {} {
116 global scidUserDir scidConfigDir
119 if {[
file isfile $scidUserDir]} {
120 file rename -force $scidUserDir "$scidUserDir.old"
124 if {[
file isfile [
file nativename "~/.scid_sent_emails"]]} {
125 catch {
file rename [
file nativename "~/.scid_sent_emails"] $email(logfile)}
128 foreach {oldname newname} {
131 scid.bkm bookmarks.dat
132 scid.rfl recentfiles.dat
133 engines.lis engines.dat
135 set oldpath [
file nativename [
file join $scidUserDir $oldname]]
136 set newpath [
file nativename [
file join $scidConfigDir $newname]]
137 if {[
file readable $oldpath] && ![
file readable $newpath]} {
138 if {[
catch {
file rename $oldpath $newpath} err]} {
139 tk_messageBox -message "Error moving $oldpath to $newpath: $err"
147 proc makeScidDir {dir} {
148 if {! [
file isdirectory $dir]} {
170 ::utils::date ::utils::font ::utils::history ::utils::pane ::utils::string
171 ::utils::sound ::utils::validate ::utils::win
173 ::file::finder ::file::maint ::maint
179 ::search::filter ::search::board ::search::header ::search::material
181 ::windows::gamelist ::windows::stats ::tree ::tree::mask ::windows::tree
182 ::windows::switcher ::windows::eco ::crosstab ::pgn ::book
183 ::windows::commenteditor
185 ::tools::analysis ::tools::email
187 ::tools::graphs::filter ::tools::graphs::absfilter ::tools::graphs::rating ::tools::graphs::score
190 ::tacgame ::sergame ::opening ::tactics ::calvar ::uci ::fics ::reviewgame ::novag
196 namespace eval $ns {}
199 proc ::splash::add {text} {
206 catch {
tk_getOpenFile -with-invalid-argument}
207 namespace eval ::tk::dialog::file {
208 variable showHiddenBtn 1
209 variable showHiddenVar 0
235 proc safeSource {filename args} {
236 if {![
info exists ::safeInterp]} {
237 set ::safeInterp [::safe::interpCreate]
238 interp hide $::safeInterp set
239 interp alias $::safeInterp set {} ::safeSet $::safeInterp
241 set f [
file nativename "$filename"]
242 set d [
file dirname $f]
244 foreach {varname value} $args {
245 $::safeInterp eval [list set $varname $value]
247 $::safeInterp eval [list set vdir [::safe::interpAddToAccessPath $::safeInterp $d]]
248 $::safeInterp eval "source \$vdir/$n"
249 foreach {varname value} $args {
250 $::safeInterp eval [list unset $varname]
253 proc safeSet {i args} {
256 foreach {varname value} $args {
257 set ::unsafe::$varname $value
259 interp invokehidden $i set {*}$args
267 proc safeAddSubDirsToAccessPath { safeInterp dir } {
268 foreach subdir [glob -nocomplain -directory $dir -type d *] {
269 ::safe::interpAddToAccessPath $safeInterp $subdir
274 proc safeSourceStyle {filename} {
275 set filename [
file nativename "$filename"]
276 set dir [
file dirname $filename]
278 set safeInterp [::safe::interpCreate]
280 set vdir [::safe::interpAddToAccessPath $safeInterp $dir]
283 interp alias $safeInterp pwd {} ::safePwd
284 interp alias $safeInterp package {} ::safePackage $safeInterp
285 interp alias $safeInterp image {} ::safeImage $safeInterp [list $vdir $dir]
286 interp alias $safeInterp ttk::style {} ::safeStyle $safeInterp
288 $safeInterp eval [list set vdir $vdir]
289 $safeInterp eval "source \$vdir/[
file tail $filename]"
290 ::safe::interpDelete $safeInterp
295 proc safePackage { interp args } {
296 set args [
lassign $args command]
299 "require" {
package require {*}$args}
300 "vsatisfies" {
package vsatisfies {*}$args}
301 "provide" {
package provide {*}$args}
306 proc safeImage {interp dir_map args} {
307 set filename [lsearch -exact $args -file]
308 if {$filename != -1} {
310 set real_filename [
string map $dir_map [
lindex $args $filename]]
311 set args [
lreplace $args $filename $filename $real_filename]
313 return [
image {*}$args]
319 proc safeStyle {interp args} {
320 lassign $args theme settings themeName script
321 if {$theme eq "theme"} {
322 if { $settings eq "settings"} {
323 set curr_theme [ttk::style theme use]
324 ttk::style theme use $themeName
326 ttk::style theme use $curr_theme
330 set script_i [lsearch -exact $args -settings]
331 if {$script_i != -1} {
332 set script_j [
expr $script_i + 1]
333 ttk::style {*}[
lreplace $args $script_i $script_j]
334 $interp eval [list ttk::style theme settings $themeName [
lindex $args $script_j]]
339 return [ttk::style {*}$args]
344 source [
file nativename [
file join $::scidTclDir "options.tcl"]]
348 if {[
info exists initialDir(tablebase)]} {
349 set initialDir(tablebase1) $initialDir(tablebase)
352 proc createFonts {} {
353 foreach name {Regular Menu Small Tiny Fixed} {
354 set opts $::fontOptions($name)
355 font create font_$name \
356 -family [
lindex $opts 0] -size [
lindex $opts 1] \
357 -weight [
lindex $opts 2] -slant [
lindex $opts 3]
360 set fontsize [font configure font_Regular -size]
361 set font [font configure font_Regular -family]
362 font create font_Bold -family $font -size $fontsize -weight bold
363 font create font_BoldItalic -family $font -size $fontsize -weight bold -slant italic
364 font create font_Italic -family $font -size $fontsize -slant italic
365 font create font_H1 -family $font -size [
expr {$fontsize + 8}] -weight bold
366 font create font_H2 -family $font -size [
expr {$fontsize + 6}] -weight bold
367 font create font_H3 -family $font -size [
expr {$fontsize + 4}] -weight bold
368 font create font_H4 -family $font -size [
expr {$fontsize + 2}] -weight bold
369 font create font_H5 -family $font -size [
expr {$fontsize + 0}] -weight bold
371 set fontsize [font configure font_Small -size]
372 set font [font configure font_Small -family]
373 font create font_SmallBold -family $font -size $fontsize -weight bold
374 font create font_SmallItalic -family $font -size $fontsize -slant italic
376 set ::utils::tooltip::font font_Small
381 if { [
file exists $::ThemePackageFile] } {
384 catch { ttk::style theme use $::lookTheme}
388 ttk::style configure TLabel -font font_Regular
389 ttk::style configure TButton -font font_Regular
390 ttk::style configure TRadiobutton -font font_Regular
391 ttk::style configure TCheckbutton -font font_Regular
392 ttk::style configure TMenubutton -font font_Regular
393 ttk::style configure TCombobox -font font_Regular
394 ttk::style configure TEntry -font font_Regular
395 ttk::style configure TNotebook.Tab -font font_Regular
398 ttk::style configure Bold.TCheckbutton -font font_Bold
399 ttk::style configure Small.TCheckbutton -font font_Small
401 ttk::style configure Small.TButton -font font_Small
402 ttk::style configure Bold.TButton -font font_Bold
403 ttk::style configure Pad0.Small.TButton -padding 0
405 ttk::style configure Small.TRadiobutton -font font_Small
406 ttk::style configure Bold.TRadiobutton -font font_Bold
407 ttk::style configure SmallBold.TRadiobutton -font font_SmallBold
409 ttk::style configure pad0.TMenubutton -padding 0 -indicatorwidth 0 -indicatorheight 0 -font font_Small
412 set ::glistRowHeight [
expr { round(1.4 * [font metrics font_Small -linespace]) }]
413 ttk::style configure Gamelist.Treeview -rowheight $::glistRowHeight
416 option add *Font font_Regular
419 option add *Menu*Font font_Menu
422 foreach col [
array names ::menuColor] {
423 option add *Menu.$col $::menuColor($col)
427 proc applyThemeColor_background { widget } {
428 set bgcolor [ttk::style lookup . -background "" #d9d9d9]
429 $widget configure -background $bgcolor
430 bind $widget <<ThemeChanged>> "::applyThemeColor_background $widget"
434 proc applyThemeStyle {style widget} {
435 $widget configure -background [ttk::style lookup $style -background "" #d9d9d9]
436 $widget configure -foreground [ttk::style lookup $style -foreground "" black]
437 $widget configure -relief [ttk::style lookup $style -relief "" flat]
438 $widget configure {*}[ttk::style configure $style]
439 bind $widget <<ThemeChanged>> "::applyThemeStyle $style $widget"
443 global scidImgDir boardStyle boardStyles textureSquare
446 set scidIconFile [
file nativename [
file join $scidImgDir "scid.gif"]]
447 if {[
file readable $scidIconFile]} {
448 wm iconphoto . -default [
image create photo -file "$scidIconFile"]
452 set dname [
file join $::scidImgDir buttons]
453 foreach {fname} [glob -directory $dname *.gif] {
454 set iname [
string range [
file tail $fname] 0 end-4]
455 image create photo $iname -file $fname
459 set dname [
file join $::scidImgDir buttons]
460 foreach {fname} [glob -directory $dname *.png] {
461 set iname [
string range [
file tail $fname] 0 end-4]
462 image create photo $iname -format png -file $fname
467 set dname [
file join $::scidImgDir boards]
468 foreach {fname} [glob -directory $dname *.gif] {
469 set iname [
string range [
file tail $fname] 0 end-4]
470 image create photo $iname -file $fname
471 if {[
string range $iname end-1 end] == "-l"} {
472 lappend textureSquare [
string range $iname 0 end-2]
478 set dname [
file join $::scidImgDir pieces]
479 foreach {piecetype} [glob -directory $dname *] {
480 if {[
file isdirectory $piecetype] == 1} {
481 lappend boardStyles [
file tail $piecetype]
486 set dname [
file join $::scidImgDir flags]
487 foreach {fname} [glob -directory $dname *.gif] {
488 set iname [
string range [
file tail $fname] 0 end-4]
489 image create photo $iname -file $fname
493 tk_messageBox -type ok -icon error -title "Scid: Error" \
494 -message "Cannot load images.\n$::errorCode\n\n$::errorInfo"
499 sc_info decimal $::locale(numeric)
502 set ::clipbase_db [
sc_info clipbase]
504 set ::curr_db [
sc_base current]
548 contrib/ezsmtp/ezsmtp.tcl
567 tools/correspondence.tcl
578 tools/inputengine.tcl
580 utils/bibliography.tcl
583 foreach f $tcl_files {
584 source -encoding utf-8 [
file nativename [
file join $::scidTclDir "$f"]]