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'
166 # Disable or enable voices button!
167 .voiceButton = .displayButton
171 call Draw_button Config Voice '.voiceButton'
174 procedure processConfigStrict .clickX .clickY .pressed$
177 .tmp = 'config.strict$'
179 if .tmp > sgc.highestLevel
182 config.strict$ = "'.tmp'"
188 # Change TTS for Strict!
190 call Draw_button '.table$' '.label$' '.displayButton'
193 procedure processConfigVoice .clickX .clickY .pressed$
198 if .tmp > sgc.lastVoice
202 if sgc2.synthesizer <= 0 or config.synthesis$ = "" or config.synthesis$ = "_DISABLED_"
207 call set_TTS_parameters
210 call Draw_button '.table$' '.label$' '.displayButton'
213 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
215 .label$ = "DisplayPinyin"
216 config.displayPinyin = not config.displayPinyin
217 .displayButton = 2*config.displayPinyin
218 call Draw_button '.table$' '.label$' '.displayButton'
221 procedure processConfigDisplayChar .clickX .clickY .pressed$
223 .label$ = "DisplayChar"
224 config.displayChar = not config.displayChar
225 .displayButton = 2*config.displayChar
226 call Draw_button '.table$' '.label$' '.displayButton'
229 procedure processConfigDisplayTrans .clickX .clickY .pressed$
231 .label$ = "DisplayTrans"
232 config.displayTrans = not config.displayTrans
233 .displayButton = 2*config.displayTrans
234 call Draw_button '.table$' '.label$' '.displayButton'
237 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
239 .label$ = "DisplayNumbers"
240 config.displayNumbers = not config.displayNumbers
241 .displayButton = 2*config.displayNumbers
242 call Draw_button '.table$' '.label$' '.displayButton'
245 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
247 .label$ = "Language_'.language$'"
248 call processLanguageCodes '.table$' '.label$'
251 procedure processConfigShowBackground .clickX .clickY .pressed$
253 .label$ = "ShowBackground"
254 config.showBackground = not config.showBackground
255 .displayButton = 2*config.showBackground
256 call Draw_button '.table$' '.label$' '.displayButton'
259 procedure processConfigInput .input$ .clickX .clickY .pressed$
261 .label$ = "Input_'.input$'"
262 call Draw_button '.table$' Input_'config.input$' 0
263 config.input$ = .input$
264 call Draw_button '.table$' Input_'config.input$' 2
267 procedure processConfigRegister .register .clickX .clickY .pressed$
269 .label$ = "Register_'.register'"
270 call setRegisterFromLabel '.table$' '.label$'
273 procedure setRegisterFromLabel .table$ .label$
274 call Draw_button '.table$' Register_'config.register' 0
275 call Draw_button '.table$' '.label$' 2
276 # Someone might have to use more than 3 chars for the config.register code
277 .numChars = length(.label$) - length("Register_")
278 .registerText$ = right$(.label$, .numChars)
279 config.register = '.registerText$'
282 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
284 .label$ = "DeleteWordlist"
286 # Do not process undeletable word lists, only those stored in the
287 # preferencesDirectory$ can be deleted
288 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
289 call findLabel '.table$' !'.label$'
291 select Table '.table$'
292 .alertText$ = Get value... 'findLabel.row' Text
293 .confirmKey$ = Get value... 'findLabel.row' Key
294 .popupText$ = Get value... 'findLabel.row' Helptext
296 exit Cannot find delete directive: '.table$' !'.label$'
298 call write_text_popup 'defaultFont$' 14 '.popupText$'
299 call Draw_button '.table$' '.label$' 2
300 alertText$ = .alertText$
301 call Draw_button '.table$' '.label$' 3
304 # Wait for confirmation
306 if demoInput(.confirmKey$)
307 .deleteWordListDir$ = wordlistName$
308 call load_word_list "'localWordlistDir$'" 1
309 call removeWordlist '.deleteWordListDir$'
310 call load_word_list "'localWordlistDir$'" 0
312 call Draw_button '.table$' '.label$' 0
313 call Draw_config_page
317 wordlistTag$ = "Wordlist name"
318 procedure processConfigInstallWordlist .clickX .clickY .pressed$
320 .label$ = "InstallWordlist"
321 call Draw_button '.table$' '.label$' 1
323 # Do not use the automatic sgc list option, ask for a wordlist NAME
325 call findLabel '.table$' '.label$'
327 select Table '.table$'
328 .openDialogue$ = Get value... '.row' Helptext
329 call convert_praat_to_latin1 '.openDialogue$'
330 .openDialogue$ = convert_praat_to_latin1.text$
331 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
332 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
333 beginPause(.openDialogue$)
334 sentence (wordlistTag$, "")
335 clicked = endPause ("Cancel", "Open", 2, 1)
338 .wordlist_Name$ = '.wordlistButton$'$
340 call install_wordlists_by_name '.wordlist_Name$'
342 call sgc2wordlist 'homeDirectory$'
343 call sgc2wordlist 'homeDirectory$'/Downloads
344 call sgc2wordlist 'homeDirectory$'/Documents
345 call sgc2wordlist 'homeDirectory$'/My Documents
346 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
347 call sgc2wordlist 'homeDirectory$'/Desktop
348 call sgc2wordlist 'preferencesAppDir$'
350 call load_word_list "'localWordlistDir$'" 0
351 call Draw_button '.table$' '.label$' 0
352 call Draw_config_page
355 procedure processConfigOpenWordlist .clickX .clickY .pressed$
357 .label$ = "OpenWordlist"
358 call Draw_button '.table$' '.label$' 1
361 call findLabel '.table$' '.label$'
363 select Table '.table$'
364 .openDialogue$ = Get value... '.row' Helptext
365 call convert_praat_to_latin1 '.openDialogue$'
366 .openDialogue$ = convert_praat_to_latin1.text$
368 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
369 call install_wordlists_by_name '.wordlist_Name$'
370 call load_word_list "'localWordlistDir$'" 0
371 call Draw_button '.table$' '.label$' 0
372 call Draw_config_page
375 procedure processConfigExportWordlist .clickX .clickY .pressed$
377 .label$ = "ExportWordlist"
379 call Draw_button '.table$' '.label$' 1
382 call findLabel '.table$' '.label$'
384 select Table '.table$'
385 .openDialogue$ = Get value... '.row' Helptext
386 call convert_praat_to_latin1 '.openDialogue$'
387 .openDialogue$ = convert_praat_to_latin1.text$
389 .newWordlistName$ = "'wordlist$'_SGC2"
391 # Ensure the right extension: ".tsv"
392 while .newWordlistName$ <> "" and not endsWith(.newWordlistName$, ".tsv")
393 .newWordlistName$ = .newWordlistName$ + ".tsv"
394 .newWordlistName$ = chooseWriteFile$ (.openDialogue$, .newWordlistName$)
396 .tableName$ = replace_regex$(.newWordlistName$, "^.*[/\\:]([^/\\:]+)\.(tsv|Table)$", "\1", 0)
397 call testLoadTable '.tableName$'
398 if testLoadTable.table > 0
399 call loadTable '.tableName$'
400 .tmpTable = selected()
401 Save as tab-separated file: .newWordlistName$
403 .newWordlistName$ = ""
407 if .newWordlistName$ <> ""
408 select sgc.currentWordlist
409 .tmpSaveWordlist = Copy: "SaveWordlist"
410 # Get the table sorted
411 .lessonCol = Get column index: "Lesson"
413 Sort rows... Lesson Pinyin
418 # Remove all words that are deselected
419 .showCol = Get column index: "Show"
421 .numRows = Get number of rows
424 .show$ = Get value: .row, "Show"
425 .sound$ = Get value: .row, "Sound"
427 .numRows = Get number of rows
428 # Do NOT remove all the rows
432 elsif .sound$ <> "" and .sound$ <> "-" and .sound$ <> "?"
433 # Put path before sound examples
434 # If there is no path, add the current wordlist path
435 if index_regex(.sound$, "^(/|~/|[A-Z]:\\)") <= 0
436 .sound$ = localWordlistDir$+"/"+wordlistName$+"/"+.sound$
437 Set string value: .row, "Sound", .sound$
442 Remove column: "Show"
444 Write to table file... '.newWordlistName$'
448 call Draw_button '.table$' '.label$' 0
449 call Draw_config_page
452 procedure processConfigPerfSummary .clickX .clickY .pressed$
454 .label$ = "PerfSummary"
456 call testLoadTable SummaryToneEvaluation
457 if testLoadTable.table > 0
458 call Draw_button '.table$' '.label$' 1
459 call loadTable SummaryToneEvaluation
460 call write_tabbed_table SummaryToneEvaluation Evaluation_'config.language$'
462 select Table SummaryToneEvaluation
465 call Draw_button '.table$' '.label$' 0
466 call Draw_config_page
470 # Wipe current performance table and initialize a new one
471 procedure processConfigClearSummary .clickX .clickY .pressed$
473 .label$ = "ClearSummary"
475 call Draw_button '.table$' '.label$' 1
477 if not sgc.saveAudioOn
478 select Table '.table$'
479 call findLabel '.table$' !'.label$'
481 .alertText$ = Get value... 'findLabel.row' Text
482 .confirmKey$ = Get value... 'findLabel.row' Key
483 .popupText$ = Get value... 'findLabel.row' Helptext
485 call write_text_popup 'defaultFont$' 14 '.popupText$'
486 call Draw_button '.table$' '.label$' 2
487 alertText$ = .alertText$
488 call Draw_button '.table$' '.label$' 3
491 # Wait for confirmation
493 if demoInput(.confirmKey$)
495 call initialize_toneevaluation_tables
500 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
501 call Draw_config_page
505 procedure processConfigListPerf .clickX .clickY .pressed$
508 call Draw_button '.table$' '.label$' 1
510 select sgc2.performanceTable
514 call Draw_button '.table$' '.label$' 0
515 call Draw_config_page
518 procedure processConfigOpenPerf .clickX .clickY .pressed$
521 call Draw_button '.table$' '.label$' 1
523 if not sgc.saveAudioOn
525 call findLabel '.table$' !'.label$'
527 select Table '.table$'
528 .openDialogue$ = Get value... '.row' Helptext
529 call convert_praat_to_latin1 '.openDialogue$'
530 .openDialogue$ = convert_praat_to_latin1.text$
531 if variableExists("eval.performance$")
532 .defaultName$= "'eval.performance$'.tsv"
534 .defaultName$= "Performance.tsv"
536 if sgc.savePerf$ <> ""
537 .defaultName$= sgc.savePerf$
539 .performance_Name$ = chooseReadFile$ (.openDialogue$)
540 while .performance_Name$ <> "" and index_regex(.performance_Name$, "\.(tsv|TSV)$") <= 0
541 .performance_Name$ = chooseReadFile$ (.openDialogue$)
543 if .performance_Name$ <> "" and fileReadable(.performance_Name$)
544 sgc.savePerf$ = .performance_Name$
545 call initialize_toneevaluation_tables
547 # Set SaveAudio directory if it is not currently "in use"
548 if not sgc.saveAudioOn
549 sgc.saveAudio$ = replace_regex$(sgc.savePerf$, "[/\\][^/\\]+$", "", 0)
550 # We are not sure yet that this is actually an audio directory
551 config.audioName$ = ""
556 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
557 call Draw_config_page
560 procedure processConfigSavePerf .clickX .clickY .pressed$
563 call Draw_button '.table$' '.label$' 1
565 if not sgc.saveAudioOn
567 call findLabel '.table$' '.label$'
569 select Table '.table$'
570 .openDialogue$ = Get value... '.row' Helptext
571 call convert_praat_to_latin1 '.openDialogue$'
572 .openDialogue$ = convert_praat_to_latin1.text$
573 if variableExists("eval.performance$")
574 .defaultName$= "'eval.performance$'.tsv"
576 .defaultName$= "Performance.tsv"
578 if sgc.savePerf$ <> ""
579 .defaultName$= sgc.savePerf$
581 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .defaultName$)
582 # Ensure the right extension: ".tsv"
583 while .performance_Name$ <> "" and not endsWith(.performance_Name$, ".tsv")
584 .performance_Name$ = .performance_Name$ + ".tsv"
585 .performance_Name$ = chooseWriteFile$ (.openDialogue$, .performance_Name$)
587 if .performance_Name$ <> ""
588 select sgc2.performanceTable
589 Write to table file... '.performance_Name$'
590 sgc.savePerf$ = .performance_Name$
594 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
595 call Draw_config_page
598 procedure processConfigManual .clickX .clickY .pressed$
601 call Draw_button '.table$' '.label$' 1
602 if fileReadable("ManPages/SpeakGoodChinese_2.man")
603 Read from file... ManPages/SpeakGoodChinese_2.man
605 Go to manual page... SpeakGoodChinese 2
607 # Wait until the manual is put to the background
609 call Draw_button '.table$' '.label$' 0
611 call Draw_config_page
614 procedure processConfigSaveAudio .clickX .clickY .pressed$
616 .label$ = "SaveAudio"
617 call Draw_button '.table$' '.label$' 1
619 if sgc.saveAudioOn = 0
621 call findLabel '.table$' '.label$'
623 select Table '.table$'
624 .openDialogue$ = Get value... '.row' Helptext
625 call convert_praat_to_latin1 '.openDialogue$'
626 .openDialogue$ = convert_praat_to_latin1.text$
628 sgc.saveAudio$ = chooseDirectory$ (.openDialogue$)
629 if sgc.saveAudio$ <> ""
631 .currentPathName$ = replace_regex$(sgc.saveAudio$, "[^/\\]*[/\\]?$", "", 0)
632 .currentDirName$ = replace$(sgc.saveAudio$, .currentPathName$, "", 0)
635 config.clearSummary = -1
636 config.audioName$ = .currentDirName$
638 # Clear performance table and open/create sgc.savePerf$
639 sgc.savePerf$ = "'sgc.saveAudio$'/'.currentDirName$'.tsv"
640 call initialize_toneevaluation_tables
642 call update_toneevaluation_file
643 if sgc.savePerf$ <> "" and initialiseSGC2.toneevaluation_table$ <> ""
644 select sgc2.performanceTable
645 Write to table file: sgc.savePerf$
648 config.audioName$ = ""
654 config.clearSummary = 0
655 # Store current performance table
656 call update_toneevaluation_file
659 call Draw_button '.table$' '.label$' 'sgc.saveAudioOn'
660 call Draw_config_page
663 ###############################################################
665 # Obligatory button Processing Routines
667 # These MUST be defined
669 ###############################################################
671 procedure processConfigReturn .clickX .clickY .pressed$
674 call Draw_button '.table$' '.label$' 1
675 call write_preferences ""
678 procedure processConfigRefresh .clickX .clickY .pressed$
681 call Draw_config_page
684 procedure processConfigCredits .clickX .clickY .pressed$
687 call Draw_button '.table$' '.label$' 1
688 call write_text_table Credits_'config.language$'
690 call Draw_button '.table$' '.label$' 0
692 call Draw_config_page
695 procedure processConfigHelp .clickX .clickY .pressed$
698 call help_loop '.table$' Draw_config_page
701 ###############################################################
703 # Miscelaneous supporting code
705 ###############################################################
706 procedure install_wordlists_by_name .wordlist_Name$
707 if .wordlist_Name$ <> ""
708 if index_regex(.wordlist_Name$, "(?iwordlist|LICENSE)\.")
709 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\](?iwordlist|LICENSE)\.([^/\\]+)$", "", 0)
710 elsif index_regex(.wordlist_Name$, "(?i\.(wav|flac|iaf[fc]|mp3))")
711 .wordlist_Name$ = replace_regex$(.wordlist_Name$, "[/\\][^/\\]+$", "", 0)
713 if index_regex(.wordlist_Name$, "[/\\]")
714 .sourceDir$ = left$(.wordlist_Name$, rindex_regex(.wordlist_Name$, "[/\\]") -1)
715 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex_regex(.wordlist_Name$, "[/\\]"))
716 call readWordlist "'.sourceDir$'" '.file$'
719 if index(.wordlist_Name$, ".")
722 .extension1$ = ".sgc"
723 .extension2$ = ".Table"
724 .extension3$ = ".txt"
725 .extension4$ = ".tsv"
727 for .e from .start to 5
728 .currentExtension$ = .extension'.e'$
729 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
730 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
731 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
732 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
733 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
734 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
735 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
741 # Word lists: It is a VERY good idea to make sure that word-lists
743 procedure load_word_list .localdir$ .relnumber
745 if sgc.allWordLists > 0
746 select sgc.allWordLists
748 sgc.allWordLists = -1
751 # Remove old word list
753 select sgc.currentWordlist
755 call wipeArea 'wipeWordlistArea$'
757 sgc.currentWordlist = -1
761 # Create Table that will recieve the wordlists and directories
762 sgc.allWordLists = Create Table with column names... AllWordLists 0 Name Directory
763 .sgc.currentWordlistRow = 0
765 # First the global word lists
766 if fileReadable(globalwordlists$) or fileReadable("'globalwordlists$'/directory.txt")
767 Create Strings as directory list... WordList 'globalwordlists$'
768 .numLists = Get number of strings
770 select Strings WordList
771 .currentName$ = Get string... '.i'
772 if .currentName$ <> "directory.txt"
773 select sgc.allWordLists
774 .listExist = Search column: "Name", .currentName$
777 .sgc.currentWordlistRow = Get number of rows
778 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
779 .currentDirectory$ = globalwordlists$+"/"+.currentName$
780 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
784 select Strings WordList
788 # Now the preferences word lists
789 if fileReadable(sgc2wordlists$) or fileReadable("'sgc2wordlists$'/directory.txt")
790 Create Strings as directory list... WordList 'sgc2wordlists$'
791 .numLists = Get number of strings
793 select Strings WordList
794 .currentName$ = Get string... '.i'
795 if .currentName$ <> "directory.txt"
796 select sgc.allWordLists
797 .listExist = Search column: "Name", .currentName$
800 .sgc.currentWordlistRow = Get number of rows
801 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
802 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
803 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
807 select Strings WordList
811 # End with the word lists in the distribution
812 call CreateCreateWordlists
813 select Table CreateWordlists
814 .numLists = Get number of rows
816 select Table CreateWordlists
817 .currentName$ = Get value... '.i' Name
818 if .currentName$ <> "directory.txt"
819 select sgc.allWordLists
820 .listExist = Search column: "Name", .currentName$
822 .procedureName$ = replace_regex$(.currentName$, "[^\w\-\.]", "_", 0)
823 select sgc.allWordLists
825 .sgc.currentWordlistRow = Get number of rows
826 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
827 .currentDirectory$ = "*call Create'.procedureName$'"
828 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
832 select Table CreateWordlists
835 # Finally, the local word lists
836 if fileReadable(.localdir$) or fileReadable("'.localdir$'/directory.txt")
837 Create Strings as directory list... WordList '.localdir$'
838 .numLists = Get number of strings
840 select Strings WordList
841 .currentName$ = Get string... '.i'
842 if .currentName$ <> "directory.txt"
843 select sgc.allWordLists
844 .listExist = Search column: "Name", .currentName$
847 .sgc.currentWordlistRow = Get number of rows
848 Set string value... '.sgc.currentWordlistRow' Name '.currentName$'
849 .currentDirectory$ = .localdir$+"/"+.currentName$
850 Set string value... '.sgc.currentWordlistRow' Directory '.currentDirectory$'
854 select Strings WordList
858 # Get the position of the current word list
859 select sgc.allWordLists
861 .numLists = Get number of rows
863 if wordlistName$ <> ""
864 select sgc.allWordLists
865 .currentNumber = Search column... Name 'wordlistName$'
866 if .currentNumber <= 0
871 wordlistNum = .currentNumber + .relnumber
872 if wordlistNum > .numLists
874 elsif wordlistNum < 1 and .numLists > 0
875 wordlistNum = .numLists
877 select sgc.allWordLists
878 wordlistName$ = Get value... 'wordlistNum' Name
879 .dirWordlistName$ = Get value... 'wordlistNum' Directory
880 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
882 # Read in full tables
883 if fileReadable("'.dirString$'/wordlist.Table")
884 call readTable '.dirString$'/wordlist.Table
885 if readTable.tableID > 0
886 Rename... 'wordlistName$'
887 # Praat wil change the name if it feels like it
888 wordlist$ = selected$("Table")
889 # Add a Sound column if it is not present
890 .soundIndex = Get column index: "Sound"
892 Append column: "Sound"
898 # Handle (legacy) simple word lists
899 elsif fileReadable("'.dirString$'/wordlist.txt")
900 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Sound Translation
901 wordlist$ = selected$("Table")
902 Read Strings from raw text file... '.dirString$'/wordlist.txt
903 Rename... RawWordList
904 .numWordStrings = Get number of strings
905 for .i to .numWordStrings
906 select Strings RawWordList
910 .currentLine$ = Get string... '.i'
911 # Remove leading whitespace
912 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
913 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
914 if .separatorIndex <= 0
915 .separatorIndex = length(.currentLine$) + 1
917 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
918 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
919 # There is more on the line, but we do not know what
920 if length(.currentLine$) > 0
921 while length(.currentLine$) > 0
922 .separatorIndex = index_regex(.currentLine$, "[\t;]")
923 if .separatorIndex <= 0
924 .separatorIndex = length(.currentLine$)+1
926 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
927 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
928 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
930 .currentFile$ = .currentItem$
931 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
933 .currentTrans$ = .currentItem$
934 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
936 .currentChar$ = .currentItem$
940 if .currentFile$ = "-"
941 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
942 .currentFile$ = .currentPinyin$+".spx"
943 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
944 .currentFile$ = .currentPinyin$+".flac"
945 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
946 .currentFile$ = .currentPinyin$+".wav"
947 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
948 .currentFile$ = .currentPinyin$+".mp3"
951 select Table 'wordlist$'
953 Set string value... '.i' Pinyin '.currentPinyin$'
954 Set string value... '.i' Sound '.currentFile$'
955 Set string value... '.i' Character '.currentChar$'
956 Set string value... '.i' Translation '.currentTrans$'
958 select Strings RawWordList
961 select Table 'wordlist$'
962 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
963 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
964 wordlist$ = selected$("Table")
965 Create Strings as file list... RawWordList '.dirString$'/*
966 .numWordStrings = Get number of strings
968 for .j to .numWordStrings
969 select Strings RawWordList
970 .currentLine$ = Get string... '.j'
971 .currentFile$ = extractWord$(.currentLine$, "")
972 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
973 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
974 select Table 'wordlist$'
977 Set string value... '.i' Pinyin '.currentPinyin$'
978 Set string value... '.i' Sound '.currentFile$'
981 select Strings RawWordList
984 select Table 'wordlist$'
985 elsif startsWith(.dirString$, "*call ")
986 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
988 wordlist$ = selected$("Table")
995 # Can this wordlist be deleted?
996 if fileReadable("'sgc2wordlists$'/'wordlistName$'") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'wordlistName$'/wordlist.Table")
997 config.deleteWordlist = 0
999 config.deleteWordlist = -1
1002 # Check first column name and add Character, Translation, Sound and Show columns if missing
1004 select Table 'wordlist$'
1005 # Hack to correct odd behavior of tables with unicode characters
1006 .firstColumn$ = Get column label: 1
1007 if index_regex(.firstColumn$, "^[^!-~]") > 0
1008 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1009 Set column label (index): 1, .firstColumn$
1012 sgc.numberOfWords = Get number of rows
1013 .characterColumn = Get column index... Character
1014 if not .characterColumn
1015 Append column... Character
1016 for .i to sgc.numberOfWords
1017 Set string value... '.i' Character -
1020 .translationColumn = Get column index... Translation
1021 if not .translationColumn
1022 Append column... Translation
1023 for .i to sgc.numberOfWords
1024 Set string value... '.i' Translation -
1027 .translationColumn = Get column index... Sound
1028 if not .translationColumn
1029 Append column... Sound
1030 for .i to sgc.numberOfWords
1031 Set string value... '.i' Sound -
1034 .showColumn = Get column index... Show
1036 Append column... Show
1037 for .i to sgc.numberOfWords
1038 Set string value... '.i' Show +
1043 # Remove all rows without Pinyin
1044 .numRows = Get number of rows
1046 .rowNum = .numRows - i + 1
1047 .pinyinValue$ = Get value... '.rowNum' Pinyin
1048 .currLength = Get number of rows
1049 if not index_regex(.pinyinValue$, "^[a-zA-Z]")
1053 Set string value: .rowNum, "Pinyin", "bu4"
1057 .numRows = Get number of rows
1058 sgc.numberOfWords = Get number of rows
1060 # Shuffle words if requested
1061 if config.shuffleLists
1065 # Determine number of words actually shown
1067 sgc.currentWordNum = 1
1068 sgc.numberOfDisplayedWords = 0
1070 .show$ = Get value: .i, "Show"
1072 if sgc.currentWord < 1
1073 sgc.currentWord = .i
1075 sgc.numberOfDisplayedWords += 1
1081 #select sgc.allWordLists
1084 # There were no Word Lists
1087 wordlistName$ = wordlistName$+" No Word Lists available"
1089 Create Table with column names... "'wordlistName$'" 1 Pinyin Character Translation Sound
1090 wordlist$ = selected$("Table")
1094 Set string value... '.i' Pinyin ni3hao3
1095 Set string value... '.i' Character 你好
1096 Set string value... '.i' Translation hello
1097 Set string value... '.i' Sound -
1100 Set string value... '.i' Pinyin xie4xie0
1101 Set string value... '.i' Character 谢谢
1102 Set string value... '.i' Translation thanks
1103 Set string value... '.i' Sound -
1106 Set string value... '.i' Pinyin zai4jian4
1107 Set string value... '.i' Character 再见
1108 Set string value... '.i' Translation goodbye
1109 Set string value... '.i' Sound -
1110 # Get rid of empty first row
1113 # Set default values
1114 sgc.numberOfWords = Get number of rows
1116 sgc.numberOfDisplayedWords = Get number of rows
1119 select Table 'wordlist$'
1120 sgc.currentWordlist = selected()
1121 call set_window_title 'buttons$' 'wordlistName$'
1124 procedure read_wordlist .wordlistName$ .dirString$
1125 # Read in full tables
1126 if fileReadable("'.dirString$'/wordlist.Table")
1127 call readTable '.dirString$'/wordlist.Table
1128 .wordlistID = selected ()
1130 Rename... '.wordlistName$'
1131 # Praat wil change the name if it feels like it
1132 .wordlist$ = selected$("Table")
1133 # Add a Sound column if it is not present
1134 .soundIndex = Get column index: "Sound"
1136 Append column: "Sound"
1139 goto EMERGENCYEXITWL
1141 # Handle (legacy) simple word lists
1142 elsif fileReadable("'.dirString$'/wordlist.txt")
1143 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Character Sound Translation
1144 .wordlist$ = selected$("Table")
1145 Read Strings from raw text file... '.dirString$'/wordlist.txt
1146 Rename... RawWordList
1147 .numWordStrings = Get number of strings
1148 for .i to .numWordStrings
1149 select Strings RawWordList
1152 .currentTrans$ = "-"
1153 .currentLine$ = Get string... '.i'
1154 # Remove leading whitespace
1155 .currentLine$ = replace_regex$(.currentLine$, "^[ \t]+", "", 0)
1156 .separatorIndex = index_regex(.currentLine$, "[ \t;\-]")
1157 if .separatorIndex <= 0
1158 .separatorIndex = length(.currentLine$) + 1
1160 .currentPinyin$ = left$(.currentLine$, .separatorIndex-1)
1161 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex)
1162 # There is more on the line, but we do not know what
1163 if length(.currentLine$) > 0
1164 while length(.currentLine$) > 0
1165 .separatorIndex = index_regex(.currentLine$, "[\t;]")
1166 if .separatorIndex <= 0
1167 .separatorIndex = length(.currentLine$)+1
1169 .currentItem$ = left$(.currentLine$, .separatorIndex-1)
1170 .currentLine$ = right$(.currentLine$, length(.currentLine$) - .separatorIndex )
1171 if index_regex(.currentItem$, ".(spx|flac|wav|mp3)")
1173 .currentFile$ = .currentItem$
1174 elsif index_regex(.currentItem$, "[a-zA-Z0-9]") > 0
1176 .currentTrans$ = .currentItem$
1177 elsif index_regex(.currentItem$, "[^ \t\r\l]") > 0 && index_regex(.currentItem$, "[a-zA-Z0-9\-]") <= 0
1179 .currentChar$ = .currentItem$
1183 if .currentFile$ = "-"
1184 if fileReadable("'.dirString$'/'.currentPinyin$'.spx")
1185 .currentFile$ = .currentPinyin$+".spx"
1186 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
1187 .currentFile$ = .currentPinyin$+".flac"
1188 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
1189 .currentFile$ = .currentPinyin$+".wav"
1190 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
1191 .currentFile$ = .currentPinyin$+".mp3"
1196 Set string value... '.i' Pinyin '.currentPinyin$'
1197 Set string value... '.i' Sound '.currentFile$'
1198 Set string value... '.i' Character '.currentChar$'
1199 Set string value... '.i' Translation '.currentTrans$'
1201 select Strings RawWordList
1205 elsif fileReadable(.dirString$) or fileReadable("'.dirString$'/directory.txt")
1206 .wordlistID = Create Table with column names... "'.wordlistName$'" 0 Pinyin Sound
1207 .wordlist$ = selected$("Table")
1208 .tmp = Create Strings as file list... RawWordList '.dirString$'/*
1209 .numWordStrings = Get number of strings
1211 for .j to .numWordStrings
1213 .currentLine$ = Get string... '.j'
1214 .currentFile$ = extractWord$(.currentLine$, "")
1215 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
1216 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
1217 select sgc.currentWordlist
1220 Set string value... '.i' Pinyin '.currentPinyin$'
1221 Set string value... '.i' Sound '.currentFile$'
1227 select sgc.currentWordlist
1228 elsif startsWith(.dirString$, "*call ")
1229 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
1231 .wordlistID = selected()
1232 .wordlist$ = selected$("Table")
1235 goto EMERGENCYEXITWL
1238 # Add the path to the file Sound file names
1240 .numRows = Get number of rows
1242 .soundfile$ = Get value: .w, "Sound"
1243 if index_regex(.soundfile$, "[/\\]") <= 0
1244 if index_regex(.dirString$, "[/\\]$")
1245 .soundfile$ = .dirString$+.soundfile$
1246 elsif index_regex(.dirString$, "[\\]")
1247 .soundfile$ = .dirString$+"\\"+.soundfile$
1249 .soundfile$ = .dirString$+"/"+.soundfile$
1251 Set string value: .w, "Sound", .soundfile$
1255 label EMERGENCYEXITWL
1259 procedure merge_into_wordlist .newTableID .lessonPostfix$
1260 select sgc.currentWordlist
1261 .oldLessonColumn = Get column index: "Lesson"
1264 .numRows = Get number of rows
1265 .lessonColumn = Get column index: "Lesson"
1266 .characterColumn = Get column index: "Character"
1267 .soundColumn = Get column index: "Sound"
1268 .translationColumn = Get column index: "Translation"
1272 .currentTrans$ = "-"
1273 .currentLesson$ = "-"
1276 .currentPinyin$ = Get value: .w, "Pinyin"
1278 .currentFile$ = Get value: .w, "Sound"
1280 if .characterColumn > 0
1281 .currentChar$ = Get value: .w, "Character"
1283 if .translationColumn > 0
1284 .currentTrans$ = Get value: .w, "Translation"
1286 if .lessonColumn > 0
1287 .currentLesson$ = Get value: .w, "Lesson"
1289 select sgc.currentWordlist
1291 .n = Get number of rows
1292 Set string value: .n, "Pinyin", .currentPinyin$
1293 Set string value: .n, "Sound", .currentFile$
1294 Set string value: .n, "Character", .currentChar$
1295 Set string value: .n, "Translation", .currentTrans$
1296 if .oldLessonColumn > 0
1297 if .currentLesson$ = "-" or .currentLesson$ = "" or .currentLesson$ = "?"
1298 Set string value: .n, "Lesson", .lessonPostfix$
1300 Set string value: .n, "Lesson", .currentLesson$+" "+.lessonPostfix$
1308 select sgc.currentWordlist
1310 if sgc.currentWord < 0 or sgc.currentWord > sgc.numberOfWords
1311 if config.shuffleLists
1315 sgc.currentWordNum = 0
1317 while .showCurrent$ = "-" and sgc.currentWord <= sgc.numberOfWords
1318 sgc.currentWord += 1
1319 if sgc.currentWord <= sgc.numberOfWords
1320 .showCurrent$ = Get value... 'sgc.currentWord' Show
1323 if sgc.currentWord > 0
1324 sgc.currentWordNum += 1
1326 sgc.currentWordNum = 0
1331 procedure previous_word
1333 select sgc.currentWordlist
1335 if sgc.currentWord <= 0
1336 if config.shuffleLists
1339 sgc.currentWord = sgc.numberOfWords + 1
1340 sgc.currentWordNum = sgc.numberOfDisplayedWords + 1
1342 while .showCurrent$ = "-" and sgc.currentWord > 0
1343 sgc.currentWord -= 1
1344 if sgc.currentWord > 0
1345 .showCurrent$ = Get value... 'sgc.currentWord' Show
1348 if sgc.currentWord > 0
1349 sgc.currentWordNum -= 1
1351 sgc.currentWordNum = 0
1356 procedure display_word_list_name
1360 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
1361 call wipeArea 'wipeWordlistArea$'
1362 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
1363 .currentFontSize = adjustFontSizeOnHeight.newFontSize
1366 demo Text special... '.xtext' Centre '.ytext' Bottom 'defaultFont$' '.currentFontSize' 0 '.displayWordList$'
1369 call set_font_size 'defaultFontSize'
1372 procedure write_word_list
1373 # Write current Pinyin text
1374 call display_text Black
1376 # Write the current word list name
1377 call display_word_list_name
1380 procedure paint_saveAudio_light
1381 select Table 'config$'
1382 .row = Search column... Label SaveAudio
1384 exit Button Table Config does not have a row with label SaveAudio
1387 .leftX = Get value... '.row' LeftX
1388 .rightX = Get value... '.row' RightX
1389 .lowY = Get value... '.row' LowY
1390 .highY = Get value... '.row' HighY
1391 .buttonColor$ = Get value... '.row' Color
1392 # The button text and symbol
1393 .horWC = demo Horizontal mm to wc... 10.0
1394 .verWC = demo Vertical mm to wc... 10.0
1396 .verCoeff = .horWC / .verWC
1401 .centerX = (.leftX + .rightX)/2
1402 .centerY = .lowY + 0.6*(.highY-.lowY)
1403 .radius = min(.verCoeff * (.highY - .lowY ), (.rightX - .leftX))/3
1404 .wipeRadius = 1.1*.radius
1405 call DrawSaveAudio White '.centerX' '.centerY' '.wipeRadius'
1407 if sgc.saveAudioOn and sgc.saveAudio$ <> ""
1408 call DrawSaveAudio "DarkBlue" '.centerX' '.centerY' '.radius'
1413 # Uninstall word lists
1414 procedure removeWordlist .deletedWordlistName$
1416 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.txt") or fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'/wordlist.Table")
1417 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
1419 if .targetDir$ <> ""
1420 Create Strings as file list... DeleteList '.targetDir$'
1421 .numdeleteFiles = Get number of strings
1422 for .i to .numdeleteFiles
1423 .file$ = Get string... '.i'
1424 deleteFile("'.targetDir$'/'.file$'")
1426 filedelete '.targetDir$'
1427 # Check whether the directory was actually deleted. Make sure this is a valid directory name!
1428 # That is, it does not contain funny characters, nor funny names
1429 if index_regex(.deletedWordlistName$, "[^a-zA-Z0-9_ .\-]") <= 0 and index(.deletedWordlistName$, "..") <= 0 and index_regex(.deletedWordlistName$, "[a-zA-Z]") > 0
1431 nocheck system rmdir "'.targetDir$'" /s /q
1432 elsif fileReadable(.targetDir$)
1433 system bash -rc -- 'rm -r -- "'.targetDir$'"'
1436 # Remove deleted word list
1437 select Strings DeleteList
1438 plus Table 'wordlist$'
1444 # Install word lists
1445 procedure sgc2wordlist .sourceDir$
1446 if startsWith(.sourceDir$, "preferencesDirectory$")
1447 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
1450 .targetDirectory$ = "'sgc2wordlists$'"
1451 if fileReadable(.sourceDir$) or fileReadable("'.sourceDir$'/directory.txt")
1452 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
1453 .numFiles = Get number of strings
1455 select Strings PackageList
1456 .file$ = Get string... '.i'
1457 call readWordlist '.sourceDir$' '.file$'
1460 select Strings PackageList
1465 # Debuggin remarks!!!
1466 # fileReadable(<directory>) does not work in Windows
1467 # The file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
1468 # And yet only the 7z decompression has been implemented
1469 windowsUnzipCommand$ = ""
1470 if fileReadable("C:\Program Files\7-Zip\7z.exe")
1471 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z.exe"" -y e"
1472 windowsUnzipDestDir$ = " -o"
1473 elsif fileReadable("C:\Program Files\WinZip\winzip32.exe")
1474 # !!! Find a way to include the output folder !!!
1475 windowsUnzipCommand$ = "C:\Program Files\WinZip\winzip32.exe"" -min -e -o -j "
1476 windowsUnzipDestDir$ = ""
1478 procedure readWordlist .sourceDir$ .file$
1479 # No use doing anything if the source does not exist
1480 if fileReadable("'.sourceDir$'/'.file$'") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/wordlist.Table")
1481 # What will be the target wordlist directory?
1482 .targetDirectory$ = "'sgc2wordlists$'"
1483 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
1487 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
1488 # Wordlist directory does not exist, neither locally nor in the preferences
1490 .tmpDirs = nocheck Create Strings as directory list... TMPWORDLISTS '.targetDirectory$'/
1491 if .tmpDirs != undefined and .tmpDirs > 0
1492 .numDirs = Get number of strings
1495 .currentString$ = Get string... '.d'
1496 if .currentString$ = .dirname$
1502 if not (.wordListExists or fileReadable(.dirname$) or fileReadable("'.dirname$'/directory.txt") or fileReadable(.wordlistDirectory$) or fileReadable("'.wordlistDirectory$'/directory.txt"))
1504 # Move source to destination
1505 # Use this if you want to allow direct loading of ZIP files. Could lead to problems.
1506 # if index(.file$, ".sgc") or index(.file$, ".zip")
1508 if index(.file$, ".sgc")
1509 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and not (windows and windowsUnzipCommand$ = "")
1510 # Create wordlist directory
1511 createDirectory(.wordlistDirectory$)
1513 if macintosh or unix
1514 system bash -rc -- 'unzip -j "'.sourceDir$'/'.file$'" -d "'.wordlistDirectory$'"'
1515 elsif windows and windowsUnzipCommand$ <> ""
1516 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1517 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1518 system mkdir "'.winWordListDirectory$'" & 'windowsUnzipCommand$' "'.winSourceDirectory$'" 'windowsUnzipDestDir$'"'.winWordListDirectory$'"
1520 elsif (windows and windowsUnzipCommand$ = "")
1521 # Warn to install 7Zip
1522 call get_feedback_text 'config.language$' InstallUnzip
1523 call convert_praat_to_latin1 'get_feedback_text.text$'
1524 .zipText$ = convert_praat_to_latin1.text$
1525 call write_text_popup 'defaultFont$' 14 '.zipText$'
1526 # Wait for confirmation
1528 call Draw_config_page
1530 # Remove if not valid!
1531 if fileReadable("'.wordlistDirectory$'/wordlist.Table") or fileReadable("'.wordlistDirectory$'/wordlist.txt") or fileReadable("'.wordlistDirectory$'/LICENSE.txt")
1532 if fileReadable("'.wordlistDirectory$'/wordlist.Table")
1533 call readTable '.sourceDir$'/'.file$'
1534 if readTable.tableID > 0
1535 select readTable.tableID
1536 # Hack around odd behavior of column index
1538 .firstColumn$ = Get column label: 1
1539 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1540 if .firstColumn$ = "Pinyin"
1543 .pinyinCol = Get column index... Pinyin
1546 # No Pinyin in table
1555 # None of wordlist.Table, wordlist.txt, nor LICENSE.txt
1558 ### REALLY DANGEROUS STUFF, SHOULD BE HANDLED BETTER
1560 # Remove newly created directory
1561 if index_regex(.wordlistDirectory$, "[^a-zA-Z0-9_\.\- /~\:]") <= 0 and index_regex(.dirname$, "[^a-zA-Z0-9_\.\- ]") <= 0 and index(.dirname$, "..") <= 0
1562 if macintosh or unix
1563 system bash -rc -- 'rm -r "'.wordlistDirectory$'/"'
1565 system rmdir /Q /S "'.winWordListDirectory$'/"
1569 elsif index_regex(.file$, "\.(Table|tsv|csv)")
1570 # Check whether this is a valid table
1571 call readTable '.sourceDir$'/'.file$'
1572 if readTable.tableID > 0
1573 select readTable.tableID
1574 # Hack around odd behavior of column index
1576 .firstColumn$ = Get column label: 1
1577 .firstColumn$ = replace_regex$(.firstColumn$, "^[^!-~]", "", 0)
1578 if .firstColumn$ = "Pinyin"
1581 .pinyinCol = Get column index... Pinyin
1585 select readTable.tableID
1586 # Create wordlist directory
1587 createDirectory(.wordlistDirectory$)
1589 .extension$ = "Table"
1590 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1592 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1595 select readTable.tableID
1596 Save as tab-separated file: .wordlistFilePath$
1597 if not fileReadable(.wordlistFilePath$)
1601 select readTable.tableID
1604 elsif index_regex(.file$, "\.(?itxt)")
1605 # Check whether this is a valid table
1606 readTable.tableID = nocheck Read Strings from raw text file: "'.sourceDir$'/'.file$'"
1607 if readTable.tableID > 0
1609 # Create wordlist directory
1610 createDirectory(.wordlistDirectory$)
1612 .wordlistFilePath$ = "'.wordlistDirectory$'/wordlist.'.extension$'"
1614 .wordlistFilePath$ = replace_regex$(.wordlistFilePath$, "/", "\\", 0)
1616 select readTable.tableID
1617 Save as raw text file: .wordlistFilePath$
1618 select readTable.tableID
1621 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt") or fileReadable("'.sourceDir$'/'.file$'/LICENSE.txt")
1622 # Copy wordlist directory
1623 if index_regex(.file$, "[^a-zA-Z0-9_\.\- ]") <= 0
1625 if macintosh or unix
1626 system bash -rc -- 'cp -r "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'"'
1628 createDirectory(.wordlistDirectory$)
1629 .winWordListDirectory$ = replace_regex$(.wordlistDirectory$, "/", "\\", 0)
1630 .winSourceDirectory$ = replace_regex$("'.sourceDir$'\'.file$'", "/", "\\", 0)
1631 system xcopy "'.winSourceDirectory$'" "'.winWordListDirectory$'" /s /e /q
1636 # Set current word list to read list
1638 wordlistName$ = .dirname$
1641 .label$ = "!NotAWordlist"
1644 call findLabel '.table$' '.label$'
1645 .row = findLabel.row
1646 select Table '.table$'
1647 .helpText$ = Get value... '.row' Helptext
1648 .printablePath$ = "'.sourceDir$'/'.file$'"
1650 .printablePath$ = replace$("'.sourceDir$'\'.file$'", "\", "\bs", 0)
1652 .filetext$ = replace_regex$(.printablePath$, "_", "\\_ ", 0)
1653 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
1654 # Wait for confirmation