Scid  4.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 ""
15  set ::plist::maxGames ""
16  set ::plist::minElo ""
17  set ::plist::maxElo ""
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]} {
32  } else {
34  }
35 }
36 
37 proc ::plist::Open {} {
38  set w .plist
39  if {[winfo exists .plist]} { return}
40  set ::plistWin 1
41 
43  ::setTitle $w "Scid: [tr WindowsPList]"
44 
45  ttk::frame $w.t -relief sunken -borderwidth 1
46  text $w.t.text -width 55 -height 25 -font font_Small -wrap none \
47  -fg black -bg white -cursor top_left_arrow -borderwidth 0
48  autoscrollBars both $w.t $w.t.text
49  set xwidth [font measure [$w.t.text cget -font] "0"]
50  set tablist {}
51  foreach {tab justify} {4 r 10 r 18 r 24 r 32 r 35 l} {
52  set tabwidth [expr {$xwidth * $tab}]
53  lappend tablist $tabwidth $justify
54  }
55  $w.t.text configure -tabs $tablist
56  $w.t.text tag configure ng -foreground darkBlue
57  $w.t.text tag configure date -foreground darkRed
58  $w.t.text tag configure elo -foreground darkGreen
59  $w.t.text tag configure name -foreground black
60  $w.t.text tag configure title -background lightSteelBlue; #-font font_SmallBold
61 
62  set font font_Small
63  set fbold font_SmallBold
64 
65  set f $w.o1
66  ttk::frame $f
67  ttk::label $f.nlabel -text $::tr(Player:) -font $fbold
68  ttk::combobox $f.name -textvariable ::plist::name -width 20
69  ::utils::history::SetCombobox ::plist::name $f.name
70  bindFocusColors $f.name
71  focus $f.name
72  ttk::label $f.size -text $::tr(TmtLimit:) -font $fbold
73  ttk::combobox $f.esize -width 4 -justify right -textvar ::plist::size -values {50 100 200 500 1000}
74  trace variable ::plist::size w {::utils::validate::Integer 1000 0}
75  bindFocusColors $f.esize
76  # foreach n {50 100 200 500 1000} {
77  # $f.esize list insert end $n
78  # }
79  pack $f.esize -side right -padx "0 8" -pady 2
80  pack $f.size -side right -pady 2
81  pack $f.nlabel -side left -padx "8 0" -pady 2
82  pack $f.name -side left -pady 2
83 
84  set f $w.o2
85  ttk::frame $f
86  ttk::label $f.elo -text "[tr PListSortElo]:" -font $fbold
87  ttk::entry $f.emin -textvariable ::plist::minElo
88  ttk::label $f.eto -text "-"
89  ttk::entry $f.emax -textvariable ::plist::maxElo
90  ttk::label $f.games -text "[tr PListSortGames]:" -font $fbold
91  ttk::entry $f.gmin -textvariable ::plist::minGames
92  ttk::label $f.gto -text "-"
93  ttk::entry $f.gmax -textvariable ::plist::maxGames
94 
95  foreach entry {emin emax} {
96  $f.$entry configure -width 4 -justify right -font $font
97  bindFocusColors $f.$entry
98  }
99 
100  foreach entry {gmin gmax} {
101  $f.$entry configure -width 6 -justify right -font $font
102  bindFocusColors $f.$entry
103  }
104 
105  pack $f.elo -side left -padx "8 0"
106  pack $f.emin $f.eto $f.emax -side left
107  pack $f.gmax -side right -padx "0 8"
108  pack $f.gto $f.gmin $f.games -side right
109 
110  ttk::frame $w.b
111  dialogbutton $w.b.defaults -text $::tr(Defaults) -command ::plist::defaults
112  dialogbutton $w.b.update -text $::tr(Search) -command ::plist::refresh
113  packbuttons left $w.b.defaults
114  packbuttons right $w.b.update
115 
116  grid $w.o1 -sticky news
117  grid $w.o2 -sticky news
118  grid $w.b -sticky news
119  grid $w.t -sticky news
120  grid rowconfigure $w 3 -weight 1
121  grid columnconfigure $w 0 -weight 1
122 
123  bind $w <F1> {helpWindow PList}
124  bind $w.t <Destroy> { set plistWin 0 }
125  bind $w <Return> ::plist::refresh
126 
128 }
129 
130 proc ::plist::refresh {} {
131  set w .plist
132  if {! [winfo exists $w]} { return}
133 
134  busyCursor .
135  ::utils::history::AddEntry ::plist::name $::plist::name
136  set t $w.t.text
137  $t configure -state normal
138  $t delete 1.0 end
139 
140  $t insert end "\t" title
141  foreach i {Games Oldest Newest Elo Name} {
142  $t tag configure s$i -font font_SmallBold
143  $t tag bind s$i <1> "set ::plist::sort $i; ::plist::refresh"
144  $t tag bind s$i <Any-Enter> "$t tag config s$i -foreground red"
145  $t tag bind s$i <Any-Leave> "$t tag config s$i -foreground {}"
146  $t insert end "\t" title
147  $t insert end [tr PListSort$i] [list title s$i]
148  }
149  $t insert end "\n" title
150 
152  #TODO: check if this update is necessary
153  update
154 
155  if {[catch { sc_name plist {*}[::plist::getSearchOptions]} pdata]} {
156  $t insert end "\n$pdata\n"
157  unbusyCursor .
158  return
159  }
160 
161  set hc yellow
162  set count 0
163  foreach player $pdata {
164  incr count
165  set ng [lindex $player 0]
166  set oldest [lindex $player 1]
167  set newest [lindex $player 2]
168  set elo [lindex $player 3]
169  set name [lindex $player 4]
170 
171  $t tag bind p$count <ButtonPress-1> [list ::pinfo::playerInfo $name]
172  #$t tag bind p$count <ButtonPress-$::MB3> [list playerInfo $name]
173  $t tag bind p$count <Any-Enter> \
174  "$t tag configure p$count -background $hc"
175  $t tag bind p$count <Any-Leave> \
176  "$t tag configure p$count -background {}"
177  $t insert end "\n"
178  $t insert end "\t$count\t" p$count
179  $t insert end $ng [list ng p$count]
180  $t insert end "\t" p$count
181  $t insert end $oldest [list date p$count]
182  $t insert end "\t" p$count
183  $t insert end "- $newest" [list date p$count]
184  $t insert end "\t" p$count
185  $t insert end $elo [list elo p$count]
186  $t insert end "\t" p$count
187  $t insert end $name [list name p$count]
188  }
189  $t insert end "\n"
190  $t configure -state disabled
191  unbusyCursor .
192 }
193 
194 proc ::plist::check {} {
195  if { $::plist::maxGames ne "" && $::plist::minGames > $::plist::maxGames} {
196  set help $::plist::maxGames
197  set ::plist::maxGames $::plist::minGames
198  set ::plist::minGames $help
199  }
200  if {$::plist::maxElo ne "" && $::plist::minElo > $::plist::maxElo} {
201  set help $::plist::maxElo
202  set ::plist::maxElo $::plist::minElo
203  set ::plist::minElo $help
204  }
205 }
206 
207 proc ::plist::getSearchOptions {} {
208  set options {}
209  if {$::plist::name ne ""} {
210  lappend options "-name" $::plist::name
211  }
212  if {$::plist::size ne ""} {
213  lappend options "-size" $::plist::size
214  }
215  if {$::plist::minGames ne ""} {
216  lappend options "-minGames" $::plist::minGames
217  }
218  if {$::plist::maxGames ne ""} {
219  lappend options "-maxGames" $::plist::maxGames
220  }
221  if {$::plist::minElo ne ""} {
222  lappend options "-minElo" $::plist::minElo
223  }
224  if {$::plist::maxElo ne ""} {
225  lappend options "-maxElo" $::plist::maxElo
226  }
227  if {$::plist::sort ne ""} {
228  lappend options "-sort" [string tolower $::plist::sort]
229  }
230  return $options
231 }