4 namespace eval ::optable {}
5 array set ::optable::_data {}
7 set ::optable::_data(exclude) "---"
8 set ::optable::_docStart(text) {}
9 set ::optable::_docEnd(text) {}
10 set ::optable::_docStart(ctext) {}
11 set ::optable::_docEnd(ctext) {}
12 set ::optable::_flip 0
14 set ::optable::_docStart(html) {<html>
16 <title>[OprepTitle]</title>
17 <style type="text/css">
35 <body bgcolor="#ffffff">
37 set ::optable::_docEnd(html) {</body>
41 set ::optable::_docStart(latex) {\documentclass[10pt,a4paper]{article}
42 % This is a LaTeX file generated by Scid.
43 % You must have the "chess12" package installed to typeset this file.
48 \usepackage[T1]{fontenc}
50 \setlength{\columnsep}{1cm}
51 \setlength{\parindent}{0pt}
52 \setlength{\parskip}{3pt}
55 \newcommand{\B}{{\F B}}
56 \newcommand{\N}{{\F N}}
57 \newcommand{\R}{{\F R}}
58 \newcommand{\Q}{{\F Q}}
59 \newcommand{\K}{{\F K}}
60 \newcommand{\tspace}{{\vspace{0.08cm}}}
61 \newcommand{\draw}{{\small$\frac{1}{2}$:$\frac{1}{2}$}}
62 \newcommand{\loss}{\mbox{0:1}}
63 \newcommand{\win}{\mbox{1:0}}
64 \newcommand{\notenum}[1]{\hspace{-0.7cm}\makebox[0.55cm][r]{$^{ #1 }$ }\makebox[0.05cm]{}}
71 set ::optable::_docEnd(latex) {
75 proc ::optable::ConfigMenus {{lang ""}} {
76 if {! [
winfo exists .oprepWin]} {
return}
77 if {$lang == ""} {
set lang $::language}
79 foreach idx {0 1 2} tag {File Favorites Help} {
82 foreach idx {0 1 2 4 6} tag {Text Html LaTeX Options Close} {
85 foreach idx {0 1 2} tag {Add Edit Generate} {
88 foreach idx {0 1} tag {Report Index} {
93 proc ::optable::makeReportWin {args} {
94 set ::optable::opReportBase [
sc_base current]
96 set args [
linsert $args 0 "args"]
97 if {[lsearch -exact $args "-noprogress"] >= 0} {
set showProgress 0}
100 toplevel $w -background [ttk::style lookup . -background]
102 wm title $w "Scid: Generating Report"
103 bind $w <Visibility> "raiseWin $w"
105 pack [ttk::frame $w.b] -side bottom -fill x
106 set ::optable::_interrupt 0
107 ttk::button $w.b.cancel -text $::tr(Cancel) -command {
108 set ::optable::_interrupt 1
111 pack $w.b.cancel -side right -pady 5 -padx 2
113 foreach i {1 2} name { "Searching database for report games" "Generating report information" } {
114 ttk::label $w.text$i -text "$i. $name"
115 pack $w.text$i -side top
116 canvas $w.c$i -width 400 -height 20 -bg white -relief solid -border 1
117 $w.c$i create rectangle 0 0 0 0 -fill blue -outline blue -tags bar
118 $w.c$i create text 395 10 -anchor e -font font_Regular -tags time \
119 -fill black -text "0:00 / 0:00"
120 pack $w.c$i -side top -pady 10
124 set x [
winfo screenwidth $w]
set x [
expr $x - 400]
set x [
expr $x / 2]
125 set y [
winfo screenheight $w]
set y [
expr $y - 20]
set y [
expr $y / 2]
126 wm geometry $w +$x+$y
133 set newTreeData [
sc_tree search]
135 if {$::optable::_interrupt} {
136 grab release $w.b.cancel
142 sc_report opening create $::optable(ExtraMoves) $::optable(MaxGames) $::optable::_data(exclude)
144 grab release $w.b.cancel
146 if {$::optable::_interrupt} {
return}
149 set ::optable::_data(tree) $newTreeData
151 set ::optable::_data(bdLaTeX) [
sc_pos tex]
152 set ::optable::_data(bdHTML) [
sc_pos html]
153 set ::optable::_data(bdLaTeX_flip) [
sc_pos tex flip]
154 set ::optable::_data(bdHTML_flip) [
sc_pos html -flip 1]
160 if {[lsearch -exact $args "-nodisplay"] >= 0} {
return}
163 if {![
winfo exists $w]} {
169 $w.menu add cascade -label OprepFile -menu $w.menu.file
170 $w.menu add cascade -label OprepFavorites -menu $w.menu.favorites
171 $w.menu add cascade -label OprepHelp -menu $w.menu.helpmenu
172 foreach i {file favorites helpmenu} {
173 menu $w.menu.$i -tearoff 0
176 $w.menu.file add command -label OprepFileText \
177 -command {::optable::saveReport text}
178 $w.menu.file add command -label OprepFileHtml \
179 -command {::optable::saveReport html}
180 $w.menu.file add command -label OprepFileLaTeX \
181 -command {::optable::saveReport latex}
182 $w.menu.file add separator
183 $w.menu.file add command -label OprepFileOptions \
184 -command ::optable::setOptions
185 $w.menu.file add separator
186 $w.menu.file add command -label OprepFileClose \
187 -command "$w.b.close invoke"
188 $w.menu.favorites add command -label OprepFavoritesAdd \
189 -command ::optable::addFavoriteDlg
190 $w.menu.favorites add command -label OprepFavoritesEdit \
191 -command ::optable::editFavoritesDlg
192 $w.menu.favorites add command -label OprepFavoritesGenerate \
193 -command ::optable::generateFavoriteReports
194 $w.menu.favorites add separator
195 $w.menu.helpmenu add command -label OprepHelpReport \
196 -accelerator F1 -command {helpWindow Reports Opening}
197 $w.menu.helpmenu add command -label OprepHelpIndex \
198 -command {helpWindow Index}
202 bind $w <F1> {helpWindow Reports Opening}
203 bind $w <Escape> "$w.b.close invoke"
204 bind $w <Up> "$w.text yview scroll -1 units"
205 bind $w <Down> "$w.text yview scroll 1 units"
206 bind $w <Prior> "$w.text yview scroll -1 pages"
207 bind $w <Next> "$w.text yview scroll 1 pages"
208 bind $w <Key-Home> "$w.text yview moveto 0"
209 bind $w <Key-End> "$w.text yview moveto 0.99"
211 text $w.text -height 30 -width 85 -font font_Small -setgrid 1 \
212 -wrap word -bg white -foreground black -yscrollcommand "$w.ybar set" \
213 -cursor top_left_arrow
215 ttk::scrollbar $w.ybar -command "$w.text yview"
217 ttk::button $w.b.previewLaTeX -textvar ::tr(OprepViewLaTeX) \
218 -command ::optable::previewLaTeX
219 ttk::button $w.b.previewHTML -textvar ::tr(OprepViewHTML) \
220 -command ::optable::previewHTML
221 ttk::button $w.b.opts -text [
tr OprepFileOptions] -command ::optable::setOptions
222 ttk::label $w.b.lexclude -text "Exclude:"
223 ttk::menubutton $w.b.exclude -textvar ::optable::_data(exclude) -menu $w.b.exclude.m
224 menu $w.b.exclude.m -tearoff 0
225 ttk::button $w.b.update -textvar ::tr(Update) -command {
226 set ::optable::_data(yview) [lindex [.oprepWin.text yview] 0]
227 ::optable::makeReportWin
228 .oprepWin.text yview moveto $::optable::_data(yview)
231 ttk::button $w.b.mergeGames -textvar ::tr(MergeGames) -command ::optable::mergeGames
232 ttk::button $w.b.help -textvar ::tr(Help) -command {helpWindow Reports Opening}
233 ttk::button $w.b.close -textvar ::tr(Close) -command "focus .; destroy $w"
234 pack $w.b -side bottom -fill x
235 pack $w.ybar -side right -fill y
236 pack $w.text -side left -fill both -expand yes
237 pack $w.b.close $w.b.update -side right -padx 1 -pady 2
238 if {! $::windowsOS} {
239 pack $w.b.previewLaTeX -side left -padx 1 -pady 2
241 pack $w.b.previewHTML -side left -padx 1 -pady 2
243 pack $w.b.opts $w.b.lexclude $w.b.exclude $w.b.mergeGames -side left -padx 1 -pady 2
248 catch {
destroy $w.text.bd}
253 $w.text.bd configure -relief solid -borderwidth 1
254 for {
set i 0} {$i < 63} {
incr i} {
255 ::board::bind $w.text.bd $i <ButtonPress-1> ::optable::flipBoard
259 $w.b.exclude.m delete 0 end
260 $w.b.exclude.m add radiobutton -label "---" -variable ::optable::_data(exclude) -command "$w.b.update invoke"
261 foreach move $::optable::_data(moves) {
262 $w.b.exclude.m add radiobutton -label $move -variable ::optable::_data(exclude) -command "$w.b.update invoke"
264 if {[lsearch $::optable::_data(moves) $::optable::_data(exclude)] < 0} {
265 set ::optable::_data(exclude) "---"
268 $w.text configure -state normal
269 $w.text delete 1.0 end
270 regsub -all "\n" $report "<br>" report
272 $w.text configure -state disabled
280 proc ::optable::mergeGames { {game_count 50} {ply 999} } {
281 set base $::optable::opReportBase
282 set games [
split [
sc_report opening best a $game_count] "\n"]
284 if {$g == "" } { continue}
285 set res [
scan $g "%d: <g_%d>" d1 game_number]
287 if {[
info exists game_number]} {
288 tk_messageBox -title "Scid: Error writing report" -type ok -icon warning -message "Error merging game $game_number"
290 tk_messageBox -title "Scid: Error writing report" -type ok -icon warning -message "Error merging game"
294 set err [
catch {
sc_game merge $base $game_number $ply} result]
296 tk_messageBox -title "Scid" -type ok -icon info -message "Unable to merge the selected game:\n$result"
306 proc ::optable::flipBoard {} {
311 proc ::optable::resizeBoard {} {
312 set bd .oprepWin.text.bd
314 if {$size >= 40} {
set size 25}
else {
incr size 5}
318 proc ::optable::setOptions {} {
320 if {[
winfo exists $w]} {
return}
322 pack [ttk::frame $w.f] -side top -fill x -padx 5
324 foreach i {Stats Popular AvgPerf Results MovesFrom Themes Endgames} {
329 foreach i {Stats Oldest Newest Popular MostFrequent sep \
330 AvgPerf HighRating sep \
331 Results Shortest sep col \
332 MoveOrders MovesFrom Themes Endgames gap sep \
333 MaxGames ExtraMoves sep} {
334 set from 0
set to 10
set tick 1
set res 1
338 ttk::frame $w.f.colsep$left -width 8
339 grid $w.f.colsep$left -row 0 -column $left
341 set right [
expr {$left + 1}]
343 }
elseif {$i == "gap"} {
345 }
elseif {$i == "sep"} {
346 ttk::separator $w.f.fsep$row$left
347 ttk::separator $w.f.tsep$row$left
348 grid $w.f.fsep$row$left -row $row -column $left -sticky we -columnspan 4 -pady 2
349 }
elseif {[
info exists yesno($i)]} {
350 ttk::checkbutton $w.f.f$i -variable ::optable($i) -onvalue 1 -offvalue 0 -text $::tr(Oprep$i)
351 grid $w.f.f$i -row $row -column $left -sticky w -columnspan 3
355 if {$i == "MaxGames"} {
356 ttk::spinbox $w.f.s$i -textvariable ::optable($i) -from 0 -to 5000 -increment 50 \
357 -state readonly -width 5 -justify right -font font_Small
360 for {
set x $from} {$x <= $to} {
incr x $res} {
363 ttk::combobox $w.f.s$i -textvariable ::optable($i) -width 2 -values $tmpcombo -justify right -state readonly
366 ttk::label $w.f.t$i -textvar ::tr(Oprep$i) -font font_Small
367 grid $w.f.s$i -row $row -column $left -sticky w
368 if {$i == "MostFrequent" || $i == "Shortest"} {
369 ttk::checkbutton $w.f.w$i -text $::tr(White) \
370 -variable ::optable(${i}White)
371 ttk::checkbutton $w.f.b$i -text $::tr(Black) \
372 -variable ::optable(${i}Black)
373 grid $w.f.t$i -row $row -column $right -sticky w
374 grid $w.f.w$i -row $row -column 2 -sticky w -padx 5
375 grid $w.f.b$i -row $row -column 3 -sticky w
377 grid $w.f.t$i -row $row -column $right -columnspan 3 -sticky w
380 if {$i != "col"} {
incr row}
382 pack [ttk::frame $w.b] -side bottom -fill x
383 dialogbutton $w.b.defaults -textvar ::tr(Defaults) -command {
384 array set ::optable [array get ::optableDefaults]
387 destroy .oprepOptions
388 catch {set ::optable::_data(yview) [lindex [.oprepWin.text yview] 0]}
389 ::optable::makeReportWin
390 catch {.oprepWin.text yview moveto $::optable::_data(yview)}
392 dialogbutton $w.b.cancel -textvar ::tr(Cancel) -command {
393 array set ::optable [array get ::optable::backup]
394 destroy .oprepOptions
398 array set ::optable::backup [
array get ::optable]
400 wm title $w "Scid: [
tr ToolsOpReport]: [
tr OprepFileOptions]"
401 bind $w <Escape> "$w.b.cancel invoke"
408 proc ::optable::previewLaTeX {} {
410 set tmpdir $::scidLogDir
411 set tmpfile "TempOpeningReport"
412 set fname [
file join $tmpdir $tmpfile]
413 catch {
exec /bin/sh -c "rm $fname.*"}
414 if {[
catch {
set tempfile [open $fname.tex w]}]} {
415 tk_messageBox -title "Scid: Error writing report" -type ok -icon warning \
416 -message "Unable to write the file: $fname.tex"
420 puts $tempfile "\\batchmode"
423 if {! [
catch {
exec /bin/sh -c "cd $tmpdir; latex '$tmpfile.tex'" >& /dev/null}]} {
424 if {[
catch {
exec /bin/sh -c "cd $tmpdir; dvips '$tmpfile.dvi'" >& /dev/null}]} {
425 tk_messageBox -title "Scid" -icon warning -type ok \
426 -message "Unable to run \"dvips\" to convert the report to PostScript."
428 if {[
catch {
exec /bin/sh -c "ghostview '$fname.ps'" >& /dev/null &}]} {
429 tk_messageBox -title "Scid" -icon warning -type ok \
430 -message "Unable to run \"xdvi\" to view the report."
434 tk_messageBox -title "Scid: Errors producing report" -type ok \
436 -message "Errors running latex on the file: $fname.tex\n\nSee $fname.log for details."
445 proc ::optable::previewHTML {} {
447 set tmpdir $::scidLogDir
448 set tmpfile "TempOpeningReport"
449 set fname [
file join $tmpdir $tmpfile]
450 if {[
catch {
set tempfile [open $fname.html w]}]} {
451 tk_messageBox -title "Scid: Error writing report" -type ok -icon warning \
452 -message "Unable to write the file: $fname.html"
456 if {[
string match $::tcl_platform(os) "Windows NT"]} {
457 catch {
exec $::env(COMSPEC) /c start $fname.html &}
459 catch {
exec start $fname.html &}
469 proc ::optable::saveReport {fmt} {
470 set t [
tk_dialog .dialog "Scid: Select report type" \
471 "Select the report type. You may save a full report (which includes the theory table), a compact report (with no theory table), or just the theory table by itself." \
472 "" 0 "Full report" "Compact report" \
473 "Theory table" "Cancel"]
474 if {$t == 3} {
return}
477 { "Text files" {".txt"} }
478 { "All files" {"*"} }
480 if {$fmt == "latex"} {
483 { "LaTeX files" {".tex" ".ltx"} }
484 { "All files" {"*"} }
486 }
elseif {$fmt == "html"} {
489 { "HTML files" {".html" ".htm"} }
490 { "All files" {"*"} }
494 set fname [
tk_getSaveFile -initialdir [
pwd] -filetypes $ftype \
495 -defaultextension $default -title "Scid: Save opening report"]
496 if {$fname == ""} {
return}
499 if {[
catch {
set tempfile [open $fname w]}]} {
500 tk_messageBox -title "Scid: Error writing report" -type ok -icon warning \
501 -message "Unable to write the file: $fname\n\n"
510 if {$::hasEncoding && $::langEncoding($::language) != ""} {
511 catch {
set report [encoding convertto $::langEncoding($::language) $report]}
513 puts $tempfile $report
519 proc ::optable::create {} {
520 set ::optable::_data(tree) [
sc_tree search]
522 set ::optable::_data(bdLaTeX) [
sc_pos tex]
523 set ::optable::_data(bdHTML) [
sc_pos html]
524 set ::optable::_data(bdLaTeX_flip) [
sc_pos tex flip]
525 set ::optable::_data(bdHTML_flip) [
sc_pos html -flip 1]
526 sc_report opening create $::optable(ExtraMoves) $::optable(MaxGames)
534 proc ::optable::latexifyTree {} {
535 set ::optable::_data(moves) {}
536 if {! [
info exists ::optable::_data(tree)]} {
return}
537 set tree [
split $::optable::_data(tree) "\n"]
538 set ltree "\\begin{tabular}{rllr@{:}rrrrrr}\n\\hline\n"
539 append ltree " & Move & ECO & \\multicolumn{2}{c}{Frequency}"
540 append ltree " & Score & \$\\mu\$Elo & Perf & \$\\mu\$Year & \\% Draws \\\\ \n"
541 append ltree "\\hline\n"
542 set len [
llength $tree]
544 for {
set i 1} {$i < $len} {
incr i} {
545 set line [
lindex $tree $i]
546 if {[
string index $line 0] == "_"} {
547 append ltree "\\hline\n"
550 if {[
string length $line] == 0} { continue}
551 set num [
string range $line 0 1]
552 set move [
string range $line 4 9]
553 set eco [
string range $line 11 15]
554 set freq [
string range $line 17 23]
555 set fpct [
string range $line 25 29]
556 set score [
string range $line 33 37]
557 set avElo [
string range $line 41 44]
558 set perf [
string range $line 47 50]
559 set avYear [
string range $line 53 56]
560 set pctDraw [
string range $line 59 61]
561 set mv [
string trim $move]
562 regsub K $move {{\\K}} move
563 regsub Q $move {{\\Q}} move
564 regsub R $move {{\\R}} move
565 regsub B $move {{\\B}} move
566 regsub N $move {{\\N}} move
567 if {[
string index $line 0] == "T"} {
568 append ltree "\\multicolumn{2}{l}{Total}"
570 append ltree " $num & $move "
571 lappend ::optable::_data(moves) $mv
573 append ltree " & $eco & $freq & $fpct\\% & $score\\%"
574 append ltree " & $avElo & $perf & $avYear & $pctDraw\\% \\\\ \n"
576 append ltree "\\hline\n"
577 append ltree "\\end{tabular}\n"
578 set ::optable::_data(latexTree) $ltree
581 proc ::optable::setupRatios {} {
583 if {[
lindex $r 0] == 0} {
584 set ::optable::_data(ratioAll) 0
586 set ::optable::_data(ratioAll) \
587 [
expr {int(double([lindex $r 1]) / double([lindex $r 0]))}]
589 foreach {start end} {1800 1899 1900 1949 1950 1969 1970 1979
590 1980 1989 1990 1999 2000 2009} {
592 set filter [
lindex $r 0]
593 set all [
lindex $r 1]
595 set ::optable::_data(range$start) "---"
597 set ::optable::_data(range$start) \
598 [
expr {int(double($all) / double($filter))}]
605 set filter [
lindex $r 0]
606 set all [
lindex $r 1]
608 set ::optable::_data(ratio$y) 0
610 set ::optable::_data(ratio$y) \
611 [
expr {int(double($all) / double($filter))}]
613 if {$::optable::_data(ratio$y) == 0} {
616 set r [
expr {double($::optable::_data(ratioAll))}]
617 set r [
expr {$r / double($::optable::_data(ratio$y))}]
619 set ::optable::_data(delta$y) [
expr {int(($r - 1.0) * 100.0 + 0.5)}]
623 proc ::optable::_percent {x fmt} {
625 if {$fmt == "latex"} {
set p "\\%"}
626 return "[
expr $x / 10][
sc_info decimal][
expr $x % 10]$p"
629 proc ::optable::results {reportType fmt} {
631 set n "\n"
set next " "
set p "%"
632 set white "1-0"
set draw "=-="
set black "0-1"
634 if {$fmt == "latex"} {
635 set next " & "
set n "\\\\\n"
set p "\\%"
636 set white "\\win"
set draw "\\draw"
set black "\\loss"
637 append s "\\begin{tabular}{lccccccc}\n"
640 if {$fmt == "html"} {
append s "<pre>\n"}
641 if {$fmt == "ctext"} {
append s "<tt>"}
642 if {$fmt == "latex"} {
append s "\\hline\n"}
644 set lenReport [
string length $::tr(OprepReportGames)]
645 set lenAll [
string length $::tr(OprepAllGames)]
646 set len [
expr {($lenReport > $lenAll) ? $lenReport : $lenAll}]
648 set slen [
string length $score]
649 if {$slen < 7} {
set slen 7}
653 if {$fmt == "latex"} {
654 append s "\\multicolumn{3}{c}{$::tr(OprepLength)} & "
655 append s "\\multicolumn{3}{c}{$::tr(OprepFrequency)} $n "
669 if {$fmt == "latex"} {
append s "\\hline\n"}
672 set wlen [
sc_report $reportType avgLength 1]
673 set dlen [
sc_report $reportType avgLength =]
674 set blen [
sc_report $reportType avgLength 0]
697 if {$fmt == "latex"} {
append s "\\hline\n\\end{tabular}\n"}
698 if {$fmt == "html"} {
append s "</pre>\n"}
699 if {$fmt == "ctext"} {
append s "</tt>"}
704 proc ::optable::stats {fmt} {
707 set all $::tr(OprepStatAll)
708 set both $::tr(OprepStatBoth)
709 set since $::tr(OprepStatSince)
713 set alen [
string length $all]
714 set blen [
expr {[string length $both] + 6}]
715 set slen [
expr {[string length $since] + 11}]
717 if {$len < $blen} {
set len $blen}
718 if {$len < $slen} {
set len $slen}
722 set rlist [lsort -decreasing [
array names stats r*]]
723 set ylist [lsort [
array names stats y*]]
724 foreach i $rlist {
if {$stats($i)} {
set ratings 1}}
725 foreach i $ylist {
if {$stats($i)} {
set years 1}}
727 if {$fmt == "latex"} {
728 append s "\\begin{tabular}{l r r r r r @{.} l}\n\\hline\n"
729 append s " & $games & \\win & \\draw & \\loss & "
730 append s "\\multicolumn{2}{c}{$score} \\tspace \\\\ \\hline \n"
731 scan [
sc_filter stats all] "%u%u%u%u%u%\[.,\]%u" g w d l p c x
732 append s "$all & $g & $w & $d & $l & $p&$x\\% \\\\\n"
738 set elo [
string range $i 1 end]
739 scan [
sc_filter stats elo $elo] "%u%u%u%u%u%\[.,\]%u" g w d l p c x
740 append s "$both $elo+ & $g & $w & $d & $l & $p&$x\\% \\\\\n"
748 set year [
string range $i 1 end]
749 scan [
sc_filter stats year $year] "%u%u%u%u%u%\[.,\]%u" g w d l p c x
750 append s "$since $year.01.01 & $g & $w & $d & $l & $p&$x\\% \\\\\n"
754 append s "\\hline\n\\end{tabular}\n"
759 if {$fmt == "html"} {
append s "<pre>\n"}
760 if {$fmt == "ctext"} {
append s "<tt>"}
764 append s "-----------------------------------------------------------"
771 set elo [
string range $i 1 end]
772 set stat "$both $elo+"
781 set year [
string range $i 1 end]
782 set stat "$since $year.01.01"
787 append s "\n-----------------------------------------------------------\n"
788 if {$fmt == "html"} {
append s "</pre>\n"}
789 if {$fmt == "ctext"} {
append s "</tt>"}
793 proc ::optable::_reset {} {
794 set ::optable::_data(sec) 0
795 set ::optable::_data(subsec) 0
798 proc ::optable::_title {} {
799 set fmt $::optable::_data(fmt)
800 set title $::tr(OprepTitle)
801 if {$fmt == "latex"} {
802 return "\\begin{center}{\\LARGE \\bf $title}\\end{center}\n\n"
803 }
elseif {$fmt == "html"} {
804 return "<h1><center>$title</center></h1>\n\n"
805 }
elseif {$fmt == "ctext"} {
806 return "<h1><center>$title</center></h1>\n\n"
808 set r "--------------------------------------------------------------"
809 append r "\n [
string toupper $title]\n"
810 append r "--------------------------------------------------------------"
815 proc ::optable::_sec {text} {
816 set fmt $::optable::_data(fmt)
817 incr ::optable::_data(sec)
818 set ::optable::_data(subsec) 0
819 if {$fmt == "latex"} {
820 return "\n\n\\section{$text}\n"
821 }
elseif {$fmt == "html"} {
822 return "\n<h2>$::optable::_data(sec). $text</h2>\n"
823 }
elseif {$fmt == "ctext"} {
824 return "<h4>$::optable::_data(sec). $text</h4>"
826 set line "$::optable::_data(sec). [
string toupper $text]"
827 set underline "-----------------------------------------------------"
828 return "\n\n$line\n[
string range $underline 1 [
string length $line]]\n"
831 proc ::optable::_subsec {text} {
832 set fmt $::optable::_data(fmt)
833 incr ::optable::_data(subsec)
834 if {$fmt == "latex"} {
835 return "\n\\subsection{$text}\n\n"
836 }
elseif {$fmt == "html"} {
837 return "\n<h3>$::optable::_data(sec).$::optable::_data(subsec) $text</h3>\n\n"
838 }
elseif {$fmt == "ctext"} {
839 return "\n<maroon><b>$::optable::_data(sec).$::optable::_data(subsec) $text</b></maroon>\n\n"
841 return "\n$::optable::_data(sec).$::optable::_data(subsec) $text\n\n"
848 proc ::optable::report {fmt withTable {flipPos 0}} {
851 set fmt [
string tolower $fmt]
852 set ::optable::_data(fmt) $fmt
862 sc_report opening notes $withTable $numRows
864 set n "\n"
set p "\n\n"
set preText ""
set postText ""
865 set percent "%"
set bullet " * "
866 if {$fmt == "latex"} {
867 set n "\\\\\n"
set p "\n\n"
870 set percent "\\%"
set bullet "\\hspace{0.5cm}\$\\bullet\$"
871 }
elseif {$fmt == "html"} {
872 set n "<br>\n"
set p "<p>\n\n"
873 set preText "<pre>\n"
set postText "</pre>\n"
874 }
elseif {$fmt == "ctext"} {
875 set preText "<tt>"
set postText "</tt>"
882 set rgames [
lindex $counts 0]
883 set tgames [
lindex $counts 1]
886 append r $::optable::_docStart($fmt)
887 set title $::tr(OprepTitle)
888 set r [
string map [list "\[OprepTitle\]" $title] $r]
890 append r "$tr(Database): [
file tail [
sc_base filename $::curr_db]] "
893 if {$fmt == "ctext"} {
894 append r "<darkblue><run sc_report opening select all 0; ::windows::stats::Refresh>"
897 if {$fmt == "ctext"} {
append r "</run></darkblue>" }
898 append r " $games)$n"
901 append r "$tr(ECO): $eco$n"
905 if {$fmt == "latex"} {
907 append r $::optable::_data(bdLaTeX_flip)
909 append r $::optable::_data(bdLaTeX)
911 append r {$$\showboard$$}
912 }
elseif {$fmt == "html"} {
914 append r $::optable::_data(bdHTML_flip)
916 append r $::optable::_data(bdHTML)
918 }
elseif {$fmt == "ctext"} {
919 append r "\n<center><window .oprepWin.text.bd></center>\n"
922 append r $::optable::_docEnd($fmt)
926 if {$::optable(Stats) > 0 ||
927 $::optable(Oldest) > 0 ||
928 $::optable(Newest) > 0 ||
929 $::optable(Popular) > 0 ||
930 ($::optable(MostFrequent) > 0 &&
931 ($::optable(MostFrequentWhite) || $::optable(MostFrequentBlack)))} {
934 if {$::optable(Stats)} {
938 if {$::optable(Oldest) > 0} {
940 append r [
sc_report opening best o $::optable(Oldest)]
942 if {$::optable(Newest) > 0} {
944 append r [
sc_report opening best n $::optable(Newest)]
947 if {$::optable(Popular) > 0} {
950 if {$fmt == "latex"} {
set next " & "}
953 if {$fmt == "latex"} {
954 append r "\\begin{tabular}{lccccccc}\n\\hline\n"
961 regsub "%u" $sEvery X sEvery
962 set len [
string length $sYear]
963 if {[
string length $sEvery] > $len} {
set len [
string length $sEvery]}
965 foreach range {1800-99 1900-49 1950-69 1970-79 1980-89 1990-99 2000-09} {
972 foreach y {1800 1900 1950 1970 1980 1990 2000} {
977 if {$fmt == "latex"} {
978 append r "\\hline\n\\end{tabular}\n"
986 if {$fmt == "latex"} {
987 append r "\\begin{tabular}{lrr}\n"
990 foreach y {All 10 5 1} {
991 if {$fmt == "ctext"} {
append r "<tt>"}
992 append r $tr(OprepFreq$y)
993 if {$fmt == "ctext"} {
append r "</tt>"}
995 append r [
format $tr(OprepEvery) $::optable::_data(ratio$y)]
998 set d $::optable::_data(delta$y)
1000 append r " ([
format $tr(OprepUp) $d $percent])"
1002 append r " ([
format $tr(OprepDown) [
expr 0- $d] $percent])"
1004 append r " ($tr(OprepSame))"
1009 if {$fmt == "latex"} {
1010 append r "\\end{tabular}\n"
1014 if {$::optable(MostFrequent) > 0 && $::optable(MostFrequentWhite)} {
1016 append r [
sc_report opening players white $::optable(MostFrequent)]
1018 if {$::optable(MostFrequent) > 0 && $::optable(MostFrequentBlack)} {
1020 append r [
sc_report opening players black $::optable(MostFrequent)]
1023 if {$::optable(AvgPerf) || $::optable(HighRating)} {
1026 if {$::optable(AvgPerf)} {
1029 set welo [
lindex $e 0]
set wng [
lindex $e 1]
1030 set bpct [
lindex $e 2]
set bperf [
lindex $e 3]
1032 set belo [
lindex $e 0]
set bng [
lindex $e 1]
1033 set wpct [
lindex $e 2]
set wperf [
lindex $e 3]
1034 append r "$tr(OprepWRating): $welo ($wng $games); "
1035 append r "$tr(OprepWPerf): $wperf ($wpct$percent vs $belo)$n"
1036 append r "$tr(OprepBRating): $belo ($bng $games); "
1037 append r "$tr(OprepBPerf): $bperf ($bpct$percent vs $welo)$n"
1040 if {$::optable(HighRating) > 0} {
1042 append r [
sc_report opening best a $::optable(HighRating)]
1045 if {$::optable(Results) ||
1046 ($::optable(Shortest) > 0 &&
1047 ($::optable(ShortestBlack) || $::optable(ShortestBlack)))} {
1051 if {$::optable(Results)} {
1056 if {$::optable(Shortest) > 0 && $::optable(ShortestWhite)} {
1058 append r [
sc_report opening best w $::optable(Shortest)]
1060 if {$::optable(Shortest) > 0 && $::optable(ShortestBlack)} {
1062 append r [
sc_report opening best b $::optable(Shortest)]
1065 if {$::optable(MoveOrders) > 0 ||
1066 $::optable(MovesFrom) > 0 ||
1067 $::optable(Themes) > 0 ||
1068 $::optable(Endgames) > 0} {
1071 if {$::optable(MoveOrders) > 0} {
1073 set nOrders [
sc_report opening moveOrders 0]
1074 set maxOrders $::optable(MoveOrders)
1075 if {$nOrders == 1} {
1076 append r $tr(OprepMoveOrdersOne)
1077 }
elseif {$nOrders <= $maxOrders} {
1078 append r [
format $tr(OprepMoveOrdersAll) $nOrders]
1080 append r [
format $tr(OprepMoveOrdersMany) $nOrders $maxOrders]
1085 if {$::optable(MovesFrom)} {
1087 if {$fmt == "latex"} {
1088 append r $::optable::_data(latexTree)
1091 append r $::optable::_data(tree)
1096 if {$::optable(Themes) > 0} {
1098 append r [
sc_report opening themes $tr(OprepThemeDescription:) \
1099 $tr(OprepThemeSameCastling:) $tr(OprepThemeOppCastling:) \
1100 $tr(OprepThemeKPawnStorm:) $tr(OprepThemeQueenswap:) \
1101 $tr(OprepTheme1BishopPair:) \
1102 $tr(OprepThemeWIQP:) $tr(OprepThemeBIQP:) \
1103 $tr(OprepThemeWP567:) $tr(OprepThemeBP234:) \
1104 $tr(OprepThemeOpenCDE:)]
1107 if {$::optable(Endgames) > 0} {
1109 append r "$tr(OprepEndClass:)$n"
1113 if {$withTable && $::optable(MaxGames) > 0} {
1116 if {$tgames > $::optable(MaxGames)} {
1117 set comment [
format $tr(OprepTableComment) $::optable(MaxGames)]
1119 append r [
sc_report opening print $numRows $sec $comment]
1123 append r $::optable::_docEnd($fmt)
1127 if {$fmt == "latex"} { regsub -all ß $r {{\\ss}} r}
1135 proc ::optable::table {fmt} {
1137 set ::optable::_data(fmt) $fmt
1139 append r $::optable::_docStart($fmt)
1140 set r [
string map [list "\[OprepTitle\]" $::tr(OprepTitle)] $r]
1142 append r $::optable::_docEnd($fmt)
1147 set reportFavorites {}
1153 proc ::optable::updateFavoritesMenu {} {
1154 set m .oprepWin.menu.favorites
1157 foreach entry $::reportFavorites {
1158 set name [
lindex $entry 0]
1159 set moves [
lindex $entry 1]
1160 $m add command -label $name \
1161 -command "importMoveList [list $moves]; ::optable::makeReportWin"
1163 if {[
llength $::reportFavorites] == 0} {
1164 $m entryconfigure 1 -state disabled
1165 $m entryconfigure 2 -state disabled
1167 $m entryconfigure 1 -state normal
1168 $m entryconfigure 2 -state normal
1175 proc ::optable::favoriteReportNames {} {
1177 foreach entry $::reportFavorites {
1178 lappend reportNames [
lindex $entry 0]
1186 proc ::optable::addFavoriteDlg {} {
1187 set w .addFavoriteDlg
1189 wm title $w "Scid: Add Opening Report Favorite"
1190 ttk::label $w.name -text "Enter a name for the opening report of this position:"
1191 pack $w.name -side top
1194 ttk::entry $w.e -width 40
1195 pack $w.e -side top -fill x -padx 2
1197 ttk::label $w.old -text "Existing favorite report names:"
1198 pack $w.old -side top
1199 pack [ttk::frame $w.existing] -side top -fill x -padx 2
1200 text $w.existing.list -width 30 -height 10 -background gray90 \
1201 -yscrollcommand [list $w.existing.ybar set]
1202 ttk::scrollbar $w.existing.ybar -command [list $w.existing.list yview]
1203 pack $w.existing.ybar -side right -fill y
1204 pack $w.existing.list -side left -fill both -expand yes
1205 foreach entry $::reportFavorites {
1206 $w.existing.list insert end "[
lindex $entry 0]\n"
1208 $w.existing.list configure -state disabled
1211 pack $w.b -side bottom -fill x
1212 ttk::button $w.b.ok -text OK -command ::optable::addFavoriteOK
1213 ttk::button $w.b.cancel -text $::tr(Cancel) -command "grab release $w; destroy $w"
1219 proc ::optable::addFavoriteOK {} {
1220 global reportFavorites
1221 set w .addFavoriteDlg
1222 set reportName [$w.e get]
1224 if {$reportName == ""} {
1225 set err "The report name must not be empty."
1227 set err "That name is already used for another favorite report position."
1229 lappend reportFavorites [list $reportName [
sc_game moves]]
1236 tk_messageBox -title Scid -icon info -type ok -message $err
1239 set reportFavoritesName ""
1245 proc ::optable::editFavoritesDlg {} {
1246 global reportFavorites reportFavoritesTemp reportFavoritesName
1247 set w .editFavoritesDlg
1248 if {[
winfo exists $w]} {
return}
1250 set ::reportFavoritesTemp $::reportFavorites
1252 wm title $w "Scid: [
tr OprepFavoritesEdit]"
1254 bind $w <F1> {helpWindow Reports Opening}
1255 ttk::entry $w.e -width 60 \
1256 -textvariable reportFavoritesName -exportselection 0
1257 bind $w.e <FocusIn> "$w.e configure -background lightYellow"
1258 bind $w.e <FocusOut> "$w.e configure -background white"
1260 trace variable reportFavoritesName w ::optable::editFavoritesRefresh
1261 pack $w.e -side top -fill x
1262 pack [ttk::frame $w.b] -side bottom -fill x
1264 -fg black -bg white -exportselection 0 -font font_Small -setgrid 1
1265 pack $w.f -side top -fill both -expand yes
1266 bind $w.f.list <<ListboxSelect>> ::optable::editFavoritesSelect
1267 foreach entry $::reportFavoritesTemp {
1268 set name [
lindex $entry 0]
1269 set moves [
lindex $entry 1]
1270 $w.f.list insert end "$name \[$moves\]"
1272 ttk::button $w.b.delete -text $::tr(Delete) -command ::optable::editFavoritesDelete
1273 ttk::button $w.b.up -image tb_up -command {::optable::editFavoritesMove up}
1274 ttk::button $w.b.down -image tb_down -command {::optable::editFavoritesMove down}
1275 ttk::button $w.b.ok -text "OK" -command ::optable::editFavoritesOK
1276 ttk::button $w.b.cancel -text $::tr(Cancel) -command {
1277 catch {grab release .editFavoritesDlg}
1278 destroy .editFavoritesDlg
1280 pack $w.b.delete $w.b.up $w.b.down -side left -padx 2 -pady 2
1282 set editFavoritesName ""
1286 set x [
expr {[winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
1287 - [winfo vrootx .]}]
1288 set y [
expr {[winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
1289 - [winfo vrooty .]}]
1291 wm protocol $w WM_DELETE_WINDOW [list $w.b.cancel invoke]
1297 proc ::optable::editFavoritesRefresh {args} {
1298 global reportFavoritesTemp reportFavoritesName
1299 set list .editFavoritesDlg.f.list
1300 set sel [
lindex [$list curselection] 0]
1301 if {$sel == ""} {
return}
1302 set name $reportFavoritesName
1303 set e [
lindex $reportFavoritesTemp $sel]
1304 set moves [
lindex $e 1]
1305 set e [
lreplace $e 0 0 $name]
1306 set reportFavoritesTemp [
lreplace $reportFavoritesTemp $sel $sel $e]
1307 $list insert $sel "$name \[$moves\]"
1308 $list delete [
expr $sel + 1]
1309 $list selection clear 0 end
1310 $list selection set $sel
1313 proc ::optable::editFavoritesSelect {} {
1314 set list .editFavoritesDlg.f.list
1315 set sel [
lindex [$list curselection] 0]
1317 set ::reportFavoritesName ""
1320 if {$sel >= [
llength $::reportFavoritesTemp]} {
1321 $list selection clear 0 end
1322 set ::reportFavoritesName ""
1325 set e [
lindex $::reportFavoritesTemp $sel]
1326 set ::reportFavoritesName [
lindex $e 0]
1329 proc ::optable::editFavoritesDelete {} {
1330 global reportFavoritesTemp
1331 set w .editFavoritesDlg
1333 set sel [
lindex [$list curselection] 0]
1334 if {$sel == ""} {
return}
1335 set reportFavoritesTemp [
lreplace $reportFavoritesTemp $sel $sel]
1336 $list selection clear 0 end
1338 set ::reportFavoritesName ""
1342 proc ::optable::editFavoritesMove {dir} {
1343 global reportFavoritesTemp
1344 set w .editFavoritesDlg
1346 set sel [
lindex [$list curselection] 0]
1347 if {$sel == ""} {
return}
1348 set e [
lindex $reportFavoritesTemp $sel]
1349 set name [
lindex $e 0]
1350 set moves [
lindex $e 1]
1351 set text "$name \[$moves\]"
1356 if {$newsel < 0} {
return}
1359 if {$newsel >= [$list index end]} {
return}
1361 set reportFavoritesTemp [
lreplace $reportFavoritesTemp $sel $sel]
1362 set reportFavoritesTemp [
linsert $reportFavoritesTemp $newsel $e]
1363 $list selection clear 0 end
1365 $list insert $newsel $text
1366 $list selection set $newsel
1369 proc ::optable::editFavoritesOK {} {
1370 set w .editFavoritesDlg
1371 catch {grab release $w}
1373 set ::reportFavorites $::reportFavoritesTemp
1378 proc ::optable::favoritesFilename {} {
1382 proc ::optable::saveFavorites {} {
1384 if {[
catch {open $fname w} f]} {
1388 puts $f "# Scid opening report favorites file"
1390 puts $f "set reportFavorites [list $::reportFavorites]"
1394 proc ::optable::loadFavorites {} {
1395 global reportFavorites
1397 catch {source $fname}
1402 set reportFormat html
1405 proc ::optable::generateFavoriteReports {} {
1406 global reportFavorites
1407 if {[
llength $reportFavorites] == 0} {
1408 tk_messageBox -title "Scid" -type ok -icon info \
1409 -message "You have no favorite report positions."
1412 set ::reportDir $::initialDir(report)
1414 set w .reportFavoritesDlg
1415 if {[
winfo exists $w]} {
return}
1417 wm title $w "Scid: Generate Reports..."
1418 pack [ttk::label $w.typelabel -text "Select the report type:" -font font_Bold] -side top -anchor w
1419 pack [ttk::frame $w.type] -side top -anchor w
1420 ttk::radiobutton $w.type.full -text "Full" -variable reportType -value full
1421 ttk::radiobutton $w.type.compact -text "Compact (no theory table)" -variable reportType -value compact
1422 ttk::radiobutton $w.type.theory -text "Theory table only" -variable reportType -value theory
1423 pack $w.type.full $w.type.compact $w.type.theory -side left -padx 5
1425 pack [ttk::label $w.fmtlabel -text "Select the report file format:" -font font_Bold] -side top -anchor w
1426 pack [ttk::frame $w.fmt] -side top -anchor w
1427 ttk::radiobutton $w.fmt.text -text "Plain text (.txt)" -variable reportFormat -value text
1428 ttk::radiobutton $w.fmt.html -text "HTML" -variable reportFormat -value html
1429 ttk::radiobutton $w.fmt.latex -text "LaTeX" -variable reportFormat -value latex
1430 pack $w.fmt.text $w.fmt.html $w.fmt.latex -side left -padx 5
1432 pack [ttk::frame $w.dir] -side top
1433 ttk::label $w.dir.label -text "Save reports in the folder: " -font font_Bold
1434 ttk::entry $w.dir.entry -textvariable ::reportDir
1435 ttk::button $w.dir.choose -text $::tr(Browse...) -command {
1436 set tmpdir [tk_chooseDirectory -parent .reportFavoritesDlg \
1437 -title "Scid: Choose Report Folder"]
1438 if {$tmpdir != ""} {
1439 set ::reportDir [file nativename $tmpdir]
1442 pack $w.dir.label -side left
1443 pack $w.dir.choose -side right -pady 3
1444 pack $w.dir.entry -side left -fill x -padx 5
1446 pack [ttk::frame $w.b] -side bottom -fill x
1447 ttk::button $w.b.ok -text "OK"\
1448 -command "::optable::reportFavoritesOK; grab release $w; destroy $w; ::optable::makeReportWin"
1449 ttk::button $w.b.cancel -text $::tr(Cancel) -command "grab release $w; destroy $w"
1454 proc ::optable::reportFavoritesOK {} {
1455 global reportDir reportFormat reportType
1456 set ::initialDir(report) $reportDir
1457 set fmt $reportFormat
1458 switch $reportFormat {
1459 "html" {
set suffix ".html"}
1460 "text" {
set suffix ".txt"}
1461 "latex" {
set suffix "tex"}
1464 set w .reportsProgress
1467 wm title $w "Scid: Generating Reports"
1468 bind $w <Visibility> "raiseWin $w"
1469 pack [ttk::label $w.t -width 40 -text "Generating reports. Please wait..." -font font_Bold] -side top -pady 5
1470 pack [ttk::label $w.report] -side top -pady 5
1477 set total [
llength $::reportFavorites]
1478 foreach entry $::reportFavorites {
1479 set name [
lindex $entry 0]
1480 set moves [
lindex $entry 1]
1481 set fname [
file join $reportDir "$name$suffix"]
1482 if {[
catch {open $fname w} f]} {
1483 tk_messageBox -title "Scid" -icon warning -type ok \
1484 -message "Unable to write file: $fname\n$f"
1490 $w.report configure -text "$count / $total: $name$suffix"
1495 if {$reportType == "theory"} {
1497 }
elseif {$reportType == "compact"} {
1502 if {$::hasEncoding && $::langEncoding($::language) != ""} {
1503 catch {
set report [encoding convertto $::langEncoding($::language) $report]}