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 sgc.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 call Draw_button '.table$' '.label$' '.displayButton'
159 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
161 .label$ = "DisplayPinyin"
162 config.displayPinyin = not config.displayPinyin
163 .displayButton = 2*config.displayPinyin
164 call Draw_button '.table$' '.label$' '.displayButton'
167 procedure processConfigDisplayChar .clickX .clickY .pressed$
169 .label$ = "DisplayChar"
170 config.displayChar = not config.displayChar
171 .displayButton = 2*config.displayChar
172 call Draw_button 'table$' '.label$' '.displayButton'
175 procedure processConfigDisplayTrans .clickX .clickY .pressed$
177 .label$ = "DisplayTrans"
178 config.displayTrans = not config.displayTrans
179 .displayButton = 2*config.displayTrans
180 call Draw_button 'table$' '.label$' '.displayButton'
183 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
185 .label$ = "DisplayNumbers"
186 config.displayNumbers = not config.displayNumbers
187 .displayButton = 2*config.displayNumbers
188 call Draw_button 'table$' '.label$' '.displayButton'
191 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
193 .label$ = "Language_'.language$'"
194 call processLanguageCodes '.table$' '.label$'
197 procedure processConfigShowBackground .clickX .clickY .pressed$
199 .label$ = "ShowBackground"
200 config.showBackground = not config.showBackground
201 .displayButton = 2*config.showBackground
202 call Draw_button 'table$' '.label$' '.displayButton'
205 procedure processConfigInput .input$ .clickX .clickY .pressed$
207 .label$ = "Input_'.input$'"
208 call Draw_button '.table$' Input_'config.input$' 0
209 config.input$ = .input$
210 call Draw_button '.table$' Input_'config.input$' 2
213 procedure processConfigRegister .register .clickX .clickY .pressed$
215 .label$ = "Register_'.register'"
216 call setRegisterFromLabel '.table$' '.label$'
219 procedure setRegisterFromLabel .table$ .label$
220 call Draw_button '.table$' Register_'config.register' 0
221 call Draw_button '.table$' '.label$' 2
222 # Someone might have to use more than 3 chars for the config.register code
223 .numChars = length(.label$) - length("Register_")
224 .registerText$ = right$(.label$, .numChars)
225 config.register = '.registerText$'
228 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
230 .label$ = "DeleteWordlist"
232 # Do not process undeletable word lists, only those stored in the
233 # preferencesDirectory$ can be deleted
234 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
235 call findLabel '.table$' !'.label$'
237 select Table '.table$'
238 .alertText$ = Get value... 'findLabel.row' Text
239 .confirmKey$ = Get value... 'findLabel.row' Key
240 .popupText$ = Get value... 'findLabel.row' Helptext
242 exit Cannot find delete directive: '.table$' !'.label$'
244 call write_text_popup 'defaultFont$' 14 '.popupText$'
245 call Draw_button '.table$' '.label$' 2
246 alertText$ = .alertText$
247 call Draw_button '.table$' '.label$' 3
250 # Wait for confirmation
252 if demoInput(.confirmKey$)
253 .deleteWordListDir$ = wordlistName$
254 call load_word_list "'localWordlistDir$'" 1
255 call removeWordlist '.deleteWordListDir$'
256 call load_word_list "'localWordlistDir$'" 0
258 call Draw_button '.table$' '.label$' 0
259 call Draw_config_page
263 wordlistTag$ = "Wordlist name"
264 procedure processConfigInstallWordlist .clickX .clickY .pressed$
266 .label$ = "InstallWordlist"
267 call Draw_button '.table$' '.label$' 1
269 # Do not use the automatic sgc list option, ask for a wordlist NAME
271 call findLabel '.table$' '.label$'
273 select Table '.table$'
274 .openDialogue$ = Get value... '.row' Helptext
275 call convert_praat_to_latin1 '.openDialogue$'
276 .openDialogue$ = convert_praat_to_latin1.text$
277 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
278 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
279 beginPause(.openDialogue$)
280 sentence (wordlistTag$, "")
281 clicked = endPause ("Cancel", "Open", 2)
284 .wordlist_Name$ = '.wordlistButton$'$
286 call install_wordlists_by_name '.wordlist_Name$'
288 call sgc2wordlist 'homeDirectory$'
289 call sgc2wordlist 'homeDirectory$'/Downloads
290 call sgc2wordlist 'homeDirectory$'/Documents
291 call sgc2wordlist 'homeDirectory$'/My Documents
292 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
293 call sgc2wordlist 'homeDirectory$'/Desktop
294 call sgc2wordlist 'preferencesAppDir$'
296 call load_word_list "'localWordlistDir$'" 0
297 call Draw_button '.table$' '.label$' 0
298 call Draw_config_page
301 procedure processConfigOpenWordlist .clickX .clickY .pressed$
303 .label$ = "OpenWordlist"
304 call Draw_button '.table$' '.label$' 1
307 call findLabel '.table$' '.label$'
309 select Table '.table$'
310 .openDialogue$ = Get value... '.row' Helptext
311 call convert_praat_to_latin1 '.openDialogue$'
312 .openDialogue$ = convert_praat_to_latin1.text$
314 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
315 call install_wordlists_by_name '.wordlist_Name$'
316 call load_word_list "'localWordlistDir$'" 0
317 call Draw_button '.table$' '.label$' 0
318 call Draw_config_page
321 procedure processConfigPerfSummary .clickX .clickY .pressed$
323 .label$ = "PerfSummary"
324 call Draw_button '.table$' '.label$' 1
326 call loadTable SummaryToneEvaluation
327 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
329 select Table SummaryToneEvaluation
332 call Draw_button '.table$' '.label$' 0
333 call Draw_config_page
336 procedure processConfigListPerf .clickX .clickY .pressed$
339 call Draw_button '.table$' '.label$' 1
341 call write_tabbed_table 'initialiseSGC2.toneevaluation_table$' Evaluation_'config.language$'
344 call Draw_button '.table$' '.label$' 0
345 call Draw_config_page
348 procedure processConfigSavePerf .clickX .clickY .pressed$
351 call Draw_button '.table$' '.label$' 1
354 call findLabel '.table$' '.label$'
356 select Table '.table$'
357 .openDialogue$ = Get value... '.row' Helptext
358 call convert_praat_to_latin1 '.openDialogue$'
359 .openDialogue$ = convert_praat_to_latin1.text$
361 .wordlist_Name$ = chooseWriteFile$ (.openDialogue$, "Performance.Table")
362 if .wordlist_Name$ <> ""
363 select Table 'initialiseSGC2.toneevaluation_table$'
364 Write to table file... '.wordlist_Name$'
367 call Draw_button '.table$' '.label$' 0
368 call Draw_config_page
371 procedure processConfigManual .clickX .clickY .pressed$
374 call Draw_button '.table$' '.label$' 1
375 if fileReadable("ManPages/Demo_Application.man")
376 Read from file... ManPages/Demo_Application.man
378 Go to manual page... Demo Application
380 # Wait until the manual is put to the background
382 call Draw_button '.table$' '.label$' 0
384 call Draw_config_page
387 ###############################################################
389 # Obligatory button Processing Routines
391 # These MUST be defined
393 ###############################################################
395 procedure processConfigReturn .clickX .clickY .pressed$
398 call Draw_button '.table$' '.label$' 1
399 call write_preferences ""
402 procedure processConfigRefresh .clickX .clickY .pressed$
405 call Draw_config_page
408 procedure processConfigCredits .clickX .clickY .pressed$
411 call Draw_button '.table$' '.label$' 1
412 call write_text_table Credits_'config.language$'
414 call Draw_button '.table$' '.label$' 0
416 call Draw_config_page
419 procedure processConfigHelp .clickX .clickY .pressed$
422 call help_loop '.table$' Draw_config_page
425 ###############################################################
427 # Miscelaneous supporting code
429 ###############################################################
430 procedure install_wordlists_by_name .wordlist_Name$
431 if .wordlist_Name$ <> ""
432 if index(.wordlist_Name$, "wordlist.")
433 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\]wordlist\.([^/\\]+)$", "", 0)
434 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
435 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
437 if index_regex(.wordlist_Name$, "[/\\]")
438 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
439 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
440 call readWordlist "'.sourceDir$'" '.file$'
443 if index(.wordlist_Name$, ".")
446 .extension1$ = ".sgc"
447 .extension2$ = ".Table"
448 .extension3$ = ".txt"
450 for .e from .start to 4
451 .currentExtension$ = .extension'.e'$
452 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
453 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
454 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
455 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
456 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
457 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
458 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
464 # Word lists: It is a VERY good idea to make sure that word-lists
466 procedure load_word_list .localdir$ .relnumber
467 # Remove old word list
469 select Table 'wordlist$'
471 call wipeArea 'wipeWordlistArea$'
475 # Create Table that will recieve the wordlists and directories
476 Create Table with column names... AllWordLists 0 Name Directory
477 .currentWordlistRow = 0
479 # Start with the word lists in the distribution, unless the local directory exists!
480 call CreateCreateWordlists
481 select Table CreateWordlists
482 .numLists = Get number of rows
484 select Table CreateWordlists
485 .currentName$ = Get value... '.i' Name
486 if not (fileReadable("'.localdir$'/'.currentName$'") or fileReadable("'.localdir$'/'.currentName$'/wordlist.Table") or fileReadable("'.localdir$'/'.currentName$'/wordlist.txt"))
487 .currentDirectory$ = "*call Create'.currentName$'"
488 select Table AllWordLists
490 .currentWordlistRow = Get number of rows
491 Set string value... '.currentWordlistRow' Name '.currentName$'
492 .currentDirectory$ = "*call Create'.currentName$'"
493 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
496 select Table CreateWordlists
499 # First the global word lists
500 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
501 Create Strings as directory list... WordList 'globalwordlists$'
502 .numLists = Get number of strings
504 select Strings WordList
505 .currentName$ = Get string... '.i'
506 if .currentName$ <> "directory.txt"
507 select Table AllWordLists
509 .currentWordlistRow = Get number of rows
510 Set string value... '.currentWordlistRow' Name '.currentName$'
511 .currentDirectory$ = globalwordlists$+"/"+.currentName$
512 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
515 select Strings WordList
519 # Now the preferences word lists
520 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
521 Create Strings as directory list... WordList 'sgc2wordlists$'
522 .numLists = Get number of strings
524 select Strings WordList
525 .currentName$ = Get string... '.i'
526 if .currentName$ <> "directory.txt"
527 select Table AllWordLists
529 .currentWordlistRow = Get number of rows
530 Set string value... '.currentWordlistRow' Name '.currentName$'
531 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
532 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
535 select Strings WordList
539 # Finally, the local word lists
540 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
541 Create Strings as directory list... WordList '.localdir$'
542 .numLists = Get number of strings
544 select Strings WordList
545 .currentName$ = Get string... '.i'
546 if .currentName$ <> "directory.txt"
547 select Table AllWordLists
549 .currentWordlistRow = Get number of rows
550 Set string value... '.currentWordlistRow' Name '.currentName$'
551 .currentDirectory$ = .localdir$+"/"+.currentName$
552 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
555 select Strings WordList
559 # Get the position of the current word list
560 select Table AllWordLists
562 .numLists = Get number of rows
564 if wordlistName$ <> ""
565 select Table AllWordLists
566 .currentNumber = Search column... Name 'wordlistName$'
569 wordlistNum = .currentNumber + .relnumber
570 if wordlistNum > .numLists
572 elsif wordlistNum < 1 and .numLists > 0
573 wordlistNum = .numLists
575 select Table AllWordLists
576 wordlistName$ = Get value... 'wordlistNum' Name
577 .dirWordlistName$ = Get value... 'wordlistNum' Directory
578 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
580 # Read in full tables
581 if fileReadable("'.dirString$'/wordlist.Table")
582 Read from file... '.dirString$'/wordlist.Table
583 Rename... 'wordlistName$'
584 # Praat wil change the name if it feels like it
585 wordlist$ = selected$("Table")
586 # Handle (legacy) simple word lists
587 elsif fileReadable("'.dirString$'/wordlist.txt")
588 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
589 wordlist$ = selected$("Table")
590 Read Strings from raw text file... '.dirString$'/wordlist.txt
591 Rename... RawWordList
592 .numWordStrings = Get number of strings
593 for .i to .numWordStrings
594 select Strings RawWordList
595 .currentLine$ = Get string... '.i'
596 .currentPinyin$ = extractWord$(.currentLine$, "")
597 if length(.currentLine$) > length(.currentPinyin$)+1
598 .currentFile$ = right$(.currentLine$, length(.currentPinyin$)+1)
599 elsif fileReadable("'.dirString$'/'.currentPinyin$'.spx")
600 .currentFile$ = .currentPinyin$+".spx"
601 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
602 .currentFile$ = .currentPinyin$+".flac"
603 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
604 .currentFile$ = .currentPinyin$+".wav"
605 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
606 .currentFile$ = .currentPinyin$+".mp3"
610 select Table 'wordlist$'
612 Set string value... '.i' Pinyin '.currentPinyin$'
613 Set string value... '.i' Sound '.currentFile$'
615 select Strings RawWordList
618 select Table 'wordlist$'
619 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
620 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
621 wordlist$ = selected$("Table")
622 Create Strings as file list... RawWordList '.dirString$'/*
623 .numWordStrings = Get number of strings
625 for .j to .numWordStrings
626 select Strings RawWordList
627 .currentLine$ = Get string... '.j'
628 .currentFile$ = extractWord$(.currentLine$, "")
629 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
630 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
631 select Table 'wordlist$'
634 Set string value... '.i' Pinyin '.currentPinyin$'
635 Set string value... '.i' Sound '.currentFile$'
638 select Strings RawWordList
641 select Table 'wordlist$'
642 elsif startsWith(.dirString$, "*call ")
643 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
645 wordlist$ = selected$("Table")
648 # Can this wordlist be deleted?
649 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
650 config.deleteWordlist = 0
652 config.deleteWordlist = -1
655 # Add a Character and Translation column if missing
657 select Table 'wordlist$'
658 numberOfWords = Get number of rows
659 .characterColumn = Get column index... Character
660 if not .characterColumn
661 Append column... Character
662 for .i to numberOfWords
663 Set string value... '.i' Character -
666 .translationColumn = Get column index... Translation
667 if not .translationColumn
668 Append column... Translation
669 for .i to numberOfWords
670 Set string value... '.i' Translation -
675 # Remove all rows without Pinyin
676 .numRows = Get number of rows
678 .rowNum = .numRows - i + 1
679 .pinyinValue$ = Get value... '.rowNum' Pinyin
680 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
681 Remove row... '.rowNum'
684 numberOfWords = Get number of rows
686 # Shuffle words if requested
687 if config.shuffleLists
692 select Table AllWordLists
695 # There were no Word Lists
698 wordlistName$ = "No Word Lists available"
700 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
701 wordlist$ = selected$("Table")
705 Set string value... '.i' Pinyin ni3hao3
706 Set string value... '.i' Character -
707 Set string value... '.i' Translation -
708 Set string value... '.i' Sound -
711 Set string value... '.i' Pinyin xie4xie0
712 Set string value... '.i' Character -
713 Set string value... '.i' Translation -
714 Set string value... '.i' Sound -
717 Set string value... '.i' Pinyin zai4jian4
718 Set string value... '.i' Character -
719 Set string value... '.i' Translation -
720 Set string value... '.i' Sound -
721 numberOfWords = Get number of rows
724 call set_window_title 'buttons$' 'wordlistName$'
727 procedure display_word_list_name
731 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
732 call wipeArea 'wipeWordlistArea$'
733 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
734 .currentFontSize = adjustFontSizeOnHeight.newFontSize
737 demo Text special... '.xtext' Centre '.ytext' Bottom Helvetica '.currentFontSize' 0 '.displayWordList$'
740 call set_font_size 'defaultFontSize'
743 procedure write_word_list
745 call draw_tone_contour
747 # Write current Pinyin text
748 call display_text Black
750 # Write the current word list name
751 call display_word_list_name
754 procedure start_logging
755 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
756 .logDirectory$ < 'preferencesLogDir$'/logPerformance.txt
757 .logDirectory$ = extractWord$(.logDirectory$, "")
758 if .logDirectory$ = "" or not (fileReadable(.logDirectory$) or fileReadable("'.logDirectory$'/directory.txt")
759 .logDirectory$ = "'preferencesLogDir$'"
761 currentLogDirectory$ = "'.logDirectory$'/log'logtimeStamp$'"
762 createDirectory(currentLogDirectory$)
763 if not fileReadable("'currentLogDirectory$'/wordlist.Table")
764 .headerLine$ = "Pinyin'tab$'Character'tab$'Sound'newline$'"
765 .headerLine$ > 'currentLogDirectory$'/wordlist.Table
768 config.logPerformance = 1
772 procedure log_command .logtext$
774 fileappend "'currentLogDirectory$'/logFile.txt" '.logtext$''newline$'
778 procedure log_performance .recordedSound$ .register .proficiency .pinyin$ .choice$
780 .currentDate$ = date$()
781 .timeStamp$ = replace_regex$(.currentDate$, "[^a-zA-Z0-9\-_]", "-", 0)
782 .choiceText$ = replace_regex$(.choice$, "[^a-zA-Z0-9\-_]", "-", 0)
784 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
785 .outfilename$ = .pinyin$+"_"+.choice$+"_'.register'_"+.timeStamp$+".wav"
786 .logtext$ = "# #+.pinyin$+tab$+.choice$+tab$+"'.register'Hz"+tab$+.currentDate$+tab$+.outfilename$+newline$
788 fileappend 'currentLogDirectory$'/logFile.txt '.logtext$'
791 fileappend 'currentLogDirectory$'/wordlist.Table '.pinyin$''tab$''.choice$''tab$''.outfilename$''newline$'
793 select Sound 'recordedSound$'
794 Write to WAV file... 'currentLogDirectory$'/'.outfilename$'
798 procedure paint_logging_light
800 .row = Search column... Label !Logging
802 exit Button Table Config does not have a row with label !Logging
805 .leftX = Get value... '.row' LeftX
806 .rightX = Get value... '.row' RightX
807 .lowY = Get value... '.row' LowY
808 .highY = Get value... '.row' HighY
809 .buttonColor$ = Get value... '.row' Color
810 .centerX = (.leftX + .rightX)/2
811 .centerY = (.lowY + .highY)/2
812 .radius = (.highY - .lowY )/(4*2)
813 .wipeRadius = 1.1*.radius
814 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
815 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
816 demo Paint circle... '.buttonColor$' '.centerX' '.centerY' '.radius'
819 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
824 # Uninstall word lists
825 procedure removeWordlist .deletedWordlistName$
827 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
828 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
831 Create Strings as file list... DeleteList '.targetDir$'/*
832 .numdeleteFiles = Get number of strings
833 for .i to .numdeleteFiles
834 .file$ = Get string... '.i'
835 deleteFile("'.targetDir$'/'.file$'")
837 filedelete '.targetDir$'
839 system rmdir "'.targetDir$'" /s /q
841 # Remove deleted word list
842 select Strings DeleteList
843 plus Table 'wordlist$'
850 procedure sgc2wordlist .sourceDir$
851 if startsWith(.sourceDir$, "preferencesDirectory$")
852 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
855 .targetDirectory$ = "'sgc2wordlists$'"
856 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
857 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
858 .numFiles = Get number of strings
860 select Strings PackageList
861 .file$ = Get string... '.i'
862 call readWordlist '.sourceDir$' '.file$'
865 select Strings PackageList
870 # Debuggin remarks!!!
871 # fileReadable(<directory>) does not work in Windows
872 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
873 # And yet only the 7z decompression has been implemented
874 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z"" x"
875 procedure readWordlist .sourceDir$ .file$
876 # No use doing anything if the source does not exist
877 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
878 # What will be the target wordlist directory?
879 .targetDirectory$ = "'sgc2wordlists$'"
880 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
884 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
885 # Wordlist directory does not exist, neither locally nor in the preferences
886 if not (fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
888 # Move source to destination
889 if index(.file$, ".sgc") or index(.file$, ".zip")
890 # Create wordlist directory
891 createDirectory(.wordlistDirectory$)
894 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"'
895 system cd ''.wordlistDirectory$'';bash -rc -- 'unzip "'.file$'"'
897 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
898 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
899 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /q
900 system chdir "'.winWordListDirectory$'" && 'windowsUnzipCommand$' "'.file$'"
902 deleteFile("'.wordlistDirectory$'/'.file$'")
903 elsif index_regex(.file$, "\.(Table|txt)")
904 # Create wordlist directory
905 createDirectory(.wordlistDirectory$)
907 .extension$ = replace_regex$(.file$, "^.+\.(Table|txt)$", "\1", 0)
909 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"'
911 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
912 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
913 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'\wordlist.'.extension$'" /q
915 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
916 # Copy wordlist directory
919 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
921 createDirectory(.wordlistDirectory$)
922 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
923 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
924 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
928 # Set current word list to read list
930 wordlistName$ = .dirname$
933 .label$ = "!NotAWordlist"
936 call findLabel '.table$' '.label$'
938 select Table '.table$'
939 .helpText$ = Get value... '.row' Helptext
940 .filetext$ = replace_regex$("'.sourceDir$'/'.file$'", "_", "\\_ ", 0)
941 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
942 # Wait for confirmation