def excel_popup(field): sub_window = Toplevel(background="#333", padx=15, pady=15) sub_window.title("Aya's Finder: Import data from Excel file") sub_window.wm_iconbitmap(r"images\Dna-Helix.ico") row_col = StringVar() row_col.set("row") Radiobutton(sub_window, variable=row_col, value="row", text="Row").grid(row=0, column=0) Radiobutton(sub_window, variable=row_col, value="col", text="Column").grid(row=0, column=1) file_name_var = StringVar() sheet_name_var = StringVar() num_var = IntVar() Label(sub_window, justify="left", width="17", text="File name").grid(row=1, column=0) Label(sub_window, justify="left", width="17", text="Sheet name").grid(row=2, column=0) Label(sub_window, justify="left", width="17", text="Row/Column number").grid(row=3, column=0) Entry(sub_window, width="32", textvariable=file_name_var).grid(row=1, column=1) Entry(sub_window, width="7", textvariable=num_var).grid(row=3, column=1) sheets = OptionMenu(sub_window, sheet_name_var, '') sheets.config(width=32) sheets.grid(row=2, column=1) def get(): file_name = file_name_var.get() sheet_name = sheet_name_var.get() num = num_var.get() try: if row_col.get() == "row": field.delete(1.0, END) field.insert(INSERT, get_from_excel(file_name, sheet_name, row_num=num)) else: field.delete(1.0, END) field.insert(INSERT, get_from_excel(file_name, sheet_name, col_num=num)) sub_window.destroy() except Exception: pass def browser(): try: name = askopenfilename(parent=sub_window) file_name_var.set(name) sheets.set_menu('---', *get_excel_sheets(file_name_var.get())) sub_window.focus() except IOError: pass Button(sub_window, text="OK", command=get).grid(row=5, column=0) Button(sub_window, text="Cancel", command=lambda: sub_window.destroy()).grid(row=5, column=1) Button(sub_window, text="browse", command=browser).grid(row=1, column=3)
class EngineGui(): def __init__(self, communicationProtocal): self.communicationProtocal = communicationProtocal def StartGui(self): self.tkRoot = Tk(baseName="") self.tkRoot.geometry("350x300+0+0") self.tkRoot.title("Engine SAPI GUI") self.GUIVisible = True frame = Frame(self.tkRoot) frame.style = Style() frame.style.theme_use("alt") frame.pack(fill=BOTH, expand=1) frame.columnconfigure(1, weight=1) frame.columnconfigure(7, pad=7) frame.rowconfigure(13, weight=1) frame.rowconfigure(13, pad=7) Label(frame, text="Start:").grid(row = 0, column=0) self.labelStart = Label(frame, text="0") self.labelStart.grid(row = 1, column=0) Label(frame, text="Length:").grid(row = 0, column=1) self.labelLength = Label(frame, text="0") self.labelLength.grid(row = 1, column=1) Label(frame, text="Total:").grid(row = 0, column=2) self.labelTotal = Label(frame, text="0") self.labelTotal.grid(row = 1, column=2) self.labelSentenceLeft = Label(frame, text="...") self.labelSentenceLeft.grid(row = 2, column=0, sticky=E) self.labelSentenceSpoken = Label(frame, text="...", foreground="red") self.labelSentenceSpoken.grid(row = 2, column=1) self.labelSentenceRight = Label(frame, text="...") self.labelSentenceRight.grid(row = 2, column=2, sticky=W, columnspan=2) scrollbar = Scrollbar(frame, orient=VERTICAL) self.labelQueueToSpeak = Label(frame, text="Queue to speak:").grid(row = 3, column=0, pady=4, padx=5, sticky=W) self.listboxQueueToSpeak = Listbox(frame, width=50, height=3, yscrollcommand=scrollbar.set) scrollbar.config(command=self.listboxQueueToSpeak.yview) self.listboxQueueToSpeak.grid( sticky=N+S+E+W, row = 4, column = 0, columnspan = 2 ,rowspan = 3, padx=3) scrollbar.grid(sticky=N+S+W, row = 4, column = 2, rowspan = 3) self.buttonPauze = Button(frame, text="Pauze", command=self.communicationProtocal.handlePauze) self.buttonPauze.grid(row = 4, column=3) self.buttonStop = Button(frame, text="Stop", command=self.communicationProtocal.restartProcess) self.buttonStop.grid(row = 5, column=3) self.buttonResume = Button(frame, text="Resume", command=self.communicationProtocal.handleResume) self.buttonResume.grid(row = 6, column=3) Label(frame, text="Text to say:").grid(row = 7, column=0, padx=3, sticky=W) self.stringVarTextToSay = StringVar() self.entryTextToSay = Entry(frame, textvariable=self.stringVarTextToSay, width=500) self.entryTextToSay.grid(row=8, column=0, columnspan=3, padx=3, sticky=W) self.stringVarTextToSay.set("Hello SAPI Speak Engine") self.entryTextToSay.bind('<Return>', self.CallBackReturnSay) self.buttonSay = Button(frame, text="Say", command=self.CallBackButtonSay) self.buttonSay.grid(row = 8, column=3) Label(frame, text="Recover action:").grid(row = 9, column=0, padx=3, sticky=W) self.recoverActionLabelText = "None" self.labelRecoverAction = Label(frame, text=self.recoverActionLabelText, foreground="blue") self.labelRecoverAction.grid(row = 10, column=0) Label(frame, text="Voice speed:").grid(row = 9, column=1, sticky=W) self.buttonSpeedDown = Button(frame, text="Speed down", command=self.communicationProtocal.handleSpeedDown) self.buttonSpeedDown.grid(row = 10, column=1, padx=3, sticky=E) self.speedValue = 0 self.intVarSpeed = IntVar() vcmd = (self.tkRoot.register(self.OnValidateEntrySpeakSpeed), '%d', '%i', '%P', '%s', '%S', '%v', '%V', '%W') self.entrySpeakSpeed = Entry(frame, textvariable=self.intVarSpeed, validate="key", validatecommand=vcmd, width=5) self.entrySpeakSpeed.grid(row=10,column=2) self.entrySpeakSpeed.bind('<Return>', self.CallBackSetSpeed) self.buttonSpeedUp = Button(frame, text="Speed up", command=self.communicationProtocal.handleSpeedUp) self.buttonSpeedUp.grid(row = 10, column=3) Label(frame, text="voice:").grid(row = 11, column=0, padx=3, sticky=W) self.buttonPrevVoice = Button(frame, text="Prev voice", command=self.communicationProtocal.handlePrevVoice) self.buttonPrevVoice.grid(row = 12, column=0, padx=3, sticky=W) self.buttonNextVoice = Button(frame, text="Next voice", command=self.communicationProtocal.handleNextVoice) self.buttonNextVoice.grid(row = 12, column=3) self.currentVoice = StringVar(self.tkRoot) self.currentVoice.set(self.communicationProtocal.CurrentVoiceName) engine = pyttsx.init() voices = engine.getProperty("voices") voiceNames = list() for x in xrange(0, len(voices)): voiceNames.append(voices[x].name) self.optionMenuVoices = OptionMenu(frame, self.currentVoice, *tuple(voiceNames), command=self.CallBackOptionMenuVoices) self.optionMenuVoices.config(width=500) self.optionMenuVoices.grid(sticky=W, row = 12, column = 1) #hide if close button is clicked self.tkRoot.protocol("WM_DELETE_WINDOW", self.HideGui) self.tkRoot.after(1000/32, self.Update) self.tkRoot.mainloop() def Update(self): wordLocation = self.communicationProtocal.OnWordStartLocation wordLength = self.communicationProtocal.OnWordLength wordTotal = self.communicationProtocal.OnWordTotal if wordLocation: self.labelStart.configure(text=wordLocation) else: self.labelStart.configure(text="0") self.labelLength.configure(text=wordLength) if wordLength != 0 and wordTotal == 0: self.labelTotal.configure(text="Introduce") else: self.labelTotal.configure(text=wordTotal) if len(self.communicationProtocal.SpeakQueue) != 0: if (wordLocation < 25): self.labelSentenceLeft.configure(text=str(self.communicationProtocal.SpeakQueue[0])[0:wordLocation]) else: self.labelSentenceLeft.configure(text=str(self.communicationProtocal.SpeakQueue[0])[wordLocation-25:wordLocation]) self.labelSentenceSpoken.configure(text=str(self.communicationProtocal.SpeakQueue[0])[wordLocation:wordLocation+wordLength]) if (wordTotal - wordLocation - wordLength < 25): self.labelSentenceRight.configure(text=str(self.communicationProtocal.SpeakQueue[0])[wordLocation+wordLength:wordTotal]) else: self.labelSentenceRight.configure(text=str(self.communicationProtocal.SpeakQueue[0])[wordLocation+wordLength:wordLocation+wordLength+25]) else: self.labelSentenceLeft.configure(text="...") self.labelSentenceSpoken.configure(text="...") self.labelSentenceRight.configure(text="...") if (self.communicationProtocal.SpeakQueue != None and self.listboxQueueToSpeak.size() != len(self.communicationProtocal.SpeakQueue)): self.listboxQueueToSpeak.delete(0,self.listboxQueueToSpeak.size()) for x in xrange(0,len(self.communicationProtocal.SpeakQueue)): self.listboxQueueToSpeak.insert(x, str(x)+": "+self.communicationProtocal.SpeakQueue[x]) if (self.currentVoice.get() != self.communicationProtocal.CurrentVoiceName): self.currentVoice.set(self.communicationProtocal.CurrentVoiceName) if self.speedValue != self.communicationProtocal.CurrentRate: self.intVarSpeed.set(self.communicationProtocal.CurrentRate) self.speedValue = self.communicationProtocal.CurrentRate if self.recoverActionLabelText != self.communicationProtocal.recoveryTask: self.recoverActionLabelText = self.communicationProtocal.recoveryTask self.labelRecoverAction.configure(text=self.recoverActionLabelText) if self.GUIVisible != self.communicationProtocal.GUIVisible: # self.GUIVisible ? self.HideGui : self.ShowGui self.HideGui() if self.GUIVisible else self.ShowGui() self.tkRoot.after(1000/32,self.Update) def OnValidateEntrySpeakSpeed(self, d, i, P, s, S, v, V, W): try : int(S) return True except ValueError: return False def CallBackSetSpeed(self): self.communicationProtocal.handleSetSpeed(self.intVarSpeed.get()) def CallBackReturnSay(self, event): self.CallBackButtonSay() def CallBackButtonSay(self): self.communicationProtocal.handleSay(self.stringVarTextToSay.get()) def CallBackOptionMenuVoices(self, selectedItem): self.communicationProtocal.handleSetVoice(selectedItem) def Close(self): self.tkRoot.quit() def HideGui(self): self.GUIVisible = False self.communicationProtocal.GUIVisible = False self.tkRoot.withdraw() def ShowGui(self): self.GUIVisible = True self.communicationProtocal.GUIVisible = True self.tkRoot.deiconify()