Scid  4.6.5
tourney.tcl
Go to the documentation of this file.
1 
2 ####################
3 # Tournament window
4 
5 namespace eval ::tourney {}
6 
7 foreach {n v} {start 0000.00.00 end 2047.12.31 minPlayers 2 maxPlayers 999 \
8  minGames 1 maxGames 9999 minElo 0 maxElo 4000 sort Date \
9  country "" site "" event "" player "" size 50} {
10  set ::tourney::$n $v
11 }
12 
13 trace variable ::tourney::start w ::utils::validate::Date
14 trace variable ::tourney::end w ::utils::validate::Date
15 foreach {n v} {minPlayers 999 maxPlayers 999 minGames 9999 maxGames 9999 \
16  minElo [sc_info limit elo] maxElo [sc_info limit elo]} {
17  trace variable ::tourney::$n w [list ::utils::validate::Integer $v 0]
18 }
19 
20 set tourneyWin 0
21 
22 proc ::tourney::toggle {} {
23  set w .tourney
24  if {[winfo exists $w]} {
25  destroy $w
26  } else {
28  }
29 }
30 
31 proc ::tourney::Open {} {
32  global tourneyWin
33  set w .tourney
34  if {[winfo exists $w]} { return}
35  set tourneyWin 1
36 
37  if {! [info exists ::tourney::_defaults]} { ::tourney::defaults}
38 
39  toplevel $w
40  wm title $w "Scid: [tr WindowsTmt]"
42  bind $w <Configure> "recordWinSize $w"
43 
44  bind $w <F1> {helpWindow Tmt}
45  bind $w <Escape> "$w.b.close invoke"
46  bind $w <Return> ::tourney::refresh
47  bind $w <Destroy> { set tourneyWin 0 }
49  bind $w <Up> "$w.t.text yview scroll -1 units"
50  bind $w <Down> "$w.t.text yview scroll 1 units"
51  bind $w <Prior> "$w.t.text yview scroll -1 pages"
52  bind $w <Next> "$w.t.text yview scroll 1 pages"
53  bind $w <Key-Home> "$w.t.text yview moveto 0"
54  bind $w <Key-End> "$w.t.text yview moveto 0.99"
55 
56  menu $w.menu
57  $w configure -menu $w.menu
58  $w.menu add cascade -label TmtFile -menu $w.menu.file
59  menu $w.menu.file
60  $w.menu.file add command -label TmtFileUpdate -command ::tourney::refresh
61  $w.menu.file add command -label TmtFileClose -command "destroy $w"
62  $w.menu add cascade -label TmtSort -menu $w.menu.sort
63  menu $w.menu.sort
64  foreach name {Date Players Games Elo Site Event} {
65  $w.menu.sort add radiobutton -label TmtSor$name \
66  -variable ::tourney::sort -value $name -command {::tourney::refresh}
67  }
68 
69  foreach i {t o1 o2 o3 b} {frame $w.$i}
70  text $w.t.text -width 75 -height 22 -font font_Small -wrap none \
71  -fg black -bg white -yscrollcommand "$w.t.ybar set" -setgrid 1 \
72  -cursor top_left_arrow -xscrollcommand "$w.t.xbar set"
73  scrollbar $w.t.ybar -command "$w.t.text yview" -width 12 -takefocus 0
74  scrollbar $w.t.xbar -orient horiz -command "$w.t.text xview" -width 12 \
75  -takefocus 0
76  set xwidth [font measure [$w.t.text cget -font] "0"]
77  set tablist {}
78  foreach {tab justify} {3 r 4 l 18 r 23 r 30 r 32 l 55 l} {
79  set tabwidth [expr {$xwidth * $tab}]
80  lappend tablist $tabwidth $justify
81  }
82  $w.t.text configure -tabs $tablist
83  $w.t.text tag configure date -foreground darkRed
84  $w.t.text tag configure np -foreground darkBlue
85  $w.t.text tag configure elo -foreground darkGreen
86  $w.t.text tag configure best -foreground steelBlue
87  $w.t.text tag configure event -foreground darkRed
88  $w.t.text tag configure title -font font_SmallBold
89 
90  set font font_Small
91  set fbold font_SmallBold
92  set f $w.o1
93  label $f.from -text "[tr TmtSortDate]:" -font $fbold
94  entry $f.efrom -textvariable ::tourney::start -width 10 -font $font
95  bindFocusColors $f.efrom
96  bind $f.efrom <FocusOut> +::tourney::check
97  label $f.to -text "-" -font $font
98  entry $f.eto -textvariable ::tourney::end -width 10 -font $font
99  bindFocusColors $f.eto
100  bind $f.eto <FocusOut> +::tourney::check
101  pack $f.from $f.efrom $f.to $f.eto -side left
102 
103  label $f.cn -text " $::tr(Country):" -font $fbold
104  ttk::combobox $f.ecn -width 4 -textvar ::tourney::country -values {{} AUT CZE DEN ENG ESP FRA GER GRE HUN ITA NED POL RUS \
105  SCG SUI SWE USA YUG}
106 
107  bindFocusColors $f.ecn
108  bind $f.ecn <FocusOut> +::tourney::check
109  pack $f.cn $f.ecn -side left
110 
111  label $f.size -text $::tr(TmtLimit:) -font $fbold
112  ttk::combobox $f.esize -width 4 -justify right -textvar ::tourney::size -values {10 20 50 100 200 500 1000}
113  trace variable ::tourney::size w {::utils::validate::Integer 1000 0}
114  bindFocusColors $f.esize
115 
116  pack $f.esize $f.size -side right
117 
118  set f $w.o2
119  label $f.players -text "[tr TmtSortPlayers]:" -font $fbold
120  entry $f.pmin -textvariable ::tourney::minPlayers \
121  -width 3 -justify right -font $font
122  bindFocusColors $f.pmin
123  bind $f.pmin <FocusOut> +::tourney::check
124  label $f.pto -text "-"
125  entry $f.pmax -textvariable ::tourney::maxPlayers \
126  -width 3 -justify right -font $font
127  bindFocusColors $f.pmax
128  bind $f.pmax <FocusOut> +::tourney::check
129  pack $f.players $f.pmin $f.pto $f.pmax -side left
130 
131  label $f.games -text " [tr TmtSortGames]:" -font $fbold
132  entry $f.gmin -textvariable ::tourney::minGames \
133  -width 4 -justify right -font $font
134  bindFocusColors $f.gmin
135  bind $f.gmin <FocusOut> +::tourney::check
136  label $f.gto -text "-" -font $font
137  entry $f.gmax -textvariable ::tourney::maxGames \
138  -width 4 -justify right -font $font
139  bindFocusColors $f.gmax
140  bind $f.gmax <FocusOut> +::tourney::check
141  pack $f.games $f.gmin $f.gto $f.gmax -side left
142  label $f.elolab -text "$::tr(TmtMeanElo):" -font $fbold
143  entry $f.elomin -textvariable ::tourney::minElo \
144  -width 5 -justify right -font $font
145  bindFocusColors $f.elomin
146  label $f.eto -text "-" -font $font
147  entry $f.elomax -textvariable ::tourney::maxElo \
148  -width 5 -justify right -font $font
149  bindFocusColors $f.elomax
150  pack $f.elomax $f.eto $f.elomin $f.elolab -side right
151 
152  set f $w.o3
153  label $f.sitelab -text "$::tr(Site):" -font $fbold
154  ttk::combobox $f.site -textvariable ::tourney::site -width 12
155  ::utils::history::SetCombobox ::tourney::site $f.site
156  bindFocusColors $f.site
157  pack $f.sitelab $f.site -side left
158 
159  label $f.eventlab -text " $::tr(Event):" -font $fbold
160  ttk::combobox $f.event -textvariable ::tourney::event -width 12
161  ::utils::history::SetCombobox ::tourney::event $f.event
162  bindFocusColors $f.event
163  pack $f.eventlab $f.event -side left
164 
165  label $f.playerlab -text "$::tr(Player):" -font $fbold
166  ttk::combobox $f.player -textvariable ::tourney::player -width 12
167  ::utils::history::SetCombobox ::tourney::player $f.player
168  bindFocusColors $f.player
169  pack $f.player $f.playerlab -side right
170  focus $f.site
171 
172  dialogbutton $w.b.defaults -textvar ::tr(Defaults) -command ::tourney::defaults
173  dialogbutton $w.b.help -textvar ::tr(Help) -command {helpWindow Tmt}
174  dialogbutton $w.b.update -textvar ::tr(Update) -command ::tourney::refresh
175  dialogbutton $w.b.close -textvar ::tr(Close) -command "destroy $w"
176  pack $w.b -side bottom -fill x
177  packbuttons right $w.b.close $w.b.update $w.b.help
178  packbuttons left $w.b.defaults
179  pack $w.o3 -side bottom -fill x -padx 2 -pady 2
180  pack $w.o2 -side bottom -fill x -padx 2 -pady 2
181  pack $w.o1 -side bottom -fill x -padx 2 -pady 2
182  pack $w.t -side top -fill both -expand yes
183  grid $w.t.text -row 0 -column 0 -sticky news
184  grid $w.t.ybar -row 0 -column 1 -sticky news
185  grid $w.t.xbar -row 1 -column 0 -sticky news
186  grid rowconfig $w.t 0 -weight 1 -minsize 0
187  grid columnconfig $w.t 0 -weight 1 -minsize 0
188 
191 }
192 
193 proc ::tourney::ConfigMenus {{lang ""}} {
194  set w .tourney
195  if {! [winfo exists $w]} { return}
196  if {$lang == ""} { set lang $::language}
197  set m $w.menu
198  foreach idx {0 1} tag {File Sort} {
199  configMenuText $m $idx Tmt$tag $lang
200  }
201  foreach idx {0 2} tag {Update Close} {
202  configMenuText $m.file $idx TmtFile$tag $lang
203  }
204  foreach idx {0 1 2 3 4 5} tag {Date Players Games Elo Site Event} {
205  configMenuText $m.sort $idx TmtSort$tag $lang
206  }
207 }
208 
209 proc ::tourney::defaults {} {
210  set ::tourney::_defaults 1
211  set year [::utils::date::today year]
212  #set ::tourney::start "$year.??.??"
213  set ::tourney::start "1800.??.??"
214  set ::tourney::end "$year.12.31"
215  set ::tourney::size 50
216  set ::tourney::minPlayers 2
217  set ::tourney::maxPlayers 999
218  set ::tourney::minGames 1
219  set ::tourney::maxGames 9999
220  set ::tourney::minElo 0
221  set ::tourney::maxElo 4000
222  set ::tourney::country ""
223  set ::tourney::site ""
224  set ::tourney::event ""
225  set ::tourney::player ""
226 }
227 
228 proc ::tourney::refresh {{option ""}} {
229  set w .tourney
230  if {! [winfo exists $w]} { return}
231 
232  busyCursor $w
233  ::utils::history::AddEntry ::tourney::site $::tourney::site
234  ::utils::history::AddEntry ::tourney::event $::tourney::event
235  ::utils::history::AddEntry ::tourney::player $::tourney::player
236 
237  set t $w.t.text
238  $t configure -state normal
239  $t delete 1.0 end
240  update
241 
242  set ::curr_db [sc_base current]
243  set filter [sc_filter new $::curr_db]
244  sc_filter search $::curr_db $filter header \
245  -filter RESET \
246  -date [list $::tourney::start $::tourney::end] \
247  -site $::tourney::site \
248  -sitecountry [string toupper $::tourney::country] \
249  -event $::tourney::event
250  set err [catch {sc_base tournaments $::curr_db $filter $::tourney::size \
251  -n_players [list $::tourney::minPlayers $::tourney::maxPlayers] \
252  -n_games [list $::tourney::minGames $::tourney::maxGames] \
253  -avgelo [list $::tourney::minElo $::tourney::maxElo] \
254  -player $::tourney::player \
255  -sort $::tourney::sort} tlist]
256  sc_filter release $::curr_db $filter
257  unbusyCursor .
258 
259  if {$err} {
261  return
262  }
263 
264  if {[llength $tlist] > 0} {
265  foreach i {Date Players Games Elo Site Event} {
266  $t tag configure s$i -font font_SmallBold
267  $t tag bind s$i <1> "set ::tourney::sort $i; ::tourney::refresh"
268  $t tag bind s$i <Any-Enter> "$t tag config s$i -foreground red"
269  $t tag bind s$i <Any-Leave> "$t tag config s$i -foreground {}"
270  }
271  $t tag configure sWinner -font font_SmallBold
272  $t insert end "\t\t"
273  $t insert end [tr TmtSortDate] sDate
274  $t insert end "\t"
275  $t insert end [tr TmtSortPlayers] sPlayers
276  $t insert end "\t"
277  $t insert end [tr TmtSortGames] sGames
278  $t insert end "\t"
279  $t insert end [tr TmtSortElo] sElo
280  $t insert end "\t"
281  $t insert end [tr TmtSortSite] sSite
282  $t insert end ": "
283  $t insert end [tr TmtSortEvent] sEvent
284  $t insert end "\t"
285  $t insert end [tr TmtSortWinner] sWinner
286  $t insert end "\n"
287  } else {
288  $t insert end $::tr(TmtNone)
289  }
290 
291  set hc yellow
292  set count 0
293  foreach tmt $tlist {
294  incr count
295  if {$count > $::tourney::size} { break}
296  set date [lindex $tmt 0]
297  set site [lindex $tmt 1]
298  set event [lindex $tmt 2]
299  set np [lindex $tmt 3]
300  set ng [lindex $tmt 4]
301  set elo [lindex $tmt 5]
302  set g [lindex $tmt 6]
303  set white [::utils::string::Surname [lindex $tmt 7]]
304  set welo [lindex $tmt 8]
305  set wscore [lindex $tmt 9]
306  set black [::utils::string::Surname [lindex $tmt 10]]
307  set belo [lindex $tmt 11]
308  set bscore [lindex $tmt 12]
309  if {$welo > 0} { append white "($welo)"}
310  if {$belo > 0} { append black "($belo)"}
311  append white " $wscore"
312  append black " $bscore"
313  set one "1."
314  set two "2."
315  if {$wscore == $bscore} {
316  set one "1="; set two "1="
317  }
318  set best "$one $white, $two $black, ..."
319  if {$np == 2} { set best "$one $white, $two $black"}
320 
321  $t tag bind g$count <ButtonPress-1> [list ::tourney::select $g]
322  $t tag bind g$count <ButtonPress-$::MB3> [list ::tourney::select $g]
323  $t tag bind g$count <Any-Enter> \
324  "$t tag configure g$count -background $hc"
325  $t tag bind g$count <Any-Leave> \
326  "$t tag configure g$count -background {}"
327  $t insert end "\n"
328  $t insert end "\t$count\t" g$count
329  $t insert end $date [list date g$count]
330  $t insert end "\t" g$count
331  $t insert end $np [list np g$count]
332  $t insert end "\t" g$count
333  $t insert end $ng [list ng g$count]
334  $t insert end "\t" g$count
335  $t insert end $elo [list elo g$count]
336  $t insert end "\t" g$count
337  $t insert end "$site: " [list site g$count]
338  $t insert end "$event" [list event g$count]
339  $t insert end "\t$best" [list best g$count]
340  }
341  $t insert end "\n"
342  $t configure -state disabled
343 }
344 
345 proc ::tourney::check {} {
346  set start $::tourney::start
347  set end $::tourney::end
348  if {[string length $start] == 0} { set start "0000"}
349  if {[string length $end] == 0} { set end [sc_info limit year]}
350  if {[string length $start] == 4} { append start ".??.??"}
351  if {[string length $end] == 4} { append end ".12.31"}
352  if {[string length $start] == 7} { append start ".??"}
353  if {[string length $end] == 7} { append end ".31"}
354  set ::tourney::start $start
355  set ::tourney::end $end
356  if {$::tourney::minPlayers < 2} {set ::tourney::minPlayers 2}
357  if {$::tourney::minPlayers > $::tourney::maxPlayers} {
358  set ::tourney::maxPlayers $::tourney::minPlayers
359  }
360  set s $::tourney::country
361  set s [string toupper [string trim $s]]
362  if {[string length $s] > 3} { set s [string range $s 0 2]}
363  set ::tourney::country $s
364  if {$::tourney::country == "---"} {
365  set ::tourney::country ""
366  }
367 }
368 
369 proc ::tourney::select {gnum} {
370  if {[catch {::game::Load $gnum} result]} {
371  tk_messageBox -type ok -icon info -title "Scid" -message $result
372  return
373  }
374  updateBoard -pgn
377 }
378