4 # Praat script handling configuration page
6 # SpeakGoodChinese: Config.praat loads the code needed for the
7 # settings and the Settings page of SpeakGoodChinese.
9 # Copyright (C) 2007-2010 R.J.J.H. van Son and 2010 the Netherlands Cancer Institute
10 # The SpeakGoodChinese team are:
11 # Guangqin Chen, Zhonyan Chen, Stefan de Koning, Eveline van Hagen,
12 # Rob van Son, Dennis Vierkant, David Weenink
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29 ###############################################################
31 # Button Drawing Routines
33 ###############################################################
35 procedure DrawCredits .color$ .x .y .size
38 call adjustFontSizeOnHeight 'defaultFont$' 24 '.lineheight'
39 .currentFontSize = adjustFontSizeOnHeight.newFontSize
40 demo Paint circle... {0.2,0.2,0.8} '.x' '.y' '.size'
42 demo Text special... '.x' centre '.y' half Times '.currentFontSize' 0 i
45 call set_font_size 'defaultFontSize'
48 procedure DrawDeleteList .color$ .x .y .size
56 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
59 .maxWidth = (.rightX - .leftX)
60 .currentFontSize = defaultFontSize
61 call adjustFontSizeOnWidth 'defaultFont$' '.currentFontSize' '.maxWidth' '.displayWordList$'
62 .currentFontSize = adjustFontSizeOnWidth.newFontSize
63 if adjustFontSizeOnWidth.diff > 0
64 .rightX += adjustFontSizeOnWidth.diff/2
65 .leftX -= adjustFontSizeOnWidth.diff/2
67 call set_font_size '.currentFontSize'
68 demo Paint rectangle... White '.leftX' '.rightX' '.botY' '.topY'
70 demo Text... '.x' Centre '.botY' Bottom '.displayWordList$'
73 call set_font_size 'defaultFontSize'
76 procedure DrawLogging .color$ .x .y .size
80 .color$ = "{0.5,0.5,1}"
84 demo Paint circle... '.color$' '.x' '.y' '.size'
87 ###############################################################
89 # Obligatory button Drawing Routines
91 # These MUST be defined
93 ###############################################################
95 procedure DrawReturn .color$ .x .y .size
96 call DrawConfig '.color$' '.x' '.y' '.size'
99 # Set the correct button states after redrawing the window
100 procedure setConfigMainPage
101 # Handle logging buttons with forced button draw
102 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
103 call Draw_button 'config$' +!Logging 'config.logPerformance'
107 ###############################################################
109 # Button Processing Routines
111 ###############################################################
113 procedure processConfigShuffleLists .clickX .clickY .pressed$
115 .label$ = "ShuffleLists"
116 config.shuffleLists = not config.shuffleLists
117 .displayButton = 2*config.shuffleLists
118 call Draw_button '.table$' '.label$' '.displayButton'
121 procedure processConfigUseSoundExample .clickX .clickY .pressed$
123 .label$ = "UseSoundExample"
124 config.useSoundExample = not config.useSoundExample
125 .displayButton = 2*config.useSoundExample
126 call Draw_button '.table$' '.label$' '.displayButton'
129 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
131 .label$ = "Synthesis_'.tts$'"
132 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
133 if config.synthesis$ = ""
134 config.synthesis$ = .tts$
137 config.synthesis$ = ""
141 config.synthesis$ = "_DISABLED_"
144 call Draw_button '.table$' '.label$' '.displayButton'
147 procedure processConfigStrict .clickX .clickY .pressed$
150 config.strict = not config.strict
156 # Change TTS for Strict!
158 call Draw_button '.table$' '.label$' '.displayButton'
161 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
163 .label$ = "DisplayPinyin"
164 config.displayPinyin = not config.displayPinyin
165 .displayButton = 2*config.displayPinyin
166 call Draw_button '.table$' '.label$' '.displayButton'
169 procedure processConfigDisplayChar .clickX .clickY .pressed$
171 .label$ = "DisplayChar"
172 config.displayChar = not config.displayChar
173 .displayButton = 2*config.displayChar
174 call Draw_button 'table$' '.label$' '.displayButton'
177 procedure processConfigDisplayTrans .clickX .clickY .pressed$
179 .label$ = "DisplayTrans"
180 config.displayTrans = not config.displayTrans
181 .displayButton = 2*config.displayTrans
182 call Draw_button 'table$' '.label$' '.displayButton'
185 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
187 .label$ = "DisplayNumbers"
188 config.displayNumbers = not config.displayNumbers
189 .displayButton = 2*config.displayNumbers
190 call Draw_button 'table$' '.label$' '.displayButton'
193 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
195 .label$ = "Language_'.language$'"
196 call processLanguageCodes '.table$' '.label$'
199 procedure processConfigShowBackground .clickX .clickY .pressed$
201 .label$ = "ShowBackground"
202 config.showBackground = not config.showBackground
203 .displayButton = 2*config.showBackground
204 call Draw_button 'table$' '.label$' '.displayButton'
207 procedure processConfigInput .input$ .clickX .clickY .pressed$
209 .label$ = "Input_'.input$'"
210 call Draw_button '.table$' Input_'config.input$' 0
211 config.input$ = .input$
212 call Draw_button '.table$' Input_'config.input$' 2
215 procedure processConfigRegister .register .clickX .clickY .pressed$
217 .label$ = "Register_'.register'"
218 call setRegisterFromLabel '.table$' '.label$'
221 procedure setRegisterFromLabel .table$ .label$
222 call Draw_button '.table$' Register_'config.register' 0
223 call Draw_button '.table$' '.label$' 2
224 # Someone might have to use more than 3 chars for the config.register code
225 .numChars = length(.label$) - length("Register_")
226 .registerText$ = right$(.label$, .numChars)
227 config.register = '.registerText$'
230 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
232 .label$ = "DeleteWordlist"
234 # Do not process undeletable word lists, only those stored in the
235 # preferencesDirectory$ can be deleted
236 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
237 call findLabel '.table$' !'.label$'
239 select Table '.table$'
240 .alertText$ = Get value... 'findLabel.row' Text
241 .confirmKey$ = Get value... 'findLabel.row' Key
242 .popupText$ = Get value... 'findLabel.row' Helptext
244 exit Cannot find delete directive: '.table$' !'.label$'
246 call write_text_popup 'defaultFont$' 14 '.popupText$'
247 call Draw_button '.table$' '.label$' 2
248 alertText$ = .alertText$
249 call Draw_button '.table$' '.label$' 3
252 # Wait for confirmation
254 if demoInput(.confirmKey$)
255 .deleteWordListDir$ = wordlistName$
256 call load_word_list "'localWordlistDir$'" 1
257 call removeWordlist '.deleteWordListDir$'
258 call load_word_list "'localWordlistDir$'" 0
260 call Draw_button '.table$' '.label$' 0
261 call Draw_config_page
265 wordlistTag$ = "Wordlist name"
266 procedure processConfigInstallWordlist .clickX .clickY .pressed$
268 .label$ = "InstallWordlist"
269 call Draw_button '.table$' '.label$' 1
271 # Do not use the automatic sgc list option, ask for a wordlist NAME
273 call findLabel '.table$' '.label$'
275 select Table '.table$'
276 .openDialogue$ = Get value... '.row' Helptext
277 call convert_praat_to_latin1 '.openDialogue$'
278 .openDialogue$ = convert_praat_to_latin1.text$
279 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
280 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
281 beginPause(.openDialogue$)
282 sentence (wordlistTag$, "")
283 clicked = endPause ("Cancel", "Open", 2)
286 .wordlist_Name$ = '.wordlistButton$'$
288 call install_wordlists_by_name '.wordlist_Name$'
290 call sgc2wordlist 'homeDirectory$'
291 call sgc2wordlist 'homeDirectory$'/Downloads
292 call sgc2wordlist 'homeDirectory$'/Documents
293 call sgc2wordlist 'homeDirectory$'/My Documents
294 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
295 call sgc2wordlist 'homeDirectory$'/Desktop
296 call sgc2wordlist 'preferencesAppDir$'
298 call load_word_list "'localWordlistDir$'" 0
299 call Draw_button '.table$' '.label$' 0
300 call Draw_config_page
303 procedure processConfigOpenWordlist .clickX .clickY .pressed$
305 .label$ = "OpenWordlist"
306 call Draw_button '.table$' '.label$' 1
309 call findLabel '.table$' '.label$'
311 select Table '.table$'
312 .openDialogue$ = Get value... '.row' Helptext
313 call convert_praat_to_latin1 '.openDialogue$'
314 .openDialogue$ = convert_praat_to_latin1.text$
316 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
317 call install_wordlists_by_name '.wordlist_Name$'
318 call load_word_list "'localWordlistDir$'" 0
319 call Draw_button '.table$' '.label$' 0
320 call Draw_config_page
323 procedure processConfigPerfSummary .clickX .clickY .pressed$
325 .label$ = "PerfSummary"
326 call Draw_button '.table$' '.label$' 1
328 call loadTable SummaryToneEvaluation
329 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
331 select Table SummaryToneEvaluation
334 call Draw_button '.table$' '.label$' 0
335 call Draw_config_page
338 procedure processConfigListPerf .clickX .clickY .pressed$
341 call Draw_button '.table$' '.label$' 1
343 call write_tabbed_table 'initialiseSGC2.toneevaluation_table$' Evaluation_'config.language$'
346 call Draw_button '.table$' '.label$' 0
347 call Draw_config_page
350 procedure processConfigSavePerf .clickX .clickY .pressed$
353 call Draw_button '.table$' '.label$' 1
356 call findLabel '.table$' '.label$'
358 select Table '.table$'
359 .openDialogue$ = Get value... '.row' Helptext
360 call convert_praat_to_latin1 '.openDialogue$'
361 .openDialogue$ = convert_praat_to_latin1.text$
363 .wordlist_Name$ = chooseWriteFile$ (.openDialogue$, "Performance.Table")
364 if .wordlist_Name$ <> ""
365 select Table 'initialiseSGC2.toneevaluation_table$'
366 Write to table file... '.wordlist_Name$'
369 call Draw_button '.table$' '.label$' 0
370 call Draw_config_page
373 procedure processConfigManual .clickX .clickY .pressed$
376 call Draw_button '.table$' '.label$' 1
377 if fileReadable("ManPages/Demo_Application.man")
378 Read from file... ManPages/Demo_Application.man
380 Go to manual page... Demo Application
382 # Wait until the manual is put to the background
384 call Draw_button '.table$' '.label$' 0
386 call Draw_config_page
389 ###############################################################
391 # Obligatory button Processing Routines
393 # These MUST be defined
395 ###############################################################
397 procedure processConfigReturn .clickX .clickY .pressed$
400 call Draw_button '.table$' '.label$' 1
401 call write_preferences ""
404 procedure processConfigRefresh .clickX .clickY .pressed$
407 call Draw_config_page
410 procedure processConfigCredits .clickX .clickY .pressed$
413 call Draw_button '.table$' '.label$' 1
414 call write_text_table Credits_'config.language$'
416 call Draw_button '.table$' '.label$' 0
418 call Draw_config_page
421 procedure processConfigHelp .clickX .clickY .pressed$
424 call help_loop '.table$' Draw_config_page
427 ###############################################################
429 # Miscelaneous supporting code
431 ###############################################################
432 procedure install_wordlists_by_name .wordlist_Name$
433 if .wordlist_Name$ <> ""
434 if index(.wordlist_Name$, "wordlist.")
435 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\]wordlist\.([^/\\]+)$", "", 0)
436 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
437 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
439 if index_regex(.wordlist_Name$, "[/\\]")
440 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
441 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
442 call readWordlist "'.sourceDir$'" '.file$'
445 if index(.wordlist_Name$, ".")
448 .extension1$ = ".sgc"
449 .extension2$ = ".Table"
450 .extension3$ = ".txt"
452 for .e from .start to 4
453 .currentExtension$ = .extension'.e'$
454 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
455 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
456 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
457 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
458 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
459 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
460 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
466 # Word lists: It is a VERY good idea to make sure that word-lists
468 procedure load_word_list .localdir$ .relnumber
469 # Remove old word list
471 select Table 'wordlist$'
473 call wipeArea 'wipeWordlistArea$'
477 # Create Table that will recieve the wordlists and directories
478 Create Table with column names... AllWordLists 0 Name Directory
479 .currentWordlistRow = 0
481 # Start with the word lists in the distribution, unless the local directory exists!
482 call CreateCreateWordlists
483 select Table CreateWordlists
484 .numLists = Get number of rows
486 select Table CreateWordlists
487 .currentName$ = Get value... '.i' Name
488 if not (fileReadable("'.localdir$'/'.currentName$'") or fileReadable("'.localdir$'/'.currentName$'/wordlist.Table") or fileReadable("'.localdir$'/'.currentName$'/wordlist.txt"))
489 .currentDirectory$ = "*call Create'.currentName$'"
490 select Table AllWordLists
492 .currentWordlistRow = Get number of rows
493 Set string value... '.currentWordlistRow' Name '.currentName$'
494 .currentDirectory$ = "*call Create'.currentName$'"
495 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
498 select Table CreateWordlists
501 # First the global word lists
502 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
503 Create Strings as directory list... WordList 'globalwordlists$'
504 .numLists = Get number of strings
506 select Strings WordList
507 .currentName$ = Get string... '.i'
508 if .currentName$ <> "directory.txt"
509 select Table AllWordLists
511 .currentWordlistRow = Get number of rows
512 Set string value... '.currentWordlistRow' Name '.currentName$'
513 .currentDirectory$ = globalwordlists$+"/"+.currentName$
514 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
517 select Strings WordList
521 # Now the preferences word lists
522 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
523 Create Strings as directory list... WordList 'sgc2wordlists$'
524 .numLists = Get number of strings
526 select Strings WordList
527 .currentName$ = Get string... '.i'
528 if .currentName$ <> "directory.txt"
529 select Table AllWordLists
531 .currentWordlistRow = Get number of rows
532 Set string value... '.currentWordlistRow' Name '.currentName$'
533 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
534 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
537 select Strings WordList
541 # Finally, the local word lists
542 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
543 Create Strings as directory list... WordList '.localdir$'
544 .numLists = Get number of strings
546 select Strings WordList
547 .currentName$ = Get string... '.i'
548 if .currentName$ <> "directory.txt"
549 select Table AllWordLists
551 .currentWordlistRow = Get number of rows
552 Set string value... '.currentWordlistRow' Name '.currentName$'
553 .currentDirectory$ = .localdir$+"/"+.currentName$
554 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
557 select Strings WordList
561 # Get the position of the current word list
562 select Table AllWordLists
564 .numLists = Get number of rows
566 if wordlistName$ <> ""
567 select Table AllWordLists
568 .currentNumber = Search column... Name 'wordlistName$'
571 wordlistNum = .currentNumber + .relnumber
572 if wordlistNum > .numLists
574 elsif wordlistNum < 1 and .numLists > 0
575 wordlistNum = .numLists
577 select Table AllWordLists
578 wordlistName$ = Get value... 'wordlistNum' Name
579 .dirWordlistName$ = Get value... 'wordlistNum' Directory
580 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
582 # Read in full tables
583 if fileReadable("'.dirString$'/wordlist.Table")
584 Read from file... '.dirString$'/wordlist.Table
585 Rename... 'wordlistName$'
586 # Praat wil change the name if it feels like it
587 wordlist$ = selected$("Table")
588 # Handle (legacy) simple word lists
589 elsif fileReadable("'.dirString$'/wordlist.txt")
590 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
591 wordlist$ = selected$("Table")
592 Read Strings from raw text file... '.dirString$'/wordlist.txt
593 Rename... RawWordList
594 .numWordStrings = Get number of strings
595 for .i to .numWordStrings
596 select Strings RawWordList
597 .currentLine$ = Get string... '.i'
598 .currentPinyin$ = extractWord$(.currentLine$, "")
599 if length(.currentLine$) > length(.currentPinyin$)+1
600 .currentFile$ = right$(.currentLine$, length(.currentPinyin$)+1)
601 elsif fileReadable("'.dirString$'/'.currentPinyin$'.spx")
602 .currentFile$ = .currentPinyin$+".spx"
603 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
604 .currentFile$ = .currentPinyin$+".flac"
605 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
606 .currentFile$ = .currentPinyin$+".wav"
607 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
608 .currentFile$ = .currentPinyin$+".mp3"
612 select Table 'wordlist$'
614 Set string value... '.i' Pinyin '.currentPinyin$'
615 Set string value... '.i' Sound '.currentFile$'
617 select Strings RawWordList
620 select Table 'wordlist$'
621 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
622 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
623 wordlist$ = selected$("Table")
624 Create Strings as file list... RawWordList '.dirString$'/*
625 .numWordStrings = Get number of strings
627 for .j to .numWordStrings
628 select Strings RawWordList
629 .currentLine$ = Get string... '.j'
630 .currentFile$ = extractWord$(.currentLine$, "")
631 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
632 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
633 select Table 'wordlist$'
636 Set string value... '.i' Pinyin '.currentPinyin$'
637 Set string value... '.i' Sound '.currentFile$'
640 select Strings RawWordList
643 select Table 'wordlist$'
644 elsif startsWith(.dirString$, "*call ")
645 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
647 wordlist$ = selected$("Table")
650 # Can this wordlist be deleted?
651 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
652 config.deleteWordlist = 0
654 config.deleteWordlist = -1
657 # Add a Character and Translation column if missing
659 select Table 'wordlist$'
660 numberOfWords = Get number of rows
661 .characterColumn = Get column index... Character
662 if not .characterColumn
663 Append column... Character
664 for .i to numberOfWords
665 Set string value... '.i' Character -
668 .translationColumn = Get column index... Translation
669 if not .translationColumn
670 Append column... Translation
671 for .i to numberOfWords
672 Set string value... '.i' Translation -
677 # Remove all rows without Pinyin
678 .numRows = Get number of rows
680 .rowNum = .numRows - i + 1
681 .pinyinValue$ = Get value... '.rowNum' Pinyin
682 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
683 Remove row... '.rowNum'
686 numberOfWords = Get number of rows
688 # Shuffle words if requested
689 if config.shuffleLists
694 select Table AllWordLists
697 # There were no Word Lists
700 wordlistName$ = "No Word Lists available"
702 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
703 wordlist$ = selected$("Table")
707 Set string value... '.i' Pinyin ni3hao3
708 Set string value... '.i' Character -
709 Set string value... '.i' Translation -
710 Set string value... '.i' Sound -
713 Set string value... '.i' Pinyin xie4xie0
714 Set string value... '.i' Character -
715 Set string value... '.i' Translation -
716 Set string value... '.i' Sound -
719 Set string value... '.i' Pinyin zai4jian4
720 Set string value... '.i' Character -
721 Set string value... '.i' Translation -
722 Set string value... '.i' Sound -
723 numberOfWords = Get number of rows
726 call set_window_title 'buttons$' 'wordlistName$'
729 procedure display_word_list_name
733 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
734 call wipeArea 'wipeWordlistArea$'
735 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
736 .currentFontSize = adjustFontSizeOnHeight.newFontSize
739 demo Text special... '.xtext' Centre '.ytext' Bottom Helvetica '.currentFontSize' 0 '.displayWordList$'
742 call set_font_size 'defaultFontSize'
745 procedure write_word_list
747 call draw_tone_contour
749 # Write current Pinyin text
750 call display_text Black
752 # Write the current word list name
753 call display_word_list_name
756 procedure start_logging
757 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
758 .logDirectory$ < 'preferencesLogDir$'/logPerformance.txt
759 .logDirectory$ = extractWord$(.logDirectory$, "")
760 if .logDirectory$ = "" or not (fileReadable(.logDirectory$) or fileReadable("'.logDirectory$'/directory.txt")
761 .logDirectory$ = "'preferencesLogDir$'"
763 currentLogDirectory$ = "'.logDirectory$'/log'logtimeStamp$'"
764 createDirectory(currentLogDirectory$)
765 if not fileReadable("'currentLogDirectory$'/wordlist.Table")
766 .headerLine$ = "Pinyin'tab$'Character'tab$'Sound'newline$'"
767 .headerLine$ > 'currentLogDirectory$'/wordlist.Table
770 config.logPerformance = 1
774 procedure log_command .logtext$
776 fileappend "'currentLogDirectory$'/logFile.txt" '.logtext$''newline$'
780 procedure log_performance .recordedSound$ .register .proficiency .pinyin$ .choice$
782 .currentDate$ = date$()
783 .timeStamp$ = replace_regex$(.currentDate$, "[^a-zA-Z0-9\-_]", "-", 0)
784 .choiceText$ = replace_regex$(.choice$, "[^a-zA-Z0-9\-_]", "-", 0)
786 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
787 .outfilename$ = .pinyin$+"_"+.choice$+"_'.register'_"+.timeStamp$+".wav"
788 .logtext$ = "# #+.pinyin$+tab$+.choice$+tab$+"'.register'Hz"+tab$+.currentDate$+tab$+.outfilename$+newline$
790 fileappend 'currentLogDirectory$'/logFile.txt '.logtext$'
793 fileappend 'currentLogDirectory$'/wordlist.Table '.pinyin$''tab$''.choice$''tab$''.outfilename$''newline$'
795 select Sound 'recordedSound$'
796 Write to WAV file... 'currentLogDirectory$'/'.outfilename$'
800 procedure paint_logging_light
802 .row = Search column... Label !Logging
804 exit Button Table Config does not have a row with label !Logging
807 .leftX = Get value... '.row' LeftX
808 .rightX = Get value... '.row' RightX
809 .lowY = Get value... '.row' LowY
810 .highY = Get value... '.row' HighY
811 .buttonColor$ = Get value... '.row' Color
812 .centerX = (.leftX + .rightX)/2
813 .centerY = (.lowY + .highY)/2
814 .radius = (.highY - .lowY )/(4*2)
815 .wipeRadius = 1.1*.radius
816 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
817 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
818 demo Paint circle... '.buttonColor$' '.centerX' '.centerY' '.radius'
821 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
826 # Uninstall word lists
827 procedure removeWordlist .deletedWordlistName$
829 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
830 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
833 Create Strings as file list... DeleteList '.targetDir$'/*
834 .numdeleteFiles = Get number of strings
835 for .i to .numdeleteFiles
836 .file$ = Get string... '.i'
837 deleteFile("'.targetDir$'/'.file$'")
839 filedelete '.targetDir$'
841 system rmdir "'.targetDir$'" /s /q
843 # Remove deleted word list
844 select Strings DeleteList
845 plus Table 'wordlist$'
852 procedure sgc2wordlist .sourceDir$
853 if startsWith(.sourceDir$, "preferencesDirectory$")
854 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
857 .targetDirectory$ = "'sgc2wordlists$'"
858 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
859 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
860 .numFiles = Get number of strings
862 select Strings PackageList
863 .file$ = Get string... '.i'
864 call readWordlist '.sourceDir$' '.file$'
867 select Strings PackageList
872 # Debuggin remarks!!!
873 # fileReadable(<directory>) does not work in Windows
874 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
875 # And yet only the 7z decompression has been implemented
876 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z"" x"
877 procedure readWordlist .sourceDir$ .file$
878 # No use doing anything if the source does not exist
879 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
880 # What will be the target wordlist directory?
881 .targetDirectory$ = "'sgc2wordlists$'"
882 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
886 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
887 # Wordlist directory does not exist, neither locally nor in the preferences
888 if not (fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
890 # Move source to destination
891 if index(.file$, ".sgc") or index(.file$, ".zip")
892 # Create wordlist directory
893 createDirectory(.wordlistDirectory$)
896 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"'
897 system cd ''.wordlistDirectory$'';bash -rc -- 'unzip "'.file$'"'
899 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
900 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
901 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /q
902 system chdir "'.winWordListDirectory$'" && 'windowsUnzipCommand$' "'.file$'"
904 deleteFile("'.wordlistDirectory$'/'.file$'")
905 elsif index_regex(.file$, "\.(Table|txt)")
906 # Create wordlist directory
907 createDirectory(.wordlistDirectory$)
909 .extension$ = replace_regex$(.file$, "^.+\.(Table|txt)$", "\1", 0)
911 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"'
913 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
914 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
915 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'\wordlist.'.extension$'" /q
917 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
918 # Copy wordlist directory
921 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
923 createDirectory(.wordlistDirectory$)
924 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
925 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
926 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
930 # Set current word list to read list
932 wordlistName$ = .dirname$
935 .label$ = "!NotAWordlist"
938 call findLabel '.table$' '.label$'
940 select Table '.table$'
941 .helpText$ = Get value... '.row' Helptext
942 .filetext$ = replace_regex$("'.sourceDir$'/'.file$'", "_", "\\_ ", 0)
943 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
944 # Wait for confirmation