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 DrawManual .color$ .x .y .size
79 call adjustFontSizeOnHeight 'defaultFont$' 24 '.lineheight'
80 .currentFontSize = adjustFontSizeOnHeight.newFontSize
81 demo Paint circle... {0.2,0.2,0.8} '.x' '.y' '.size'
83 demo Text special... '.x' centre '.y' half Times '.currentFontSize' 0 M
86 call set_font_size 'defaultFontSize'
89 procedure DrawLogging .color$ .x .y .size
93 .color$ = "{0.5,0.5,1}"
97 demo Paint circle... '.color$' '.x' '.y' '.size'
100 ###############################################################
102 # Obligatory button Drawing Routines
104 # These MUST be defined
106 ###############################################################
108 procedure DrawReturn .color$ .x .y .size
109 call DrawConfig '.color$' '.x' '.y' '.size'
112 # Set the correct button states after redrawing the window
113 procedure setConfigMainPage
114 call testLoadTable SummaryToneEvaluation
115 if testLoadTable.table <= 0
116 call Draw_button 'config$' PerfSummary 1
118 # Handle logging buttons with forced button draw
119 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
120 call Draw_button 'config$' +!Logging 'config.logPerformance'
124 ###############################################################
126 # Button Processing Routines
128 ###############################################################
130 procedure processConfigShuffleLists .clickX .clickY .pressed$
132 .label$ = "ShuffleLists"
133 config.shuffleLists = not config.shuffleLists
134 .displayButton = 2*config.shuffleLists
135 call Draw_button '.table$' '.label$' '.displayButton'
138 procedure processConfigUseSoundExample .clickX .clickY .pressed$
140 .label$ = "UseSoundExample"
141 config.useSoundExample = not config.useSoundExample
142 .displayButton = 2*config.useSoundExample
143 call Draw_button '.table$' '.label$' '.displayButton'
146 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
148 .label$ = "Synthesis_'.tts$'"
149 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
150 if config.synthesis$ = ""
151 config.synthesis$ = .tts$
154 config.synthesis$ = ""
158 config.synthesis$ = "_DISABLED_"
161 call Draw_button '.table$' '.label$' '.displayButton'
164 procedure processConfigStrict .clickX .clickY .pressed$
167 config.strict = not config.strict
173 # Change TTS for Strict!
175 call Draw_button '.table$' '.label$' '.displayButton'
178 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
180 .label$ = "DisplayPinyin"
181 config.displayPinyin = not config.displayPinyin
182 .displayButton = 2*config.displayPinyin
183 call Draw_button '.table$' '.label$' '.displayButton'
186 procedure processConfigDisplayChar .clickX .clickY .pressed$
188 .label$ = "DisplayChar"
189 config.displayChar = not config.displayChar
190 .displayButton = 2*config.displayChar
191 call Draw_button 'table$' '.label$' '.displayButton'
194 procedure processConfigDisplayTrans .clickX .clickY .pressed$
196 .label$ = "DisplayTrans"
197 config.displayTrans = not config.displayTrans
198 .displayButton = 2*config.displayTrans
199 call Draw_button 'table$' '.label$' '.displayButton'
202 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
204 .label$ = "DisplayNumbers"
205 config.displayNumbers = not config.displayNumbers
206 .displayButton = 2*config.displayNumbers
207 call Draw_button 'table$' '.label$' '.displayButton'
210 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
212 .label$ = "Language_'.language$'"
213 call processLanguageCodes '.table$' '.label$'
216 procedure processConfigShowBackground .clickX .clickY .pressed$
218 .label$ = "ShowBackground"
219 config.showBackground = not config.showBackground
220 .displayButton = 2*config.showBackground
221 call Draw_button 'table$' '.label$' '.displayButton'
224 procedure processConfigInput .input$ .clickX .clickY .pressed$
226 .label$ = "Input_'.input$'"
227 call Draw_button '.table$' Input_'config.input$' 0
228 config.input$ = .input$
229 call Draw_button '.table$' Input_'config.input$' 2
232 procedure processConfigRegister .register .clickX .clickY .pressed$
234 .label$ = "Register_'.register'"
235 call setRegisterFromLabel '.table$' '.label$'
238 procedure setRegisterFromLabel .table$ .label$
239 call Draw_button '.table$' Register_'config.register' 0
240 call Draw_button '.table$' '.label$' 2
241 # Someone might have to use more than 3 chars for the config.register code
242 .numChars = length(.label$) - length("Register_")
243 .registerText$ = right$(.label$, .numChars)
244 config.register = '.registerText$'
247 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
249 .label$ = "DeleteWordlist"
251 # Do not process undeletable word lists, only those stored in the
252 # preferencesDirectory$ can be deleted
253 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
254 call findLabel '.table$' !'.label$'
256 select Table '.table$'
257 .alertText$ = Get value... 'findLabel.row' Text
258 .confirmKey$ = Get value... 'findLabel.row' Key
259 .popupText$ = Get value... 'findLabel.row' Helptext
261 exit Cannot find delete directive: '.table$' !'.label$'
263 call write_text_popup 'defaultFont$' 14 '.popupText$'
264 call Draw_button '.table$' '.label$' 2
265 alertText$ = .alertText$
266 call Draw_button '.table$' '.label$' 3
269 # Wait for confirmation
271 if demoInput(.confirmKey$)
272 .deleteWordListDir$ = wordlistName$
273 call load_word_list "'localWordlistDir$'" 1
274 call removeWordlist '.deleteWordListDir$'
275 call load_word_list "'localWordlistDir$'" 0
277 call Draw_button '.table$' '.label$' 0
278 call Draw_config_page
282 wordlistTag$ = "Wordlist name"
283 procedure processConfigInstallWordlist .clickX .clickY .pressed$
285 .label$ = "InstallWordlist"
286 call Draw_button '.table$' '.label$' 1
288 # Do not use the automatic sgc list option, ask for a wordlist NAME
290 call findLabel '.table$' '.label$'
292 select Table '.table$'
293 .openDialogue$ = Get value... '.row' Helptext
294 call convert_praat_to_latin1 '.openDialogue$'
295 .openDialogue$ = convert_praat_to_latin1.text$
296 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
297 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
298 beginPause(.openDialogue$)
299 sentence (wordlistTag$, "")
300 clicked = endPause ("Cancel", "Open", 2)
303 .wordlist_Name$ = '.wordlistButton$'$
305 call install_wordlists_by_name '.wordlist_Name$'
307 call sgc2wordlist 'homeDirectory$'
308 call sgc2wordlist 'homeDirectory$'/Downloads
309 call sgc2wordlist 'homeDirectory$'/Documents
310 call sgc2wordlist 'homeDirectory$'/My Documents
311 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
312 call sgc2wordlist 'homeDirectory$'/Desktop
313 call sgc2wordlist 'preferencesAppDir$'
315 call load_word_list "'localWordlistDir$'" 0
316 call Draw_button '.table$' '.label$' 0
317 call Draw_config_page
320 procedure processConfigOpenWordlist .clickX .clickY .pressed$
322 .label$ = "OpenWordlist"
323 call Draw_button '.table$' '.label$' 1
326 call findLabel '.table$' '.label$'
328 select Table '.table$'
329 .openDialogue$ = Get value... '.row' Helptext
330 call convert_praat_to_latin1 '.openDialogue$'
331 .openDialogue$ = convert_praat_to_latin1.text$
333 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
334 call install_wordlists_by_name '.wordlist_Name$'
335 call load_word_list "'localWordlistDir$'" 0
336 call Draw_button '.table$' '.label$' 0
337 call Draw_config_page
340 procedure processConfigPerfSummary .clickX .clickY .pressed$
342 .label$ = "PerfSummary"
344 call testLoadTable SummaryToneEvaluation
345 if testLoadTable.table > 0
346 call Draw_button '.table$' '.label$' 1
347 call loadTable SummaryToneEvaluation
348 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
350 select Table SummaryToneEvaluation
353 call Draw_button '.table$' '.label$' 0
354 call Draw_config_page
358 procedure processConfigListPerf .clickX .clickY .pressed$
361 call Draw_button '.table$' '.label$' 1
363 call write_tabbed_table 'initialiseSGC2.toneevaluation_table$' Evaluation_'config.language$'
366 call Draw_button '.table$' '.label$' 0
367 call Draw_config_page
370 procedure processConfigSavePerf .clickX .clickY .pressed$
373 call Draw_button '.table$' '.label$' 1
376 call findLabel '.table$' '.label$'
378 select Table '.table$'
379 .openDialogue$ = Get value... '.row' Helptext
380 call convert_praat_to_latin1 '.openDialogue$'
381 .openDialogue$ = convert_praat_to_latin1.text$
383 .wordlist_Name$ = chooseWriteFile$ (.openDialogue$, "Performance.Table")
384 if .wordlist_Name$ <> ""
385 select Table 'initialiseSGC2.toneevaluation_table$'
386 Write to table file... '.wordlist_Name$'
389 call Draw_button '.table$' '.label$' 0
390 call Draw_config_page
393 procedure processConfigManual .clickX .clickY .pressed$
396 call Draw_button '.table$' '.label$' 1
397 if fileReadable("ManPages/SpeakGoodChinese_2.man")
398 Read from file... ManPages/SpeakGoodChinese_2.man
400 Go to manual page... SpeakGoodChinese 2
402 # Wait until the manual is put to the background
404 call Draw_button '.table$' '.label$' 0
406 call Draw_config_page
409 ###############################################################
411 # Obligatory button Processing Routines
413 # These MUST be defined
415 ###############################################################
417 procedure processConfigReturn .clickX .clickY .pressed$
420 call Draw_button '.table$' '.label$' 1
421 call write_preferences ""
424 procedure processConfigRefresh .clickX .clickY .pressed$
427 call Draw_config_page
430 procedure processConfigCredits .clickX .clickY .pressed$
433 call Draw_button '.table$' '.label$' 1
434 call write_text_table Credits_'config.language$'
436 call Draw_button '.table$' '.label$' 0
438 call Draw_config_page
441 procedure processConfigHelp .clickX .clickY .pressed$
444 call help_loop '.table$' Draw_config_page
447 ###############################################################
449 # Miscelaneous supporting code
451 ###############################################################
452 procedure install_wordlists_by_name .wordlist_Name$
453 if .wordlist_Name$ <> ""
454 if index(.wordlist_Name$, "wordlist.")
455 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\]wordlist\.([^/\\]+)$", "", 0)
456 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
457 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
459 if index_regex(.wordlist_Name$, "[/\\]")
460 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
461 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
462 call readWordlist "'.sourceDir$'" '.file$'
465 if index(.wordlist_Name$, ".")
468 .extension1$ = ".sgc"
469 .extension2$ = ".Table"
470 .extension3$ = ".txt"
471 .extension4$ = ".tsv"
473 for .e from .start to 5
474 .currentExtension$ = .extension'.e'$
475 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
476 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
477 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
478 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
479 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
480 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
481 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
487 # Word lists: It is a VERY good idea to make sure that word-lists
489 procedure load_word_list .localdir$ .relnumber
492 # Remove old word list
494 select Table 'wordlist$'
496 call wipeArea 'wipeWordlistArea$'
500 # Create Table that will recieve the wordlists and directories
501 Create Table with column names... AllWordLists 0 Name Directory
502 .te.currentWordlistRow = 0
504 # Start with the word lists in the distribution, unless the local directory exists!
505 call CreateCreateWordlists
506 select Table CreateWordlists
507 .numLists = Get number of rows
509 select Table CreateWordlists
510 .currentName$ = Get value... '.i' Name
511 if not (fileReadable("'.localdir$'/'.currentName$'") or fileReadable("'.localdir$'/'.currentName$'/wordlist.Table") or fileReadable("'.localdir$'/'.currentName$'/wordlist.txt"))
512 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
513 select Table AllWordLists
515 .te.currentWordlistRow = Get number of rows
516 Set string value... '.te.currentWordlistRow' Name '.currentName$'
517 .currentDirectory$ = "*call Create'.procedureName$'"
518 Set string value... '.te.currentWordlistRow' Directory '.currentDirectory$'
521 select Table CreateWordlists
524 # First the global word lists
525 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
526 Create Strings as directory list... WordList 'globalwordlists$'
527 .numLists = Get number of strings
529 select Strings WordList
530 .currentName$ = Get string... '.i'
531 if .currentName$ <> "directory.txt"
532 select Table AllWordLists
533 .listExist = Search column: "Name", .currentName$
536 .te.currentWordlistRow = Get number of rows
537 Set string value... '.te.currentWordlistRow' Name '.currentName$'
538 .currentDirectory$ = globalwordlists$+"/"+.currentName$
539 Set string value... '.te.currentWordlistRow' Directory '.currentDirectory$'
543 select Strings WordList
547 # Now the preferences word lists
548 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
549 Create Strings as directory list... WordList 'sgc2wordlists$'
550 .numLists = Get number of strings
552 select Strings WordList
553 .currentName$ = Get string... '.i'
554 if .currentName$ <> "directory.txt"
555 select Table AllWordLists
556 .listExist = Search column: "Name", .currentName$
559 .te.currentWordlistRow = Get number of rows
560 Set string value... '.te.currentWordlistRow' Name '.currentName$'
561 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
562 Set string value... '.te.currentWordlistRow' Directory '.currentDirectory$'
566 select Strings WordList
570 # Finally, the local word lists
571 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
572 Create Strings as directory list... WordList '.localdir$'
573 .numLists = Get number of strings
575 select Strings WordList
576 .currentName$ = Get string... '.i'
577 if .currentName$ <> "directory.txt"
578 select Table AllWordLists
579 .listExist = Search column: "Name", .currentName$
582 .te.currentWordlistRow = Get number of rows
583 Set string value... '.te.currentWordlistRow' Name '.currentName$'
584 .currentDirectory$ = .localdir$+"/"+.currentName$
585 Set string value... '.te.currentWordlistRow' Directory '.currentDirectory$'
589 select Strings WordList
593 # Get the position of the current word list
594 select Table AllWordLists
596 .numLists = Get number of rows
598 if wordlistName$ <> ""
599 select Table AllWordLists
600 .currentNumber = Search column... Name 'wordlistName$'
603 wordlistNum = .currentNumber + .relnumber
604 if wordlistNum > .numLists
606 elsif wordlistNum < 1 and .numLists > 0
607 wordlistNum = .numLists
609 select Table AllWordLists
610 wordlistName$ = Get value... 'wordlistNum' Name
611 .dirWordlistName$ = Get value... 'wordlistNum' Directory
612 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
614 # Read in full tables
615 if fileReadable("'.dirString$'/wordlist.Table")
616 Read from file... '.dirString$'/wordlist.Table
617 Rename... 'wordlistName$'
618 # Praat wil change the name if it feels like it
619 wordlist$ = selected$("Table")
620 # Handle (legacy) simple word lists
621 elsif fileReadable("'.dirString$'/wordlist.txt")
622 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
623 wordlist$ = selected$("Table")
624 Read Strings from raw text file... '.dirString$'/wordlist.txt
625 Rename... RawWordList
626 .numWordStrings = Get number of strings
627 for .i to .numWordStrings
628 select Strings RawWordList
632 .currentLine$ = Get string... '.i'
633 # Remove leading whitespace
634 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
635 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
636 if .separatorIndex <= 0
637 .separatorIndex = length(.currentLine$) + 1
639 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
640 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
641 # There is more on the line, but we do not know what
642 if length(.currentLine$) > 0
643 while length(.currentLine$) > 0
644 .separatorIndex = index_regex(.currentLine$, "[\t;]")
645 if .separatorIndex <= 0
646 .separatorIndex = length(.currentLine$)+1
648 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
649 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
650 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
652 .currentFile$ = .currentItem$
653 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
655 .currentTrans$ = .currentItem$
656 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
658 .currentChar$ = .currentItem$
662 if .currentFile$ = "-"
663 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
664 .currentFile$ = .currentPinyin$+".spx"
665 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
666 .currentFile$ = .currentPinyin$+".flac"
667 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
668 .currentFile$ = .currentPinyin$+".wav"
669 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
670 .currentFile$ = .currentPinyin$+".mp3"
673 select Table 'wordlist$'
675 Set string value... '.i' Pinyin '.currentPinyin$'
676 Set string value... '.i' Sound '.currentFile$'
677 Set string value... '.i' Character '.currentChar$'
678 Set string value... '.i' Translation '.currentTrans$'
680 select Strings RawWordList
683 select Table 'wordlist$'
684 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
685 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
686 wordlist$ = selected$("Table")
687 Create Strings as file list... RawWordList '.dirString$'/*
688 .numWordStrings = Get number of strings
690 for .j to .numWordStrings
691 select Strings RawWordList
692 .currentLine$ = Get string... '.j'
693 .currentFile$ = extractWord$(.currentLine$, "")
694 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
695 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
696 select Table 'wordlist$'
699 Set string value... '.i' Pinyin '.currentPinyin$'
700 Set string value... '.i' Sound '.currentFile$'
703 select Strings RawWordList
706 select Table 'wordlist$'
707 elsif startsWith(.dirString$, "*call ")
708 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
710 wordlist$ = selected$("Table")
713 # Can this wordlist be deleted?
714 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
715 config.deleteWordlist = 0
717 config.deleteWordlist = -1
720 # Add a Character and Translation column if missing
722 select Table 'wordlist$'
723 te.numberOfWords = Get number of rows
724 .characterColumn = Get column index... Character
725 if not .characterColumn
726 Append column... Character
727 for .i to te.numberOfWords
728 Set string value... '.i' Character -
731 .translationColumn = Get column index... Translation
732 if not .translationColumn
733 Append column... Translation
734 for .i to te.numberOfWords
735 Set string value... '.i' Translation -
740 # Remove all rows without Pinyin
741 .numRows = Get number of rows
743 .rowNum = .numRows - i + 1
744 .pinyinValue$ = Get value... '.rowNum' Pinyin
745 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
746 Remove row... '.rowNum'
749 te.numberOfWords = Get number of rows
751 # Shuffle words if requested
752 if config.shuffleLists
757 select Table AllWordLists
760 # There were no Word Lists
763 wordlistName$ = "No Word Lists available"
765 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
766 wordlist$ = selected$("Table")
770 Set string value... '.i' Pinyin ni3hao3
771 Set string value... '.i' Character 你好
772 Set string value... '.i' Translation hello
773 Set string value... '.i' Sound -
776 Set string value... '.i' Pinyin xie4xie0
777 Set string value... '.i' Character 谢谢
778 Set string value... '.i' Translation thanks
779 Set string value... '.i' Sound -
782 Set string value... '.i' Pinyin zai4jian4
783 Set string value... '.i' Character 再见
784 Set string value... '.i' Translation goodbye
785 Set string value... '.i' Sound -
786 te.numberOfWords = Get number of rows
789 call set_window_title 'buttons$' 'wordlistName$'
792 procedure display_word_list_name
796 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
797 call wipeArea 'wipeWordlistArea$'
798 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
799 .currentFontSize = adjustFontSizeOnHeight.newFontSize
802 demo Text special... '.xtext' Centre '.ytext' Bottom Helvetica '.currentFontSize' 0 '.displayWordList$'
805 call set_font_size 'defaultFontSize'
808 procedure write_word_list
809 # Write current Pinyin text
810 call display_text Black
812 # Write the current word list name
813 call display_word_list_name
816 procedure start_logging
817 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
818 .logDirectory$ < 'preferencesLogDir$'/logPerformance.txt
819 .logDirectory$ = extractWord$(.logDirectory$, "")
820 if .logDirectory$ = "" or not (fileReadable(.logDirectory$) or fileReadable("'.logDirectory$'/directory.txt")
821 .logDirectory$ = "'preferencesLogDir$'"
823 currentLogDirectory$ = "'.logDirectory$'/log'logtimeStamp$'"
824 createDirectory(currentLogDirectory$)
825 if not fileReadable("'currentLogDirectory$'/wordlist.Table")
826 .headerLine$ = "Pinyin'tab$'Character'tab$'Sound'newline$'"
827 .headerLine$ > 'currentLogDirectory$'/wordlist.Table
830 config.logPerformance = 1
834 procedure log_command .logtext$
836 fileappend "'currentLogDirectory$'/logFile.txt" '.logtext$''newline$'
840 procedure log_performance .recordedSound$ .register .proficiency .pinyin$ .choice$
842 .currentDate$ = date$()
843 .timeStamp$ = replace_regex$(.currentDate$, "[^a-zA-Z0-9\-_]", "-", 0)
844 .choiceText$ = replace_regex$(.choice$, "[^a-zA-Z0-9\-_]", "-", 0)
846 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
847 .outfilename$ = .pinyin$+"_"+.choice$+"_'.register'_"+.timeStamp$+".wav"
848 .logtext$ = "# #+.pinyin$+tab$+.choice$+tab$+"'.register'Hz"+tab$+.currentDate$+tab$+.outfilename$+newline$
850 fileappend 'currentLogDirectory$'/logFile.txt '.logtext$'
853 fileappend 'currentLogDirectory$'/wordlist.Table '.pinyin$''tab$''.choice$''tab$''.outfilename$''newline$'
855 select Sound 'recordedSound$'
856 Write to WAV file... 'currentLogDirectory$'/'.outfilename$'
860 procedure paint_logging_light
862 .row = Search column... Label !Logging
864 exit Button Table Config does not have a row with label !Logging
867 .leftX = Get value... '.row' LeftX
868 .rightX = Get value... '.row' RightX
869 .lowY = Get value... '.row' LowY
870 .highY = Get value... '.row' HighY
871 .buttonColor$ = Get value... '.row' Color
872 .centerX = (.leftX + .rightX)/2
873 .centerY = (.lowY + .highY)/2
874 .radius = (.highY - .lowY )/(4*2)
875 .wipeRadius = 1.1*.radius
876 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
877 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
878 demo Paint circle... '.buttonColor$' '.centerX' '.centerY' '.radius'
881 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
886 # Uninstall word lists
887 procedure removeWordlist .deletedWordlistName$
889 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
890 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
893 Create Strings as file list... DeleteList '.targetDir$'/*
894 .numdeleteFiles = Get number of strings
895 for .i to .numdeleteFiles
896 .file$ = Get string... '.i'
897 deleteFile("'.targetDir$'/'.file$'")
899 filedelete '.targetDir$'
901 system rmdir "'.targetDir$'" /s /q
903 # Remove deleted word list
904 select Strings DeleteList
905 plus Table 'wordlist$'
912 procedure sgc2wordlist .sourceDir$
913 if startsWith(.sourceDir$, "preferencesDirectory$")
914 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
917 .targetDirectory$ = "'sgc2wordlists$'"
918 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
919 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
920 .numFiles = Get number of strings
922 select Strings PackageList
923 .file$ = Get string... '.i'
924 call readWordlist '.sourceDir$' '.file$'
927 select Strings PackageList
932 # Debuggin remarks!!!
933 # fileReadable(<directory>) does not work in Windows
934 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
935 # And yet only the 7z decompression has been implemented
936 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z"" x"
937 procedure readWordlist .sourceDir$ .file$
938 # No use doing anything if the source does not exist
939 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
940 # What will be the target wordlist directory?
941 .targetDirectory$ = "'sgc2wordlists$'"
942 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
946 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
947 # Wordlist directory does not exist, neither locally nor in the preferences
948 if not (fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
950 # Move source to destination
951 if index(.file$, ".sgc") or index(.file$, ".zip")
952 # Create wordlist directory
953 createDirectory(.wordlistDirectory$)
956 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"'
957 system cd ''.wordlistDirectory$'';bash -rc -- 'unzip "'.file$'"'
959 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
960 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
961 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /q
962 system chdir "'.winWordListDirectory$'" && 'windowsUnzipCommand$' "'.file$'"
964 deleteFile("'.wordlistDirectory$'/'.file$'")
965 elsif index_regex(.file$, "\.(Table|txt|tsv)")
966 # Create wordlist directory
967 createDirectory(.wordlistDirectory$)
969 .extension$ = replace_regex$(.file$, "^.+\.(Table|txt|tsv)$", "\1", 0)
970 if .extension$ = "tsv"
971 .extension$ = "Table"
974 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"'
976 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
977 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
978 system copy "'.winSourceDirectory$'" "'.winWordListDirectory$'\wordlist.'.extension$'" /q
980 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
981 # Copy wordlist directory
984 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
986 createDirectory(.wordlistDirectory$)
987 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
988 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
989 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
993 # Set current word list to read list
995 wordlistName$ = .dirname$
998 .label$ = "!NotAWordlist"
1001 call findLabel '.table$' '.label$'
1002 .row = findLabel.row
1003 select Table '.table$'
1004 .helpText$ = Get value... '.row' Helptext
1005 .filetext$ = replace_regex$("'.sourceDir$'/'.file$'", "_", "\\_ ", 0)
1006 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1007 # Wait for confirmation