Scid  4.6.5
eco.tcl
Go to the documentation of this file.
1 
2 ####################
3 # ECO Browser window
4 
5 set ::windows::eco::code ""
6 set ::windows::eco::count 0
7 set ::windows::eco::isOpen 0
8 
9 proc ::windows::eco::OpenClose {} {
10  if {[winfo exists .ecograph]} {
11  destroy .ecograph
12  } else {
14  }
15 }
16 
17 # ::windows::eco::Refresh
18 #
19 # Updates the ECO Browser window, opening it if necessary.
20 # If the ECO code "code" is "x", then the value of the
21 # variable ::windows::eco::code is used instead.
22 #
23 proc ::windows::eco::Refresh {{code "x"}} {
24  set w .ecograph
25  set graph $w.pane.graph
26  set text $w.pane.text
27  if {$code != "x"} { set ::windows::eco::code $code}
28  if {! [winfo exists $w]} {
29  set ::windows::eco::isOpen 1
31  wm minsize $w 200 100
33  bind $w <Escape> "destroy $w"
34  bind $w <F1> {helpWindow ECO}
35  bind $w <Destroy> {set ::windows::eco::isOpen 0}
36  text $w.title -relief flat -height 1 -width 1 -wrap word -font font_Bold
37  $w.title tag configure center -justify center
38  $w.title configure -cursor top_left_arrow
39  pack $w.title -side top -fill x
40  ttk::frame $w.b
41  pack $w.b -side bottom -fill x
42  ttk::button $w.b.classify -textvar ::tr(ReclassifyGames) -command classifyAllGames
43  dialogbutton $w.b.help -textvar ::tr(Help) -command {helpWindow ECO}
44  dialogbutton $w.b.close -textvar ::tr(Close) -command "destroy $w"
45  pack $w.b.classify -side left -padx 5 -pady 5
46  packbuttons right $w.b.close $w.b.help
47  set pane [::utils::pane::Create $w.pane graph text 500 400 0.5]
48  ::utils::pane::SetRange $w.pane 0.3 0.7
49  ::utils::pane::SetDrag $w.pane 0
50  pack $pane -side top -expand true -fill both
51 
52  canvas $graph.c -width 500 -height 250
53  pack $graph.c -side top -fill both -expand yes
54  text $text.text -height 12 -width 75 -wrap word -font font_Regular \
55  -background white -selectbackground lightBlue \
56  -yscroll "$text.ybar set" -xscroll "$text.xbar set"
57  $text.text tag configure bold -font font_Bold
58  $text.text tag configure indent -lmargin2 20
59  $text.text configure -cursor top_left_arrow
60  ::htext::init $text.text
61  ttk::scrollbar $text.ybar -command "$text.text yview"
62  ttk::scrollbar $text.xbar -orient horizontal -command "$text.text xview"
63  grid $text.text -row 0 -column 0 -sticky nesw
64  grid $text.ybar -row 0 -column 1 -sticky nesw
65  #grid $text.xbar -row 1 -column 0 -sticky nesw
66  grid rowconfig $text 0 -weight 1 -minsize 0
67  grid columnconfig $text 0 -weight 1 -minsize 0
68 
69  foreach i {0 1 2 3 4 5 6 7 8 9 A B C D E a b c d e f g h i j k l m n o p
70  q r s t u v w x y z} {
71  bind $w <KeyPress-$i> "::windows::eco::KeyPress $i"
72  }
73 
74  foreach i {Left Delete less BackSpace} {
75  bind $w <KeyPress-$i> {::windows::eco::KeyPress "<"}
76  }
77 
78  bind $w <Home> {.ecograph.pane.text.text yview moveto 0}
79  bind $w <End> {.ecograph.pane.text.text yview moveto 1.0}
80  bind $w <Up> {.ecograph.pane.text.text yview scroll -1 units}
81  bind $w <Down> {.ecograph.pane.text.text yview scroll 1 units}
82  bind $w <Prior> {.ecograph.pane.text.text yview scroll -1 pages}
83  bind $w <Next> {.ecograph.pane.text.text yview scroll 1 pages}
85 
86  bind $graph.c <1> { ::windows::eco::Select %x }
87  bind $graph.c <$::MB3> { ::windows::eco::KeyPress "<" }
88 
89  bind $graph <Configure> {
90  ::utils::graph::configure eco -height [expr {[winfo height .ecograph.pane.graph.c] - 50} ]
91  ::utils::graph::configure eco -width [expr {[winfo width .ecograph.pane.graph.c] - 60} ]
92  ::utils::graph::redraw eco
93  }
94  bind $w <Configure> {
95  ::utils::graph::configure eco -height [expr {[winfo height .ecograph.pane.graph.c] - 50} ]
96  ::utils::graph::configure eco -width [expr {[winfo width .ecograph.pane.graph.c] - 60} ]
97  ::utils::graph::redraw eco
98  }
99  ::setTitle $w "Scid: [tr WindowsECO]"
100  ::utils::graph::create eco -width 1 -height 1 -xtop 50 -ytop 20 \
101  -xmin 0.5 -xtick 1 -ytick 5 -font font_Small -canvas $graph.c
102  update
104  }
105 
106  set height [expr {[winfo height $graph.c] - 50}]
107  set width [expr {[winfo width $graph.c] - 60}]
108 
109  set code $::windows::eco::code
110  # Collect data:
111  set len [string length $code]
112  set subcodes {}
113  if {$len == 0} {
114  set subcodes {A B C D E}
115  } elseif {$len == 1 || $len == 2} {
116  set subcodes {0 1 2 3 4 5 6 7 8 9}
117  } elseif {$len == 3} {
118  set subcodes {a b c d e f g h i j k l m n o p q r s t u v w x y z}
119  }
120 
121  set xlabels {}
122  set count 0
123  set data {}
124  set maxfreq 1
125  set wins {}
126  set draws {}
127 
128  set ::curr_db [sc_base current]
129  foreach i $subcodes {
130  set subcode "$code$i"
131  set stats [sc_base stats $::curr_db eco $subcode]
132  set freq [lindex $stats 0]
133  incr count
134  lappend data $count
135  lappend data $freq
136  lappend wins $count
137  lappend wins [lindex $stats 1]
138  lappend draws $count
139  lappend draws [expr {[lindex $stats 1] + [lindex $stats 2] + [lindex $stats 4]}]
140  if {$freq > $maxfreq} {set maxfreq $freq}
141  if {$len == 3} {
142  set subcode $i
143  }
144  lappend xlabels [list $count $subcode]
145  }
146  set hline 5
147  if {$maxfreq > 20} { set hline 10}
148  if {$maxfreq > 50} { set hline 25}
149  if {$maxfreq > 100} { set hline 50}
150  if {$maxfreq > 200} { set hline 100}
151  if {$maxfreq > 500} { set hline 250}
152  if {$maxfreq > 1000} { set hline 500}
153  if {$maxfreq > 2000} { set hline 1000}
154  if {$maxfreq > 5000} { set hline 2500}
155  if {$maxfreq > 10000} { set hline 5000}
156  if {$maxfreq > 20000} { set hline 10000}
157  if {$maxfreq > 50000} { set hline 25000}
158  if {$maxfreq > 100000} { set hline 50000}
159 
160  ::utils::graph::create eco -width $width -height $height -xtop 50 -ytop 20 \
161  -xmin 0.5 -xtick 1 -ytick $hline -font font_Small -canvas $graph.c
162  ::utils::graph::data eco data -color SteelBlue4 -points 0 -lines 0 -bars 1 \
163  -barwidth 0.8 -outline black -coords $data
164  ::utils::graph::data eco draws -color SteelBlue3 -points 0 -lines 0 -bars 1 \
165  -barwidth 0.8 -outline black -coords $draws
166  ::utils::graph::data eco wins -color SteelBlue1 -points 0 -lines 0 -bars 1 \
167  -barwidth 0.8 -outline black -coords $wins
168  ::utils::graph::data eco bounds -points 0 -lines 0 -bars 0 -coords {1 0 1 1}
169  ::utils::graph::configure eco -ymin 0 -xmin 0.4 -xmax [expr {$count + 0.6}] \
170  -xlabels $xlabels -hline [list [list gray80 1 each $hline]]
172  $text.text configure -state normal
173  $text.text delete 1.0 end
174  set stats [sc_base stats $::curr_db eco $code]
175  if {$len == 0} {
176  set section $::tr(ECOAllSections)
177  } elseif {$len < 3} {
178  set section "$::tr(ECOSection) \"$code\""
179  } else {
180  set section "$::tr(ECOCode) \"$code\""
181  }
182  set header "<center><b>$::tr(ECOSummary) $section</b><br>"
183  append header "[lindex $stats 0] $::tr(games): +[lindex $stats 1] =[lindex $stats 2] -[lindex $stats 3] ([lindex $stats 5]%)</center>\n\n"
184  ::htext::display $text.text "$header[sc_eco summary $code 1]"
185  $text.text configure -state disabled
186  $w.title configure -state normal
187  $w.title delete 1.0 end
188  $w.title insert end "$::tr(ECOFrequency) $section" center
189  $w.title configure -state disabled
190  set ::windows::eco::count $count
191 }
192 
193 proc ::windows::eco::Select {xc} {
194  variable count
195  variable code
196 
197  set x [::utils::graph::xunmap eco $xc]
198  set selection 0
199  for {set i 1} {$i <= $count} {incr i} {
200  if {$x >= [expr {$i - 0.4}] && $x <= [expr {$i + 0.4}]} {
201  set selection $i
202  }
203  }
204  if {$selection == 0} { return}
205  incr selection -1
206  set len [string length $code]
207  if {$len == 0} {
208  set code [lindex {A B C D E} $selection]
209  } elseif {$len == 1 || $len == 2} {
210  append code $selection
211  } elseif {$len == 3} {
212  append code [lindex {a b c d e f g h i j k l m n o p q r s t u v w x y z} $selection]
213  } else {
214  return
215  }
217 }
218 
219 # ::windows::eco::KeyPress
220 #
221 # Handles keyboard events in ECO browser window
222 #
223 proc ::windows::eco::KeyPress {key} {
224  set code $::windows::eco::code
225  set len [string length $code]
226  if {$key == "<"} {
227  set ::windows::eco::code [string range $code 0 [expr {$len - 2}]]
229  return
230  }
231  if {$key == "top"} {
232  set ::windows::eco::code ""
234  return
235  }
236 
237  if {$len == 0} {
238  set key [string toupper $key]
239  switch $key {
240  A - B - C - D - E {
241  # nothing
242  }
243  default { set key ""}
244  }
245  } elseif {$len == 1 || $len == 2} {
246  switch $key {
247  0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 {
248  # nothing
249  }
250  default { set key ""}
251  }
252  } elseif {$len == 3} {
253  set key [string tolower $key]
254  switch $key {
255  a - b - c - d - e - f - g - h - i - j - k - l - m - n - o - p - q - r -
256  s - t - u - v - w - x - y - z {
257  # nothing
258  }
259  default { set key ""}
260  }
261  }
262 
263  if {$key != ""} {
264  set ::windows::eco::code "$code$key"
266  }
267 }
268