5 namespace eval ::crosstab {
6 variable win .crosstableWin
9 set crosstab(sort) score
10 set crosstab(type) auto
11 set crosstab(ages) "+ages"
12 set crosstab(colors) "+colors"
13 set crosstab(ratings) "+ratings"
14 set crosstab(countries) "+countries"
15 set crosstab(titles) "+titles"
16 set crosstab(groups) "-groups"
17 set crosstab(breaks) "-breaks"
18 set crosstab(deleted) "-deleted"
19 set crosstab(cnumbers) "-numcolumns"
20 set crosstab(text) hypertext
22 proc ::crosstab::ConfigMenus {{lang ""}} {
23 set m $::crosstab::win.menu
24 if {! [
winfo exists $m] } {
return}
26 if {$lang == ""} {
set lang $::language}
27 foreach idx {0 1 2 3 4 5} tag {File Edit Opt Sort Color Help} {
30 foreach idx {0 1 2 4} tag {Text Html LaTeX Close} {
33 foreach idx {0 1 2} tag {Event Site Date} {
36 foreach idx {0 1 2 3 5 6 7 8 9 10 12 13 15} tag {All Swiss Knockout Auto Ages Nats Ratings Titles Breaks Deleted Colors ColumnNumbers Group} {
39 foreach idx {0 1 2} tag {Name Rating Score} {
42 foreach idx {0 1} tag {Plain Hyper} {
45 foreach idx {0 1} tag {Cross Index} {
50 proc ::crosstab::OpenClose {} {
51 if {[
winfo exists $::crosstab::win]} {
58 proc ::crosstab::Open {} {
60 set w $::crosstab::win
69 $w.menu add cascade -label CrosstabFile -menu $w.menu.file
70 $w.menu add cascade -label CrosstabEdit -menu $w.menu.edit
71 $w.menu add cascade -label CrosstabOpt -menu $w.menu.opt
72 $w.menu add cascade -label CrosstabSort -menu $w.menu.sort
73 $w.menu add cascade -label CrosstabText -menu $w.menu.color
74 $w.menu add cascade -label CrosstabHelp -menu $w.menu.helpmenu
75 foreach i {file edit opt sort color helpmenu} {
76 menu $w.menu.$i -tearoff 0
79 $w.menu.file add command -label CrosstabFileText -command {
81 { "Text files" {".txt"} }
84 set fname [tk_getSaveFile -initialdir [pwd] -filetypes $ftype -title "Save Crosstable"]
86 if {[catch {set tempfile [open $fname w]}]} {
87 tk_messageBox -title "Scid: Error saving file" -type ok -icon warning -message "Unable to save the file: $fname\n\n"
89 puts -nonewline $tempfile [$::crosstab::win.f.text get 1.0 end]
94 $w.menu.file add command -label CrosstabFileHtml -command {
96 { "HTML files" {".html" ".htm"} }
99 set fname [tk_getSaveFile -initialdir $::initialDir(html) -filetypes $ftype -title "Save Crosstable as HTML"]
101 if {[file extension $fname] != ".html" && [file extension $fname] != ".htm" } {
104 if {[catch {set tempfile [open $fname w]}]} {
105 tk_messageBox -title "Scid: Error saving file" -type ok -icon warning -message "Unable to save the file: $fname\n\n"
107 catch {sc_game crosstable html $crosstab(sort) $crosstab(type) \
108 $crosstab(ratings) $crosstab(countries) $crosstab(titles) \
109 $crosstab(colors) $crosstab(groups) $crosstab(ages) \
110 $crosstab(breaks) $crosstab(cnumbers) $crosstab(deleted)} \
112 puts $tempfile $result
117 $w.menu.file add command -label CrosstabFileLaTeX -command {
119 { "LaTeX files" {".tex" ".ltx"} }
120 { "All files" {"*"} }
122 set fname [tk_getSaveFile -initialdir $::initialDir(tex) -filetypes $ftype -title "Save Crosstable as LaTeX"]
124 if {[file extension $fname] != ".tex" && [file extension $fname] != ".ltx" } {
127 if {[catch {set tempfile [open $fname w]}]} {
128 tk_messageBox -title "Scid: Error saving file" \
129 -type ok -icon warning \
130 -message "Unable to save the file: $fname\n\n"
132 catch {sc_game crosstable latex $crosstab(sort) $crosstab(type) \
133 $crosstab(ratings) $crosstab(countries) $crosstab(titles) \
134 $crosstab(colors) $crosstab(groups) $crosstab(ages) \
135 $crosstab(breaks) $crosstab(cnumbers) $crosstab(deleted)} \
137 puts $tempfile $result
142 $w.menu.file add separator
143 $w.menu.file add command -label CrosstabFileClose \
144 -command "::win::closeWindow $w"
146 $w.menu.edit add command -label CrosstabEditEvent -command {
148 setNameEditorType event
149 set editName [sc_game info event]
151 set editNameSelect crosstable
153 $w.menu.edit add command -label CrosstabEditSite -command {
155 setNameEditorType site
156 set editName [sc_game info site]
158 set editNameSelect crosstable
160 $w.menu.edit add command -label CrosstabEditDate -command {
162 setNameEditorType date
164 set editDate [sc_game info date]
165 set editDateNew [sc_game info date]
166 set editNameSelect crosstable
169 $w.menu.opt add radiobutton -label CrosstabOptAll \
170 -variable crosstab(type) -value allplay -command crosstab::Refresh
171 $w.menu.opt add radiobutton -label CrosstabOptSwiss \
172 -variable crosstab(type) -value swiss -command crosstab::Refresh
173 $w.menu.opt add radiobutton -label CrosstabOptKnockout \
174 -variable crosstab(type) -value knockout -command crosstab::Refresh
175 $w.menu.opt add radiobutton -label CrosstabOptAuto \
176 -variable crosstab(type) -value auto -command crosstab::Refresh
177 $w.menu.opt add separator
178 $w.menu.opt add checkbutton -label CrosstabOptAges \
179 -variable crosstab(ages) -onvalue "+ages" \
180 -offvalue "-ages" -command crosstab::Refresh
181 $w.menu.opt add checkbutton -label CrosstabOptNats \
182 -variable crosstab(countries) -onvalue "+countries" \
183 -offvalue "-countries" -command crosstab::Refresh
184 $w.menu.opt add checkbutton -label CrosstabOptRatings \
185 -variable crosstab(ratings) -onvalue "+ratings" -offvalue "-ratings" \
186 -command crosstab::Refresh
187 $w.menu.opt add checkbutton -label CrosstabOptTitles \
188 -variable crosstab(titles) -onvalue "+titles" -offvalue "-titles" \
189 -command crosstab::Refresh
190 $w.menu.opt add checkbutton -label CrosstabOptBreaks \
191 -variable crosstab(breaks) -onvalue "+breaks" \
192 -offvalue "-breaks" -command crosstab::Refresh
193 $w.menu.opt add checkbutton -label CrosstabOptDeleted \
194 -variable crosstab(deleted) -onvalue "+deleted" \
195 -offvalue "-deleted" -command crosstab::Refresh
196 $w.menu.opt add separator
197 $w.menu.opt add checkbutton -label CrosstabOptColors \
198 -underline 0 -variable crosstab(colors) \
199 -onvalue "+colors" -offvalue "-colors" -command crosstab::Refresh
200 $w.menu.opt add checkbutton -label CrosstabOptColumnNumbers \
201 -underline 0 -variable crosstab(cnumbers) \
202 -onvalue "+numcolumns" -offvalue "-numcolumns" -command crosstab::Refresh
203 $w.menu.opt add separator
204 $w.menu.opt add checkbutton -label CrosstabOptGroup \
205 -underline 0 -variable crosstab(groups) \
206 -onvalue "+groups" -offvalue "-groups" -command crosstab::Refresh
208 $w.menu.sort add radiobutton -label CrosstabSortName \
209 -variable crosstab(sort) -value name -command crosstab::Refresh
210 $w.menu.sort add radiobutton -label CrosstabSortRating \
211 -variable crosstab(sort) -value rating -command crosstab::Refresh
212 $w.menu.sort add radiobutton -label CrosstabSortScore \
213 -variable crosstab(sort) -value score -command crosstab::Refresh
215 $w.menu.color add radiobutton -label CrosstabColorPlain \
216 -variable crosstab(text) -value plain -command crosstab::Refresh
217 $w.menu.color add radiobutton -label CrosstabColorHyper \
218 -variable crosstab(text) -value hypertext -command crosstab::Refresh
220 $w.menu.helpmenu add command -label CrosstabHelpCross \
221 -command {helpWindow Crosstable}
222 $w.menu.helpmenu add command -label CrosstabHelpIndex \
223 -command {helpWindow Index}
230 -wrap none -font font_Fixed \
231 -background white -cursor top_left_arrow
233 $w.f.text tag configure bgGray -background gray95
235 ttk::button $w.b.stop -textvar ::tr(Stop) -state disabled \
236 -command { set ::htext::interrupt 1 }
237 ttk::menubutton $w.b.type -text "" -menu $w.b.type.menu
239 $w.b.type.menu add radiobutton -label [
tr CrosstabOptAll] \
240 -variable crosstab(type) -value allplay -command crosstab::Refresh
241 $w.b.type.menu add radiobutton -label [
tr CrosstabOptSwiss] \
242 -variable crosstab(type) -value swiss -command crosstab::Refresh
243 $w.b.type.menu add radiobutton -label [
tr CrosstabOptKnockout] \
244 -variable crosstab(type) -value knockout -command crosstab::Refresh
245 $w.b.type.menu add radiobutton -label [
tr CrosstabOptAuto] \
246 -variable crosstab(type) -value auto -command crosstab::Refresh
247 ttk::button $w.b.update -textvar ::tr(Update) -command ::crosstab::Refresh
248 ttk::button $w.b.cancel -textvar ::tr(Close) -command "::win::closeWindow $w"
249 ttk::button $w.b.setfilter -textvar ::tr(SetFilter) -command {
250 sc_filter reset $::crosstab::dbase_ dbfilter empty
251 ::crosstab::AddToFilter
253 ttk::button $w.b.addfilter -textvar ::tr(AddToFilter) -command {
254 ::crosstab::AddToFilter
256 pack $w.b.cancel $w.b.update $w.b.type \
257 -side right -pady 3 -padx 5
258 pack $w.b.setfilter $w.b.addfilter -side left -pady 3 -padx 5
259 pack $w.b -side bottom -fill x
260 pack $w.f -side top -fill both -expand true
263 bind $w.f.text <ButtonPress-1> "focus %W"
268 proc ::crosstab::AddToFilter {} {
269 set curr_base [
sc_base current]
270 sc_base switch $::crosstab::dbase_
276 proc ::crosstab::Refresh {} {
278 set w $::crosstab::win
279 if {! [
winfo exists $w]} {
return}
281 switch $crosstab(type) {
282 allplay { $w.b.type configure -text [
tr CrosstabOptAll]}
283 swiss { $w.b.type configure -text [
tr CrosstabOptSwiss]}
284 knockout { $w.b.type configure -text [
tr CrosstabOptKnockout]}
285 auto { $w.b.type configure -text [
tr CrosstabOptAuto]}
287 $w.f.text configure -state normal
288 $w.f.text delete 1.0 end
290 $w.f.text configure -state disabled
292 $w.b.stop configure -state normal
293 foreach button {update cancel setfilter addfilter type} {
294 $w.b.$button configure -state disabled
296 pack $w.b.stop -side right -padx 5 -pady 3
297 catch {grab $w.b.stop}
299 set ::crosstab::dbase_ [
sc_base current]
300 catch {
sc_game crosstable $crosstab(text) $crosstab(sort) $crosstab(type) \
301 $crosstab(ratings) $crosstab(countries) $crosstab(titles) \
302 $crosstab(colors) $crosstab(groups) $crosstab(ages) \
303 $crosstab(breaks) $crosstab(cnumbers) $crosstab(deleted)} result
304 $w.f.text configure -state normal
305 if {$crosstab(text) == "plain"} {
306 $w.f.text insert end $result
311 set lastLineNum [
expr {int([$w.f.text index end])}]
312 for {
set i 2} {$i <= $lastLineNum} {
incr i 2} {
313 $w.f.text tag add bgGray $i.0 "$i.0 lineend +1c"
316 catch {grab release $w.b.stop}
317 $w.b.stop configure -state disabled
318 pack forget $w.b.stop
319 foreach button {update cancel setfilter addfilter type} {
320 $w.b.$button configure -state normal
322 $w.f.text configure -state disabled