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'
117 if sgc2.synthesizer < 0 or config.synthesis$ = "" or config.synthesis$ = "_DISABLED_"
118 call Draw_button 'config$' Voice -1
120 call Draw_button 'config$' Voice 2
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 processConfigAdaptiveLists .clickX .clickY .pressed$
140 .label$ = "AdaptiveLists"
141 config.adaptiveLists = not config.adaptiveLists
142 .displayButton = 2*config.adaptiveLists
143 call Draw_button '.table$' '.label$' '.displayButton'
146 procedure processConfigUseSoundExample .clickX .clickY .pressed$
148 .label$ = "UseSoundExample"
149 config.useSoundExample = not config.useSoundExample
150 .displayButton = 2*config.useSoundExample
151 call Draw_button '.table$' '.label$' '.displayButton'
154 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
156 .label$ = "Synthesis_'.tts$'"
157 if sgc2.synthesizer > 0 or (speakCommandFile$ <> "" and fileReadable(speakCommandFile$))
158 if config.synthesis$ = ""
159 config.synthesis$ = .tts$
162 config.synthesis$ = ""
166 config.synthesis$ = "_DISABLED_"
169 call Draw_button '.table$' '.label$' '.displayButton'
171 # Disable or enable voices button!
172 .voiceButton = .displayButton
176 call Draw_button Config Voice '.voiceButton'
179 procedure processConfigStrict .clickX .clickY .pressed$
182 .tmp = 'config.strict$'
184 if .tmp > sgc.highestLevel
187 config.strict$ = "'.tmp'"
193 # Change TTS for Strict!
195 call Draw_button '.table$' '.label$' '.displayButton'
198 procedure processConfigVoice .clickX .clickY .pressed$
203 if .tmp > sgc.lastVoice
207 if sgc2.synthesizer <= 0 or config.synthesis$ = "" or config.synthesis$ = "_DISABLED_"
212 call set_TTS_parameters
215 call Draw_button '.table$' '.label$' '.displayButton'
218 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
220 .label$ = "DisplayPinyin"
221 config.displayPinyin = not config.displayPinyin
222 .displayButton = 2*config.displayPinyin
223 call Draw_button '.table$' '.label$' '.displayButton'
226 procedure processConfigDisplayChar .clickX .clickY .pressed$
228 .label$ = "DisplayChar"
229 config.displayChar = not config.displayChar
230 .displayButton = 2*config.displayChar
231 call Draw_button '.table$' '.label$' '.displayButton'
234 procedure processConfigDisplayTrans .clickX .clickY .pressed$
236 .label$ = "DisplayTrans"
237 config.displayTrans = not config.displayTrans
238 .displayButton = 2*config.displayTrans
239 call Draw_button '.table$' '.label$' '.displayButton'
242 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
244 .label$ = "DisplayNumbers"
245 config.displayNumbers = not config.displayNumbers
246 .displayButton = 2*config.displayNumbers
247 call Draw_button '.table$' '.label$' '.displayButton'
250 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
252 .label$ = "Language_'.language$'"
253 call processLanguageCodes '.table$' '.label$'
256 procedure processConfigShowBackground .clickX .clickY .pressed$
258 .label$ = "ShowBackground"
259 config.showBackground = not config.showBackground
260 .displayButton = 2*config.showBackground
261 call Draw_button '.table$' '.label$' '.displayButton'
264 procedure processConfigInput .input$ .clickX .clickY .pressed$
266 .label$ = "Input_'.input$'"
267 call Draw_button '.table$' Input_'config.input$' 0
268 config.input$ = .input$
269 call Draw_button '.table$' Input_'config.input$' 2
272 procedure processConfigRegister .register .clickX .clickY .pressed$
274 .label$ = "Register_'.register'"
275 call setRegisterFromLabel '.table$' '.label$'
278 procedure setRegisterFromLabel .table$ .label$
279 call Draw_button '.table$' Register_'config.register' 0
280 call Draw_button '.table$' '.label$' 2
281 # Someone might have to use more than 3 chars for the config.register code
282 .numChars = length(.label$) - length("Register_")
283 .registerText$ = right$(.label$, .numChars)
284 config.register = '.registerText$'
287 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
289 .label$ = "DeleteWordlist"
291 # Do not process undeletable word lists, only those stored in the
292 # preferencesDirectory$ can be deleted
293 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
294 call findLabel '.table$' !'.label$'
296 select Table '.table$'
297 .alertText$ = Get value... 'findLabel.row' Text
298 .confirmKey$ = Get value... 'findLabel.row' Key
299 .popupText$ = Get value... 'findLabel.row' Helptext
301 exit Cannot find delete directive: '.table$' !'.label$'
303 call write_text_popup 'defaultFont$' 14 '.popupText$'
304 call Draw_button '.table$' '.label$' 2
305 alertText$ = .alertText$
306 call Draw_button '.table$' '.label$' 3
309 # Wait for confirmation
311 if demoInput(.confirmKey$)
312 .deleteWordListDir$ = wordlistName$
313 call load_word_list "'localWordlistDir$'" 1
314 call removeWordlist '.deleteWordListDir$'
315 call load_word_list "'localWordlistDir$'" 0
317 call Draw_button '.table$' '.label$' 0
318 call Draw_config_page
322 wordlistTag$ = "Wordlist name"
323 procedure processConfigInstallWordlist .clickX .clickY .pressed$
325 .label$ = "InstallWordlist"
326 call Draw_button '.table$' '.label$' 1
328 # Do not use the automatic sgc list option, ask for a wordlist NAME
330 call findLabel '.table$' '.label$'
332 select Table '.table$'
333 .openDialogue$ = Get value... '.row' Helptext
334 call convert_praat_to_latin1 '.openDialogue$'
335 .openDialogue$ = convert_praat_to_latin1.text$
336 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
337 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
338 beginPause(.openDialogue$)
339 sentence (wordlistTag$, "")
340 clicked = endPause ("Cancel", "Open", 2, 1)
343 .wordlist_Name$ = '.wordlistButton$'$
345 call install_wordlists_by_name '.wordlist_Name$'
347 call sgc2wordlist 'homeDirectory$'
348 call sgc2wordlist 'homeDirectory$'/Downloads
349 call sgc2wordlist 'homeDirectory$'/Documents
350 call sgc2wordlist 'homeDirectory$'/My Documents
351 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
352 call sgc2wordlist 'homeDirectory$'/Desktop
353 call sgc2wordlist 'preferencesAppDir$'
355 call load_word_list "'localWordlistDir$'" 0
356 call Draw_button '.table$' '.label$' 0
357 call Draw_config_page
360 procedure processConfigOpenWordlist .clickX .clickY .pressed$
362 .label$ = "OpenWordlist"
363 call Draw_button '.table$' '.label$' 1
366 call findLabel '.table$' '.label$'
368 select Table '.table$'
369 .openDialogue$ = Get value... '.row' Helptext
370 call convert_praat_to_latin1 '.openDialogue$'
371 .openDialogue$ = convert_praat_to_latin1.text$
373 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
374 call install_wordlists_by_name '.wordlist_Name$'
375 call load_word_list "'localWordlistDir$'" 0
376 call Draw_button '.table$' '.label$' 0
377 call Draw_config_page
380 procedure processConfigExportWordlist .clickX .clickY .pressed$
382 .label$ = "ExportWordlist"
384 call Draw_button '.table$' '.label$' 1
387 call findLabel '.table$' '.label$'
389 select Table '.table$'
390 .openDialogue$ = Get value... '.row' Helptext
391 call convert_praat_to_latin1 '.openDialogue$'
392 .openDialogue$ = convert_praat_to_latin1.text$
394 .newWordlistName$ = "'wordlist$'_SGC2"
396 # Ensure the right extension: ".tsv"
397 while .newWordlistName$ <> "" and not endsWith(.newWordlistName$, ".tsv")
398 .newWordlistName$ = .newWordlistName$ + ".tsv"
399 .newWordlistName$ = chooseWriteFile$ (.openDialogue$, .newWordlistName$)
401 .tableName$ = replace_regex$(.newWordlistName$, "^.*[/\\:]([^/\\:]+)\.(tsv|Table)$", "\1", 0)
402 call testLoadTable '.tableName$'
403 if testLoadTable.table > 0
404 call loadTable '.tableName$'
405 .tmpTable = selected()
406 Save as tab-separated file: .newWordlistName$
408 .newWordlistName$ = ""
412 if .newWordlistName$ <> ""
413 select sgc.currentWordlist
414 .tmpSaveWordlist = Copy: "SaveWordlist"
415 # Get the table sorted
416 .lessonCol = Get column index: "Lesson"
418 Sort rows... Lesson Pinyin
423 # Remove all words that are deselected
424 .showCol = Get column index: "Show"
426 .numRows = Get number of rows
429 .show$ = Get value: .row, "Show"
430 .sound$ = Get value: .row, "Sound"
432 .numRows = Get number of rows
433 # Do NOT remove all the rows
437 elsif .sound$ <> "" and .sound$ <> "-" and .sound$ <> "?"
438 # Put path before sound examples
439 # If there is no path, add the current wordlist path
440 if index_regex(.sound$, "^(/|~/|[A-Z]:\\)") <= 0
441 .sound$ = localWordlistDir$+"/"+wordlistName$+"/"+.sound$
442 Set string value: .row, "Sound", .sound$
447 Remove column: "Show"
449 Write to table file... '.newWordlistName$'
453 call Draw_button '.table$' '.label$' 0
454 call Draw_config_page
457 procedure processConfigPerfSummary .clickX .clickY .pressed$
459 .label$ = "PerfSummary"
461 call testLoadTable SummaryToneEvaluation
462 if testLoadTable.table > 0
463 call Draw_button '.table$' '.label$' 1
464 call loadTable SummaryToneEvaluation
465 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
467 select Table SummaryToneEvaluation
470 call Draw_button '.table$' '.label$' 0
471 call Draw_config_page
475 # Wipe current performance table and initialize a new one
476 procedure processConfigClearSummary .clickX .clickY .pressed$
478 .label$ = "ClearSummary"
480 call Draw_button '.table$' '.label$' 1
482 if not sgc.saveAudioOn
483 select Table '.table$'
484 call findLabel '.table$' !'.label$'
486 .alertText$ = Get value... 'findLabel.row' Text
487 .confirmKey$ = Get value... 'findLabel.row' Key
488 .popupText$ = Get value... 'findLabel.row' Helptext
490 call write_text_popup 'defaultFont$' 14 '.popupText$'
491 call Draw_button '.table$' '.label$' 2
492 alertText$ = .alertText$
493 call Draw_button '.table$' '.label$' 3
496 # Wait for confirmation
498 if demoInput(.confirmKey$)
500 call initialize_toneevaluation_tables
505 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
506 call Draw_config_page
510 procedure processConfigListPerf .clickX .clickY .pressed$
513 call Draw_button '.table$' '.label$' 1
515 select sgc2.performanceTable
519 call Draw_button '.table$' '.label$' 0
520 call Draw_config_page
523 procedure processConfigOpenPerf .clickX .clickY .pressed$
526 call Draw_button '.table$' '.label$' 1
528 if not sgc.saveAudioOn
530 call findLabel '.table$' !'.label$'
532 select Table '.table$'
533 .openDialogue$ = Get value... '.row' Helptext
534 call convert_praat_to_latin1 '.openDialogue$'
535 .openDialogue$ = convert_praat_to_latin1.text$
536 if variableExists("eval.performance$")
537 .defaultName$= "'eval.performance$'.tsv"
539 .defaultName$= "Performance.tsv"
541 if sgc.savePerf$ <> ""
542 .defaultName$= sgc.savePerf$
545 while .notChoosen > 0
547 .performance_Name$ = chooseReadFile$ (.openDialogue$)
548 while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0
549 .performance_Name$ = chooseReadFile$ (.openDialogue$)
551 if .performance_Name$ <> "" and fileReadable(.performance_Name$)
552 sgc.savePerf$ = .performance_Name$
554 # Set SaveAudio directory if it is not currently "in use"
555 if not sgc.saveAudioOn
556 sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0)
557 .fileName$ = right$(sgc.savePerf$, length(sgc.savePerf$) - index_regex(sgc.savePerf$, "[/\\][^/\\]+$"))
558 .dirName$ = replace_regex$(.fileName$, "(?i\.tsv$)", "", 0)
559 if fileReadable("'sgc.saveAudio$'/'.dirName$'/'.fileName$'")
560 sgc.saveAudio$ = "'sgc.saveAudio$'/'.dirName$'"
562 .audioDir = Create Strings as directory list: "AudioDir", "'sgc.saveAudio$'/*"
563 .numStrings = Get number of strings
564 for .d to .numStrings
565 .subdir$ = Get string: .d
566 if fileReadable("'sgc.saveAudio$'/'.subdir$'/'.dirName$'/'.fileName$'")
567 sgc.saveAudio$ = "'sgc.saveAudio$'/'.subdir$'/'.dirName$'"
571 # We are not sure yet that this is actually an audio directory
572 config.audioName$ = ""
575 # Initialize the table
576 call initialize_toneevaluation_tables
577 .notChoosen = initialize_toneevaluation_tables.invalidperformanceTable
582 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
583 call Draw_config_page
586 procedure processConfigSavePerf .clickX .clickY .pressed$
589 call Draw_button '.table$' '.label$' 1
591 if not sgc.saveAudioOn
593 call findLabel '.table$' '.label$'
595 select Table '.table$'
596 .openDialogue$ = Get value... '.row' Helptext
597 call convert_praat_to_latin1 '.openDialogue$'
598 .openDialogue$ = convert_praat_to_latin1.text$
599 if variableExists("eval.performance$")
600 .defaultName$= "'eval.performance$'.tsv"
602 .defaultName$= "Performance.tsv"
604 if sgc.savePerf$ <> ""
605 .defaultName$= sgc.savePerf$
607 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .defaultName$)
608 # Ensure the right extension: ".tsv"
609 while .performance_Name$ <> "" and not endsWith(.performance_Name$, ".tsv")
610 .performance_Name$ = .performance_Name$ + ".tsv"
611 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .performance_Name$)
613 if .performance_Name$ <> ""
614 select sgc2.performanceTable
615 Write to table file... '.performance_Name$'
616 sgc.savePerf$ = .performance_Name$
620 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
621 call Draw_config_page
624 procedure processConfigManual .clickX .clickY .pressed$
627 call Draw_button '.table$' '.label$' 1
628 if fileReadable("ManPages/SpeakGoodChinese_2.man")
629 Read from file... ManPages/SpeakGoodChinese_2.man
631 Go to manual page... SpeakGoodChinese 2
633 # Wait until the manual is put to the background
635 call Draw_button '.table$' '.label$' 0
637 call Draw_config_page
640 procedure processConfigSaveAudio .clickX .clickY .pressed$
642 .label$ = "SaveAudio"
643 call Draw_button '.table$' '.label$' 1
645 if sgc.saveAudioOn = 0
647 call findLabel '.table$' '.label$'
649 select Table '.table$'
650 .openDialogue$ = Get value... '.row' Helptext
651 call convert_praat_to_latin1 '.openDialogue$'
652 .openDialogue$ = convert_praat_to_latin1.text$
654 sgc.saveAudio$ = chooseDirectory$ (.openDialogue$)
655 if sgc.saveAudio$ <> ""
657 .currentPathName$ = replace_regex$(sgc.saveAudio$, "[^/\\]*[/\\]?$", "", 0)
658 .currentDirName$ = replace$(sgc.saveAudio$, .currentPathName$, "", 0)
661 config.clearSummary = -1
662 config.audioName$ = .currentDirName$
664 # Clear performance table and open/create sgc.savePerf$
665 sgc.savePerf$ = "'sgc.saveAudio$'/'.currentDirName$'.tsv"
666 call initialize_toneevaluation_tables
668 call update_toneevaluation_file
669 if sgc.savePerf$ <> "" and initialiseSGC2.toneevaluation_table$ <> ""
670 select sgc2.performanceTable
671 Write to table file: sgc.savePerf$
674 config.audioName$ = ""
680 config.clearSummary = 0
681 # Store current performance table
682 call update_toneevaluation_file
685 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
686 call Draw_config_page
689 ###############################################################
691 # Obligatory button Processing Routines
693 # These MUST be defined
695 ###############################################################
697 procedure processConfigReturn .clickX .clickY .pressed$
700 call Draw_button '.table$' '.label$' 1
701 call write_preferences ""
704 procedure processConfigRefresh .clickX .clickY .pressed$
707 call Draw_config_page
710 procedure processConfigCredits .clickX .clickY .pressed$
713 call Draw_button '.table$' '.label$' 1
714 call write_text_table Credits_'config.language$'
716 call Draw_button '.table$' '.label$' 0
718 call Draw_config_page
721 procedure processConfigHelp .clickX .clickY .pressed$
724 call help_loop '.table$' Draw_config_page
727 ###############################################################
729 # Miscelaneous supporting code
731 ###############################################################
732 procedure install_wordlists_by_name .wordlist_Name$
733 if .wordlist_Name$ <> ""
734 if index_regex(.wordlist_Name$, "(?iwordlist|LICENSE)\.")
735 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\](?iwordlist|LICENSE)\.([^/\\]+)$", "", 0)
736 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
737 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
739 if index_regex(.wordlist_Name$, "[/\\]")
740 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
741 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
742 call readWordlist "'.sourceDir$'" '.file$'
745 if index(.wordlist_Name$, ".")
748 .extension1$ = ".sgc"
749 .extension2$ = ".Table"
750 .extension3$ = ".txt"
751 .extension4$ = ".tsv"
753 for .e from .start to 5
754 .currentExtension$ = .extension'.e'$
755 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
756 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
757 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
758 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
759 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
760 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
761 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
767 # Word lists: It is a VERY good idea to make sure that word-lists
769 procedure load_word_list .localdir$ .relnumber
771 if sgc.allWordLists > 0
772 select sgc.allWordLists
774 sgc.allWordLists = -1
777 # Remove old word list
779 select sgc.currentWordlist
781 call wipeArea 'wipeWordlistArea$'
783 sgc.currentWordlist = -1
787 # Create Table that will recieve the wordlists and directories
788 sgc.allWordLists = Create Table with column names... AllWordLists 0 Name Directory
789 .sgc.currentWordlistRow = 0
791 # First the global word lists
792 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
793 Create Strings as directory list... WordList 'globalwordlists$'
794 .numLists = Get number of strings
796 select Strings WordList
797 .currentName$ = Get string... '.i'
798 if .currentName$ <> "directory.txt"
799 select sgc.allWordLists
800 .listExist = Search column: "Name", .currentName$
803 .sgc.currentWordlistRow = Get number of rows
804 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
805 .currentDirectory$ = globalwordlists$+"/"+.currentName$
806 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
810 select Strings WordList
814 # Now the preferences word lists
815 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
816 Create Strings as directory list... WordList 'sgc2wordlists$'
817 .numLists = Get number of strings
819 select Strings WordList
820 .currentName$ = Get string... '.i'
821 if .currentName$ <> "directory.txt"
822 select sgc.allWordLists
823 .listExist = Search column: "Name", .currentName$
826 .sgc.currentWordlistRow = Get number of rows
827 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
828 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
829 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
833 select Strings WordList
837 # End with the word lists in the distribution
838 call CreateCreateWordlists
839 select Table CreateWordlists
840 .numLists = Get number of rows
842 select Table CreateWordlists
843 .currentName$ = Get value... '.i' Name
844 if .currentName$ <> "directory.txt"
845 select sgc.allWordLists
846 .listExist = Search column: "Name", .currentName$
848 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
849 select sgc.allWordLists
851 .sgc.currentWordlistRow = Get number of rows
852 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
853 .currentDirectory$ = "*call Create'.procedureName$'"
854 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
858 select Table CreateWordlists
861 # Finally, the local word lists
862 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
863 Create Strings as directory list... WordList '.localdir$'
864 .numLists = Get number of strings
866 select Strings WordList
867 .currentName$ = Get string... '.i'
868 if .currentName$ <> "directory.txt"
869 select sgc.allWordLists
870 .listExist = Search column: "Name", .currentName$
873 .sgc.currentWordlistRow = Get number of rows
874 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
875 .currentDirectory$ = .localdir$+"/"+.currentName$
876 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
880 select Strings WordList
884 # Get the position of the current word list
885 select sgc.allWordLists
887 .numLists = Get number of rows
889 if wordlistName$ <> ""
890 select sgc.allWordLists
891 .currentNumber = Search column... Name 'wordlistName$'
892 if .currentNumber <= 0
897 wordlistNum = .currentNumber + .relnumber
898 if wordlistNum > .numLists
900 elsif wordlistNum < 1 and .numLists > 0
901 wordlistNum = .numLists
903 select sgc.allWordLists
904 wordlistName$ = Get value... 'wordlistNum' Name
905 .dirWordlistName$ = Get value... 'wordlistNum' Directory
906 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
908 # Read in full tables
909 if fileReadable("'.dirString$'/wordlist.Table")
910 call readTable '.dirString$'/wordlist.Table
911 if readTable.tableID > 0
912 Rename... 'wordlistName$'
913 # Praat wil change the name if it feels like it
914 wordlist$ = selected$("Table")
915 # Add a Sound column if it is not present
916 .soundIndex = Get column index: "Sound"
918 Append column: "Sound"
924 # Handle (legacy) simple word lists
925 elsif fileReadable("'.dirString$'/wordlist.txt")
926 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
927 wordlist$ = selected$("Table")
928 Read Strings from raw text file... '.dirString$'/wordlist.txt
929 Rename... RawWordList
930 .numWordStrings = Get number of strings
931 for .i to .numWordStrings
932 select Strings RawWordList
936 .currentLine$ = Get string... '.i'
937 # Remove leading whitespace
938 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
939 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
940 if .separatorIndex <= 0
941 .separatorIndex = length(.currentLine$) + 1
943 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
944 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
945 # There is more on the line, but we do not know what
946 if length(.currentLine$) > 0
947 while length(.currentLine$) > 0
948 .separatorIndex = index_regex(.currentLine$, "[\t;]")
949 if .separatorIndex <= 0
950 .separatorIndex = length(.currentLine$)+1
952 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
953 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
954 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
956 .currentFile$ = .currentItem$
957 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
959 .currentTrans$ = .currentItem$
960 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
962 .currentChar$ = .currentItem$
966 if .currentFile$ = "-"
967 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
968 .currentFile$ = .currentPinyin$+".spx"
969 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
970 .currentFile$ = .currentPinyin$+".flac"
971 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
972 .currentFile$ = .currentPinyin$+".wav"
973 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
974 .currentFile$ = .currentPinyin$+".mp3"
977 select Table 'wordlist$'
979 Set string value... '.i' Pinyin '.currentPinyin$'
980 Set string value... '.i' Sound '.currentFile$'
981 Set string value... '.i' Character '.currentChar$'
982 Set string value... '.i' Translation '.currentTrans$'
984 select Strings RawWordList
987 select Table 'wordlist$'
988 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
989 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
990 wordlist$ = selected$("Table")
991 Create Strings as file list... RawWordList '.dirString$'/*
992 .numWordStrings = Get number of strings
994 for .j to .numWordStrings
995 select Strings RawWordList
996 .currentLine$ = Get string... '.j'
997 .currentFile$ = extractWord$(.currentLine$, "")
998 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
999 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1000 select Table 'wordlist$'
1003 Set string value... '.i' Pinyin '.currentPinyin$'
1004 Set string value... '.i' Sound '.currentFile$'
1007 select Strings RawWordList
1010 select Table 'wordlist$'
1011 elsif startsWith(.dirString$, "*call ")
1012 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1014 wordlist$ = selected$("Table")
1021 # Can this wordlist be deleted?
1022 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
1023 config.deleteWordlist = 0
1025 config.deleteWordlist = -1
1028 # Check first column name and add Character, Translation, Sound and Show columns if missing
1030 select Table 'wordlist$'
1031 # Hack to correct odd behavior of tables with unicode characters
1032 .firstColumn$ = Get column label: 1
1033 if index_regex(.firstColumn$, "^[^!-~]") > 0
1034 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1035 Set column label (index): 1, .firstColumn$
1038 sgc.numberOfWords = Get number of rows
1039 .characterColumn = Get column index... Character
1040 if not .characterColumn
1041 Append column... Character
1042 for .i to sgc.numberOfWords
1043 Set string value... '.i' Character -
1046 .translationColumn = Get column index... Translation
1047 if not .translationColumn
1048 Append column... Translation
1049 for .i to sgc.numberOfWords
1050 Set string value... '.i' Translation -
1053 .translationColumn = Get column index... Sound
1054 if not .translationColumn
1055 Append column... Sound
1056 for .i to sgc.numberOfWords
1057 Set string value... '.i' Sound -
1060 .showColumn = Get column index... Show
1062 Append column... Show
1063 for .i to sgc.numberOfWords
1064 Set string value... '.i' Show +
1069 # Remove all rows without Pinyin
1070 .numRows = Get number of rows
1072 .rowNum = .numRows - i + 1
1073 .pinyinValue$ = Get value... '.rowNum' Pinyin
1074 .currLength = Get number of rows
1075 if not index_regex(.pinyinValue$, "^[a-zA-Z]")
1079 Set string value: .rowNum, "Pinyin", "bu4"
1083 .numRows = Get number of rows
1084 sgc.numberOfWords = Get number of rows
1086 # Shuffle words if requested
1087 if config.shuffleLists
1091 # Determine number of words actually shown
1093 sgc.currentWordNum = 1
1094 sgc.numberOfDisplayedWords = 0
1096 .show$ = Get value: .i, "Show"
1098 if sgc.currentWord < 1
1099 sgc.currentWord = .i
1101 sgc.numberOfDisplayedWords += 1
1107 #select sgc.allWordLists
1110 # There were no Word Lists
1113 wordlistName$ = wordlistName$+" No Word Lists available"
1115 Create Table with column names... "'wordlistName$'" 1 Pinyin Character Translation Sound
1116 wordlist$ = selected$("Table")
1120 Set string value... '.i' Pinyin ni3hao3
1121 Set string value... '.i' Character 你好
1122 Set string value... '.i' Translation hello
1123 Set string value... '.i' Sound -
1126 Set string value... '.i' Pinyin xie4xie0
1127 Set string value... '.i' Character 谢谢
1128 Set string value... '.i' Translation thanks
1129 Set string value... '.i' Sound -
1132 Set string value... '.i' Pinyin zai4jian4
1133 Set string value... '.i' Character 再见
1134 Set string value... '.i' Translation goodbye
1135 Set string value... '.i' Sound -
1136 # Get rid of empty first row
1139 # Set default values
1140 sgc.numberOfWords = Get number of rows
1142 sgc.numberOfDisplayedWords = Get number of rows
1145 select Table 'wordlist$'
1146 sgc.currentWordlist = selected()
1147 call set_window_title 'buttons$' 'wordlistName$'
1150 procedure read_wordlist .wordlistName$ .dirString$
1151 # Read in full tables
1152 if fileReadable("'.dirString$'/wordlist.Table")
1153 call readTable '.dirString$'/wordlist.Table
1154 .wordlistID = selected ()
1156 Rename... '.wordlistName$'
1157 # Praat wil change the name if it feels like it
1158 .wordlist$ = selected$("Table")
1159 # Add a Sound column if it is not present
1160 .soundIndex = Get column index: "Sound"
1162 Append column: "Sound"
1165 goto EMERGENCYEXITWL
1167 # Handle (legacy) simple word lists
1168 elsif fileReadable("'.dirString$'/wordlist.txt")
1169 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Character Sound Translation
1170 .wordlist$ = selected$("Table")
1171 Read Strings from raw text file... '.dirString$'/wordlist.txt
1172 Rename... RawWordList
1173 .numWordStrings = Get number of strings
1174 for .i to .numWordStrings
1175 select Strings RawWordList
1178 .currentTrans$ = "-"
1179 .currentLine$ = Get string... '.i'
1180 # Remove leading whitespace
1181 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1182 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1183 if .separatorIndex <= 0
1184 .separatorIndex = length(.currentLine$) + 1
1186 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1187 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1188 # There is more on the line, but we do not know what
1189 if length(.currentLine$) > 0
1190 while length(.currentLine$) > 0
1191 .separatorIndex = index_regex(.currentLine$, "[\t;]")
1192 if .separatorIndex <= 0
1193 .separatorIndex = length(.currentLine$)+1
1195 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1196 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1197 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1199 .currentFile$ = .currentItem$
1200 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1202 .currentTrans$ = .currentItem$
1203 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1205 .currentChar$ = .currentItem$
1209 if .currentFile$ = "-"
1210 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1211 .currentFile$ = .currentPinyin$+".spx"
1212 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1213 .currentFile$ = .currentPinyin$+".flac"
1214 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1215 .currentFile$ = .currentPinyin$+".wav"
1216 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1217 .currentFile$ = .currentPinyin$+".mp3"
1222 Set string value... '.i' Pinyin '.currentPinyin$'
1223 Set string value... '.i' Sound '.currentFile$'
1224 Set string value... '.i' Character '.currentChar$'
1225 Set string value... '.i' Translation '.currentTrans$'
1227 select Strings RawWordList
1231 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1232 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Sound
1233 .wordlist$ = selected$("Table")
1234 .tmp = Create Strings as file list... RawWordList '.dirString$'/*
1235 .numWordStrings = Get number of strings
1237 for .j to .numWordStrings
1239 .currentLine$ = Get string... '.j'
1240 .currentFile$ = extractWord$(.currentLine$, "")
1241 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1242 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1243 select sgc.currentWordlist
1246 Set string value... '.i' Pinyin '.currentPinyin$'
1247 Set string value... '.i' Sound '.currentFile$'
1253 select sgc.currentWordlist
1254 elsif startsWith(.dirString$, "*call ")
1255 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1257 .wordlistID = selected()
1258 .wordlist$ = selected$("Table")
1261 goto EMERGENCYEXITWL
1264 # Add the path to the file Sound file names
1266 .numRows = Get number of rows
1268 .soundfile$ = Get value: .w, "Sound"
1269 if index_regex(.soundfile$, "[/\\]") <= 0
1270 if index_regex(.dirString$, "[/\\]$")
1271 .soundfile$ = .dirString$+.soundfile$
1272 elsif index_regex(.dirString$, "[\\]")
1273 .soundfile$ = .dirString$+"\\"+.soundfile$
1275 .soundfile$ = .dirString$+"/"+.soundfile$
1277 Set string value: .w, "Sound", .soundfile$
1281 label EMERGENCYEXITWL
1285 procedure merge_into_wordlist .newTableID .lessonPostfix$
1286 select sgc.currentWordlist
1287 .oldLessonColumn = Get column index: "Lesson"
1290 .numRows = Get number of rows
1291 .lessonColumn = Get column index: "Lesson"
1292 .characterColumn = Get column index: "Character"
1293 .soundColumn = Get column index: "Sound"
1294 .translationColumn = Get column index: "Translation"
1298 .currentTrans$ = "-"
1299 .currentLesson$ = "-"
1302 .currentPinyin$ = Get value: .w, "Pinyin"
1304 .currentFile$ = Get value: .w, "Sound"
1306 if .characterColumn > 0
1307 .currentChar$ = Get value: .w, "Character"
1309 if .translationColumn > 0
1310 .currentTrans$ = Get value: .w, "Translation"
1312 if .lessonColumn > 0
1313 .currentLesson$ = Get value: .w, "Lesson"
1315 select sgc.currentWordlist
1317 .n = Get number of rows
1318 Set string value: .n, "Pinyin", .currentPinyin$
1319 Set string value: .n, "Sound", .currentFile$
1320 Set string value: .n, "Character", .currentChar$
1321 Set string value: .n, "Translation", .currentTrans$
1322 if .oldLessonColumn > 0
1323 if .currentLesson$ = "-" or .currentLesson$ = "" or .currentLesson$ = "?"
1324 Set string value: .n, "Lesson", .lessonPostfix$
1326 Set string value: .n, "Lesson", .currentLesson$+" "+.lessonPostfix$
1334 select sgc.currentWordlist
1336 if sgc.currentWord < 0 or sgc.currentWord > sgc.numberOfWords
1337 if config.shuffleLists
1341 sgc.currentWordNum = 0
1343 while .showCurrent$ = "-" and sgc.currentWord <= sgc.numberOfWords
1344 sgc.currentWord += 1
1345 if sgc.currentWord <= sgc.numberOfWords
1346 .showCurrent$ = Get value... 'sgc.currentWord' Show
1349 if sgc.currentWord > 0
1350 sgc.currentWordNum += 1
1352 sgc.currentWordNum = 0
1357 procedure previous_word
1359 select sgc.currentWordlist
1361 if sgc.currentWord <= 0
1362 if config.shuffleLists
1365 sgc.currentWord = sgc.numberOfWords + 1
1366 sgc.currentWordNum = sgc.numberOfDisplayedWords + 1
1368 while .showCurrent$ = "-" and sgc.currentWord > 0
1369 sgc.currentWord -= 1
1370 if sgc.currentWord > 0
1371 .showCurrent$ = Get value... 'sgc.currentWord' Show
1374 if sgc.currentWord > 0
1375 sgc.currentWordNum -= 1
1377 sgc.currentWordNum = 0
1382 procedure display_word_list_name
1386 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
1387 call wipeArea 'wipeWordlistArea$'
1388 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
1389 .currentFontSize = adjustFontSizeOnHeight.newFontSize
1392 demo Text special... '.xtext' Centre '.ytext' Bottom 'defaultFont$' '.currentFontSize' 0 '.displayWordList$'
1395 call set_font_size 'defaultFontSize'
1398 procedure write_word_list
1399 # Write current Pinyin text
1400 call display_text Black
1402 # Write the current word list name
1403 call display_word_list_name
1406 procedure paint_saveAudio_light
1407 select Table 'config$'
1408 .row = Search column... Label SaveAudio
1410 exit Button Table Config does not have a row with label SaveAudio
1413 .leftX = Get value... '.row' LeftX
1414 .rightX = Get value... '.row' RightX
1415 .lowY = Get value... '.row' LowY
1416 .highY = Get value... '.row' HighY
1417 .buttonColor$ = Get value... '.row' Color
1418 # The button text and symbol
1419 .horWC = demo Horizontal mm to wc... 10.0
1420 .verWC = demo Vertical mm to wc... 10.0
1422 .verCoeff = .horWC / .verWC
1427 .centerX = (.leftX + .rightX)/2
1428 .centerY = .lowY + 0.6*(.highY-.lowY)
1429 .radius = min(.verCoeff * (.highY - .lowY ), (.rightX - .leftX))/3
1430 .wipeRadius = 1.1*.radius
1431 call DrawSaveAudio White '.centerX' '.centerY' '.wipeRadius'
1433 if sgc.saveAudioOn and sgc.saveAudio$ <> ""
1434 call DrawSaveAudio "DarkBlue" '.centerX' '.centerY' '.radius'
1439 # Uninstall word lists
1440 procedure removeWordlist .deletedWordlistName$
1442 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1443 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1445 if .targetDir$ <> ""
1446 Create Strings as file list... DeleteList '.targetDir$'
1447 .numdeleteFiles = Get number of strings
1448 for .i to .numdeleteFiles
1449 .file$ = Get string... '.i'
1450 deleteFile("'.targetDir$'/'.file$'")
1452 filedelete '.targetDir$'
1453 # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1454 # That is, it does not contain funny characters, nor funny names
1455 if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1457 nocheck system rmdir "'.targetDir$'" /s /q
1458 elsif fileReadable(.targetDir$)
1459 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1462 # Remove deleted word list
1463 select Strings DeleteList
1464 plus Table 'wordlist$'
1470 # Install word lists
1471 procedure sgc2wordlist .sourceDir$
1472 if startsWith(.sourceDir$, "preferencesDirectory$")
1473 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1476 .targetDirectory$ = "'sgc2wordlists$'"
1477 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1478 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1479 .numFiles = Get number of strings
1481 select Strings PackageList
1482 .file$ = Get string... '.i'
1483 call readWordlist '.sourceDir$' '.file$'
1486 select Strings PackageList
1491 # Debuggin remarks!!!
1492 # fileReadable(<directory>) does not work in Windows
1493 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1494 # And yet only the 7z decompression has been implemented
1495 windowsUnzipCommand$ = ""
1496 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1497 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" -y e"
1498 windowsUnzipDestDir$ = " -o"
1499 elsif fileReadable("C:\Program Files\WinZip\winzip32.exe")
1500 # !!! Find a way to include the output folder !!!
1501 windowsUnzipCommand$ = "C:\Program Files\WinZip\winzip32.exe"" -min -e -o -j "
1502 windowsUnzipDestDir$ = ""
1504 procedure readWordlist .sourceDir$ .file$
1505 # No use doing anything if the source does not exist
1506 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1507 # What will be the target wordlist directory?
1508 .targetDirectory$ = "'sgc2wordlists$'"
1509 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1513 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1514 # Wordlist directory does not exist, neither locally nor in the preferences
1516 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1517 if .tmpDirs != undefined and .tmpDirs > 0
1518 .numDirs = Get number of strings
1521 .currentString$ = Get string... '.d'
1522 if .currentString$ = .dirname$
1528 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1530 # Move source to destination
1531 # Use this if you want to allow direct loading of ZIP files. Could lead to problems.
1532 # if index(.file$, ".sgc") or index(.file$, ".zip")
1534 if index(.file$, ".sgc")
1535 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1536 # Create wordlist directory
1537 createDirectory(.wordlistDirectory$)
1539 if macintosh or unix
1540 system bash -rc -- 'unzip -j "'.sourceDir$'/'.file$'" -d "'.wordlistDirectory$'"'
1541 elsif windows and windowsUnzipCommand$ <> ""
1542 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1543 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1544 system mkdir "'.winWordListDirectory$'" & 'windowsUnzipCommand$' "'.winSourceDirectory$'" 'windowsUnzipDestDir$'"'.winWordListDirectory$'"
1546 elsif (windows and windowsUnzipCommand$ = "")
1547 # Warn to install 7Zip
1548 call get_feedback_text 'config.language$' InstallUnzip
1549 call convert_praat_to_latin1 'get_feedback_text.text$'
1550 .zipText$ = convert_praat_to_latin1.text$
1551 call write_text_popup 'defaultFont$' 14 '.zipText$'
1552 # Wait for confirmation
1554 call Draw_config_page
1556 # Remove if not valid!
1557 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1558 if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1559 call readTable '.sourceDir$'/'.file$'
1560 if readTable.tableID > 0
1561 select readTable.tableID
1562 # Hack around odd behavior of column index
1564 .firstColumn$ = Get column label: 1
1565 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1566 if .firstColumn$ = "Pinyin"
1569 .pinyinCol = Get column index... Pinyin
1572 # No Pinyin in table
1581 # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1584 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1586 # Remove newly created directory
1587 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1588 if macintosh or unix
1589 system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1591 system rmdir /Q /S "'.winWordListDirectory$'/"
1595 elsif index_regex(.file$, "\.(Table|tsv|csv)")
1596 # Check whether this is a valid table
1597 call readTable '.sourceDir$'/'.file$'
1598 if readTable.tableID > 0
1599 select readTable.tableID
1600 # Hack around odd behavior of column index
1602 .firstColumn$ = Get column label: 1
1603 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1604 if .firstColumn$ = "Pinyin"
1607 .pinyinCol = Get column index... Pinyin
1611 select readTable.tableID
1612 # Create wordlist directory
1613 createDirectory(.wordlistDirectory$)
1615 .extension$ = "Table"
1616 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1618 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1621 select readTable.tableID
1622 Save as tab-separated file: .wordlistFilePath$
1623 if not fileReadable(.wordlistFilePath$)
1627 select readTable.tableID
1630 elsif index_regex(.file$, "\.(?itxt)")
1631 # Check whether this is a valid table
1632 readTable.tableID = nocheck Read Strings from raw text file: "'.sourceDir$'/'.file$'"
1633 if readTable.tableID > 0
1635 # Create wordlist directory
1636 createDirectory(.wordlistDirectory$)
1638 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1640 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1642 select readTable.tableID
1643 Save as raw text file: .wordlistFilePath$
1644 select readTable.tableID
1647 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1648 # Copy wordlist directory
1649 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1651 if macintosh or unix
1652 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1654 createDirectory(.wordlistDirectory$)
1655 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1656 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1657 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1662 # Set current word list to read list
1664 wordlistName$ = .dirname$
1667 .label$ = "!NotAWordlist"
1670 call findLabel '.table$' '.label$'
1671 .row = findLabel.row
1672 select Table '.table$'
1673 .helpText$ = Get value... '.row' Helptext
1674 .printablePath$ = "'.sourceDir$'/'.file$'"
1676 .printablePath$ = replace$("'.sourceDir$'\'.file$'", "\", "\bs", 0)
1678 .filetext$ = replace_regex$(.printablePath$, "_", "\\_ ", 0)
1679 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1680 # Wait for confirmation