14 set currentTuningBook ""
16 set cancelBookExport 0
29 proc scBookOpen { name slot } {
30 if {$slot == $::book::bookSlot} {
31 if {$::book::currentBook != ""} {
34 set ::book::currentBook $name
36 if {$slot == $::book::bookTuningSlot} {
37 if {$::book::currentTuningBook != ""} {
38 sc_book close $::book::bookTuningSlot
40 set ::book::currentTuningBook $name
43 set bn [
file join $::scidBooksDir $name]
44 set ::book::isReadonly [
sc_book load $bn $slot]
51 proc getMove { book fen slot} {
54 set bookmoves [
sc_book moves $slot]
55 if {[
llength $bookmoves] == 0} {
58 set r [
expr {(int (rand() * 100))}]
59 for {
set i 0} {$i<[
llength $bookmoves]} {
incr i 2} {
60 set m [
lindex $bookmoves $i]
61 set prob [
string range [
lindex $bookmoves [
expr $i + 1]] 0 end-1]
74 proc togglePositionsDisplay {} {
75 global ::book::oppMovesVisible
76 if { $::book::oppMovesVisible == 0} {
77 set ::book::oppMovesVisible 1
78 pack .bookWin.f.text1 -expand yes -fill both
80 set ::book::oppMovesVisible 0
81 pack forget .bookWin.f.text1
89 proc open { {name ""} } {
90 global ::book::bookList ::book::bookPath ::book::currentBook ::book::isOpen ::book::lastBook
94 if {[
winfo exists $w]} {
return}
105 if { $name == "" && $lastBook != "" } {
108 set bookPath $::scidBooksDir
109 set bookList [ lsort -dictionary [ glob -nocomplain -directory $bookPath *.bin]]
112 if { [
llength $bookList] == 0 } {
113 tk_messageBox -title "Scid" -type ok -icon error -message "No books found. Check books directory"
115 set ::book::currentBook ""
123 foreach file $bookList {
124 set f [
file tail $file]
131 ttk::combobox $w.f.combo -width 12 -values $tmp
133 catch { $w.f.combo current $idx}
137 ttk::frame $w.f.fscroll
138 autoscrollframe -bars y $w.f.fscroll text $w.f.text -wrap word -state disabled -width 12
140 ttk::button $w.f.b -text $::tr(OtherBookMoves) -command { ::book::togglePositionsDisplay }
143 text $w.f.text1 -wrap word -state disabled -width 12
145 pack $w.f.fscroll -expand yes -fill both
147 pack $w.f.text1 -expand yes -fill both
149 pack $w.f -expand 1 -fill both
151 bind $w.f.combo <<ComboboxSelected>> ::book::bookSelect
152 bind $w <Destroy> "::book::closeMainBook"
155 tk_messageBox -title "Scid" -type ok -icon error -message "No books found. Check books directory"
157 set ::book::currentBook ""
164 proc closeMainBook {} {
165 if { $::book::currentBook == "" } {
return}
167 sc_book close $::book::bookSlot
169 set ::book::currentBook ""
175 global ::book::bookMoves
177 foreach t [.bookWin.f.text tag names] {
178 if { [
string match "bookMove*" $t] } {
179 .bookWin.f.text tag delete $t
182 foreach t [.bookWin.f.text1 tag names] {
183 if { [
string match "bookMove*" $t] } {
184 .bookWin.f.text1 tag delete $t
187 set bookMoves [
sc_book moves $::book::bookSlot]
188 .bookWin.f.text configure -state normal
189 .bookWin.f.text delete 1.0 end
190 for {
set i 0} {$i<[
llength $bookMoves]} {
incr i 2} {
191 set line [
expr $i /2 +1]
193 append m [
::trans [
lindex $bookMoves $i]] "\t" [
lindex $bookMoves [
expr $i + 1]] "\n"
194 .bookWin.f.text insert end $m
195 .bookWin.f.text tag add bookMove$line $line.0 $line.end
196 .bookWin.f.text tag bind bookMove$line <ButtonPress-1> "::book::makeBookMove [
lindex $bookMoves $i]"
198 .bookWin.f.text configure -state disabled -height [
expr [
llength $bookMoves] / 2]
201 set oppBookMoves [
sc_book positions $::book::bookSlot]
202 .bookWin.f.text1 configure -state normal
203 .bookWin.f.text1 delete 1.0 end
204 for {
set i 0} {$i<[
llength $oppBookMoves]} {
incr i 1} {
205 set line [
expr $i +1]
207 append m [
::trans [
lindex $oppBookMoves $i]] "\n"
208 .bookWin.f.text1 insert end $m
209 .bookWin.f.text1 tag add bookMove$line $line.0 $line.end
210 .bookWin.f.text1 tag bind bookMove$line <ButtonPress-1> "::book::makeBookMove [
lindex $oppBookMoves $i]"
212 .bookWin.f.text1 configure -state disabled -height [
llength $oppBookMoves]
213 if { $::book::oppMovesVisible == 0 } {
214 pack forget .bookWin.f.text1
220 proc makeBookMove { move } {
226 proc bookSelect { { n "" } { v 0} } {
227 set ::book::lastBook [.bookWin.f.combo get]
228 scBookOpen [.bookWin.f.combo get] $::book::bookSlot
234 proc tuning { {name ""} } {
235 global ::book::bookList ::book::bookPath ::book::currentBook ::book::isOpen
239 if {[
winfo exists $w]} {
247 bind $w <F1> { helpWindow BookTuningWindow }
253 set bookPath $::scidBooksDir
254 set bookList [ lsort -dictionary [ glob -nocomplain -directory $bookPath *.bin]]
257 if { [
llength $bookList] == 0 } {
258 tk_messageBox -title "Scid" -type ok -icon error -message "No books found. Check books directory"
260 set ::book::currentBook ""
268 foreach file $bookList {
269 set f [
file tail $file]
277 ttk::combobox $w.fcombo.combo -width 12 -values $tmp
278 catch { $w.fcombo.combo current $idx}
279 pack $w.fcombo.combo -expand yes -fill x
281 ttk::frame $w.fbutton
284 ttk::menubutton $w.fbutton.mbAdd -text $::tr(AddMove) -menu $w.fbutton.mbAdd.otherMoves
285 menu $w.fbutton.mbAdd.otherMoves
288 ttk::button $w.fbutton.bExport -text $::tr(Export) -command ::book::export
289 ttk::button $w.fbutton.bSave -text $::tr(Save) -command ::book::save
291 pack $w.fbutton.mbAdd $w.fbutton.bExport $w.fbutton.bSave -side top -fill x -expand yes
294 pack $w.fcombo $w.f $w.fbutton -side top
296 bind $w.fcombo.combo <<ComboboxSelected>> ::book::bookTuningSelect
298 bind $w <Destroy> "if {\[string equal $w %W\]} { ::book::closeTuningBook }"
299 bind $w <F1> { helpWindow BookTuning }
307 proc closeTuningBook {} {
308 if { $::book::currentTuningBook == "" } {
return}
310 sc_book close $::book::bookTuningSlot
311 set ::book::currentTuningBook ""
316 proc bookTuningSelect { { n "" } { v 0} } {
318 scBookOpen [.bookTuningWin.fcombo.combo get] $::book::bookTuningSlot
319 if { $::book::isReadonly > 0 } {
320 $w.fbutton.bSave configure -state disabled
322 $w.fbutton.bSave configure -state normal
329 proc addBookMove { move } {
330 global ::book::bookTuningMoves
332 if { $::book::isReadonly > 0 } {
return}
335 set children [
winfo children $w.f]
336 set count [
expr [
llength $children] / 2]
337 ttk::label $w.f.m$count -text [
::trans $move]
338 bind $w.f.m$count <ButtonPress-1> " ::book::makeBookMove $move"
339 ttk::spinbox $w.f.sp$count -from 0 -to 100 -width 3
341 grid $w.f.m$count -row $count -column 0 -sticky w
342 grid $w.f.sp$count -row $count -column 1 -sticky w
343 $w.fbutton.mbAdd.otherMoves delete [
::trans $move]
344 lappend ::book::bookTuningMoves $move
349 proc refreshTuning {} {
351 if { $::book::isReadonly > 0 } {
return}
355 global ::book::bookTuningMoves
356 set ::book::bookTuningMoves {}
357 set moves [
sc_book moves $::book::bookTuningSlot]
361 set children [
winfo children $w.f]
362 foreach c $children {
367 for {
set i 0} {$i<[
llength $moves]} {
incr i 2} {
368 lappend ::book::bookTuningMoves [
lindex $moves $i]
369 ttk::label $w.f.m$row -text [
::trans [
lindex $moves $i]]
370 bind $w.f.m$row <ButtonPress-1> " ::book::makeBookMove [
lindex $moves $i] "
371 ttk::spinbox $w.f.sp$row -from 0 -to 100 -width 3
372 set pct [
lindex $moves [
expr $i+1]]
373 set value [
string replace $pct end end ""]
374 $w.f.sp$row set $value
375 grid $w.f.m$row -row $row -column 0 -sticky w
376 grid $w.f.sp$row -row $row -column 1 -sticky w
380 $w.fbutton.mbAdd.otherMoves delete 0 end
381 $w.fbutton.mbAdd.otherMoves add command -label $::tr(None)
382 set moveList [
sc_pos moves]
383 foreach move $moveList {
384 if { [ lsearch $moves $move] == -1 } {
385 $w.fbutton.mbAdd.otherMoves add command -label [
::trans $move] -command "::book::addBookMove $move"
393 global ::book::bookTuningMoves
394 if { $::book::isReadonly > 0 } {
return}
398 set children [
winfo children $w.f]
399 set count [
expr [
llength $children] / 2]
400 for {
set row 0} {$row < $count} {
incr row} {
401 lappend prob [$w.f.sp$row get]
403 set tempfile [
file join $::scidUserDir tempfile.[
pid]]
404 sc_book movesupdate $::book::bookTuningMoves $prob $::book::bookTuningSlot $tempfile
405 file delete $tempfile
406 if { [
winfo exists .bookWin] } {
416 progressWindow "Scid" "ExportingBook..." $::tr(Cancel) "::book::sc_progressBar"
417 set ::book::cancelBookExport 0
418 set ::book::exportCount 0
420 set ::book::hashList ""
422 if { $::book::exportCount >= $::book::exportMax } {
423 tk_messageBox -title "Scid" -type ok -icon info \
424 -message "$::tr(Movesloaded) $::book::exportCount\n$::tr(BookPartiallyLoaded)"
426 tk_messageBox -title "Scid" -type ok -icon info -message "$::tr(Movesloaded) $::book::exportCount"
435 global ::book::hashList
437 if {$::book::cancelBookExport} {
return}
438 if { $::book::exportCount >= $::book::exportMax } {
442 if {[lsearch -sorted -integer -exact $hashList $hash] != -1} {
445 lappend hashList $hash
446 set hashList [lsort -integer -unique $hashList]
451 set bookMoves [
sc_book moves $::book::bookTuningSlot]
452 incr ::book::exportCount
453 if {[
expr $::book::exportCount % 50] == 0} {
457 if {[
llength $bookMoves] == 0} {
return}
459 for {
set i 0} {$i<[
llength $bookMoves]} {
incr i 2} {
460 set move [
lindex $bookMoves $i]
477 proc sc_progressBar {} {
478 set ::book::cancelBookExport 1