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"
400 .numRows = Get number of rows
401 # Do NOT remove all the rows
405 elsif .sound$ <> "" and .sound$ <> "-" and .sound$ <> "?"
406 # Put path before sound examples
407 # If there is no path, add the current wordlist path
408 if index_regex(.sound$, "^(/|~/|[A-Z]:\\)") <= 0
409 .sound$ = localWordlistDir$+"/"+wordlistName$+"/"+.sound$
410 Set string value: .row, "Sound", .sound$
415 Remove column: "Show"
417 Write to table file... '.newWordlistName$'
421 call Draw_button '.table$' '.label$' 0
422 call Draw_config_page
425 procedure processConfigPerfSummary .clickX .clickY .pressed$
427 .label$ = "PerfSummary"
429 call testLoadTable SummaryToneEvaluation
430 if testLoadTable.table > 0
431 call Draw_button '.table$' '.label$' 1
432 call loadTable SummaryToneEvaluation
433 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
435 select Table SummaryToneEvaluation
438 call Draw_button '.table$' '.label$' 0
439 call Draw_config_page
443 # Wipe current performance table and initialize a new one
444 procedure processConfigClearSummary .clickX .clickY .pressed$
446 .label$ = "ClearSummary"
448 call Draw_button '.table$' '.label$' 1
450 if not sgc.saveAudioOn
451 select Table '.table$'
452 call findLabel '.table$' !'.label$'
454 .alertText$ = Get value... 'findLabel.row' Text
455 .confirmKey$ = Get value... 'findLabel.row' Key
456 .popupText$ = Get value... 'findLabel.row' Helptext
458 call write_text_popup 'defaultFont$' 14 '.popupText$'
459 call Draw_button '.table$' '.label$' 2
460 alertText$ = .alertText$
461 call Draw_button '.table$' '.label$' 3
464 # Wait for confirmation
466 if demoInput(.confirmKey$)
468 call initialize_toneevaluation_tables
473 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
474 call Draw_config_page
478 procedure processConfigListPerf .clickX .clickY .pressed$
481 call Draw_button '.table$' '.label$' 1
483 select sgc2.performanceTable
487 call Draw_button '.table$' '.label$' 0
488 call Draw_config_page
491 procedure processConfigOpenPerf .clickX .clickY .pressed$
494 call Draw_button '.table$' '.label$' 1
496 if not sgc.saveAudioOn
498 call findLabel '.table$' !'.label$'
500 select Table '.table$'
501 .openDialogue$ = Get value... '.row' Helptext
502 call convert_praat_to_latin1 '.openDialogue$'
503 .openDialogue$ = convert_praat_to_latin1.text$
504 if variableExists("eval.performance$")
505 .defaultName$= "'eval.performance$'.tsv"
507 .defaultName$= "Performance.tsv"
509 if sgc.savePerf$ <> ""
510 .defaultName$= sgc.savePerf$
512 .performance_Name$ = chooseReadFile$ (.openDialogue$)
513 while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0
514 .performance_Name$ = chooseReadFile$ (.openDialogue$)
516 if .performance_Name$ <> "" and fileReadable(.performance_Name$)
517 sgc.savePerf$ = .performance_Name$
518 call initialize_toneevaluation_tables
520 # Set SaveAudio directory if it is not currently "in use"
521 if not sgc.saveAudioOn
522 sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0)
523 # We are not sure yet that this is actually an audio directory
524 config.audioName$ = ""
529 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
530 call Draw_config_page
533 procedure processConfigSavePerf .clickX .clickY .pressed$
536 call Draw_button '.table$' '.label$' 1
538 if not sgc.saveAudioOn
540 call findLabel '.table$' '.label$'
542 select Table '.table$'
543 .openDialogue$ = Get value... '.row' Helptext
544 call convert_praat_to_latin1 '.openDialogue$'
545 .openDialogue$ = convert_praat_to_latin1.text$
546 if variableExists("eval.performance$")
547 .defaultName$= "'eval.performance$'.tsv"
549 .defaultName$= "Performance.tsv"
551 if sgc.savePerf$ <> ""
552 .defaultName$= sgc.savePerf$
554 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .defaultName$)
555 # Ensure the right extension: ".tsv"
556 while .performance_Name$ <> "" and not endsWith(.performance_Name$, ".tsv")
557 .performance_Name$ = .performance_Name$ + ".tsv"
558 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .performance_Name$)
560 if .performance_Name$ <> ""
561 select sgc2.performanceTable
562 Write to table file... '.performance_Name$'
563 sgc.savePerf$ = .performance_Name$
567 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
568 call Draw_config_page
571 procedure processConfigManual .clickX .clickY .pressed$
574 call Draw_button '.table$' '.label$' 1
575 if fileReadable("ManPages/SpeakGoodChinese_2.man")
576 Read from file... ManPages/SpeakGoodChinese_2.man
578 Go to manual page... SpeakGoodChinese 2
580 # Wait until the manual is put to the background
582 call Draw_button '.table$' '.label$' 0
584 call Draw_config_page
587 procedure processConfigSaveAudio .clickX .clickY .pressed$
589 .label$ = "SaveAudio"
590 call Draw_button '.table$' '.label$' 1
592 if sgc.saveAudioOn = 0
594 call findLabel '.table$' '.label$'
596 select Table '.table$'
597 .openDialogue$ = Get value... '.row' Helptext
598 call convert_praat_to_latin1 '.openDialogue$'
599 .openDialogue$ = convert_praat_to_latin1.text$
601 sgc.saveAudio$ = chooseDirectory$ (.openDialogue$)
602 if sgc.saveAudio$ <> ""
604 .currentPathName$ = replace_regex$(sgc.saveAudio$, "[^/\\]*[/\\]?$", "", 0)
605 .currentDirName$ = replace$(sgc.saveAudio$, .currentPathName$, "", 0)
608 config.clearSummary = -1
609 config.audioName$ = .currentDirName$
611 # Clear performance table and open/create sgc.savePerf$
612 sgc.savePerf$ = "'sgc.saveAudio$'/'.currentDirName$'.tsv"
613 call initialize_toneevaluation_tables
615 call update_toneevaluation_file
616 if sgc.savePerf$ <> "" and initialiseSGC2.toneevaluation_table$ <> ""
617 select sgc2.performanceTable
618 Write to table file: sgc.savePerf$
621 config.audioName$ = ""
627 config.clearSummary = 0
628 # Store current performance table
629 call update_toneevaluation_file
632 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
633 call Draw_config_page
636 ###############################################################
638 # Obligatory button Processing Routines
640 # These MUST be defined
642 ###############################################################
644 procedure processConfigReturn .clickX .clickY .pressed$
647 call Draw_button '.table$' '.label$' 1
648 call write_preferences ""
651 procedure processConfigRefresh .clickX .clickY .pressed$
654 call Draw_config_page
657 procedure processConfigCredits .clickX .clickY .pressed$
660 call Draw_button '.table$' '.label$' 1
661 call write_text_table Credits_'config.language$'
663 call Draw_button '.table$' '.label$' 0
665 call Draw_config_page
668 procedure processConfigHelp .clickX .clickY .pressed$
671 call help_loop '.table$' Draw_config_page
674 ###############################################################
676 # Miscelaneous supporting code
678 ###############################################################
679 procedure install_wordlists_by_name .wordlist_Name$
680 if .wordlist_Name$ <> ""
681 if index_regex(.wordlist_Name$, "(?iwordlist|LICENSE)\.")
682 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\](?iwordlist|LICENSE)\.([^/\\]+)$", "", 0)
683 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
684 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
686 if index_regex(.wordlist_Name$, "[/\\]")
687 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
688 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
689 call readWordlist "'.sourceDir$'" '.file$'
692 if index(.wordlist_Name$, ".")
695 .extension1$ = ".sgc"
696 .extension2$ = ".Table"
697 .extension3$ = ".txt"
698 .extension4$ = ".tsv"
700 for .e from .start to 5
701 .currentExtension$ = .extension'.e'$
702 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
703 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
704 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
705 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
706 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
707 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
708 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
714 # Word lists: It is a VERY good idea to make sure that word-lists
716 procedure load_word_list .localdir$ .relnumber
718 if sgc.allWordLists > 0
719 select sgc.allWordLists
721 sgc.allWordLists = -1
724 # Remove old word list
726 select sgc.currentWordlist
728 call wipeArea 'wipeWordlistArea$'
730 sgc.currentWordlist = -1
734 # Create Table that will recieve the wordlists and directories
735 sgc.allWordLists = Create Table with column names... AllWordLists 0 Name Directory
736 .sgc.currentWordlistRow = 0
738 # First the global word lists
739 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
740 Create Strings as directory list... WordList 'globalwordlists$'
741 .numLists = Get number of strings
743 select Strings WordList
744 .currentName$ = Get string... '.i'
745 if .currentName$ <> "directory.txt"
746 select sgc.allWordLists
747 .listExist = Search column: "Name", .currentName$
750 .sgc.currentWordlistRow = Get number of rows
751 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
752 .currentDirectory$ = globalwordlists$+"/"+.currentName$
753 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
757 select Strings WordList
761 # Now the preferences word lists
762 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
763 Create Strings as directory list... WordList 'sgc2wordlists$'
764 .numLists = Get number of strings
766 select Strings WordList
767 .currentName$ = Get string... '.i'
768 if .currentName$ <> "directory.txt"
769 select sgc.allWordLists
770 .listExist = Search column: "Name", .currentName$
773 .sgc.currentWordlistRow = Get number of rows
774 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
775 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
776 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
780 select Strings WordList
784 # End with the word lists in the distribution
785 call CreateCreateWordlists
786 select Table CreateWordlists
787 .numLists = Get number of rows
789 select Table CreateWordlists
790 .currentName$ = Get value... '.i' Name
791 if .currentName$ <> "directory.txt"
792 select sgc.allWordLists
793 .listExist = Search column: "Name", .currentName$
795 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
796 select sgc.allWordLists
798 .sgc.currentWordlistRow = Get number of rows
799 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
800 .currentDirectory$ = "*call Create'.procedureName$'"
801 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
805 select Table CreateWordlists
808 # Finally, the local word lists
809 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
810 Create Strings as directory list... WordList '.localdir$'
811 .numLists = Get number of strings
813 select Strings WordList
814 .currentName$ = Get string... '.i'
815 if .currentName$ <> "directory.txt"
816 select sgc.allWordLists
817 .listExist = Search column: "Name", .currentName$
820 .sgc.currentWordlistRow = Get number of rows
821 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
822 .currentDirectory$ = .localdir$+"/"+.currentName$
823 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
827 select Strings WordList
831 # Get the position of the current word list
832 select sgc.allWordLists
834 .numLists = Get number of rows
836 if wordlistName$ <> ""
837 select sgc.allWordLists
838 .currentNumber = Search column... Name 'wordlistName$'
841 wordlistNum = .currentNumber + .relnumber
842 if wordlistNum > .numLists
844 elsif wordlistNum < 1 and .numLists > 0
845 wordlistNum = .numLists
847 select sgc.allWordLists
848 wordlistName$ = Get value... 'wordlistNum' Name
849 .dirWordlistName$ = Get value... 'wordlistNum' Directory
850 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
852 # Read in full tables
853 if fileReadable("'.dirString$'/wordlist.Table")
854 call readTable '.dirString$'/wordlist.Table
855 if readTable.tableID > 0
856 Rename... 'wordlistName$'
857 # Praat wil change the name if it feels like it
858 wordlist$ = selected$("Table")
859 # Add a Sound column if it is not present
860 .soundIndex = Get column index: "Sound"
862 Append column: "Sound"
868 # Handle (legacy) simple word lists
869 elsif fileReadable("'.dirString$'/wordlist.txt")
870 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
871 wordlist$ = selected$("Table")
872 Read Strings from raw text file... '.dirString$'/wordlist.txt
873 Rename... RawWordList
874 .numWordStrings = Get number of strings
875 for .i to .numWordStrings
876 select Strings RawWordList
880 .currentLine$ = Get string... '.i'
881 # Remove leading whitespace
882 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
883 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
884 if .separatorIndex <= 0
885 .separatorIndex = length(.currentLine$) + 1
887 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
888 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
889 # There is more on the line, but we do not know what
890 if length(.currentLine$) > 0
891 while length(.currentLine$) > 0
892 .separatorIndex = index_regex(.currentLine$, "[\t;]")
893 if .separatorIndex <= 0
894 .separatorIndex = length(.currentLine$)+1
896 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
897 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
898 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
900 .currentFile$ = .currentItem$
901 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
903 .currentTrans$ = .currentItem$
904 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
906 .currentChar$ = .currentItem$
910 if .currentFile$ = "-"
911 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
912 .currentFile$ = .currentPinyin$+".spx"
913 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
914 .currentFile$ = .currentPinyin$+".flac"
915 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
916 .currentFile$ = .currentPinyin$+".wav"
917 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
918 .currentFile$ = .currentPinyin$+".mp3"
921 select Table 'wordlist$'
923 Set string value... '.i' Pinyin '.currentPinyin$'
924 Set string value... '.i' Sound '.currentFile$'
925 Set string value... '.i' Character '.currentChar$'
926 Set string value... '.i' Translation '.currentTrans$'
928 select Strings RawWordList
931 select Table 'wordlist$'
932 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
933 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
934 wordlist$ = selected$("Table")
935 Create Strings as file list... RawWordList '.dirString$'/*
936 .numWordStrings = Get number of strings
938 for .j to .numWordStrings
939 select Strings RawWordList
940 .currentLine$ = Get string... '.j'
941 .currentFile$ = extractWord$(.currentLine$, "")
942 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
943 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
944 select Table 'wordlist$'
947 Set string value... '.i' Pinyin '.currentPinyin$'
948 Set string value... '.i' Sound '.currentFile$'
951 select Strings RawWordList
954 select Table 'wordlist$'
955 elsif startsWith(.dirString$, "*call ")
956 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
958 wordlist$ = selected$("Table")
965 # Can this wordlist be deleted?
966 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
967 config.deleteWordlist = 0
969 config.deleteWordlist = -1
972 # Check first column name and add Character, Translation, Sound and Show columns if missing
974 select Table 'wordlist$'
975 # Hack to correct odd behavior of tables with unicode characters
976 .firstColumn$ = Get column label: 1
977 if index_regex(.firstColumn$, "^[^!-~]") > 0
978 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
979 Set column label (index): 1, .firstColumn$
982 sgc.numberOfWords = Get number of rows
983 .characterColumn = Get column index... Character
984 if not .characterColumn
985 Append column... Character
986 for .i to sgc.numberOfWords
987 Set string value... '.i' Character -
990 .translationColumn = Get column index... Translation
991 if not .translationColumn
992 Append column... Translation
993 for .i to sgc.numberOfWords
994 Set string value... '.i' Translation -
997 .translationColumn = Get column index... Sound
998 if not .translationColumn
999 Append column... Sound
1000 for .i to sgc.numberOfWords
1001 Set string value... '.i' Sound -
1004 .showColumn = Get column index... Show
1006 Append column... Show
1007 for .i to sgc.numberOfWords
1008 Set string value... '.i' Show +
1013 # Remove all rows without Pinyin
1014 .numRows = Get number of rows
1016 .rowNum = .numRows - i + 1
1017 .pinyinValue$ = Get value... '.rowNum' Pinyin
1018 .currLength = Get number of rows
1019 if not index_regex(.pinyinValue$, "^[a-zA-Z]")
1023 Set string value: .rowNum, "Pinyin", "bu4"
1027 .numRows = Get number of rows
1028 sgc.numberOfWords = Get number of rows
1030 # Shuffle words if requested
1031 if config.shuffleLists
1035 # Determine number of words actually shown
1037 sgc.currentWordNum = 1
1038 sgc.numberOfDisplayedWords = 0
1040 .show$ = Get value: .i, "Show"
1042 if sgc.currentWord < 1
1043 sgc.currentWord = .i
1045 sgc.numberOfDisplayedWords += 1
1051 #select sgc.allWordLists
1054 # There were no Word Lists
1057 wordlistName$ = wordlistName$+" No Word Lists available"
1059 Create Table with column names... "'wordlistName$'" 1 Pinyin Character Translation Sound
1060 wordlist$ = selected$("Table")
1064 Set string value... '.i' Pinyin ni3hao3
1065 Set string value... '.i' Character 你好
1066 Set string value... '.i' Translation hello
1067 Set string value... '.i' Sound -
1070 Set string value... '.i' Pinyin xie4xie0
1071 Set string value... '.i' Character 谢谢
1072 Set string value... '.i' Translation thanks
1073 Set string value... '.i' Sound -
1076 Set string value... '.i' Pinyin zai4jian4
1077 Set string value... '.i' Character 再见
1078 Set string value... '.i' Translation goodbye
1079 Set string value... '.i' Sound -
1080 # Get rid of empty first row
1083 # Set default values
1084 sgc.numberOfWords = Get number of rows
1086 sgc.numberOfDisplayedWords = Get number of rows
1089 select Table 'wordlist$'
1090 sgc.currentWordlist = selected()
1091 call set_window_title 'buttons$' 'wordlistName$'
1094 procedure read_wordlist .wordlistName$ .dirString$
1095 # Read in full tables
1096 if fileReadable("'.dirString$'/wordlist.Table")
1097 call readTable '.dirString$'/wordlist.Table
1098 .wordlistID = selected ()
1100 Rename... '.wordlistName$'
1101 # Praat wil change the name if it feels like it
1102 .wordlist$ = selected$("Table")
1103 # Add a Sound column if it is not present
1104 .soundIndex = Get column index: "Sound"
1106 Append column: "Sound"
1109 goto EMERGENCYEXITWL
1111 # Handle (legacy) simple word lists
1112 elsif fileReadable("'.dirString$'/wordlist.txt")
1113 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Character Sound Translation
1114 .wordlist$ = selected$("Table")
1115 Read Strings from raw text file... '.dirString$'/wordlist.txt
1116 Rename... RawWordList
1117 .numWordStrings = Get number of strings
1118 for .i to .numWordStrings
1119 select Strings RawWordList
1122 .currentTrans$ = "-"
1123 .currentLine$ = Get string... '.i'
1124 # Remove leading whitespace
1125 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1126 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1127 if .separatorIndex <= 0
1128 .separatorIndex = length(.currentLine$) + 1
1130 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1131 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1132 # There is more on the line, but we do not know what
1133 if length(.currentLine$) > 0
1134 while length(.currentLine$) > 0
1135 .separatorIndex = index_regex(.currentLine$, "[\t;]")
1136 if .separatorIndex <= 0
1137 .separatorIndex = length(.currentLine$)+1
1139 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1140 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1141 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1143 .currentFile$ = .currentItem$
1144 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1146 .currentTrans$ = .currentItem$
1147 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1149 .currentChar$ = .currentItem$
1153 if .currentFile$ = "-"
1154 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1155 .currentFile$ = .currentPinyin$+".spx"
1156 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1157 .currentFile$ = .currentPinyin$+".flac"
1158 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1159 .currentFile$ = .currentPinyin$+".wav"
1160 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1161 .currentFile$ = .currentPinyin$+".mp3"
1166 Set string value... '.i' Pinyin '.currentPinyin$'
1167 Set string value... '.i' Sound '.currentFile$'
1168 Set string value... '.i' Character '.currentChar$'
1169 Set string value... '.i' Translation '.currentTrans$'
1171 select Strings RawWordList
1175 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1176 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Sound
1177 .wordlist$ = selected$("Table")
1178 .tmp = Create Strings as file list... RawWordList '.dirString$'/*
1179 .numWordStrings = Get number of strings
1181 for .j to .numWordStrings
1183 .currentLine$ = Get string... '.j'
1184 .currentFile$ = extractWord$(.currentLine$, "")
1185 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1186 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1187 select sgc.currentWordlist
1190 Set string value... '.i' Pinyin '.currentPinyin$'
1191 Set string value... '.i' Sound '.currentFile$'
1197 select sgc.currentWordlist
1198 elsif startsWith(.dirString$, "*call ")
1199 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1201 .wordlistID = selected()
1202 .wordlist$ = selected$("Table")
1205 goto EMERGENCYEXITWL
1208 # Add the path to the file Sound file names
1210 .numRows = Get number of rows
1212 .soundfile$ = Get value: .w, "Sound"
1213 if index_regex(.soundfile$, "[/\\]") <= 0
1214 if index_regex(.dirString$, "[/\\]$")
1215 .soundfile$ = .dirString$+.soundfile$
1216 elsif index_regex(.dirString$, "[\\]")
1217 .soundfile$ = .dirString$+"\\"+.soundfile$
1219 .soundfile$ = .dirString$+"/"+.soundfile$
1221 Set string value: .w, "Sound", .soundfile$
1225 label EMERGENCYEXITWL
1229 procedure merge_into_wordlist .newTableID .lessonPostfix$
1230 select sgc.currentWordlist
1231 .oldLessonColumn = Get column index: "Lesson"
1234 .numRows = Get number of rows
1235 .lessonColumn = Get column index: "Lesson"
1236 .characterColumn = Get column index: "Character"
1237 .soundColumn = Get column index: "Sound"
1238 .translationColumn = Get column index: "Translation"
1242 .currentTrans$ = "-"
1243 .currentLesson$ = "-"
1246 .currentPinyin$ = Get value: .w, "Pinyin"
1248 .currentFile$ = Get value: .w, "Sound"
1250 if .characterColumn > 0
1251 .currentChar$ = Get value: .w, "Character"
1253 if .translationColumn > 0
1254 .currentTrans$ = Get value: .w, "Translation"
1256 if .lessonColumn > 0
1257 .currentLesson$ = Get value: .w, "Lesson"
1259 select sgc.currentWordlist
1261 .n = Get number of rows
1262 Set string value: .n, "Pinyin", .currentPinyin$
1263 Set string value: .n, "Sound", .currentFile$
1264 Set string value: .n, "Character", .currentChar$
1265 Set string value: .n, "Translation", .currentTrans$
1266 if .oldLessonColumn > 0
1267 if .currentLesson$ = "-" or .currentLesson$ = "" or .currentLesson$ = "?"
1268 Set string value: .n, "Lesson", .lessonPostfix$
1270 Set string value: .n, "Lesson", .currentLesson$+" "+.lessonPostfix$
1278 select sgc.currentWordlist
1280 if sgc.currentWord < 0 or sgc.currentWord > sgc.numberOfWords
1281 if config.shuffleLists
1285 sgc.currentWordNum = 0
1287 while .showCurrent$ = "-" and sgc.currentWord <= sgc.numberOfWords
1288 sgc.currentWord += 1
1289 if sgc.currentWord <= sgc.numberOfWords
1290 .showCurrent$ = Get value... 'sgc.currentWord' Show
1293 if sgc.currentWord > 0
1294 sgc.currentWordNum += 1
1296 sgc.currentWordNum = 0
1301 procedure previous_word
1303 select sgc.currentWordlist
1305 if sgc.currentWord <= 0
1306 if config.shuffleLists
1309 sgc.currentWord = sgc.numberOfWords + 1
1310 sgc.currentWordNum = sgc.numberOfDisplayedWords + 1
1312 while .showCurrent$ = "-" and sgc.currentWord > 0
1313 sgc.currentWord -= 1
1314 if sgc.currentWord > 0
1315 .showCurrent$ = Get value... 'sgc.currentWord' Show
1318 if sgc.currentWord > 0
1319 sgc.currentWordNum -= 1
1321 sgc.currentWordNum = 0
1326 procedure display_word_list_name
1330 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
1331 call wipeArea 'wipeWordlistArea$'
1332 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
1333 .currentFontSize = adjustFontSizeOnHeight.newFontSize
1336 demo Text special... '.xtext' Centre '.ytext' Bottom 'defaultFont$' '.currentFontSize' 0 '.displayWordList$'
1339 call set_font_size 'defaultFontSize'
1342 procedure write_word_list
1343 # Write current Pinyin text
1344 call display_text Black
1346 # Write the current word list name
1347 call display_word_list_name
1350 procedure paint_saveAudio_light
1351 select Table 'config$'
1352 .row = Search column... Label SaveAudio
1354 exit Button Table Config does not have a row with label SaveAudio
1357 .leftX = Get value... '.row' LeftX
1358 .rightX = Get value... '.row' RightX
1359 .lowY = Get value... '.row' LowY
1360 .highY = Get value... '.row' HighY
1361 .buttonColor$ = Get value... '.row' Color
1362 # The button text and symbol
1363 .horWC = demo Horizontal mm to wc... 10.0
1364 .verWC = demo Vertical mm to wc... 10.0
1366 .verCoeff = .horWC / .verWC
1371 .centerX = (.leftX + .rightX)/2
1372 .centerY = .lowY + 0.6*(.highY-.lowY)
1373 .radius = min(.verCoeff * (.highY - .lowY ), (.rightX - .leftX))/3
1374 .wipeRadius = 1.1*.radius
1375 call DrawSaveAudio White '.centerX' '.centerY' '.wipeRadius'
1377 if sgc.saveAudioOn and sgc.saveAudio$ <> ""
1378 call DrawSaveAudio "DarkBlue" '.centerX' '.centerY' '.radius'
1383 # Uninstall word lists
1384 procedure removeWordlist .deletedWordlistName$
1386 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1387 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1389 if .targetDir$ <> ""
1390 Create Strings as file list... DeleteList '.targetDir$'
1391 .numdeleteFiles = Get number of strings
1392 for .i to .numdeleteFiles
1393 .file$ = Get string... '.i'
1394 deleteFile("'.targetDir$'/'.file$'")
1396 filedelete '.targetDir$'
1397 # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1398 # That is, it does not contain funny characters, nor funny names
1399 if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1401 nocheck system rmdir "'.targetDir$'" /s /q
1402 elsif fileReadable(.targetDir$)
1403 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1406 # Remove deleted word list
1407 select Strings DeleteList
1408 plus Table 'wordlist$'
1414 # Install word lists
1415 procedure sgc2wordlist .sourceDir$
1416 if startsWith(.sourceDir$, "preferencesDirectory$")
1417 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1420 .targetDirectory$ = "'sgc2wordlists$'"
1421 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1422 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1423 .numFiles = Get number of strings
1425 select Strings PackageList
1426 .file$ = Get string... '.i'
1427 call readWordlist '.sourceDir$' '.file$'
1430 select Strings PackageList
1435 # Debuggin remarks!!!
1436 # fileReadable(<directory>) does not work in Windows
1437 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1438 # And yet only the 7z decompression has been implemented
1439 windowsUnzipCommand$ = ""
1440 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1441 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" -y e"
1442 windowsUnzipDestDir$ = " -o"
1443 elsif fileReadable("C:\Program Files\WinZip\winzip32.exe")
1444 # !!! Find a way to include the output folder !!!
1445 windowsUnzipCommand$ = "C:\Program Files\WinZip\winzip32.exe"" -min -e -o -j "
1446 windowsUnzipDestDir$ = ""
1448 procedure readWordlist .sourceDir$ .file$
1449 # No use doing anything if the source does not exist
1450 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1451 # What will be the target wordlist directory?
1452 .targetDirectory$ = "'sgc2wordlists$'"
1453 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1457 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1458 # Wordlist directory does not exist, neither locally nor in the preferences
1460 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1461 if .tmpDirs != undefined and .tmpDirs > 0
1462 .numDirs = Get number of strings
1465 .currentString$ = Get string... '.d'
1466 if .currentString$ = .dirname$
1472 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1474 # Move source to destination
1475 # Use this if you want to allow direct loading of ZIP files. Could lead to problems.
1476 # if index(.file$, ".sgc") or index(.file$, ".zip")
1478 if index(.file$, ".sgc")
1479 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1480 # Create wordlist directory
1481 createDirectory(.wordlistDirectory$)
1483 if macintosh or unix
1484 system bash -rc -- 'unzip -j "'.sourceDir$'/'.file$'" -d "'.wordlistDirectory$'"'
1485 elsif windows and windowsUnzipCommand$ <> ""
1486 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1487 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1488 system mkdir "'.winWordListDirectory$'" & 'windowsUnzipCommand$' "'.winSourceDirectory$'" 'windowsUnzipDestDir$'"'.winWordListDirectory$'"
1490 elsif (windows and windowsUnzipCommand$ = "")
1491 # Warn to install 7Zip
1492 call get_feedback_text 'config.language$' InstallUnzip
1493 call convert_praat_to_latin1 'get_feedback_text.text$'
1494 .zipText$ = convert_praat_to_latin1.text$
1495 call write_text_popup 'defaultFont$' 14 '.zipText$'
1496 # Wait for confirmation
1498 call Draw_config_page
1500 # Remove if not valid!
1501 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1502 if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1503 call readTable '.sourceDir$'/'.file$'
1504 if readTable.tableID > 0
1505 select readTable.tableID
1506 # Hack around odd behavior of column index
1508 .firstColumn$ = Get column label: 1
1509 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1510 if .firstColumn$ = "Pinyin"
1513 .pinyinCol = Get column index... Pinyin
1516 # No Pinyin in table
1525 # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1528 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1530 # Remove newly created directory
1531 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1532 if macintosh or unix
1533 system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1535 system rmdir /Q /S "'.winWordListDirectory$'/"
1539 elsif index_regex(.file$, "\.(Table|tsv|csv)")
1540 # Check whether this is a valid table
1541 call readTable '.sourceDir$'/'.file$'
1542 if readTable.tableID > 0
1543 select readTable.tableID
1544 # Hack around odd behavior of column index
1546 .firstColumn$ = Get column label: 1
1547 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1548 if .firstColumn$ = "Pinyin"
1551 .pinyinCol = Get column index... Pinyin
1555 select readTable.tableID
1556 # Create wordlist directory
1557 createDirectory(.wordlistDirectory$)
1559 .extension$ = "Table"
1560 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1562 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1565 select readTable.tableID
1566 Save as tab-separated file: .wordlistFilePath$
1567 if not fileReadable(.wordlistFilePath$)
1571 select readTable.tableID
1574 elsif index_regex(.file$, "\.(?itxt)")
1575 # Check whether this is a valid table
1576 readTable.tableID = nocheck Read Strings from raw text file: "'.sourceDir$'/'.file$'"
1577 if readTable.tableID > 0
1579 # Create wordlist directory
1580 createDirectory(.wordlistDirectory$)
1582 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1584 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1586 select readTable.tableID
1587 Save as raw text file: .wordlistFilePath$
1588 select readTable.tableID
1591 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1592 # Copy wordlist directory
1593 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1595 if macintosh or unix
1596 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1598 createDirectory(.wordlistDirectory$)
1599 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1600 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1601 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1606 # Set current word list to read list
1608 wordlistName$ = .dirname$
1611 .label$ = "!NotAWordlist"
1614 call findLabel '.table$' '.label$'
1615 .row = findLabel.row
1616 select Table '.table$'
1617 .helpText$ = Get value... '.row' Helptext
1618 .printablePath$ = "'.sourceDir$'/'.file$'"
1620 .printablePath$ = replace$("'.sourceDir$'\'.file$'", "\", "\bs", 0)
1622 .filetext$ = replace_regex$(.printablePath$, "_", "\\_ ", 0)
1623 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1624 # Wait for confirmation