5 namespace eval ::tourney {}
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} {
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]
22 proc ::tourney::toggle {} {
24 if {[
winfo exists $w]} {
31 proc ::tourney::Open {} {
34 if {[
winfo exists $w]} {
return}
42 wm title $w "Scid: [
tr WindowsTmt]"
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 }
48 bind $w <Up> "$w.t.text yview scroll -1 units"
49 bind $w <Down> "$w.t.text yview scroll 1 units"
50 bind $w <Prior> "$w.t.text yview scroll -1 pages"
51 bind $w <Next> "$w.t.text yview scroll 1 pages"
52 bind $w <Key-Home> "$w.t.text yview moveto 0"
53 bind $w <Key-End> "$w.t.text yview moveto 0.99"
55 foreach i {t o1 o2 o3 b} {ttk::frame $w.$i}
56 text $w.t.text -width 75 -height 22 -font font_Small -wrap none \
57 -fg black -bg white -yscrollcommand "$w.t.ybar set" -setgrid 1 \
58 -cursor top_left_arrow -xscrollcommand "$w.t.xbar set"
60 set xwidth [font measure [$w.t.text cget -font] "0"]
62 foreach {tab justify} {3 r 4 l 18 r 23 r 30 r 32 l 55 l} {
63 set tabwidth [
expr {$xwidth * $tab}]
64 lappend tablist $tabwidth $justify
66 $w.t.text configure -tabs $tablist
67 $w.t.text tag configure date -foreground darkRed
68 $w.t.text tag configure np -foreground darkBlue
69 $w.t.text tag configure elo -foreground darkGreen
70 $w.t.text tag configure best -foreground steelBlue
71 $w.t.text tag configure event -foreground darkRed
72 $w.t.text tag configure title -font font_SmallBold
75 set fbold font_SmallBold
77 ttk::label $f.from -text "[
tr TmtSortDate]:" -font $fbold
78 ttk::entry $f.efrom -textvariable ::tourney::start -width 10 -font $font
80 ttk::label $f.to -text "-" -font $font
81 ttk::entry $f.eto -textvariable ::tourney::end -width 10 -font $font
83 pack $f.from $f.efrom $f.to $f.eto -side left
85 ttk::label $f.cn -text " $::tr(Country):" -font $fbold
86 ttk::combobox $f.ecn -width 4 -textvar ::tourney::country -values {{} AUT CZE DEN ENG ESP FRA GER GRE HUN ITA NED POL RUS \
90 pack $f.cn $f.ecn -side left
92 ttk::label $f.size -text $::tr(TmtLimit:) -font $fbold
93 ttk::combobox $f.esize -width 4 -justify right -textvar ::tourney::size -values {10 20 50 100 200 500 1000}
94 trace variable ::tourney::size w {::utils::validate::Integer 1000 0}
97 pack $f.esize $f.size -side right -pady "2 0"
100 ttk::label $f.players -text "[
tr TmtSortPlayers]:" -font $fbold
101 ttk::entry $f.pmin -textvariable ::tourney::minPlayers \
102 -width 3 -justify right -font $font
104 ttk::label $f.pto -text "-"
105 ttk::entry $f.pmax -textvariable ::tourney::maxPlayers \
106 -width 3 -justify right -font $font
108 pack $f.players $f.pmin $f.pto $f.pmax -side left -pady "2 0"
110 ttk::label $f.games -text " [
tr TmtSortGames]:" -font $fbold
111 ttk::entry $f.gmin -textvariable ::tourney::minGames \
112 -width 4 -justify right -font $font
114 ttk::label $f.gto -text "-" -font $font
115 ttk::entry $f.gmax -textvariable ::tourney::maxGames \
116 -width 4 -justify right -font $font
118 pack $f.games $f.gmin $f.gto $f.gmax -side left -pady "2 0"
119 ttk::label $f.elolab -text "$::tr(TmtMeanElo):" -font $fbold
120 ttk::entry $f.elomin -textvariable ::tourney::minElo \
121 -width 5 -justify right -font $font
123 ttk::label $f.eto -text "-" -font $font
124 ttk::entry $f.elomax -textvariable ::tourney::maxElo \
125 -width 5 -justify right -font $font
127 pack $f.elomax $f.eto $f.elomin $f.elolab -side right
130 ttk::label $f.sitelab -text "$::tr(Site):" -font $fbold
131 ttk::combobox $f.site -textvariable ::tourney::site -width 12
134 pack $f.sitelab $f.site -side left
136 ttk::label $f.eventlab -text " $::tr(Event):" -font $fbold
137 ttk::combobox $f.event -textvariable ::tourney::event -width 12
140 pack $f.eventlab $f.event -side left -pady "2 0"
142 ttk::label $f.playerlab -text "$::tr(Player):" -font $fbold
143 ttk::combobox $f.player -textvariable ::tourney::player -width 12
146 pack $f.player $f.playerlab -side right
149 dialogbutton $w.b.defaults -textvar ::tr(Defaults) -command ::tourney::defaults
150 dialogbutton $w.b.help -textvar ::tr(Help) -command {helpWindow Tmt}
151 dialogbutton $w.b.update -textvar ::tr(Search) -command ::tourney::refresh
154 grid $w.o1 -sticky news
155 grid $w.o2 -sticky news
156 grid $w.o3 -sticky news
157 grid $w.b -sticky news
158 grid $w.t -sticky news
159 grid rowconfigure $w 4 -weight 1
160 grid columnconfigure $w 0 -weight 1
166 proc ::tourney::defaults {} {
167 set ::tourney::_defaults 1
168 set ::tourney::start ""
169 set ::tourney::end ""
170 set ::tourney::size 50
171 set ::tourney::minPlayers ""
172 set ::tourney::maxPlayers ""
173 set ::tourney::minGames ""
174 set ::tourney::maxGames ""
175 set ::tourney::minElo ""
176 set ::tourney::maxElo ""
177 set ::tourney::country ""
178 set ::tourney::site ""
179 set ::tourney::event ""
180 set ::tourney::player ""
183 proc ::tourney::refresh {{option ""}} {
185 if {! [
winfo exists $w]} {
return}
193 $t configure -state normal
198 set ::curr_db [
sc_base current]
200 set start $::tourney::start
201 set end $::tourney::end
202 if { $start eq "" } {
set start "1800.01.01"}
204 sc_filter search $::curr_db $filter header \
206 -date [list $start $end] \
207 -site $::tourney::site \
208 -sitecountry [
string toupper $::tourney::country] \
209 -event $::tourney::event
219 if {[
llength $tlist] > 0} {
220 foreach i {Date Players Games Elo Site Event} {
221 $t tag configure s$i -font font_SmallBold
222 $t tag bind s$i <1> "set ::tourney::sort $i; ::tourney::refresh"
223 $t tag bind s$i <Any-Enter> "$t tag config s$i -foreground red"
224 $t tag bind s$i <Any-Leave> "$t tag config s$i -foreground {}"
226 $t tag configure sWinner -font font_SmallBold
228 $t insert end [
tr TmtSortDate] sDate
230 $t insert end [
tr TmtSortPlayers] sPlayers
232 $t insert end [
tr TmtSortGames] sGames
234 $t insert end [
tr TmtSortElo] sElo
236 $t insert end [
tr TmtSortSite] sSite
238 $t insert end [
tr TmtSortEvent] sEvent
240 $t insert end [
tr TmtSortWinner] sWinner
243 $t insert end $::tr(TmtNone)
250 if {$count > $::tourney::size} { break}
251 set date [
lindex $tmt 0]
252 set site [
lindex $tmt 1]
253 set event [
lindex $tmt 2]
254 set np [
lindex $tmt 3]
255 set ng [
lindex $tmt 4]
256 set elo [
lindex $tmt 5]
257 set g [
lindex $tmt 6]
259 set welo [
lindex $tmt 8]
260 set wscore [
lindex $tmt 9]
262 set belo [
lindex $tmt 11]
263 set bscore [
lindex $tmt 12]
264 if {$welo > 0} {
append white "($welo)"}
265 if {$belo > 0} {
append black "($belo)"}
266 append white " $wscore"
267 append black " $bscore"
270 if {$wscore == $bscore} {
271 set one "1="
set two "1="
273 set best "$one $white, $two $black, ..."
274 if {$np == 2} {
set best "$one $white, $two $black"}
276 $t tag bind g$count <ButtonPress-1> [list ::tourney::select $g]
277 $t tag bind g$count <ButtonPress-$::MB3> [list ::tourney::select $g]
278 $t tag bind g$count <Any-Enter> \
279 "$t tag configure g$count -background $hc"
280 $t tag bind g$count <Any-Leave> \
281 "$t tag configure g$count -background {}"
283 $t insert end "\t$count\t" g$count
284 $t insert end $date [list date g$count]
285 $t insert end "\t" g$count
286 $t insert end $np [list np g$count]
287 $t insert end "\t" g$count
288 $t insert end $ng [list ng g$count]
289 $t insert end "\t" g$count
290 $t insert end $elo [list elo g$count]
291 $t insert end "\t" g$count
292 $t insert end "$site: " [list site g$count]
293 $t insert end "$event" [list event g$count]
294 $t insert end "\t$best" [list best g$count]
297 $t configure -state disabled
300 proc ::tourney::check {} {
301 set start $::tourney::start
302 set end $::tourney::end
303 if {[
string length $start] == 4} {
append start ".??.??"}
304 if {[
string length $end] == 4} {
append end ".12.31"}
305 if {[
string length $start] == 7} {
append start ".??"}
306 if {[
string length $end] == 7} {
append end ".31"}
307 set ::tourney::start $start
308 set ::tourney::end $end
309 set s $::tourney::country
310 set s [
string toupper [
string trim $s]]
311 if {[
string length $s] > 3} {
set s [
string range $s 0 2]}
312 set ::tourney::country $s
313 if {$::tourney::country == "---"} {
314 set ::tourney::country ""
316 if { $::tourney::maxGames ne "" && $::tourney::minGames > $::tourney::maxGames} {
317 set help $::tourney::maxGames
318 set ::tourney::maxGames $::tourney::minGames
319 set ::tourney::minGames $help
321 if {$::tourney::maxElo ne "" && $::tourney::minElo > $::tourney::maxElo} {
322 set help $::tourney::maxElo
323 set ::tourney::maxElo $::tourney::minElo
324 set ::tourney::minElo $help
326 if {$::tourney::maxPlayers ne "" && $::tourney::minPlayers > $::tourney::maxPlayers} {
327 set help $::tourney::maxPlayers
328 set ::tourney::maxPlayers $::tourney::minPlayers
329 set ::tourney::minPlayers $help
333 proc ::tourney::select {gnum} {
335 tk_messageBox -type ok -icon info -title "Scid" -message $result
343 proc ::tourney::getSearchOptions {} {
344 set options [list $::tourney::size]
345 if {$::tourney::player ne ""} {
346 lappend options "-player" $::tourney::player
348 if {$::tourney::sort ne ""} {
349 lappend options "-sort" $::tourney::sort
351 if {$::tourney::minPlayers ne "" || $::tourney::maxPlayers ne ""} {
354 if {$::tourney::minPlayers ne ""} {
355 set minp $::tourney::minPlayers
357 if {$::tourney::maxPlayers ne ""} {
358 set maxp $::tourney::maxPlayers
360 lappend options "-n_players" [list $minp $maxp]
362 if {$::tourney::minGames ne "" || $::tourney::maxGames ne ""} {
365 if {$::tourney::minGames ne ""} {
366 set ming $::tourney::minGames
368 if {$::tourney::maxGames ne ""} {
369 set maxg $::tourney::maxGames
371 lappend options "-n_games" [list $ming $maxg]
373 if {$::tourney::minElo ne "" || $::tourney::maxElo ne ""} {
376 if {$::tourney::minElo ne ""} {
377 set mine $::tourney::minElo
379 if {$::tourney::maxElo ne ""} {
380 set maxe $::tourney::maxElo
382 lappend options "-avgelo" [list $mine $maxe]