Scid  4.6.5
pfinder.tcl
Go to the documentation of this file.
1 ### file pfinder.tcl: part of Scid.
2 
3 ####################
4 # Player List window
5 
6 namespace eval ::plist {}
7 
8 set plistWin 0
9 
10 set ::plist::sort Name
11 
12 proc ::plist::defaults {} {
13  set ::plist::name ""
14  set ::plist::minGames 0
15  set ::plist::maxGames 9999
16  set ::plist::minElo 0
17  set ::plist::maxElo [sc_info limit elo]
18  set ::plist::size 50
19 }
20 
22 
23 trace variable ::plist::minElo w [list ::utils::validate::Integer [sc_info limit elo] 0]
24 trace variable ::plist::maxElo w [list ::utils::validate::Integer [sc_info limit elo] 0]
25 trace variable ::plist::minGames w [list ::utils::validate::Integer 9999 0]
26 trace variable ::plist::maxGames w [list ::utils::validate::Integer 9999 0]
27 
28 proc ::plist::toggle {} {
29  set w .plist
30  if {[winfo exists $w]} {
31  destroy $w
32  } else {
34  }
35 }
36 
37 proc ::plist::Open {} {
38  global plistWin
39  set w .plist
40  if {[winfo exists .plist]} { return}
41  set plistWin 1
42 
43  toplevel $w
44  wm title $w "Scid: [tr WindowsPList]"
46  bind $w <Configure> "recordWinSize $w"
47 
48  bind $w <F1> {helpWindow PList}
49  bind $w <Escape> "$w.b.close invoke"
50  bind $w <Return> ::plist::refresh
51  bind $w <Destroy> { set plistWin 0 }
53  bind $w <Up> "$w.t.text yview scroll -1 units"
54  bind $w <Down> "$w.t.text yview scroll 1 units"
55  bind $w <Prior> "$w.t.text yview scroll -1 pages"
56  bind $w <Next> "$w.t.text yview scroll 1 pages"
57  bind $w <Key-Home> "$w.t.text yview moveto 0"
58  bind $w <Key-End> "$w.t.text yview moveto 0.99"
59 
60  menu $w.menu
61  $w configure -menu $w.menu
62  $w.menu add cascade -label PListFile -menu $w.menu.file
63  menu $w.menu.file
64  $w.menu.file add command -label Update -command ::plist::refresh
65  $w.menu.file add command -label Close -command "destroy $w"
66  $w.menu add cascade -label PListSort -menu $w.menu.sort
67  menu $w.menu.sort
68  foreach name {Name Elo Games Oldest Newest} {
69  $w.menu.sort add radiobutton -label $name -variable ::plist::sort \
70  -value $name -command ::plist::refresh
71  }
72 
73  foreach i {t o1 o2 o3 b} {frame $w.$i}
74  $w.t configure -relief sunken -borderwidth 1
75  text $w.t.text -width 55 -height 25 -font font_Small -wrap none \
76  -fg black -bg white -yscrollcommand "$w.t.ybar set" -setgrid 1 \
77  -cursor top_left_arrow -xscrollcommand "$w.t.xbar set" -borderwidth 0
78  scrollbar $w.t.ybar -command "$w.t.text yview" -takefocus 0
79  scrollbar $w.t.xbar -orient horiz -command "$w.t.text xview" -takefocus 0
80  set xwidth [font measure [$w.t.text cget -font] "0"]
81  set tablist {}
82  foreach {tab justify} {4 r 10 r 18 r 24 r 32 r 35 l} {
83  set tabwidth [expr {$xwidth * $tab}]
84  lappend tablist $tabwidth $justify
85  }
86  $w.t.text configure -tabs $tablist
87  $w.t.text tag configure ng -foreground darkBlue
88  $w.t.text tag configure date -foreground darkRed
89  $w.t.text tag configure elo -foreground darkGreen
90  $w.t.text tag configure name -foreground black
91  $w.t.text tag configure title -background lightSteelBlue; #-font font_SmallBold
92 
93  set font font_Small
94  set fbold font_SmallBold
95 
96  set f $w.o1
97  label $f.nlabel -text $::tr(Player:) -font $fbold
98  ttk::combobox $f.name -textvariable ::plist::name -width 20
99  ::utils::history::SetCombobox ::plist::name $f.name
100  bindFocusColors $f.name
101  focus $f.name
102  label $f.size -text $::tr(TmtLimit:) -font $fbold
103  ttk::combobox $f.esize -width 4 -justify right -textvar ::plist::size -values {50 100 200 500 1000}
104  trace variable ::plist::size w {::utils::validate::Integer 1000 0}
105  bindFocusColors $f.esize
106  # foreach n {50 100 200 500 1000} {
107  # $f.esize list insert end $n
108  # }
109  pack $f.esize $f.size -side right
110  pack $f.nlabel $f.name -side left
111 
112  set f $w.o2
113  label $f.elo -text "[tr PListSortElo]:" -font $fbold
114  entry $f.emin -textvariable ::plist::minElo
115  label $f.eto -text "-"
116  entry $f.emax -textvariable ::plist::maxElo
117  label $f.games -text "[tr PListSortGames]:" -font $fbold
118  entry $f.gmin -textvariable ::plist::minGames
119  label $f.gto -text "-"
120  entry $f.gmax -textvariable ::plist::maxGames
121 
122  foreach entry {emin emax} {
123  $f.$entry configure -width 4 -justify right -font $font
124  bindFocusColors $f.$entry
125  bind $f.$entry <FocusOut> +::plist::check
126  }
127 
128  foreach entry {gmin gmax} {
129  $f.$entry configure -width 6 -justify right -font $font
130  bindFocusColors $f.$entry
131  bind $f.$entry <FocusOut> +::plist::check
132  }
133 
134  pack $f.elo $f.emin $f.eto $f.emax -side left
135  pack $f.gmax $f.gto $f.gmin $f.games -side right
136 
137  dialogbutton $w.b.defaults -text $::tr(Defaults) -command ::plist::defaults
138  dialogbutton $w.b.update -text $::tr(Update) -command ::plist::refresh
139  dialogbutton $w.b.close -text $::tr(Close) -command "destroy $w"
140  packbuttons left $w.b.defaults
141  packbuttons right $w.b.close $w.b.update
142 
143  pack $w.b -side bottom -fill x
144  pack $w.o3 -side bottom -fill x -padx 2 -pady 2
145  pack $w.o2 -side bottom -fill x -padx 2 -pady 2
146  pack $w.o1 -side bottom -fill x -padx 2 -pady 2
147 
148  pack $w.t -side top -fill both -expand yes
149  grid $w.t.text -row 0 -column 0 -sticky news
150  grid $w.t.ybar -row 0 -column 1 -sticky news
151  grid $w.t.xbar -row 1 -column 0 -sticky news
152  grid rowconfig $w.t 0 -weight 1 -minsize 0
153  grid columnconfig $w.t 0 -weight 1 -minsize 0
154 
157 }
158 
159 proc ::plist::ConfigMenus {{lang ""}} {
160  set w .plist
161  if {! [winfo exists $w]} { return}
162  if {$lang == ""} { set lang $::language}
163  set m $w.menu
164  foreach idx {0 1} tag {File Sort} {
165  configMenuText $m $idx PList$tag $lang
166  }
167  foreach idx {0 2} tag {Update Close} {
168  configMenuText $m.file $idx PListFile$tag $lang
169  }
170  foreach idx {0 1 2 3 4} tag {Name Elo Games Oldest Newest } {
171  configMenuText $m.sort $idx PListSort$tag $lang
172  }
173 }
174 
175 proc ::plist::refresh {} {
176  set w .plist
177  if {! [winfo exists $w]} { return}
178 
179  busyCursor .
180  ::utils::history::AddEntry ::plist::name $::plist::name
181  set t $w.t.text
182  $t configure -state normal
183  $t delete 1.0 end
184 
185  $t insert end "\t" title
186  foreach i {Games Oldest Newest Elo Name} {
187  $t tag configure s$i -font font_SmallBold
188  $t tag bind s$i <1> "set ::plist::sort $i; ::plist::refresh"
189  $t tag bind s$i <Any-Enter> "$t tag config s$i -foreground red"
190  $t tag bind s$i <Any-Leave> "$t tag config s$i -foreground {}"
191  $t insert end "\t" title
192  $t insert end [tr PListSort$i] [list title s$i]
193  }
194  $t insert end "\n" title
195 
196  update
197  set err [catch {sc_name plist -name $::plist::name -size $::plist::size \
198  -minGames $::plist::minGames -maxGames $::plist::maxGames \
199  -minElo $::plist::minElo -maxElo $::plist::maxElo \
200  -sort [string tolower $::plist::sort]} pdata]
201  if {$err} {
202  $t insert end "\n$pdata\n"
203  unbusyCursor .
204  return
205  }
206 
207  set hc yellow
208  set count 0
209  foreach player $pdata {
210  incr count
211  set ng [lindex $player 0]
212  set oldest [lindex $player 1]
213  set newest [lindex $player 2]
214  set elo [lindex $player 3]
215  set name [lindex $player 4]
216 
217  $t tag bind p$count <ButtonPress-1> [list ::pinfo::playerInfo $name]
218  #$t tag bind p$count <ButtonPress-$::MB3> [list playerInfo $name]
219  $t tag bind p$count <Any-Enter> \
220  "$t tag configure p$count -background $hc"
221  $t tag bind p$count <Any-Leave> \
222  "$t tag configure p$count -background {}"
223  $t insert end "\n"
224  $t insert end "\t$count\t" p$count
225  $t insert end $ng [list ng p$count]
226  $t insert end "\t" p$count
227  $t insert end $oldest [list date p$count]
228  $t insert end "\t" p$count
229  $t insert end "- $newest" [list date p$count]
230  $t insert end "\t" p$count
231  $t insert end $elo [list elo p$count]
232  $t insert end "\t" p$count
233  $t insert end $name [list name p$count]
234  }
235  $t insert end "\n"
236  $t configure -state disabled
237  unbusyCursor .
238 }
239 
240 proc ::plist::check {} {
241  if {$::plist::minGames > $::plist::maxGames} {
242  set ::plist::maxGames $::plist::minGames
243  }
244  if {$::plist::minElo > $::plist::maxElo} {
245  set ::plist::maxElo $::plist::minElo
246  }
247 }
248 ### End of file pfinder.tcl: part of Scid.