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 DrawSaveAudio .color$ .x .y .size
94 elsif .color$ = "Blue"
95 .color$ = "{0.5,0.5,1}"
99 demo Paint circle... '.color$' '.x' '.y' '.size'
102 ###############################################################
104 # Obligatory button Drawing Routines
106 # These MUST be defined
108 ###############################################################
110 procedure DrawReturn .color$ .x .y .size
111 call DrawConfig '.color$' '.x' '.y' '.size'
114 # Set the correct button states after redrawing the window
115 procedure setConfigMainPage
116 call Draw_button 'config$' +SaveAudio 'sgc.saveAudioOn'
119 ###############################################################
121 # Button Processing Routines
123 ###############################################################
125 procedure processConfigShuffleLists .clickX .clickY .pressed$
127 .label$ = "ShuffleLists"
128 config.shuffleLists = not config.shuffleLists
129 .displayButton = 2*config.shuffleLists
130 call Draw_button '.table$' '.label$' '.displayButton'
133 procedure processConfigAdaptiveLists .clickX .clickY .pressed$
135 .label$ = "AdaptiveLists"
136 config.adaptiveLists = not config.adaptiveLists
137 .displayButton = 2*config.adaptiveLists
138 call Draw_button '.table$' '.label$' '.displayButton'
141 procedure processConfigUseSoundExample .clickX .clickY .pressed$
143 .label$ = "UseSoundExample"
144 config.useSoundExample = not config.useSoundExample
145 .displayButton = 2*config.useSoundExample
146 call Draw_button '.table$' '.label$' '.displayButton'
149 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
151 .label$ = "Synthesis_'.tts$'"
152 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
153 if config.synthesis$ = ""
154 config.synthesis$ = .tts$
157 config.synthesis$ = ""
161 config.synthesis$ = "_DISABLED_"
164 call Draw_button '.table$' '.label$' '.displayButton'
167 procedure processConfigStrict .clickX .clickY .pressed$
170 .tmp = 'config.strict$'
172 if .tmp > sgc.highestLevel
175 config.strict$ = "'.tmp'"
181 # Change TTS for Strict!
183 call Draw_button '.table$' '.label$' '.displayButton'
186 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
188 .label$ = "DisplayPinyin"
189 config.displayPinyin = not config.displayPinyin
190 .displayButton = 2*config.displayPinyin
191 call Draw_button '.table$' '.label$' '.displayButton'
194 procedure processConfigDisplayChar .clickX .clickY .pressed$
196 .label$ = "DisplayChar"
197 config.displayChar = not config.displayChar
198 .displayButton = 2*config.displayChar
199 call Draw_button 'table$' '.label$' '.displayButton'
202 procedure processConfigDisplayTrans .clickX .clickY .pressed$
204 .label$ = "DisplayTrans"
205 config.displayTrans = not config.displayTrans
206 .displayButton = 2*config.displayTrans
207 call Draw_button 'table$' '.label$' '.displayButton'
210 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
212 .label$ = "DisplayNumbers"
213 config.displayNumbers = not config.displayNumbers
214 .displayButton = 2*config.displayNumbers
215 call Draw_button 'table$' '.label$' '.displayButton'
218 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
220 .label$ = "Language_'.language$'"
221 call processLanguageCodes '.table$' '.label$'
224 procedure processConfigShowBackground .clickX .clickY .pressed$
226 .label$ = "ShowBackground"
227 config.showBackground = not config.showBackground
228 .displayButton = 2*config.showBackground
229 call Draw_button 'table$' '.label$' '.displayButton'
232 procedure processConfigInput .input$ .clickX .clickY .pressed$
234 .label$ = "Input_'.input$'"
235 call Draw_button '.table$' Input_'config.input$' 0
236 config.input$ = .input$
237 call Draw_button '.table$' Input_'config.input$' 2
240 procedure processConfigRegister .register .clickX .clickY .pressed$
242 .label$ = "Register_'.register'"
243 call setRegisterFromLabel '.table$' '.label$'
246 procedure setRegisterFromLabel .table$ .label$
247 call Draw_button '.table$' Register_'config.register' 0
248 call Draw_button '.table$' '.label$' 2
249 # Someone might have to use more than 3 chars for the config.register code
250 .numChars = length(.label$) - length("Register_")
251 .registerText$ = right$(.label$, .numChars)
252 config.register = '.registerText$'
255 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
257 .label$ = "DeleteWordlist"
259 # Do not process undeletable word lists, only those stored in the
260 # preferencesDirectory$ can be deleted
261 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
262 call findLabel '.table$' !'.label$'
264 select Table '.table$'
265 .alertText$ = Get value... 'findLabel.row' Text
266 .confirmKey$ = Get value... 'findLabel.row' Key
267 .popupText$ = Get value... 'findLabel.row' Helptext
269 exit Cannot find delete directive: '.table$' !'.label$'
271 call write_text_popup 'defaultFont$' 14 '.popupText$'
272 call Draw_button '.table$' '.label$' 2
273 alertText$ = .alertText$
274 call Draw_button '.table$' '.label$' 3
277 # Wait for confirmation
279 if demoInput(.confirmKey$)
280 .deleteWordListDir$ = wordlistName$
281 call load_word_list "'localWordlistDir$'" 1
282 call removeWordlist '.deleteWordListDir$'
283 call load_word_list "'localWordlistDir$'" 0
285 call Draw_button '.table$' '.label$' 0
286 call Draw_config_page
290 wordlistTag$ = "Wordlist name"
291 procedure processConfigInstallWordlist .clickX .clickY .pressed$
293 .label$ = "InstallWordlist"
294 call Draw_button '.table$' '.label$' 1
296 # Do not use the automatic sgc list option, ask for a wordlist NAME
298 call findLabel '.table$' '.label$'
300 select Table '.table$'
301 .openDialogue$ = Get value... '.row' Helptext
302 call convert_praat_to_latin1 '.openDialogue$'
303 .openDialogue$ = convert_praat_to_latin1.text$
304 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
305 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
306 beginPause(.openDialogue$)
307 sentence (wordlistTag$, "")
308 clicked = endPause ("Cancel", "Open", 2, 1)
311 .wordlist_Name$ = '.wordlistButton$'$
313 call install_wordlists_by_name '.wordlist_Name$'
315 call sgc2wordlist 'homeDirectory$'
316 call sgc2wordlist 'homeDirectory$'/Downloads
317 call sgc2wordlist 'homeDirectory$'/Documents
318 call sgc2wordlist 'homeDirectory$'/My Documents
319 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
320 call sgc2wordlist 'homeDirectory$'/Desktop
321 call sgc2wordlist 'preferencesAppDir$'
323 call load_word_list "'localWordlistDir$'" 0
324 call Draw_button '.table$' '.label$' 0
325 call Draw_config_page
328 procedure processConfigOpenWordlist .clickX .clickY .pressed$
330 .label$ = "OpenWordlist"
331 call Draw_button '.table$' '.label$' 1
334 call findLabel '.table$' '.label$'
336 select Table '.table$'
337 .openDialogue$ = Get value... '.row' Helptext
338 call convert_praat_to_latin1 '.openDialogue$'
339 .openDialogue$ = convert_praat_to_latin1.text$
341 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
342 call install_wordlists_by_name '.wordlist_Name$'
343 call load_word_list "'localWordlistDir$'" 0
344 call Draw_button '.table$' '.label$' 0
345 call Draw_config_page
348 # Select the words to practise. This is quite a complex piece of code
349 procedure processConfigSelectWords .clickX .clickY .pressed$
351 .label$ = "SelectWords"
352 call Draw_button '.table$' '.label$' 1
355 call findLabel '.table$' '.label$'
357 select Table '.table$'
358 .helpText$ = Get value... '.row' Helptext
359 call convert_praat_to_latin1 '.helpText$'
360 .helpText$ = convert_praat_to_latin1.text$
363 select Table 'wordlist$'
364 .tmpOriginalWordlist = Copy: "Original_'wordlist$'"
368 select Table 'wordlist$'
369 sgc.numberOfWords = Get number of rows
370 .currentWord = sgc.currentWord
371 if .currentWord <= 0 or .currentWord > sgc.numberOfWords or config.shuffleLists
376 call get_feedback_text 'config.language$' Part
377 call convert_praat_to_latin1 'get_feedback_text.text$'
378 .partText$ = convert_praat_to_latin1.text$
379 call get_feedback_text 'config.language$' Tones
380 call convert_praat_to_latin1 'get_feedback_text.text$'
381 .toneText$ = convert_praat_to_latin1.text$
382 call get_feedback_text 'config.language$' Cancel
383 call convert_praat_to_latin1 'get_feedback_text.text$'
384 .cancelText$ = convert_praat_to_latin1.text$
385 call get_feedback_text 'config.language$' Clear
386 call convert_praat_to_latin1 'get_feedback_text.text$'
387 .clearText$ = convert_praat_to_latin1.text$
388 call get_feedback_text 'config.language$' All
389 call convert_praat_to_latin1 'get_feedback_text.text$'
390 .allText$ = convert_praat_to_latin1.text$
391 call get_feedback_text 'config.language$' Previous
392 call convert_praat_to_latin1 'get_feedback_text.text$'
393 .prevWord$ = convert_praat_to_latin1.text$
394 call get_feedback_text 'config.language$' Next
395 call convert_praat_to_latin1 'get_feedback_text.text$'
396 .nextWord$ = convert_praat_to_latin1.text$
397 call get_feedback_text 'config.language$' Continue
398 call convert_praat_to_latin1 'get_feedback_text.text$'
399 .continueText$ = convert_praat_to_latin1.text$
400 call get_feedback_text 'config.language$' Show
401 call convert_praat_to_latin1 'get_feedback_text.text$'
402 .showText$ = convert_praat_to_latin1.text$
404 .pinyinText$ = "Pinyin"
405 .characterText$ = "Character"
408 select Table 'wordlist$'
409 .lessonCol = Get column index: "Lesson"
412 # All shown keeps track whether all words are shown
413 # If so, selecting a lesson is preceded by a Clear All
415 # Sort words for consistent selection interface
416 if config.shuffleLists
417 # Allow subdivision in lessons
419 Sort rows... Lesson Pinyin
425 for .i to sgc.numberOfWords
426 .currentLesson$ = Get value: .i, "Lesson"
427 if .currentLesson$ <> "" and .currentLesson$ <> "-" and index_regex(.lessonList$, "\t'.currentLesson$'\t") <= 0
428 .lessonList$ = .lessonList$ + .currentLesson$ + tab$
430 .lessonName$['.numLessons'] = .currentLesson$
432 .shown$ = Get value: .i, "Show"
440 .numWordsPerScreen = 15
441 while clicked <> 6 and clicked <> 1
446 select Table 'wordlist$'
447 .lessonCol = Get column index: "Lesson"
448 # Sort words for consistent selection interface
449 if config.shuffleLists
450 # Allow subdivision in lessons
452 Sort rows... Lesson Pinyin
457 .max = .numWordsPerScreen - 1
458 if .currentWord + .max > sgc.numberOfWords
459 .max = sgc.numberOfWords - .currentWord
461 for .i from 0 to .numWordsPerScreen - 1
463 .currentPinyin$ = Get value: .currentWord+.i, "Pinyin"
464 if index_regex(.currentPinyin$, "[0-9]") <= 0
465 call pinyin2numbers '.currentPinyin$'
466 .currentPinyin$ = replace_regex$(pinyin2numbers.intermediatePinyin$, ".+", "\l&", 0)
467 .currentPinyin$ = replace_regex$(.currentPinyin$, "[^a-zA-Z0-9]", "", 0)
469 .pinyin$[.i] = .currentPinyin$
471 .character$[.i] = Get value: .currentWord+.i, "Character"
474 .lessonNum$[.i] = Get value: .currentWord+.i, "Lesson"
475 .lessonNum$[.i] = " : " + .lessonNum$[.i]
477 .showText$[.i] = .pinyin$['.i']
478 if .character$['.i'] <> "-"
479 .showText$[.i] = .pinyin$['.i']+" ("+.character$['.i']+.lessonNum$['.i']+")"
480 elsif .lessonNum$['.i'] <> ""
481 .showText$[.i] = .pinyin$['.i']+" ( -"+.lessonNum$['.i']+")"
483 .showValueText$[.i] = Get value: .currentWord+.i, "Show"
484 if .showValueText$[.i] = "-"
489 .showVariable$[.i] = .pinyin$[.i]
490 .tmp$ = .showVariable$[.i]
491 '.tmp$' = .showValue[.i]
498 # The user text input window (beginPause .... endPause)
499 beginPause(.helpText$)
500 boolean (.showText$[0], .showValue[0])
501 boolean (.showText$[1], .showValue[1])
502 boolean (.showText$[2], .showValue[2])
503 boolean (.showText$[3], .showValue[3])
504 boolean (.showText$[4], .showValue[4])
505 boolean (.showText$[5], .showValue[5])
506 boolean (.showText$[6], .showValue[6])
507 boolean (.showText$[7], .showValue[7])
508 boolean (.showText$[8], .showValue[8])
509 boolean (.showText$[9], .showValue[9])
510 boolean (.showText$[10], .showValue[10])
511 boolean (.showText$[11], .showValue[11])
512 boolean (.showText$[12], .showValue[12])
513 boolean (.showText$[13], .showValue[13])
514 boolean (.showText$[14], .showValue[14])
516 optionMenu: .partText$, 1
519 for .j to .numLessons
520 option: .lessonName$['.j']
523 optionMenu: .toneText$, 1
530 clicked = endPause ("'.cancelText$'", "'.clearText$'", "'.allText$'", "'.prevWord$'", "'.nextWord$'", "'.continueText$'", 6, 1)
533 for .i to sgc.numberOfWords
534 Set string value: .i, "Show", "-"
538 for .i to sgc.numberOfWords
539 Set string value: .i, "Show", "+"
543 # Get selected Part BEFORE we do anything else
545 .tmp$ = replace_regex$(.partText$, "^(.)", "\l\1", 0)
546 .lessonSelected = '.tmp$' - 1
548 if .lessonSelected > 0
551 select Table 'wordlist$'
552 for .i to sgc.numberOfWords
553 # Keep track of whether all are shown
554 .shown$ = Get value: .i, "Show"
559 for .i to sgc.numberOfWords
561 .currentLesson$ = Get value: .i, "Lesson"
562 if .currentLesson$ = .lessonName$['.lessonSelected']
563 Set string value: .i, "Show", "+"
565 Set string value: .i, "Show", "-"
568 for .i to sgc.numberOfWords
569 # Keep track of whether all are shown
570 .shown$ = Get value: .i, "Show"
571 if .firstShown <=0 and .shown$ <> "-"
576 for .i from 0 to .max
577 .tmp$ = .showVariable$['.i']
578 .showValue['.i'] = '.tmp$'
579 .showWord$['.i'] = "-"
580 if .showValue['.i'] <> 0
581 .showWord$['.i'] = "+"
583 Set string value: .currentWord+.i, "Show", .showWord$['.i']
586 .tmp$ = replace_regex$(.toneText$, "^(.)", "\l\1", 0)
587 .toneSelected = '.tmp$' - 2
588 if .toneSelected >= 0
589 select Table 'wordlist$'
590 for .i to sgc.numberOfWords
591 .currentPinyin$ = Get value: .i, "Pinyin"
592 if index_regex(.currentPinyin$, "[0-9]") <= 0
593 call pinyin2numbers '.currentPinyin$'
594 .currentPinyin$ = replace_regex$(pinyin2numbers.intermediatePinyin$, ".+", "\l&", 0)
595 .currentPinyin$ = replace_regex$(.currentPinyin$, "[^a-zA-Z0-9]", "", 0)
597 .tmp$ = Get value: .i, "Show"
598 if .tmp$ <> "-" and index(.currentPinyin$, "'.toneSelected'") > 0
599 Set string value: .i, "Show", "+"
601 Set string value: .i, "Show", "-"
609 .currentWord = (.firstShown div .numWordsPerScreen) * .numWordsPerScreen + 1
610 elsif .toneSelected < 0
611 .currentWord -= .numWordsPerScreen
614 .currentWord = (sgc.numberOfWords div .numWordsPerScreen) * .numWordsPerScreen + 1
618 .currentWord = (.firstShown div .numWordsPerScreen) * .numWordsPerScreen + 1
619 elsif .toneSelected < 0
620 .currentWord += .numWordsPerScreen
622 if .currentWord > sgc.numberOfWords
627 # Reset and go to the first selected word (can shuffle list)
636 select Table 'wordlist$'
638 select .tmpOriginalWordlist
641 select .tmpOriginalWordlist
643 call Draw_button '.table$' '.label$' 0
646 procedure processConfigPerfSummary .clickX .clickY .pressed$
648 .label$ = "PerfSummary"
650 call testLoadTable SummaryToneEvaluation
651 if testLoadTable.table > 0
652 call Draw_button '.table$' '.label$' 1
653 call loadTable SummaryToneEvaluation
654 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
656 select Table SummaryToneEvaluation
659 call Draw_button '.table$' '.label$' 0
660 call Draw_config_page
664 # Wipe current performance table and initialize a new one
665 procedure processConfigClearSummary .clickX .clickY .pressed$
667 .label$ = "ClearSummary"
669 call Draw_button '.table$' '.label$' 1
671 if not sgc.saveAudioOn
672 select Table '.table$'
673 call findLabel '.table$' !'.label$'
675 .alertText$ = Get value... 'findLabel.row' Text
676 .confirmKey$ = Get value... 'findLabel.row' Key
677 .popupText$ = Get value... 'findLabel.row' Helptext
679 call write_text_popup 'defaultFont$' 14 '.popupText$'
680 call Draw_button '.table$' '.label$' 2
681 alertText$ = .alertText$
682 call Draw_button '.table$' '.label$' 3
685 # Wait for confirmation
687 if demoInput(.confirmKey$)
689 call initialize_toneevaluation_tables
694 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
695 call Draw_config_page
699 procedure processConfigListPerf .clickX .clickY .pressed$
702 call Draw_button '.table$' '.label$' 1
704 select sgc2.performanceTable
708 call Draw_button '.table$' '.label$' 0
709 call Draw_config_page
712 procedure processConfigOpenPerf .clickX .clickY .pressed$
715 call Draw_button '.table$' '.label$' 1
717 if not sgc.saveAudioOn
719 call findLabel '.table$' !'.label$'
721 select Table '.table$'
722 .openDialogue$ = Get value... '.row' Helptext
723 call convert_praat_to_latin1 '.openDialogue$'
724 .openDialogue$ = convert_praat_to_latin1.text$
725 if variableExists("eval.performance$")
726 .defaultName$= "'eval.performance$'.tsv"
728 .defaultName$= "Performance.tsv"
730 if sgc.savePerf$ <> ""
731 .defaultName$= sgc.savePerf$
733 .performance_Name$ = chooseReadFile$ (.openDialogue$)
734 while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0
735 .performance_Name$ = chooseReadFile$ (.openDialogue$)
737 if .performance_Name$ <> "" and fileReadable(.performance_Name$)
738 sgc.savePerf$ = .performance_Name$
739 call initialize_toneevaluation_tables
741 # Set SaveAudio directory if it is not currently "in use"
742 if not sgc.saveAudioOn
743 sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0)
744 # We are not sure yet that this is actually an audio directory
745 config.audioName$ = ""
750 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
751 call Draw_config_page
754 procedure processConfigSavePerf .clickX .clickY .pressed$
757 call Draw_button '.table$' '.label$' 1
759 if not sgc.saveAudioOn
761 call findLabel '.table$' '.label$'
763 select Table '.table$'
764 .openDialogue$ = Get value... '.row' Helptext
765 call convert_praat_to_latin1 '.openDialogue$'
766 .openDialogue$ = convert_praat_to_latin1.text$
767 if variableExists("eval.performance$")
768 .defaultName$= "'eval.performance$'.tsv"
770 .defaultName$= "Performance.tsv"
772 if sgc.savePerf$ <> ""
773 .defaultName$= sgc.savePerf$
775 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .defaultName$)
776 # Ensure the right extension: ".tsv"
777 while .performance_Name$ <> "" and not endsWith(.performance_Name$, ".tsv")
778 .performance_Name$ = .performance_Name$ + ".tsv"
779 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .performance_Name$)
781 if .performance_Name$ <> ""
782 select sgc2.performanceTable
783 Write to table file... '.performance_Name$'
784 sgc.savePerf$ = .performance_Name$
788 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
789 call Draw_config_page
792 procedure processConfigManual .clickX .clickY .pressed$
795 call Draw_button '.table$' '.label$' 1
796 if fileReadable("ManPages/SpeakGoodChinese_2.man")
797 Read from file... ManPages/SpeakGoodChinese_2.man
799 Go to manual page... SpeakGoodChinese 2
801 # Wait until the manual is put to the background
803 call Draw_button '.table$' '.label$' 0
805 call Draw_config_page
808 procedure processConfigSaveAudio .clickX .clickY .pressed$
810 .label$ = "SaveAudio"
811 call Draw_button '.table$' '.label$' 1
813 if sgc.saveAudioOn = 0
815 call findLabel '.table$' '.label$'
817 select Table '.table$'
818 .openDialogue$ = Get value... '.row' Helptext
819 call convert_praat_to_latin1 '.openDialogue$'
820 .openDialogue$ = convert_praat_to_latin1.text$
822 sgc.saveAudio$ = chooseDirectory$ (.openDialogue$)
823 if sgc.saveAudio$ <> ""
825 .currentPathName$ = replace_regex$(sgc.saveAudio$, "[^/\\]*[/\\]?$", "", 0)
826 .currentDirName$ = replace$(sgc.saveAudio$, .currentPathName$, "", 0)
829 config.clearSummary = -1
830 config.audioName$ = .currentDirName$
832 # Clear performance table and open/create sgc.savePerf$
833 sgc.savePerf$ = "'sgc.saveAudio$'/'.currentDirName$'.tsv"
834 call initialize_toneevaluation_tables
836 call update_toneevaluation_file
837 if sgc.savePerf$ <> "" and initialiseSGC2.toneevaluation_table$ <> ""
838 select sgc2.performanceTable
839 Write to table file: sgc.savePerf$
842 config.audioName$ = ""
848 config.clearSummary = 0
849 # Store current performance table
850 call update_toneevaluation_file
853 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
854 call Draw_config_page
857 ###############################################################
859 # Obligatory button Processing Routines
861 # These MUST be defined
863 ###############################################################
865 procedure processConfigReturn .clickX .clickY .pressed$
868 call Draw_button '.table$' '.label$' 1
869 call write_preferences ""
872 procedure processConfigRefresh .clickX .clickY .pressed$
875 call Draw_config_page
878 procedure processConfigCredits .clickX .clickY .pressed$
881 call Draw_button '.table$' '.label$' 1
882 call write_text_table Credits_'config.language$'
884 call Draw_button '.table$' '.label$' 0
886 call Draw_config_page
889 procedure processConfigHelp .clickX .clickY .pressed$
892 call help_loop '.table$' Draw_config_page
895 ###############################################################
897 # Miscelaneous supporting code
899 ###############################################################
900 procedure install_wordlists_by_name .wordlist_Name$
901 if .wordlist_Name$ <> ""
902 if index_regex(.wordlist_Name$, "(?iwordlist|LICENSE)\.")
903 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\](?iwordlist|LICENSE)\.([^/\\]+)$", "", 0)
904 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
905 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
907 if index_regex(.wordlist_Name$, "[/\\]")
908 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
909 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
910 call readWordlist "'.sourceDir$'" '.file$'
913 if index(.wordlist_Name$, ".")
916 .extension1$ = ".sgc"
917 .extension2$ = ".Table"
918 .extension3$ = ".txt"
919 .extension4$ = ".tsv"
921 for .e from .start to 5
922 .currentExtension$ = .extension'.e'$
923 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
924 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
925 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
926 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
927 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
928 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
929 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
935 # Word lists: It is a VERY good idea to make sure that word-lists
937 procedure load_word_list .localdir$ .relnumber
940 # Remove old word list
942 select Table 'wordlist$'
944 call wipeArea 'wipeWordlistArea$'
948 # Create Table that will recieve the wordlists and directories
949 Create Table with column names... AllWordLists 0 Name Directory
950 .sgc.currentWordlistRow = 0
952 # First the global word lists
953 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
954 Create Strings as directory list... WordList 'globalwordlists$'
955 .numLists = Get number of strings
957 select Strings WordList
958 .currentName$ = Get string... '.i'
959 if .currentName$ <> "directory.txt"
960 select Table AllWordLists
961 .listExist = Search column: "Name", .currentName$
964 .sgc.currentWordlistRow = Get number of rows
965 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
966 .currentDirectory$ = globalwordlists$+"/"+.currentName$
967 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
971 select Strings WordList
975 # Now the preferences word lists
976 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
977 Create Strings as directory list... WordList 'sgc2wordlists$'
978 .numLists = Get number of strings
980 select Strings WordList
981 .currentName$ = Get string... '.i'
982 if .currentName$ <> "directory.txt"
983 select Table AllWordLists
984 .listExist = Search column: "Name", .currentName$
987 .sgc.currentWordlistRow = Get number of rows
988 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
989 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
990 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
994 select Strings WordList
998 # End with the word lists in the distribution
999 call CreateCreateWordlists
1000 select Table CreateWordlists
1001 .numLists = Get number of rows
1003 select Table CreateWordlists
1004 .currentName$ = Get value... '.i' Name
1005 if .currentName$ <> "directory.txt"
1006 select Table AllWordLists
1007 .listExist = Search column: "Name", .currentName$
1009 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
1010 select Table AllWordLists
1012 .sgc.currentWordlistRow = Get number of rows
1013 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
1014 .currentDirectory$ = "*call Create'.procedureName$'"
1015 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
1019 select Table CreateWordlists
1022 # Finally, the local word lists
1023 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
1024 Create Strings as directory list... WordList '.localdir$'
1025 .numLists = Get number of strings
1027 select Strings WordList
1028 .currentName$ = Get string... '.i'
1029 if .currentName$ <> "directory.txt"
1030 select Table AllWordLists
1031 .listExist = Search column: "Name", .currentName$
1034 .sgc.currentWordlistRow = Get number of rows
1035 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
1036 .currentDirectory$ = .localdir$+"/"+.currentName$
1037 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
1041 select Strings WordList
1045 # Get the position of the current word list
1046 select Table AllWordLists
1048 .numLists = Get number of rows
1050 if wordlistName$ <> ""
1051 select Table AllWordLists
1052 .currentNumber = Search column... Name 'wordlistName$'
1055 wordlistNum = .currentNumber + .relnumber
1056 if wordlistNum > .numLists
1058 elsif wordlistNum < 1 and .numLists > 0
1059 wordlistNum = .numLists
1061 select Table AllWordLists
1062 wordlistName$ = Get value... 'wordlistNum' Name
1063 .dirWordlistName$ = Get value... 'wordlistNum' Directory
1064 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
1066 # Read in full tables
1067 if fileReadable("'.dirString$'/wordlist.Table")
1068 call readTable '.dirString$'/wordlist.Table
1069 if readTable.tableID > 0
1070 Rename... 'wordlistName$'
1071 # Praat wil change the name if it feels like it
1072 wordlist$ = selected$("Table")
1073 # Add a Sound column if it is not present
1074 .soundIndex = Get column index: "Sound"
1076 Append column: "Sound"
1082 # Handle (legacy) simple word lists
1083 elsif fileReadable("'.dirString$'/wordlist.txt")
1084 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
1085 wordlist$ = selected$("Table")
1086 Read Strings from raw text file... '.dirString$'/wordlist.txt
1087 Rename... RawWordList
1088 .numWordStrings = Get number of strings
1089 for .i to .numWordStrings
1090 select Strings RawWordList
1093 .currentTrans$ = "-"
1094 .currentLine$ = Get string... '.i'
1095 # Remove leading whitespace
1096 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1097 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1098 if .separatorIndex <= 0
1099 .separatorIndex = length(.currentLine$) + 1
1101 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1102 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1103 # There is more on the line, but we do not know what
1104 if length(.currentLine$) > 0
1105 while length(.currentLine$) > 0
1106 .separatorIndex = index_regex(.currentLine$, "[\t;]")
1107 if .separatorIndex <= 0
1108 .separatorIndex = length(.currentLine$)+1
1110 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1111 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1112 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1114 .currentFile$ = .currentItem$
1115 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1117 .currentTrans$ = .currentItem$
1118 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1120 .currentChar$ = .currentItem$
1124 if .currentFile$ = "-"
1125 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1126 .currentFile$ = .currentPinyin$+".spx"
1127 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1128 .currentFile$ = .currentPinyin$+".flac"
1129 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1130 .currentFile$ = .currentPinyin$+".wav"
1131 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1132 .currentFile$ = .currentPinyin$+".mp3"
1135 select Table 'wordlist$'
1137 Set string value... '.i' Pinyin '.currentPinyin$'
1138 Set string value... '.i' Sound '.currentFile$'
1139 Set string value... '.i' Character '.currentChar$'
1140 Set string value... '.i' Translation '.currentTrans$'
1142 select Strings RawWordList
1145 select Table 'wordlist$'
1146 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1147 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
1148 wordlist$ = selected$("Table")
1149 Create Strings as file list... RawWordList '.dirString$'/*
1150 .numWordStrings = Get number of strings
1152 for .j to .numWordStrings
1153 select Strings RawWordList
1154 .currentLine$ = Get string... '.j'
1155 .currentFile$ = extractWord$(.currentLine$, "")
1156 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1157 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1158 select Table 'wordlist$'
1161 Set string value... '.i' Pinyin '.currentPinyin$'
1162 Set string value... '.i' Sound '.currentFile$'
1165 select Strings RawWordList
1168 select Table 'wordlist$'
1169 elsif startsWith(.dirString$, "*call ")
1170 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1172 wordlist$ = selected$("Table")
1179 # Can this wordlist be deleted?
1180 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
1181 config.deleteWordlist = 0
1183 config.deleteWordlist = -1
1186 # Check first column name and add Character, Translation and Show columns if missing
1188 select Table 'wordlist$'
1189 # HAck to correct odd behavior of tables with unicode characters
1190 .firstColumn$ = Get column label: 1
1191 if index_regex(.firstColumn$, "^[^!-~]") > 0
1192 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1193 Set column label (index): 1, .firstColumn$
1196 sgc.numberOfWords = Get number of rows
1197 .characterColumn = Get column index... Character
1198 if not .characterColumn
1199 Append column... Character
1200 for .i to sgc.numberOfWords
1201 Set string value... '.i' Character -
1204 .translationColumn = Get column index... Translation
1205 if not .translationColumn
1206 Append column... Translation
1207 for .i to sgc.numberOfWords
1208 Set string value... '.i' Translation -
1211 .showColumn = Get column index... Show
1213 Append column... Show
1214 for .i to sgc.numberOfWords
1215 Set string value... '.i' Show +
1220 # Remove all rows without Pinyin
1221 .numRows = Get number of rows
1223 .rowNum = .numRows - i + 1
1224 .pinyinValue$ = Get value... '.rowNum' Pinyin
1225 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
1226 Remove row... '.rowNum'
1229 sgc.numberOfWords = Get number of rows
1231 # Shuffle words if requested
1232 if config.shuffleLists
1238 select Table AllWordLists
1241 # There were no Word Lists
1244 wordlistName$ = wordlistName$+" No Word Lists available"
1246 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
1247 wordlist$ = selected$("Table")
1251 Set string value... '.i' Pinyin ni3hao3
1252 Set string value... '.i' Character 你好
1253 Set string value... '.i' Translation hello
1254 Set string value... '.i' Sound -
1257 Set string value... '.i' Pinyin xie4xie0
1258 Set string value... '.i' Character 谢谢
1259 Set string value... '.i' Translation thanks
1260 Set string value... '.i' Sound -
1263 Set string value... '.i' Pinyin zai4jian4
1264 Set string value... '.i' Character 再见
1265 Set string value... '.i' Translation goodbye
1266 Set string value... '.i' Sound -
1267 sgc.numberOfWords = Get number of rows
1270 call set_window_title 'buttons$' 'wordlistName$'
1275 select Table 'wordlist$'
1277 if sgc.currentWord < 0 or sgc.currentWord > sgc.numberOfWords
1278 if config.shuffleLists
1283 while .showCurrent$ = "-" and sgc.currentWord <= sgc.numberOfWords
1284 sgc.currentWord += 1
1285 if sgc.currentWord <= sgc.numberOfWords
1286 .showCurrent$ = Get value... 'sgc.currentWord' Show
1292 procedure previous_word
1294 select Table 'wordlist$'
1296 if sgc.currentWord <= 0
1297 if config.shuffleLists
1300 sgc.currentWord = sgc.numberOfWords + 1
1302 while .showCurrent$ = "-" and sgc.currentWord > 0
1303 sgc.currentWord -= 1
1304 if sgc.currentWord > 0
1305 .showCurrent$ = Get value... 'sgc.currentWord' Show
1311 procedure display_word_list_name
1315 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
1316 call wipeArea 'wipeWordlistArea$'
1317 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
1318 .currentFontSize = adjustFontSizeOnHeight.newFontSize
1321 demo Text special... '.xtext' Centre '.ytext' Bottom 'defaultFont$' '.currentFontSize' 0 '.displayWordList$'
1324 call set_font_size 'defaultFontSize'
1327 procedure write_word_list
1328 # Write current Pinyin text
1329 call display_text Black
1331 # Write the current word list name
1332 call display_word_list_name
1335 procedure paint_saveAudio_light
1336 select Table 'config$'
1337 .row = Search column... Label SaveAudio
1339 exit Button Table Config does not have a row with label SaveAudio
1342 .leftX = Get value... '.row' LeftX
1343 .rightX = Get value... '.row' RightX
1344 .lowY = Get value... '.row' LowY
1345 .highY = Get value... '.row' HighY
1346 .buttonColor$ = Get value... '.row' Color
1347 # The button text and symbol
1348 .horWC = demo Horizontal mm to wc... 10.0
1349 .verWC = demo Vertical mm to wc... 10.0
1351 .verCoeff = .horWC / .verWC
1356 .centerX = (.leftX + .rightX)/2
1357 .centerY = .lowY + 0.6*(.highY-.lowY)
1358 .radius = min(.verCoeff * (.highY - .lowY ), (.rightX - .leftX))/3
1359 .wipeRadius = 1.1*.radius
1360 call DrawSaveAudio White '.centerX' '.centerY' '.wipeRadius'
1362 if sgc.saveAudioOn and sgc.saveAudio$ <> ""
1363 call DrawSaveAudio "DarkBlue" '.centerX' '.centerY' '.radius'
1368 # Uninstall word lists
1369 procedure removeWordlist .deletedWordlistName$
1371 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1372 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1374 if .targetDir$ <> ""
1375 Create Strings as file list... DeleteList '.targetDir$'
1376 .numdeleteFiles = Get number of strings
1377 for .i to .numdeleteFiles
1378 .file$ = Get string... '.i'
1379 deleteFile("'.targetDir$'/'.file$'")
1381 filedelete '.targetDir$'
1382 # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1383 # That is, it does not contain funny characters, nor funny names
1384 if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1386 nocheck system rmdir "'.targetDir$'" /s /q
1387 elsif fileReadable(.targetDir$)
1388 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1391 # Remove deleted word list
1392 select Strings DeleteList
1393 plus Table 'wordlist$'
1399 # Install word lists
1400 procedure sgc2wordlist .sourceDir$
1401 if startsWith(.sourceDir$, "preferencesDirectory$")
1402 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1405 .targetDirectory$ = "'sgc2wordlists$'"
1406 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1407 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1408 .numFiles = Get number of strings
1410 select Strings PackageList
1411 .file$ = Get string... '.i'
1412 call readWordlist '.sourceDir$' '.file$'
1415 select Strings PackageList
1420 # Debuggin remarks!!!
1421 # fileReadable(<directory>) does not work in Windows
1422 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1423 # And yet only the 7z decompression has been implemented
1424 windowsUnzipCommand$ = ""
1425 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1426 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" -y e"
1427 windowsUnzipDestDir$ = " -o"
1428 elsif fileReadable("C:\Program Files\WinZip\winzip32.exe")
1429 # !!! Find a way to include the output folder !!!
1430 windowsUnzipCommand$ = "C:\Program Files\WinZip\winzip32.exe"" -min -e -o -j "
1431 windowsUnzipDestDir$ = ""
1433 procedure readWordlist .sourceDir$ .file$
1434 # No use doing anything if the source does not exist
1435 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1436 # What will be the target wordlist directory?
1437 .targetDirectory$ = "'sgc2wordlists$'"
1438 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1442 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1443 # Wordlist directory does not exist, neither locally nor in the preferences
1445 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1446 if .tmpDirs != undefined and .tmpDirs > 0
1447 .numDirs = Get number of strings
1450 .currentString$ = Get string... '.d'
1451 if .currentString$ = .dirname$
1457 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1459 # Move source to destination
1460 # Use this if you want to allow direct loading of ZIP files. Could lead to problems.
1461 # if index(.file$, ".sgc") or index(.file$, ".zip")
1463 if index(.file$, ".sgc")
1464 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1465 # Create wordlist directory
1466 createDirectory(.wordlistDirectory$)
1468 if macintosh or unix
1469 system bash -rc -- 'unzip -j "'.sourceDir$'/'.file$'" -d "'.wordlistDirectory$'"'
1470 elsif windows and windowsUnzipCommand$ <> ""
1471 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1472 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1473 system mkdir "'.winWordListDirectory$'" & 'windowsUnzipCommand$' "'.winSourceDirectory$'" 'windowsUnzipDestDir$'"'.winWordListDirectory$'"
1475 elsif (windows and windowsUnzipCommand$ = "")
1476 # Warn to install 7Zip
1477 call get_feedback_text 'config.language$' InstallUnzip
1478 call convert_praat_to_latin1 'get_feedback_text.text$'
1479 .zipText$ = convert_praat_to_latin1.text$
1480 call write_text_popup 'defaultFont$' 14 '.zipText$'
1481 # Wait for confirmation
1483 call Draw_config_page
1485 # Remove if not valid!
1486 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1487 if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1488 call readTable '.sourceDir$'/'.file$'
1489 if readTable.tableID > 0
1490 select readTable.tableID
1491 # Hack around odd behavior of column index
1493 .firstColumn$ = Get column label: 1
1494 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1495 if .firstColumn$ = "Pinyin"
1498 .pinyinCol = Get column index... Pinyin
1501 # No Pinyin in table
1510 # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1513 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1515 # Remove newly created directory
1516 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1517 if macintosh or unix
1518 system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1520 system rmdir /Q /S "'.winWordListDirectory$'/"
1524 elsif index_regex(.file$, "\.(Table|txt|tsv)")
1525 # Check whether this is a valid table
1526 call readTable '.sourceDir$'/'.file$'
1527 if readTable.tableID > 0
1528 select readTable.tableID
1529 # Hack around odd behavior of column index
1531 .firstColumn$ = Get column label: 1
1532 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1533 if .firstColumn$ = "Pinyin"
1536 .pinyinCol = Get column index... Pinyin
1540 select readTable.tableID
1541 # Create wordlist directory
1542 createDirectory(.wordlistDirectory$)
1544 .extension$ = "Table"
1545 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1547 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1550 select readTable.tableID
1551 Save as tab-separated file: .wordlistFilePath$
1552 if not fileReadable(.wordlistFilePath$)
1556 select readTable.tableID
1559 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1560 # Copy wordlist directory
1561 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1563 if macintosh or unix
1564 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1566 createDirectory(.wordlistDirectory$)
1567 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1568 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1569 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1574 # Set current word list to read list
1576 wordlistName$ = .dirname$
1579 .label$ = "!NotAWordlist"
1582 call findLabel '.table$' '.label$'
1583 .row = findLabel.row
1584 select Table '.table$'
1585 .helpText$ = Get value... '.row' Helptext
1586 .printablePath$ = "'.sourceDir$'/'.file$'"
1588 .printablePath$ = replace$("'.sourceDir$'\'.file$'", "\", "\bs", 0)
1590 .filetext$ = replace_regex$(.printablePath$, "_", "\\_ ", 0)
1591 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1592 # Wait for confirmation