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$'
839 if .currentNumber <= 0
844 wordlistNum = .currentNumber + .relnumber
845 if wordlistNum > .numLists
847 elsif wordlistNum < 1 and .numLists > 0
848 wordlistNum = .numLists
850 select sgc.allWordLists
851 wordlistName$ = Get value... 'wordlistNum' Name
852 .dirWordlistName$ = Get value... 'wordlistNum' Directory
853 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
855 # Read in full tables
856 if fileReadable("'.dirString$'/wordlist.Table")
857 call readTable '.dirString$'/wordlist.Table
858 if readTable.tableID > 0
859 Rename... 'wordlistName$'
860 # Praat wil change the name if it feels like it
861 wordlist$ = selected$("Table")
862 # Add a Sound column if it is not present
863 .soundIndex = Get column index: "Sound"
865 Append column: "Sound"
871 # Handle (legacy) simple word lists
872 elsif fileReadable("'.dirString$'/wordlist.txt")
873 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
874 wordlist$ = selected$("Table")
875 Read Strings from raw text file... '.dirString$'/wordlist.txt
876 Rename... RawWordList
877 .numWordStrings = Get number of strings
878 for .i to .numWordStrings
879 select Strings RawWordList
883 .currentLine$ = Get string... '.i'
884 # Remove leading whitespace
885 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
886 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
887 if .separatorIndex <= 0
888 .separatorIndex = length(.currentLine$) + 1
890 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
891 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
892 # There is more on the line, but we do not know what
893 if length(.currentLine$) > 0
894 while length(.currentLine$) > 0
895 .separatorIndex = index_regex(.currentLine$, "[\t;]")
896 if .separatorIndex <= 0
897 .separatorIndex = length(.currentLine$)+1
899 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
900 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
901 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
903 .currentFile$ = .currentItem$
904 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
906 .currentTrans$ = .currentItem$
907 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
909 .currentChar$ = .currentItem$
913 if .currentFile$ = "-"
914 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
915 .currentFile$ = .currentPinyin$+".spx"
916 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
917 .currentFile$ = .currentPinyin$+".flac"
918 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
919 .currentFile$ = .currentPinyin$+".wav"
920 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
921 .currentFile$ = .currentPinyin$+".mp3"
924 select Table 'wordlist$'
926 Set string value... '.i' Pinyin '.currentPinyin$'
927 Set string value... '.i' Sound '.currentFile$'
928 Set string value... '.i' Character '.currentChar$'
929 Set string value... '.i' Translation '.currentTrans$'
931 select Strings RawWordList
934 select Table 'wordlist$'
935 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
936 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
937 wordlist$ = selected$("Table")
938 Create Strings as file list... RawWordList '.dirString$'/*
939 .numWordStrings = Get number of strings
941 for .j to .numWordStrings
942 select Strings RawWordList
943 .currentLine$ = Get string... '.j'
944 .currentFile$ = extractWord$(.currentLine$, "")
945 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
946 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
947 select Table 'wordlist$'
950 Set string value... '.i' Pinyin '.currentPinyin$'
951 Set string value... '.i' Sound '.currentFile$'
954 select Strings RawWordList
957 select Table 'wordlist$'
958 elsif startsWith(.dirString$, "*call ")
959 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
961 wordlist$ = selected$("Table")
968 # Can this wordlist be deleted?
969 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
970 config.deleteWordlist = 0
972 config.deleteWordlist = -1
975 # Check first column name and add Character, Translation, Sound and Show columns if missing
977 select Table 'wordlist$'
978 # Hack to correct odd behavior of tables with unicode characters
979 .firstColumn$ = Get column label: 1
980 if index_regex(.firstColumn$, "^[^!-~]") > 0
981 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
982 Set column label (index): 1, .firstColumn$
985 sgc.numberOfWords = Get number of rows
986 .characterColumn = Get column index... Character
987 if not .characterColumn
988 Append column... Character
989 for .i to sgc.numberOfWords
990 Set string value... '.i' Character -
993 .translationColumn = Get column index... Translation
994 if not .translationColumn
995 Append column... Translation
996 for .i to sgc.numberOfWords
997 Set string value... '.i' Translation -
1000 .translationColumn = Get column index... Sound
1001 if not .translationColumn
1002 Append column... Sound
1003 for .i to sgc.numberOfWords
1004 Set string value... '.i' Sound -
1007 .showColumn = Get column index... Show
1009 Append column... Show
1010 for .i to sgc.numberOfWords
1011 Set string value... '.i' Show +
1016 # Remove all rows without Pinyin
1017 .numRows = Get number of rows
1019 .rowNum = .numRows - i + 1
1020 .pinyinValue$ = Get value... '.rowNum' Pinyin
1021 .currLength = Get number of rows
1022 if not index_regex(.pinyinValue$, "^[a-zA-Z]")
1026 Set string value: .rowNum, "Pinyin", "bu4"
1030 .numRows = Get number of rows
1031 sgc.numberOfWords = Get number of rows
1033 # Shuffle words if requested
1034 if config.shuffleLists
1038 # Determine number of words actually shown
1040 sgc.currentWordNum = 1
1041 sgc.numberOfDisplayedWords = 0
1043 .show$ = Get value: .i, "Show"
1045 if sgc.currentWord < 1
1046 sgc.currentWord = .i
1048 sgc.numberOfDisplayedWords += 1
1054 #select sgc.allWordLists
1057 # There were no Word Lists
1060 wordlistName$ = wordlistName$+" No Word Lists available"
1062 Create Table with column names... "'wordlistName$'" 1 Pinyin Character Translation Sound
1063 wordlist$ = selected$("Table")
1067 Set string value... '.i' Pinyin ni3hao3
1068 Set string value... '.i' Character 你好
1069 Set string value... '.i' Translation hello
1070 Set string value... '.i' Sound -
1073 Set string value... '.i' Pinyin xie4xie0
1074 Set string value... '.i' Character 谢谢
1075 Set string value... '.i' Translation thanks
1076 Set string value... '.i' Sound -
1079 Set string value... '.i' Pinyin zai4jian4
1080 Set string value... '.i' Character 再见
1081 Set string value... '.i' Translation goodbye
1082 Set string value... '.i' Sound -
1083 # Get rid of empty first row
1086 # Set default values
1087 sgc.numberOfWords = Get number of rows
1089 sgc.numberOfDisplayedWords = Get number of rows
1092 select Table 'wordlist$'
1093 sgc.currentWordlist = selected()
1094 call set_window_title 'buttons$' 'wordlistName$'
1097 procedure read_wordlist .wordlistName$ .dirString$
1098 # Read in full tables
1099 if fileReadable("'.dirString$'/wordlist.Table")
1100 call readTable '.dirString$'/wordlist.Table
1101 .wordlistID = selected ()
1103 Rename... '.wordlistName$'
1104 # Praat wil change the name if it feels like it
1105 .wordlist$ = selected$("Table")
1106 # Add a Sound column if it is not present
1107 .soundIndex = Get column index: "Sound"
1109 Append column: "Sound"
1112 goto EMERGENCYEXITWL
1114 # Handle (legacy) simple word lists
1115 elsif fileReadable("'.dirString$'/wordlist.txt")
1116 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Character Sound Translation
1117 .wordlist$ = selected$("Table")
1118 Read Strings from raw text file... '.dirString$'/wordlist.txt
1119 Rename... RawWordList
1120 .numWordStrings = Get number of strings
1121 for .i to .numWordStrings
1122 select Strings RawWordList
1125 .currentTrans$ = "-"
1126 .currentLine$ = Get string... '.i'
1127 # Remove leading whitespace
1128 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1129 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1130 if .separatorIndex <= 0
1131 .separatorIndex = length(.currentLine$) + 1
1133 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1134 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1135 # There is more on the line, but we do not know what
1136 if length(.currentLine$) > 0
1137 while length(.currentLine$) > 0
1138 .separatorIndex = index_regex(.currentLine$, "[\t;]")
1139 if .separatorIndex <= 0
1140 .separatorIndex = length(.currentLine$)+1
1142 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1143 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1144 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1146 .currentFile$ = .currentItem$
1147 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1149 .currentTrans$ = .currentItem$
1150 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1152 .currentChar$ = .currentItem$
1156 if .currentFile$ = "-"
1157 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1158 .currentFile$ = .currentPinyin$+".spx"
1159 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1160 .currentFile$ = .currentPinyin$+".flac"
1161 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1162 .currentFile$ = .currentPinyin$+".wav"
1163 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1164 .currentFile$ = .currentPinyin$+".mp3"
1169 Set string value... '.i' Pinyin '.currentPinyin$'
1170 Set string value... '.i' Sound '.currentFile$'
1171 Set string value... '.i' Character '.currentChar$'
1172 Set string value... '.i' Translation '.currentTrans$'
1174 select Strings RawWordList
1178 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1179 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Sound
1180 .wordlist$ = selected$("Table")
1181 .tmp = Create Strings as file list... RawWordList '.dirString$'/*
1182 .numWordStrings = Get number of strings
1184 for .j to .numWordStrings
1186 .currentLine$ = Get string... '.j'
1187 .currentFile$ = extractWord$(.currentLine$, "")
1188 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1189 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1190 select sgc.currentWordlist
1193 Set string value... '.i' Pinyin '.currentPinyin$'
1194 Set string value... '.i' Sound '.currentFile$'
1200 select sgc.currentWordlist
1201 elsif startsWith(.dirString$, "*call ")
1202 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1204 .wordlistID = selected()
1205 .wordlist$ = selected$("Table")
1208 goto EMERGENCYEXITWL
1211 # Add the path to the file Sound file names
1213 .numRows = Get number of rows
1215 .soundfile$ = Get value: .w, "Sound"
1216 if index_regex(.soundfile$, "[/\\]") <= 0
1217 if index_regex(.dirString$, "[/\\]$")
1218 .soundfile$ = .dirString$+.soundfile$
1219 elsif index_regex(.dirString$, "[\\]")
1220 .soundfile$ = .dirString$+"\\"+.soundfile$
1222 .soundfile$ = .dirString$+"/"+.soundfile$
1224 Set string value: .w, "Sound", .soundfile$
1228 label EMERGENCYEXITWL
1232 procedure merge_into_wordlist .newTableID .lessonPostfix$
1233 select sgc.currentWordlist
1234 .oldLessonColumn = Get column index: "Lesson"
1237 .numRows = Get number of rows
1238 .lessonColumn = Get column index: "Lesson"
1239 .characterColumn = Get column index: "Character"
1240 .soundColumn = Get column index: "Sound"
1241 .translationColumn = Get column index: "Translation"
1245 .currentTrans$ = "-"
1246 .currentLesson$ = "-"
1249 .currentPinyin$ = Get value: .w, "Pinyin"
1251 .currentFile$ = Get value: .w, "Sound"
1253 if .characterColumn > 0
1254 .currentChar$ = Get value: .w, "Character"
1256 if .translationColumn > 0
1257 .currentTrans$ = Get value: .w, "Translation"
1259 if .lessonColumn > 0
1260 .currentLesson$ = Get value: .w, "Lesson"
1262 select sgc.currentWordlist
1264 .n = Get number of rows
1265 Set string value: .n, "Pinyin", .currentPinyin$
1266 Set string value: .n, "Sound", .currentFile$
1267 Set string value: .n, "Character", .currentChar$
1268 Set string value: .n, "Translation", .currentTrans$
1269 if .oldLessonColumn > 0
1270 if .currentLesson$ = "-" or .currentLesson$ = "" or .currentLesson$ = "?"
1271 Set string value: .n, "Lesson", .lessonPostfix$
1273 Set string value: .n, "Lesson", .currentLesson$+" "+.lessonPostfix$
1281 select sgc.currentWordlist
1283 if sgc.currentWord < 0 or sgc.currentWord > sgc.numberOfWords
1284 if config.shuffleLists
1288 sgc.currentWordNum = 0
1290 while .showCurrent$ = "-" and sgc.currentWord <= sgc.numberOfWords
1291 sgc.currentWord += 1
1292 if sgc.currentWord <= sgc.numberOfWords
1293 .showCurrent$ = Get value... 'sgc.currentWord' Show
1296 if sgc.currentWord > 0
1297 sgc.currentWordNum += 1
1299 sgc.currentWordNum = 0
1304 procedure previous_word
1306 select sgc.currentWordlist
1308 if sgc.currentWord <= 0
1309 if config.shuffleLists
1312 sgc.currentWord = sgc.numberOfWords + 1
1313 sgc.currentWordNum = sgc.numberOfDisplayedWords + 1
1315 while .showCurrent$ = "-" and sgc.currentWord > 0
1316 sgc.currentWord -= 1
1317 if sgc.currentWord > 0
1318 .showCurrent$ = Get value... 'sgc.currentWord' Show
1321 if sgc.currentWord > 0
1322 sgc.currentWordNum -= 1
1324 sgc.currentWordNum = 0
1329 procedure display_word_list_name
1333 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
1334 call wipeArea 'wipeWordlistArea$'
1335 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
1336 .currentFontSize = adjustFontSizeOnHeight.newFontSize
1339 demo Text special... '.xtext' Centre '.ytext' Bottom 'defaultFont$' '.currentFontSize' 0 '.displayWordList$'
1342 call set_font_size 'defaultFontSize'
1345 procedure write_word_list
1346 # Write current Pinyin text
1347 call display_text Black
1349 # Write the current word list name
1350 call display_word_list_name
1353 procedure paint_saveAudio_light
1354 select Table 'config$'
1355 .row = Search column... Label SaveAudio
1357 exit Button Table Config does not have a row with label SaveAudio
1360 .leftX = Get value... '.row' LeftX
1361 .rightX = Get value... '.row' RightX
1362 .lowY = Get value... '.row' LowY
1363 .highY = Get value... '.row' HighY
1364 .buttonColor$ = Get value... '.row' Color
1365 # The button text and symbol
1366 .horWC = demo Horizontal mm to wc... 10.0
1367 .verWC = demo Vertical mm to wc... 10.0
1369 .verCoeff = .horWC / .verWC
1374 .centerX = (.leftX + .rightX)/2
1375 .centerY = .lowY + 0.6*(.highY-.lowY)
1376 .radius = min(.verCoeff * (.highY - .lowY ), (.rightX - .leftX))/3
1377 .wipeRadius = 1.1*.radius
1378 call DrawSaveAudio White '.centerX' '.centerY' '.wipeRadius'
1380 if sgc.saveAudioOn and sgc.saveAudio$ <> ""
1381 call DrawSaveAudio "DarkBlue" '.centerX' '.centerY' '.radius'
1386 # Uninstall word lists
1387 procedure removeWordlist .deletedWordlistName$
1389 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1390 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1392 if .targetDir$ <> ""
1393 Create Strings as file list... DeleteList '.targetDir$'
1394 .numdeleteFiles = Get number of strings
1395 for .i to .numdeleteFiles
1396 .file$ = Get string... '.i'
1397 deleteFile("'.targetDir$'/'.file$'")
1399 filedelete '.targetDir$'
1400 # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1401 # That is, it does not contain funny characters, nor funny names
1402 if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1404 nocheck system rmdir "'.targetDir$'" /s /q
1405 elsif fileReadable(.targetDir$)
1406 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1409 # Remove deleted word list
1410 select Strings DeleteList
1411 plus Table 'wordlist$'
1417 # Install word lists
1418 procedure sgc2wordlist .sourceDir$
1419 if startsWith(.sourceDir$, "preferencesDirectory$")
1420 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1423 .targetDirectory$ = "'sgc2wordlists$'"
1424 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1425 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1426 .numFiles = Get number of strings
1428 select Strings PackageList
1429 .file$ = Get string... '.i'
1430 call readWordlist '.sourceDir$' '.file$'
1433 select Strings PackageList
1438 # Debuggin remarks!!!
1439 # fileReadable(<directory>) does not work in Windows
1440 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1441 # And yet only the 7z decompression has been implemented
1442 windowsUnzipCommand$ = ""
1443 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1444 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" -y e"
1445 windowsUnzipDestDir$ = " -o"
1446 elsif fileReadable("C:\Program Files\WinZip\winzip32.exe")
1447 # !!! Find a way to include the output folder !!!
1448 windowsUnzipCommand$ = "C:\Program Files\WinZip\winzip32.exe"" -min -e -o -j "
1449 windowsUnzipDestDir$ = ""
1451 procedure readWordlist .sourceDir$ .file$
1452 # No use doing anything if the source does not exist
1453 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1454 # What will be the target wordlist directory?
1455 .targetDirectory$ = "'sgc2wordlists$'"
1456 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1460 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1461 # Wordlist directory does not exist, neither locally nor in the preferences
1463 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1464 if .tmpDirs != undefined and .tmpDirs > 0
1465 .numDirs = Get number of strings
1468 .currentString$ = Get string... '.d'
1469 if .currentString$ = .dirname$
1475 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1477 # Move source to destination
1478 # Use this if you want to allow direct loading of ZIP files. Could lead to problems.
1479 # if index(.file$, ".sgc") or index(.file$, ".zip")
1481 if index(.file$, ".sgc")
1482 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1483 # Create wordlist directory
1484 createDirectory(.wordlistDirectory$)
1486 if macintosh or unix
1487 system bash -rc -- 'unzip -j "'.sourceDir$'/'.file$'" -d "'.wordlistDirectory$'"'
1488 elsif windows and windowsUnzipCommand$ <> ""
1489 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1490 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1491 system mkdir "'.winWordListDirectory$'" & 'windowsUnzipCommand$' "'.winSourceDirectory$'" 'windowsUnzipDestDir$'"'.winWordListDirectory$'"
1493 elsif (windows and windowsUnzipCommand$ = "")
1494 # Warn to install 7Zip
1495 call get_feedback_text 'config.language$' InstallUnzip
1496 call convert_praat_to_latin1 'get_feedback_text.text$'
1497 .zipText$ = convert_praat_to_latin1.text$
1498 call write_text_popup 'defaultFont$' 14 '.zipText$'
1499 # Wait for confirmation
1501 call Draw_config_page
1503 # Remove if not valid!
1504 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1505 if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1506 call readTable '.sourceDir$'/'.file$'
1507 if readTable.tableID > 0
1508 select readTable.tableID
1509 # Hack around odd behavior of column index
1511 .firstColumn$ = Get column label: 1
1512 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1513 if .firstColumn$ = "Pinyin"
1516 .pinyinCol = Get column index... Pinyin
1519 # No Pinyin in table
1528 # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1531 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1533 # Remove newly created directory
1534 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1535 if macintosh or unix
1536 system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1538 system rmdir /Q /S "'.winWordListDirectory$'/"
1542 elsif index_regex(.file$, "\.(Table|tsv|csv)")
1543 # Check whether this is a valid table
1544 call readTable '.sourceDir$'/'.file$'
1545 if readTable.tableID > 0
1546 select readTable.tableID
1547 # Hack around odd behavior of column index
1549 .firstColumn$ = Get column label: 1
1550 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1551 if .firstColumn$ = "Pinyin"
1554 .pinyinCol = Get column index... Pinyin
1558 select readTable.tableID
1559 # Create wordlist directory
1560 createDirectory(.wordlistDirectory$)
1562 .extension$ = "Table"
1563 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1565 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1568 select readTable.tableID
1569 Save as tab-separated file: .wordlistFilePath$
1570 if not fileReadable(.wordlistFilePath$)
1574 select readTable.tableID
1577 elsif index_regex(.file$, "\.(?itxt)")
1578 # Check whether this is a valid table
1579 readTable.tableID = nocheck Read Strings from raw text file: "'.sourceDir$'/'.file$'"
1580 if readTable.tableID > 0
1582 # Create wordlist directory
1583 createDirectory(.wordlistDirectory$)
1585 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1587 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1589 select readTable.tableID
1590 Save as raw text file: .wordlistFilePath$
1591 select readTable.tableID
1594 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1595 # Copy wordlist directory
1596 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1598 if macintosh or unix
1599 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1601 createDirectory(.wordlistDirectory$)
1602 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1603 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1604 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1609 # Set current word list to read list
1611 wordlistName$ = .dirname$
1614 .label$ = "!NotAWordlist"
1617 call findLabel '.table$' '.label$'
1618 .row = findLabel.row
1619 select Table '.table$'
1620 .helpText$ = Get value... '.row' Helptext
1621 .printablePath$ = "'.sourceDir$'/'.file$'"
1623 .printablePath$ = replace$("'.sourceDir$'\'.file$'", "\", "\bs", 0)
1625 .filetext$ = replace_regex$(.printablePath$, "_", "\\_ ", 0)
1626 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1627 # Wait for confirmation