def get_path(self): """Summary Returns: TYPE: Description """ filename = tkFile.askopenfilename() self.parent.lift() if not filename: filename = '.' return filename
def add_row(self, filename=''): """Summary Args: filename (None, optional): Description Returns: TYPE: Description """ if not filename: filename = tkFile.askopenfilename() self.parent.lift() if filename: button_ops = {} entry_ops = {} frame_ops = {} if self.ops: button_ops = self.ops['button'] entry_ops = self.ops['entry'] frame_ops = self.ops['frame'] new_frame = tk.Frame(self, **frame_ops) new_frame.pack(expand=1, fill=tk.BOTH) new_tvar = tk.StringVar() new_tvar.set(filename) new_entry = tk.Entry(new_frame, textvariable=new_tvar, **entry_ops) new_button = tk.Button(new_frame, command=new_frame.destroy, text='Remove', **button_ops) new_entry.pack(expand=1, side='left', fill=tk.BOTH) new_button.pack(expand=1, side='right', fill=tk.X) new_frame.grid(row=self.row_num, column=0, sticky='NEWS') new_frame.get = new_entry.get new_frame.columnconfigure(0, weight=2) new_frame.columnconfigure(1, weight=1) self.wid_list.append(new_frame) self.row_num += 1
def openParTim(self): parfile = tkFileDialog.askopenfilename(title="Open par file") timfile = tkFileDialog.askopenfilename(title="Open tim file") self.openPulsar(parfile, timfile)
def switchTOAs(self): timfile = tkFileDialog.askopenfilename() self.psr.timfile = timfile self.psr.reset_TOAs() self.widgets["plk"].update() self.widgets["tim"].set_toas()
def switchModel(self): parfile = tkFileDialog.askopenfilename(title="Open par file") self.psr.parfile = parfile self.psr.reset_model() self.widgets["plk"].update() self.widgets["par"].set_model()
def main(argv=None): dict_apikey = get_dict_apikey() if argv is None: argv = sys.argv[1:] parser = argparse.ArgumentParser() parser.add_argument( "wordlist", default='', nargs='*', help= "wordlist file(s), each containing the list of words. One word per-line" ) parser.add_argument("--wordrate", type=int, default=-2, help="voice index") parser.add_argument("--defrate", type=int, default=0, help="voice index") parser.add_argument("--maxtry", type=int, default=3, help="max try") parser.add_argument( "--missed-file", type=pathlib.Path, help= "File name to be appended with missed words. The file must already exist." "By default it's _missed.txt file in the same directory as the first wordlist file." ) options = parser.parse_args(argv) if not options.wordlist: tkgui = tkinter.Tk() tkgui.withdraw() options.wordlist = [ tkinter_filedialog.askopenfilename(title='Choose a wordlist file') ] tkgui.update() tkgui.destroy() words = [] for wl in options.wordlist: with open(wl) as f: words.extend( [w.strip().lower() for w in f.readlines() if w.strip()]) words = list(set(words)) # uniquify random.shuffle(words) msspeech = MSSpeech(options.defrate) print('Total number of words: {}'.format(len(words))) got_wrong = {} numwords = 0 for word in words: try: (word_data, wav_data) = get_word_data(word, dict_apikey) definition = (d for d in word_data[0]["shortdef"]) examples = None numwords += 1 while True: say_word(word, word_data, wav_data, msspeech) typed = get_word_or_command(numwords, len(words)) if typed == word: print('correct') break elif typed == 'd': try: msspeech.say(next(definition)) except StopIteration: definition = None msspeech.say("no other meaning") elif typed == 'e': if examples is None: examples = get_example(word) try: msspeech.say(next(examples)) except StopIteration: examples = None msspeech.say("no other examples") elif typed == 'q': got_wrong.setdefault(word, []) got_wrong[word].append('q') break elif typed == 'w': pass # loop back, say the word again elif typed == 'g': got_wrong.setdefault(word, []) got_wrong[word].append(typed) print('the word is {}'.format(word)) break else: got_wrong.setdefault(word, []) got_wrong[word].append(typed) if len(got_wrong[word]) >= options.maxtry: print('wrong, the word is {}'.format(word)) break print('wrong, try again') except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() print(f"ERROR: Exception in processing word: {word}") traceback.print_tb(exc_traceback) # continue to next word if typed == 'q': break if got_wrong: print("These are the words you got wrong:") for k in sorted(got_wrong.keys()): print('{} - typed {}'.format(k, str(got_wrong[k]))) print("You got {:.1f}% of {} words".format( (1 - (len(got_wrong.keys()) * 1.0 / numwords)) * 100.0, numwords)) if options.missed_file is None: missed_file = pathlib.Path( options.wordlist[0]).parent / '_missed.txt' if missed_file.exists(): with missed_file.open('a') as f: for k in sorted(got_wrong.keys()): f.write(k + '\n') else: print("Congratulations! You got 100% from {} words".format(numwords)) input('press <Enter> to quit program...')