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 call testLoadTable SummaryToneEvaluation
102 if testLoadTable.table <= 0
103 call Draw_button 'config$' PerfSummary 1
105 # Handle logging buttons with forced button draw
106 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
107 call Draw_button 'config$' +!Logging 'config.logPerformance'
111 ###############################################################
113 # Button Processing Routines
115 ###############################################################
117 procedure processConfigShuffleLists .clickX .clickY .pressed$
119 .label$ = "ShuffleLists"
120 config.shuffleLists = not config.shuffleLists
121 .displayButton = 2*config.shuffleLists
122 call Draw_button '.table$' '.label$' '.displayButton'
125 procedure processConfigUseSoundExample .clickX .clickY .pressed$
127 .label$ = "UseSoundExample"
128 config.useSoundExample = not config.useSoundExample
129 .displayButton = 2*config.useSoundExample
130 call Draw_button '.table$' '.label$' '.displayButton'
133 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
135 .label$ = "Synthesis_'.tts$'"
136 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
137 if config.synthesis$ = ""
138 config.synthesis$ = .tts$
141 config.synthesis$ = ""
145 config.synthesis$ = "_DISABLED_"
148 call Draw_button '.table$' '.label$' '.displayButton'
151 procedure processConfigStrict .clickX .clickY .pressed$
154 config.strict = not config.strict
160 # Change TTS for Strict!
162 call Draw_button '.table$' '.label$' '.displayButton'
165 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
167 .label$ = "DisplayPinyin"
168 config.displayPinyin = not config.displayPinyin
169 .displayButton = 2*config.displayPinyin
170 call Draw_button '.table$' '.label$' '.displayButton'
173 procedure processConfigDisplayChar .clickX .clickY .pressed$
175 .label$ = "DisplayChar"
176 config.displayChar = not config.displayChar
177 .displayButton = 2*config.displayChar
178 call Draw_button 'table$' '.label$' '.displayButton'
181 procedure processConfigDisplayTrans .clickX .clickY .pressed$
183 .label$ = "DisplayTrans"
184 config.displayTrans = not config.displayTrans
185 .displayButton = 2*config.displayTrans
186 call Draw_button 'table$' '.label$' '.displayButton'
189 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
191 .label$ = "DisplayNumbers"
192 config.displayNumbers = not config.displayNumbers
193 .displayButton = 2*config.displayNumbers
194 call Draw_button 'table$' '.label$' '.displayButton'
197 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
199 .label$ = "Language_'.language$'"
200 call processLanguageCodes '.table$' '.label$'
203 procedure processConfigShowBackground .clickX .clickY .pressed$
205 .label$ = "ShowBackground"
206 config.showBackground = not config.showBackground
207 .displayButton = 2*config.showBackground
208 call Draw_button 'table$' '.label$' '.displayButton'
211 procedure processConfigInput .input$ .clickX .clickY .pressed$
213 .label$ = "Input_'.input$'"
214 call Draw_button '.table$' Input_'config.input$' 0
215 config.input$ = .input$
216 call Draw_button '.table$' Input_'config.input$' 2
219 procedure processConfigRegister .register .clickX .clickY .pressed$
221 .label$ = "Register_'.register'"
222 call setRegisterFromLabel '.table$' '.label$'
225 procedure setRegisterFromLabel .table$ .label$
226 call Draw_button '.table$' Register_'config.register' 0
227 call Draw_button '.table$' '.label$' 2
228 # Someone might have to use more than 3 chars for the config.register code
229 .numChars = length(.label$) - length("Register_")
230 .registerText$ = right$(.label$, .numChars)
231 config.register = '.registerText$'
234 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
236 .label$ = "DeleteWordlist"
238 # Do not process undeletable word lists, only those stored in the
239 # preferencesDirectory$ can be deleted
240 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
241 call findLabel '.table$' !'.label$'
243 select Table '.table$'
244 .alertText$ = Get value... 'findLabel.row' Text
245 .confirmKey$ = Get value... 'findLabel.row' Key
246 .popupText$ = Get value... 'findLabel.row' Helptext
248 exit Cannot find delete directive: '.table$' !'.label$'
250 call write_text_popup 'defaultFont$' 14 '.popupText$'
251 call Draw_button '.table$' '.label$' 2
252 alertText$ = .alertText$
253 call Draw_button '.table$' '.label$' 3
256 # Wait for confirmation
258 if demoInput(.confirmKey$)
259 .deleteWordListDir$ = wordlistName$
260 call load_word_list "'localWordlistDir$'" 1
261 call removeWordlist '.deleteWordListDir$'
262 call load_word_list "'localWordlistDir$'" 0
264 call Draw_button '.table$' '.label$' 0
265 call Draw_config_page
269 wordlistTag$ = "Wordlist name"
270 procedure processConfigInstallWordlist .clickX .clickY .pressed$
272 .label$ = "InstallWordlist"
273 call Draw_button '.table$' '.label$' 1
275 # Do not use the automatic sgc list option, ask for a wordlist NAME
277 call findLabel '.table$' '.label$'
279 select Table '.table$'
280 .openDialogue$ = Get value... '.row' Helptext
281 call convert_praat_to_latin1 '.openDialogue$'
282 .openDialogue$ = convert_praat_to_latin1.text$
283 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
284 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
285 beginPause(.openDialogue$)
286 sentence (wordlistTag$, "")
287 clicked = endPause ("Cancel", "Open", 2)
290 .wordlist_Name$ = '.wordlistButton$'$
292 call install_wordlists_by_name '.wordlist_Name$'
294 call sgc2wordlist 'homeDirectory$'
295 call sgc2wordlist 'homeDirectory$'/Downloads
296 call sgc2wordlist 'homeDirectory$'/Documents
297 call sgc2wordlist 'homeDirectory$'/My Documents
298 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
299 call sgc2wordlist 'homeDirectory$'/Desktop
300 call sgc2wordlist 'preferencesAppDir$'
302 call load_word_list "'localWordlistDir$'" 0
303 call Draw_button '.table$' '.label$' 0
304 call Draw_config_page
307 procedure processConfigOpenWordlist .clickX .clickY .pressed$
309 .label$ = "OpenWordlist"
310 call Draw_button '.table$' '.label$' 1
313 call findLabel '.table$' '.label$'
315 select Table '.table$'
316 .openDialogue$ = Get value... '.row' Helptext
317 call convert_praat_to_latin1 '.openDialogue$'
318 .openDialogue$ = convert_praat_to_latin1.text$
320 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
321 call install_wordlists_by_name '.wordlist_Name$'
322 call load_word_list "'localWordlistDir$'" 0
323 call Draw_button '.table$' '.label$' 0
324 call Draw_config_page
327 procedure processConfigPerfSummary .clickX .clickY .pressed$
329 .label$ = "PerfSummary"
331 call testLoadTable SummaryToneEvaluation
332 if testLoadTable.table > 0
333 call Draw_button '.table$' '.label$' 1
334 call loadTable SummaryToneEvaluation
335 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
337 select Table SummaryToneEvaluation
340 call Draw_button '.table$' '.label$' 0
341 call Draw_config_page
345 procedure processConfigListPerf .clickX .clickY .pressed$
348 call Draw_button '.table$' '.label$' 1
350 call write_tabbed_table 'initialiseSGC2.toneevaluation_table$' Evaluation_'config.language$'
353 call Draw_button '.table$' '.label$' 0
354 call Draw_config_page
357 procedure processConfigSavePerf .clickX .clickY .pressed$
360 call Draw_button '.table$' '.label$' 1
363 call findLabel '.table$' '.label$'
365 select Table '.table$'
366 .openDialogue$ = Get value... '.row' Helptext
367 call convert_praat_to_latin1 '.openDialogue$'
368 .openDialogue$ = convert_praat_to_latin1.text$
370 .wordlist_Name$ = chooseWriteFile$ (.openDialogue$, "Performance.Table")
371 if .wordlist_Name$ <> ""
372 select Table 'initialiseSGC2.toneevaluation_table$'
373 Write to table file... '.wordlist_Name$'
376 call Draw_button '.table$' '.label$' 0
377 call Draw_config_page
380 procedure processConfigManual .clickX .clickY .pressed$
383 call Draw_button '.table$' '.label$' 1
384 if fileReadable("ManPages/Demo_Application.man")
385 Read from file... ManPages/Demo_Application.man
387 Go to manual page... Demo Application
389 # Wait until the manual is put to the background
391 call Draw_button '.table$' '.label$' 0
393 call Draw_config_page
396 ###############################################################
398 # Obligatory button Processing Routines
400 # These MUST be defined
402 ###############################################################
404 procedure processConfigReturn .clickX .clickY .pressed$
407 call Draw_button '.table$' '.label$' 1
408 call write_preferences ""
411 procedure processConfigRefresh .clickX .clickY .pressed$
414 call Draw_config_page
417 procedure processConfigCredits .clickX .clickY .pressed$
420 call Draw_button '.table$' '.label$' 1
421 call write_text_table Credits_'config.language$'
423 call Draw_button '.table$' '.label$' 0
425 call Draw_config_page
428 procedure processConfigHelp .clickX .clickY .pressed$
431 call help_loop '.table$' Draw_config_page
434 ###############################################################
436 # Miscelaneous supporting code
438 ###############################################################
439 procedure install_wordlists_by_name .wordlist_Name$
440 if .wordlist_Name$ <> ""
441 if index(.wordlist_Name$, "wordlist.")
442 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\]wordlist\.([^/\\]+)$", "", 0)
443 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
444 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
446 if index_regex(.wordlist_Name$, "[/\\]")
447 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
448 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
449 call readWordlist "'.sourceDir$'" '.file$'
452 if index(.wordlist_Name$, ".")
455 .extension1$ = ".sgc"
456 .extension2$ = ".Table"
457 .extension3$ = ".txt"
459 for .e from .start to 4
460 .currentExtension$ = .extension'.e'$
461 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
462 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
463 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
464 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
465 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
466 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
467 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
473 # Word lists: It is a VERY good idea to make sure that word-lists
475 procedure load_word_list .localdir$ .relnumber
476 # Remove old word list
478 select Table 'wordlist$'
480 call wipeArea 'wipeWordlistArea$'
484 # Create Table that will recieve the wordlists and directories
485 Create Table with column names... AllWordLists 0 Name Directory
486 .currentWordlistRow = 0
488 # Start with the word lists in the distribution, unless the local directory exists!
489 call CreateCreateWordlists
490 select Table CreateWordlists
491 .numLists = Get number of rows
493 select Table CreateWordlists
494 .currentName$ = Get value... '.i' Name
495 if not (fileReadable("'.localdir$'/'.currentName$'") or fileReadable("'.localdir$'/'.currentName$'/wordlist.Table") or fileReadable("'.localdir$'/'.currentName$'/wordlist.txt"))
496 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
497 select Table AllWordLists
499 .currentWordlistRow = Get number of rows
500 Set string value... '.currentWordlistRow' Name '.currentName$'
501 .currentDirectory$ = "*call Create'.procedureName$'"
502 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
505 select Table CreateWordlists
508 # First the global word lists
509 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
510 Create Strings as directory list... WordList 'globalwordlists$'
511 .numLists = Get number of strings
513 select Strings WordList
514 .currentName$ = Get string... '.i'
515 if .currentName$ <> "directory.txt"
516 select Table AllWordLists
518 .currentWordlistRow = Get number of rows
519 Set string value... '.currentWordlistRow' Name '.currentName$'
520 .currentDirectory$ = globalwordlists$+"/"+.currentName$
521 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
524 select Strings WordList
528 # Now the preferences word lists
529 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
530 Create Strings as directory list... WordList 'sgc2wordlists$'
531 .numLists = Get number of strings
533 select Strings WordList
534 .currentName$ = Get string... '.i'
535 if .currentName$ <> "directory.txt"
536 select Table AllWordLists
538 .currentWordlistRow = Get number of rows
539 Set string value... '.currentWordlistRow' Name '.currentName$'
540 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
541 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
544 select Strings WordList
548 # Finally, the local word lists
549 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
550 Create Strings as directory list... WordList '.localdir$'
551 .numLists = Get number of strings
553 select Strings WordList
554 .currentName$ = Get string... '.i'
555 if .currentName$ <> "directory.txt"
556 select Table AllWordLists
558 .currentWordlistRow = Get number of rows
559 Set string value... '.currentWordlistRow' Name '.currentName$'
560 .currentDirectory$ = .localdir$+"/"+.currentName$
561 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
564 select Strings WordList
568 # Get the position of the current word list
569 select Table AllWordLists
571 .numLists = Get number of rows
573 if wordlistName$ <> ""
574 select Table AllWordLists
575 .currentNumber = Search column... Name 'wordlistName$'
578 wordlistNum = .currentNumber + .relnumber
579 if wordlistNum > .numLists
581 elsif wordlistNum < 1 and .numLists > 0
582 wordlistNum = .numLists
584 select Table AllWordLists
585 wordlistName$ = Get value... 'wordlistNum' Name
586 .dirWordlistName$ = Get value... 'wordlistNum' Directory
587 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
589 # Read in full tables
590 if fileReadable("'.dirString$'/wordlist.Table")
591 Read from file... '.dirString$'/wordlist.Table
592 Rename... 'wordlistName$'
593 # Praat wil change the name if it feels like it
594 wordlist$ = selected$("Table")
595 # Handle (legacy) simple word lists
596 elsif fileReadable("'.dirString$'/wordlist.txt")
597 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
598 wordlist$ = selected$("Table")
599 Read Strings from raw text file... '.dirString$'/wordlist.txt
600 Rename... RawWordList
601 .numWordStrings = Get number of strings
602 for .i to .numWordStrings
603 select Strings RawWordList
604 .currentLine$ = Get string... '.i'
605 .currentPinyin$ = extractWord$(.currentLine$, "")
606 if length(.currentLine$) > length(.currentPinyin$)+1
607 .currentFile$ = right$(.currentLine$, length(.currentPinyin$)+1)
608 elsif fileReadable("'.dirString$'/'.currentPinyin$'.spx")
609 .currentFile$ = .currentPinyin$+".spx"
610 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
611 .currentFile$ = .currentPinyin$+".flac"
612 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
613 .currentFile$ = .currentPinyin$+".wav"
614 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
615 .currentFile$ = .currentPinyin$+".mp3"
619 select Table 'wordlist$'
621 Set string value... '.i' Pinyin '.currentPinyin$'
622 Set string value... '.i' Sound '.currentFile$'
624 select Strings RawWordList
627 select Table 'wordlist$'
628 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
629 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
630 wordlist$ = selected$("Table")
631 Create Strings as file list... RawWordList '.dirString$'/*
632 .numWordStrings = Get number of strings
634 for .j to .numWordStrings
635 select Strings RawWordList
636 .currentLine$ = Get string... '.j'
637 .currentFile$ = extractWord$(.currentLine$, "")
638 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
639 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
640 select Table 'wordlist$'
643 Set string value... '.i' Pinyin '.currentPinyin$'
644 Set string value... '.i' Sound '.currentFile$'
647 select Strings RawWordList
650 select Table 'wordlist$'
651 elsif startsWith(.dirString$, "*call ")
652 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
654 wordlist$ = selected$("Table")
657 # Can this wordlist be deleted?
658 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
659 config.deleteWordlist = 0
661 config.deleteWordlist = -1
664 # Add a Character and Translation column if missing
666 select Table 'wordlist$'
667 numberOfWords = Get number of rows
668 .characterColumn = Get column index... Character
669 if not .characterColumn
670 Append column... Character
671 for .i to numberOfWords
672 Set string value... '.i' Character -
675 .translationColumn = Get column index... Translation
676 if not .translationColumn
677 Append column... Translation
678 for .i to numberOfWords
679 Set string value... '.i' Translation -
684 # Remove all rows without Pinyin
685 .numRows = Get number of rows
687 .rowNum = .numRows - i + 1
688 .pinyinValue$ = Get value... '.rowNum' Pinyin
689 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
690 Remove row... '.rowNum'
693 numberOfWords = Get number of rows
695 # Shuffle words if requested
696 if config.shuffleLists
701 select Table AllWordLists
704 # There were no Word Lists
707 wordlistName$ = "No Word Lists available"
709 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
710 wordlist$ = selected$("Table")
714 Set string value... '.i' Pinyin ni3hao3
715 Set string value... '.i' Character -
716 Set string value... '.i' Translation -
717 Set string value... '.i' Sound -
720 Set string value... '.i' Pinyin xie4xie0
721 Set string value... '.i' Character -
722 Set string value... '.i' Translation -
723 Set string value... '.i' Sound -
726 Set string value... '.i' Pinyin zai4jian4
727 Set string value... '.i' Character -
728 Set string value... '.i' Translation -
729 Set string value... '.i' Sound -
730 numberOfWords = Get number of rows
733 call set_window_title 'buttons$' 'wordlistName$'
736 procedure display_word_list_name
740 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
741 call wipeArea 'wipeWordlistArea$'
742 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
743 .currentFontSize = adjustFontSizeOnHeight.newFontSize
746 demo Text special... '.xtext' Centre '.ytext' Bottom Helvetica '.currentFontSize' 0 '.displayWordList$'
749 call set_font_size 'defaultFontSize'
752 procedure write_word_list
754 call draw_tone_contour
756 # Write current Pinyin text
757 call display_text Black
759 # Write the current word list name
760 call display_word_list_name
763 procedure start_logging
764 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
765 .logDirectory$ < 'preferencesLogDir$'/logPerformance.txt
766 .logDirectory$ = extractWord$(.logDirectory$, "")
767 if .logDirectory$ = "" or not (fileReadable(.logDirectory$) or fileReadable("'.logDirectory$'/directory.txt")
768 .logDirectory$ = "'preferencesLogDir$'"
770 currentLogDirectory$ = "'.logDirectory$'/log'logtimeStamp$'"
771 createDirectory(currentLogDirectory$)
772 if not fileReadable("'currentLogDirectory$'/wordlist.Table")
773 .headerLine$ = "Pinyin'tab$'Character'tab$'Sound'newline$'"
774 .headerLine$ > 'currentLogDirectory$'/wordlist.Table
777 config.logPerformance = 1
781 procedure log_command .logtext$
783 fileappend "'currentLogDirectory$'/logFile.txt" '.logtext$''newline$'
787 procedure log_performance .recordedSound$ .register .proficiency .pinyin$ .choice$
789 .currentDate$ = date$()
790 .timeStamp$ = replace_regex$(.currentDate$, "[^a-zA-Z0-9\-_]", "-", 0)
791 .choiceText$ = replace_regex$(.choice$, "[^a-zA-Z0-9\-_]", "-", 0)
793 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
794 .outfilename$ = .pinyin$+"_"+.choice$+"_'.register'_"+.timeStamp$+".wav"
795 .logtext$ = "# #+.pinyin$+tab$+.choice$+tab$+"'.register'Hz"+tab$+.currentDate$+tab$+.outfilename$+newline$
797 fileappend 'currentLogDirectory$'/logFile.txt '.logtext$'
800 fileappend 'currentLogDirectory$'/wordlist.Table '.pinyin$''tab$''.choice$''tab$''.outfilename$''newline$'
802 select Sound 'recordedSound$'
803 Write to WAV file... 'currentLogDirectory$'/'.outfilename$'
807 procedure paint_logging_light
809 .row = Search column... Label !Logging
811 exit Button Table Config does not have a row with label !Logging
814 .leftX = Get value... '.row' LeftX
815 .rightX = Get value... '.row' RightX
816 .lowY = Get value... '.row' LowY
817 .highY = Get value... '.row' HighY
818 .buttonColor$ = Get value... '.row' Color
819 .centerX = (.leftX + .rightX)/2
820 .centerY = (.lowY + .highY)/2
821 .radius = (.highY - .lowY )/(4*2)
822 .wipeRadius = 1.1*.radius
823 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
824 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
825 demo Paint circle... '.buttonColor$' '.centerX' '.centerY' '.radius'
828 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
833 # Uninstall word lists
834 procedure removeWordlist .deletedWordlistName$
836 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
837 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
840 Create Strings as file list... DeleteList '.targetDir$'/*
841 .numdeleteFiles = Get number of strings
842 for .i to .numdeleteFiles
843 .file$ = Get string... '.i'
844 deleteFile("'.targetDir$'/'.file$'")
846 filedelete '.targetDir$'
848 system rmdir "'.targetDir$'" /s /q
850 # Remove deleted word list
851 select Strings DeleteList
852 plus Table 'wordlist$'
859 procedure sgc2wordlist .sourceDir$
860 if startsWith(.sourceDir$, "preferencesDirectory$")
861 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
864 .targetDirectory$ = "'sgc2wordlists$'"
865 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
866 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
867 .numFiles = Get number of strings
869 select Strings PackageList
870 .file$ = Get string... '.i'
871 call readWordlist '.sourceDir$' '.file$'
874 select Strings PackageList
879 # Debuggin remarks!!!
880 # fileReadable(<directory>) does not work in Windows
881 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
882 # And yet only the 7z decompression has been implemented
883 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z"" x"
884 procedure readWordlist .sourceDir$ .file$
885 # No use doing anything if the source does not exist
886 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
887 # What will be the target wordlist directory?
888 .targetDirectory$ = "'sgc2wordlists$'"
889 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
893 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
894 # Wordlist directory does not exist, neither locally nor in the preferences
895 if not (fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
897 # Move source to destination
898 if index(.file$, ".sgc") or index(.file$, ".zip")
899 # Create wordlist directory
900 createDirectory(.wordlistDirectory$)
903 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"'
904 system cd ''.wordlistDirectory$'';bash -rc -- 'unzip "'.file$'"'
906 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
907 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
908 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /q
909 system chdir "'.winWordListDirectory$'" && 'windowsUnzipCommand$' "'.file$'"
911 deleteFile("'.wordlistDirectory$'/'.file$'")
912 elsif index_regex(.file$, "\.(Table|txt)")
913 # Create wordlist directory
914 createDirectory(.wordlistDirectory$)
916 .extension$ = replace_regex$(.file$, "^.+\.(Table|txt)$", "\1", 0)
918 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"'
920 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
921 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
922 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'\wordlist.'.extension$'" /q
924 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
925 # Copy wordlist directory
928 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
930 createDirectory(.wordlistDirectory$)
931 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
932 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
933 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
937 # Set current word list to read list
939 wordlistName$ = .dirname$
942 .label$ = "!NotAWordlist"
945 call findLabel '.table$' '.label$'
947 select Table '.table$'
948 .helpText$ = Get value... '.row' Helptext
949 .filetext$ = replace_regex$("'.sourceDir$'/'.file$'", "_", "\\_ ", 0)
950 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
951 # Wait for confirmation