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 procedure processConfigExportWordlist .clickX .clickY .pressed$
350 .label$ = "ExportWordlist"
352 call Draw_button '.table$' '.label$' 1
355 call findLabel '.table$' '.label$'
357 select Table '.table$'
358 .openDialogue$ = Get value... '.row' Helptext
359 call convert_praat_to_latin1 '.openDialogue$'
360 .openDialogue$ = convert_praat_to_latin1.text$
362 .newWordlistName$ = "'wordlist$'_SGC2"
364 # Ensure the right extension: ".tsv"
365 while .newWordlistName$ <> "" and not endsWith(.newWordlistName$, ".tsv")
366 .newWordlistName$ = .newWordlistName$ + ".tsv"
367 .newWordlistName$ = chooseWriteFile$ (.openDialogue$, .newWordlistName$)
369 .tableName$ = replace_regex$(.newWordlistName$, "^.*[/\\:]([^/\\:]+)\.(tsv|Table)$", "\1", 0)
370 call testLoadTable '.tableName$'
371 if testLoadTable.table > 0
372 call loadTable '.tableName$'
373 .tmpTable = selected()
374 Save as tab-separated file: .newWordlistName$
376 .newWordlistName$ = ""
380 if .newWordlistName$ <> ""
381 select sgc.currentWordlist
382 .tmpSaveWordlist = Copy: "SaveWordlist"
383 # Get the table sorted
384 .lessonCol = Get column index: "Lesson"
386 Sort rows... Lesson Pinyin
391 # Remove all words that are deselected
392 .showCol = Get column index: "Show"
394 .numRows = Get number of rows
397 .show$ = Get value: .row, "Show"
398 .sound$ = Get value: .row, "Sound"
401 elsif .sound$ <> "" and .sound$ <> "-" and .sound$ <> "?"
402 # Put path before sound examples
403 # If there is no path, add the current wordlist path
404 if index_regex(.sound$, "^(/|~/|[A-Z]:\\)") <= 0
405 .sound$ = localWordlistDir$+"/"+wordlistName$+"/"+.sound$
406 Set string value: .row, "Sound", .sound$
411 Remove column: "Show"
413 Write to table file... '.newWordlistName$'
417 call Draw_button '.table$' '.label$' 0
418 call Draw_config_page
421 procedure processConfigPerfSummary .clickX .clickY .pressed$
423 .label$ = "PerfSummary"
425 call testLoadTable SummaryToneEvaluation
426 if testLoadTable.table > 0
427 call Draw_button '.table$' '.label$' 1
428 call loadTable SummaryToneEvaluation
429 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
431 select Table SummaryToneEvaluation
434 call Draw_button '.table$' '.label$' 0
435 call Draw_config_page
439 # Wipe current performance table and initialize a new one
440 procedure processConfigClearSummary .clickX .clickY .pressed$
442 .label$ = "ClearSummary"
444 call Draw_button '.table$' '.label$' 1
446 if not sgc.saveAudioOn
447 select Table '.table$'
448 call findLabel '.table$' !'.label$'
450 .alertText$ = Get value... 'findLabel.row' Text
451 .confirmKey$ = Get value... 'findLabel.row' Key
452 .popupText$ = Get value... 'findLabel.row' Helptext
454 call write_text_popup 'defaultFont$' 14 '.popupText$'
455 call Draw_button '.table$' '.label$' 2
456 alertText$ = .alertText$
457 call Draw_button '.table$' '.label$' 3
460 # Wait for confirmation
462 if demoInput(.confirmKey$)
464 call initialize_toneevaluation_tables
469 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
470 call Draw_config_page
474 procedure processConfigListPerf .clickX .clickY .pressed$
477 call Draw_button '.table$' '.label$' 1
479 select sgc2.performanceTable
483 call Draw_button '.table$' '.label$' 0
484 call Draw_config_page
487 procedure processConfigOpenPerf .clickX .clickY .pressed$
490 call Draw_button '.table$' '.label$' 1
492 if not sgc.saveAudioOn
494 call findLabel '.table$' !'.label$'
496 select Table '.table$'
497 .openDialogue$ = Get value... '.row' Helptext
498 call convert_praat_to_latin1 '.openDialogue$'
499 .openDialogue$ = convert_praat_to_latin1.text$
500 if variableExists("eval.performance$")
501 .defaultName$= "'eval.performance$'.tsv"
503 .defaultName$= "Performance.tsv"
505 if sgc.savePerf$ <> ""
506 .defaultName$= sgc.savePerf$
508 .performance_Name$ = chooseReadFile$ (.openDialogue$)
509 while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0
510 .performance_Name$ = chooseReadFile$ (.openDialogue$)
512 if .performance_Name$ <> "" and fileReadable(.performance_Name$)
513 sgc.savePerf$ = .performance_Name$
514 call initialize_toneevaluation_tables
516 # Set SaveAudio directory if it is not currently "in use"
517 if not sgc.saveAudioOn
518 sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0)
519 # We are not sure yet that this is actually an audio directory
520 config.audioName$ = ""
525 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
526 call Draw_config_page
529 procedure processConfigSavePerf .clickX .clickY .pressed$
532 call Draw_button '.table$' '.label$' 1
534 if not sgc.saveAudioOn
536 call findLabel '.table$' '.label$'
538 select Table '.table$'
539 .openDialogue$ = Get value... '.row' Helptext
540 call convert_praat_to_latin1 '.openDialogue$'
541 .openDialogue$ = convert_praat_to_latin1.text$
542 if variableExists("eval.performance$")
543 .defaultName$= "'eval.performance$'.tsv"
545 .defaultName$= "Performance.tsv"
547 if sgc.savePerf$ <> ""
548 .defaultName$= sgc.savePerf$
550 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .defaultName$)
551 # Ensure the right extension: ".tsv"
552 while .performance_Name$ <> "" and not endsWith(.performance_Name$, ".tsv")
553 .performance_Name$ = .performance_Name$ + ".tsv"
554 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .performance_Name$)
556 if .performance_Name$ <> ""
557 select sgc2.performanceTable
558 Write to table file... '.performance_Name$'
559 sgc.savePerf$ = .performance_Name$
563 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
564 call Draw_config_page
567 procedure processConfigManual .clickX .clickY .pressed$
570 call Draw_button '.table$' '.label$' 1
571 if fileReadable("ManPages/SpeakGoodChinese_2.man")
572 Read from file... ManPages/SpeakGoodChinese_2.man
574 Go to manual page... SpeakGoodChinese 2
576 # Wait until the manual is put to the background
578 call Draw_button '.table$' '.label$' 0
580 call Draw_config_page
583 procedure processConfigSaveAudio .clickX .clickY .pressed$
585 .label$ = "SaveAudio"
586 call Draw_button '.table$' '.label$' 1
588 if sgc.saveAudioOn = 0
590 call findLabel '.table$' '.label$'
592 select Table '.table$'
593 .openDialogue$ = Get value... '.row' Helptext
594 call convert_praat_to_latin1 '.openDialogue$'
595 .openDialogue$ = convert_praat_to_latin1.text$
597 sgc.saveAudio$ = chooseDirectory$ (.openDialogue$)
598 if sgc.saveAudio$ <> ""
600 .currentPathName$ = replace_regex$(sgc.saveAudio$, "[^/\\]*[/\\]?$", "", 0)
601 .currentDirName$ = replace$(sgc.saveAudio$, .currentPathName$, "", 0)
604 config.clearSummary = -1
605 config.audioName$ = .currentDirName$
607 # Clear performance table and open/create sgc.savePerf$
608 sgc.savePerf$ = "'sgc.saveAudio$'/'.currentDirName$'.tsv"
609 call initialize_toneevaluation_tables
611 call update_toneevaluation_file
612 if sgc.savePerf$ <> "" and initialiseSGC2.toneevaluation_table$ <> ""
613 select sgc2.performanceTable
614 Write to table file: sgc.savePerf$
617 config.audioName$ = ""
623 config.clearSummary = 0
624 # Store current performance table
625 call update_toneevaluation_file
628 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
629 call Draw_config_page
632 ###############################################################
634 # Obligatory button Processing Routines
636 # These MUST be defined
638 ###############################################################
640 procedure processConfigReturn .clickX .clickY .pressed$
643 call Draw_button '.table$' '.label$' 1
644 call write_preferences ""
647 procedure processConfigRefresh .clickX .clickY .pressed$
650 call Draw_config_page
653 procedure processConfigCredits .clickX .clickY .pressed$
656 call Draw_button '.table$' '.label$' 1
657 call write_text_table Credits_'config.language$'
659 call Draw_button '.table$' '.label$' 0
661 call Draw_config_page
664 procedure processConfigHelp .clickX .clickY .pressed$
667 call help_loop '.table$' Draw_config_page
670 ###############################################################
672 # Miscelaneous supporting code
674 ###############################################################
675 procedure install_wordlists_by_name .wordlist_Name$
676 if .wordlist_Name$ <> ""
677 if index_regex(.wordlist_Name$, "(?iwordlist|LICENSE)\.")
678 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\](?iwordlist|LICENSE)\.([^/\\]+)$", "", 0)
679 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
680 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
682 if index_regex(.wordlist_Name$, "[/\\]")
683 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
684 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
685 call readWordlist "'.sourceDir$'" '.file$'
688 if index(.wordlist_Name$, ".")
691 .extension1$ = ".sgc"
692 .extension2$ = ".Table"
693 .extension3$ = ".txt"
694 .extension4$ = ".tsv"
696 for .e from .start to 5
697 .currentExtension$ = .extension'.e'$
698 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
699 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
700 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
701 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
702 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
703 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
704 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
710 # Word lists: It is a VERY good idea to make sure that word-lists
712 procedure load_word_list .localdir$ .relnumber
714 if sgc.allWordLists > 0
715 select sgc.allWordLists
717 sgc.allWordLists = -1
720 # Remove old word list
722 select sgc.currentWordlist
724 call wipeArea 'wipeWordlistArea$'
726 sgc.currentWordlist = -1
730 # Create Table that will recieve the wordlists and directories
731 sgc.allWordLists = Create Table with column names... AllWordLists 0 Name Directory
732 .sgc.currentWordlistRow = 0
734 # First the global word lists
735 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
736 Create Strings as directory list... WordList 'globalwordlists$'
737 .numLists = Get number of strings
739 select Strings WordList
740 .currentName$ = Get string... '.i'
741 if .currentName$ <> "directory.txt"
742 select sgc.allWordLists
743 .listExist = Search column: "Name", .currentName$
746 .sgc.currentWordlistRow = Get number of rows
747 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
748 .currentDirectory$ = globalwordlists$+"/"+.currentName$
749 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
753 select Strings WordList
757 # Now the preferences word lists
758 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
759 Create Strings as directory list... WordList 'sgc2wordlists$'
760 .numLists = Get number of strings
762 select Strings WordList
763 .currentName$ = Get string... '.i'
764 if .currentName$ <> "directory.txt"
765 select sgc.allWordLists
766 .listExist = Search column: "Name", .currentName$
769 .sgc.currentWordlistRow = Get number of rows
770 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
771 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
772 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
776 select Strings WordList
780 # End with the word lists in the distribution
781 call CreateCreateWordlists
782 select Table CreateWordlists
783 .numLists = Get number of rows
785 select Table CreateWordlists
786 .currentName$ = Get value... '.i' Name
787 if .currentName$ <> "directory.txt"
788 select sgc.allWordLists
789 .listExist = Search column: "Name", .currentName$
791 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
792 select sgc.allWordLists
794 .sgc.currentWordlistRow = Get number of rows
795 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
796 .currentDirectory$ = "*call Create'.procedureName$'"
797 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
801 select Table CreateWordlists
804 # Finally, the local word lists
805 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
806 Create Strings as directory list... WordList '.localdir$'
807 .numLists = Get number of strings
809 select Strings WordList
810 .currentName$ = Get string... '.i'
811 if .currentName$ <> "directory.txt"
812 select sgc.allWordLists
813 .listExist = Search column: "Name", .currentName$
816 .sgc.currentWordlistRow = Get number of rows
817 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
818 .currentDirectory$ = .localdir$+"/"+.currentName$
819 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
823 select Strings WordList
827 # Get the position of the current word list
828 select sgc.allWordLists
830 .numLists = Get number of rows
832 if wordlistName$ <> ""
833 select sgc.allWordLists
834 .currentNumber = Search column... Name 'wordlistName$'
837 wordlistNum = .currentNumber + .relnumber
838 if wordlistNum > .numLists
840 elsif wordlistNum < 1 and .numLists > 0
841 wordlistNum = .numLists
843 select sgc.allWordLists
844 wordlistName$ = Get value... 'wordlistNum' Name
845 .dirWordlistName$ = Get value... 'wordlistNum' Directory
846 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
848 # Read in full tables
849 if fileReadable("'.dirString$'/wordlist.Table")
850 call readTable '.dirString$'/wordlist.Table
851 if readTable.tableID > 0
852 Rename... 'wordlistName$'
853 # Praat wil change the name if it feels like it
854 wordlist$ = selected$("Table")
855 # Add a Sound column if it is not present
856 .soundIndex = Get column index: "Sound"
858 Append column: "Sound"
864 # Handle (legacy) simple word lists
865 elsif fileReadable("'.dirString$'/wordlist.txt")
866 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
867 wordlist$ = selected$("Table")
868 Read Strings from raw text file... '.dirString$'/wordlist.txt
869 Rename... RawWordList
870 .numWordStrings = Get number of strings
871 for .i to .numWordStrings
872 select Strings RawWordList
876 .currentLine$ = Get string... '.i'
877 # Remove leading whitespace
878 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
879 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
880 if .separatorIndex <= 0
881 .separatorIndex = length(.currentLine$) + 1
883 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
884 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
885 # There is more on the line, but we do not know what
886 if length(.currentLine$) > 0
887 while length(.currentLine$) > 0
888 .separatorIndex = index_regex(.currentLine$, "[\t;]")
889 if .separatorIndex <= 0
890 .separatorIndex = length(.currentLine$)+1
892 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
893 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
894 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
896 .currentFile$ = .currentItem$
897 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
899 .currentTrans$ = .currentItem$
900 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
902 .currentChar$ = .currentItem$
906 if .currentFile$ = "-"
907 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
908 .currentFile$ = .currentPinyin$+".spx"
909 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
910 .currentFile$ = .currentPinyin$+".flac"
911 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
912 .currentFile$ = .currentPinyin$+".wav"
913 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
914 .currentFile$ = .currentPinyin$+".mp3"
917 select Table 'wordlist$'
919 Set string value... '.i' Pinyin '.currentPinyin$'
920 Set string value... '.i' Sound '.currentFile$'
921 Set string value... '.i' Character '.currentChar$'
922 Set string value... '.i' Translation '.currentTrans$'
924 select Strings RawWordList
927 select Table 'wordlist$'
928 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
929 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
930 wordlist$ = selected$("Table")
931 Create Strings as file list... RawWordList '.dirString$'/*
932 .numWordStrings = Get number of strings
934 for .j to .numWordStrings
935 select Strings RawWordList
936 .currentLine$ = Get string... '.j'
937 .currentFile$ = extractWord$(.currentLine$, "")
938 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
939 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
940 select Table 'wordlist$'
943 Set string value... '.i' Pinyin '.currentPinyin$'
944 Set string value... '.i' Sound '.currentFile$'
947 select Strings RawWordList
950 select Table 'wordlist$'
951 elsif startsWith(.dirString$, "*call ")
952 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
954 wordlist$ = selected$("Table")
961 # Can this wordlist be deleted?
962 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
963 config.deleteWordlist = 0
965 config.deleteWordlist = -1
968 # Check first column name and add Character, Translation, Sound and Show columns if missing
970 select Table 'wordlist$'
971 # Hack to correct odd behavior of tables with unicode characters
972 .firstColumn$ = Get column label: 1
973 if index_regex(.firstColumn$, "^[^!-~]") > 0
974 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
975 Set column label (index): 1, .firstColumn$
978 sgc.numberOfWords = Get number of rows
979 .characterColumn = Get column index... Character
980 if not .characterColumn
981 Append column... Character
982 for .i to sgc.numberOfWords
983 Set string value... '.i' Character -
986 .translationColumn = Get column index... Translation
987 if not .translationColumn
988 Append column... Translation
989 for .i to sgc.numberOfWords
990 Set string value... '.i' Translation -
993 .translationColumn = Get column index... Sound
994 if not .translationColumn
995 Append column... Sound
996 for .i to sgc.numberOfWords
997 Set string value... '.i' Sound -
1000 .showColumn = Get column index... Show
1002 Append column... Show
1003 for .i to sgc.numberOfWords
1004 Set string value... '.i' Show +
1009 # Remove all rows without Pinyin
1010 .numRows = Get number of rows
1012 .rowNum = .numRows - i + 1
1013 .pinyinValue$ = Get value... '.rowNum' Pinyin
1014 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
1015 Remove row... '.rowNum'
1018 sgc.numberOfWords = Get number of rows
1020 # Shuffle words if requested
1021 if config.shuffleLists
1025 # Determine number of words actually shown
1027 sgc.currentWordNum = 1
1028 sgc.numberOfDisplayedWords = 0
1030 .show$ = Get value: .i, "Show"
1032 if sgc.currentWord < 1
1033 sgc.currentWord = .i
1035 sgc.numberOfDisplayedWords += 1
1041 #select sgc.allWordLists
1044 # There were no Word Lists
1047 wordlistName$ = wordlistName$+" No Word Lists available"
1049 Create Table with column names... "'wordlistName$'" 1 Pinyin Character Translation Sound
1050 wordlist$ = selected$("Table")
1054 Set string value... '.i' Pinyin ni3hao3
1055 Set string value... '.i' Character 你好
1056 Set string value... '.i' Translation hello
1057 Set string value... '.i' Sound -
1060 Set string value... '.i' Pinyin xie4xie0
1061 Set string value... '.i' Character 谢谢
1062 Set string value... '.i' Translation thanks
1063 Set string value... '.i' Sound -
1066 Set string value... '.i' Pinyin zai4jian4
1067 Set string value... '.i' Character 再见
1068 Set string value... '.i' Translation goodbye
1069 Set string value... '.i' Sound -
1070 # Get rid of empty first row
1073 # Set default values
1074 sgc.numberOfWords = Get number of rows
1076 sgc.numberOfDisplayedWords = Get number of rows
1079 select Table 'wordlist$'
1080 sgc.currentWordlist = selected()
1081 call set_window_title 'buttons$' 'wordlistName$'
1084 procedure read_wordlist .wordlistName$ .dirString$
1085 # Read in full tables
1086 if fileReadable("'.dirString$'/wordlist.Table")
1087 call readTable '.dirString$'/wordlist.Table
1088 .wordlistID = selected ()
1090 Rename... '.wordlistName$'
1091 # Praat wil change the name if it feels like it
1092 .wordlist$ = selected$("Table")
1093 # Add a Sound column if it is not present
1094 .soundIndex = Get column index: "Sound"
1096 Append column: "Sound"
1099 goto EMERGENCYEXITWL
1101 # Handle (legacy) simple word lists
1102 elsif fileReadable("'.dirString$'/wordlist.txt")
1103 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Character Sound Translation
1104 .wordlist$ = selected$("Table")
1105 Read Strings from raw text file... '.dirString$'/wordlist.txt
1106 Rename... RawWordList
1107 .numWordStrings = Get number of strings
1108 for .i to .numWordStrings
1109 select Strings RawWordList
1112 .currentTrans$ = "-"
1113 .currentLine$ = Get string... '.i'
1114 # Remove leading whitespace
1115 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1116 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1117 if .separatorIndex <= 0
1118 .separatorIndex = length(.currentLine$) + 1
1120 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1121 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1122 # There is more on the line, but we do not know what
1123 if length(.currentLine$) > 0
1124 while length(.currentLine$) > 0
1125 .separatorIndex = index_regex(.currentLine$, "[\t;]")
1126 if .separatorIndex <= 0
1127 .separatorIndex = length(.currentLine$)+1
1129 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1130 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1131 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1133 .currentFile$ = .currentItem$
1134 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1136 .currentTrans$ = .currentItem$
1137 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1139 .currentChar$ = .currentItem$
1143 if .currentFile$ = "-"
1144 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1145 .currentFile$ = .currentPinyin$+".spx"
1146 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1147 .currentFile$ = .currentPinyin$+".flac"
1148 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1149 .currentFile$ = .currentPinyin$+".wav"
1150 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1151 .currentFile$ = .currentPinyin$+".mp3"
1156 Set string value... '.i' Pinyin '.currentPinyin$'
1157 Set string value... '.i' Sound '.currentFile$'
1158 Set string value... '.i' Character '.currentChar$'
1159 Set string value... '.i' Translation '.currentTrans$'
1161 select Strings RawWordList
1165 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1166 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Sound
1167 .wordlist$ = selected$("Table")
1168 .tmp = Create Strings as file list... RawWordList '.dirString$'/*
1169 .numWordStrings = Get number of strings
1171 for .j to .numWordStrings
1173 .currentLine$ = Get string... '.j'
1174 .currentFile$ = extractWord$(.currentLine$, "")
1175 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1176 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1177 select sgc.currentWordlist
1180 Set string value... '.i' Pinyin '.currentPinyin$'
1181 Set string value... '.i' Sound '.currentFile$'
1187 select sgc.currentWordlist
1188 elsif startsWith(.dirString$, "*call ")
1189 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1191 .wordlistID = selected()
1192 .wordlist$ = selected$("Table")
1195 goto EMERGENCYEXITWL
1198 # Add the path to the file Sound file names
1200 .numRows = Get number of rows
1202 .soundfile$ = Get value: .w, "Sound"
1203 if index_regex(.soundfile$, "[/\\]") <= 0
1204 if index_regex(.dirString$, "[/\\]$")
1205 .soundfile$ = .dirString$+.soundfile$
1206 elsif index_regex(.dirString$, "[\\]")
1207 .soundfile$ = .dirString$+"\\"+.soundfile$
1209 .soundfile$ = .dirString$+"/"+.soundfile$
1211 Set string value: .w, "Sound", .soundfile$
1215 label EMERGENCYEXITWL
1219 procedure merge_into_wordlist .newTableID .lessonPostfix$
1220 select sgc.currentWordlist
1221 .oldLessonColumn = Get column index: "Lesson"
1224 .numRows = Get number of rows
1225 .lessonColumn = Get column index: "Lesson"
1226 .characterColumn = Get column index: "Character"
1227 .soundColumn = Get column index: "Sound"
1228 .translationColumn = Get column index: "Translation"
1232 .currentTrans$ = "-"
1233 .currentLesson$ = "-"
1236 .currentPinyin$ = Get value: .w, "Pinyin"
1238 .currentFile$ = Get value: .w, "Sound"
1240 if .characterColumn > 0
1241 .currentChar$ = Get value: .w, "Character"
1243 if .translationColumn > 0
1244 .currentTrans$ = Get value: .w, "Translation"
1246 if .lessonColumn > 0
1247 .currentLesson$ = Get value: .w, "Lesson"
1249 select sgc.currentWordlist
1251 .n = Get number of rows
1252 Set string value: .n, "Pinyin", .currentPinyin$
1253 Set string value: .n, "Sound", .currentFile$
1254 Set string value: .n, "Character", .currentChar$
1255 Set string value: .n, "Translation", .currentTrans$
1256 if .oldLessonColumn > 0
1257 if .currentLesson$ = "-" or .currentLesson$ = "" or .currentLesson$ = "?"
1258 Set string value: .n, "Lesson", .lessonPostfix$
1260 Set string value: .n, "Lesson", .currentLesson$+" "+.lessonPostfix$
1268 select sgc.currentWordlist
1270 if sgc.currentWord < 0 or sgc.currentWord > sgc.numberOfWords
1271 if config.shuffleLists
1275 sgc.currentWordNum = 0
1277 while .showCurrent$ = "-" and sgc.currentWord <= sgc.numberOfWords
1278 sgc.currentWord += 1
1279 if sgc.currentWord <= sgc.numberOfWords
1280 .showCurrent$ = Get value... 'sgc.currentWord' Show
1283 if sgc.currentWord > 0
1284 sgc.currentWordNum += 1
1286 sgc.currentWordNum = 0
1291 procedure previous_word
1293 select sgc.currentWordlist
1295 if sgc.currentWord <= 0
1296 if config.shuffleLists
1299 sgc.currentWord = sgc.numberOfWords + 1
1300 sgc.currentWordNum = sgc.numberOfDisplayedWords + 1
1302 while .showCurrent$ = "-" and sgc.currentWord > 0
1303 sgc.currentWord -= 1
1304 if sgc.currentWord > 0
1305 .showCurrent$ = Get value... 'sgc.currentWord' Show
1308 if sgc.currentWord > 0
1309 sgc.currentWordNum -= 1
1311 sgc.currentWordNum = 0
1316 procedure display_word_list_name
1320 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
1321 call wipeArea 'wipeWordlistArea$'
1322 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
1323 .currentFontSize = adjustFontSizeOnHeight.newFontSize
1326 demo Text special... '.xtext' Centre '.ytext' Bottom 'defaultFont$' '.currentFontSize' 0 '.displayWordList$'
1329 call set_font_size 'defaultFontSize'
1332 procedure write_word_list
1333 # Write current Pinyin text
1334 call display_text Black
1336 # Write the current word list name
1337 call display_word_list_name
1340 procedure paint_saveAudio_light
1341 select Table 'config$'
1342 .row = Search column... Label SaveAudio
1344 exit Button Table Config does not have a row with label SaveAudio
1347 .leftX = Get value... '.row' LeftX
1348 .rightX = Get value... '.row' RightX
1349 .lowY = Get value... '.row' LowY
1350 .highY = Get value... '.row' HighY
1351 .buttonColor$ = Get value... '.row' Color
1352 # The button text and symbol
1353 .horWC = demo Horizontal mm to wc... 10.0
1354 .verWC = demo Vertical mm to wc... 10.0
1356 .verCoeff = .horWC / .verWC
1361 .centerX = (.leftX + .rightX)/2
1362 .centerY = .lowY + 0.6*(.highY-.lowY)
1363 .radius = min(.verCoeff * (.highY - .lowY ), (.rightX - .leftX))/3
1364 .wipeRadius = 1.1*.radius
1365 call DrawSaveAudio White '.centerX' '.centerY' '.wipeRadius'
1367 if sgc.saveAudioOn and sgc.saveAudio$ <> ""
1368 call DrawSaveAudio "DarkBlue" '.centerX' '.centerY' '.radius'
1373 # Uninstall word lists
1374 procedure removeWordlist .deletedWordlistName$
1376 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1377 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1379 if .targetDir$ <> ""
1380 Create Strings as file list... DeleteList '.targetDir$'
1381 .numdeleteFiles = Get number of strings
1382 for .i to .numdeleteFiles
1383 .file$ = Get string... '.i'
1384 deleteFile("'.targetDir$'/'.file$'")
1386 filedelete '.targetDir$'
1387 # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1388 # That is, it does not contain funny characters, nor funny names
1389 if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1391 nocheck system rmdir "'.targetDir$'" /s /q
1392 elsif fileReadable(.targetDir$)
1393 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1396 # Remove deleted word list
1397 select Strings DeleteList
1398 plus Table 'wordlist$'
1404 # Install word lists
1405 procedure sgc2wordlist .sourceDir$
1406 if startsWith(.sourceDir$, "preferencesDirectory$")
1407 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1410 .targetDirectory$ = "'sgc2wordlists$'"
1411 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1412 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1413 .numFiles = Get number of strings
1415 select Strings PackageList
1416 .file$ = Get string... '.i'
1417 call readWordlist '.sourceDir$' '.file$'
1420 select Strings PackageList
1425 # Debuggin remarks!!!
1426 # fileReadable(<directory>) does not work in Windows
1427 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1428 # And yet only the 7z decompression has been implemented
1429 windowsUnzipCommand$ = ""
1430 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1431 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" -y e"
1432 windowsUnzipDestDir$ = " -o"
1433 elsif fileReadable("C:\Program Files\WinZip\winzip32.exe")
1434 # !!! Find a way to include the output folder !!!
1435 windowsUnzipCommand$ = "C:\Program Files\WinZip\winzip32.exe"" -min -e -o -j "
1436 windowsUnzipDestDir$ = ""
1438 procedure readWordlist .sourceDir$ .file$
1439 # No use doing anything if the source does not exist
1440 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1441 # What will be the target wordlist directory?
1442 .targetDirectory$ = "'sgc2wordlists$'"
1443 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1447 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1448 # Wordlist directory does not exist, neither locally nor in the preferences
1450 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1451 if .tmpDirs != undefined and .tmpDirs > 0
1452 .numDirs = Get number of strings
1455 .currentString$ = Get string... '.d'
1456 if .currentString$ = .dirname$
1462 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1464 # Move source to destination
1465 # Use this if you want to allow direct loading of ZIP files. Could lead to problems.
1466 # if index(.file$, ".sgc") or index(.file$, ".zip")
1468 if index(.file$, ".sgc")
1469 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1470 # Create wordlist directory
1471 createDirectory(.wordlistDirectory$)
1473 if macintosh or unix
1474 system bash -rc -- 'unzip -j "'.sourceDir$'/'.file$'" -d "'.wordlistDirectory$'"'
1475 elsif windows and windowsUnzipCommand$ <> ""
1476 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1477 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1478 system mkdir "'.winWordListDirectory$'" & 'windowsUnzipCommand$' "'.winSourceDirectory$'" 'windowsUnzipDestDir$'"'.winWordListDirectory$'"
1480 elsif (windows and windowsUnzipCommand$ = "")
1481 # Warn to install 7Zip
1482 call get_feedback_text 'config.language$' InstallUnzip
1483 call convert_praat_to_latin1 'get_feedback_text.text$'
1484 .zipText$ = convert_praat_to_latin1.text$
1485 call write_text_popup 'defaultFont$' 14 '.zipText$'
1486 # Wait for confirmation
1488 call Draw_config_page
1490 # Remove if not valid!
1491 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1492 if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1493 call readTable '.sourceDir$'/'.file$'
1494 if readTable.tableID > 0
1495 select readTable.tableID
1496 # Hack around odd behavior of column index
1498 .firstColumn$ = Get column label: 1
1499 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1500 if .firstColumn$ = "Pinyin"
1503 .pinyinCol = Get column index... Pinyin
1506 # No Pinyin in table
1515 # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1518 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1520 # Remove newly created directory
1521 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1522 if macintosh or unix
1523 system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1525 system rmdir /Q /S "'.winWordListDirectory$'/"
1529 elsif index_regex(.file$, "\.(Table|txt|tsv)")
1530 # Check whether this is a valid table
1531 call readTable '.sourceDir$'/'.file$'
1532 if readTable.tableID > 0
1533 select readTable.tableID
1534 # Hack around odd behavior of column index
1536 .firstColumn$ = Get column label: 1
1537 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1538 if .firstColumn$ = "Pinyin"
1541 .pinyinCol = Get column index... Pinyin
1545 select readTable.tableID
1546 # Create wordlist directory
1547 createDirectory(.wordlistDirectory$)
1549 .extension$ = "Table"
1550 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1552 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1555 select readTable.tableID
1556 Save as tab-separated file: .wordlistFilePath$
1557 if not fileReadable(.wordlistFilePath$)
1561 select readTable.tableID
1564 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1565 # Copy wordlist directory
1566 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1568 if macintosh or unix
1569 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1571 createDirectory(.wordlistDirectory$)
1572 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1573 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1574 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1579 # Set current word list to read list
1581 wordlistName$ = .dirname$
1584 .label$ = "!NotAWordlist"
1587 call findLabel '.table$' '.label$'
1588 .row = findLabel.row
1589 select Table '.table$'
1590 .helpText$ = Get value... '.row' Helptext
1591 .printablePath$ = "'.sourceDir$'/'.file$'"
1593 .printablePath$ = replace$("'.sourceDir$'\'.file$'", "\", "\bs", 0)
1595 .filetext$ = replace_regex$(.printablePath$, "_", "\\_ ", 0)
1596 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1597 # Wait for confirmation