from tkinter import * from tkinter import ttk from tkinter import filedialog import atexit import random # Start of Code - Start of Tkinter loop Root_Window = Tk() Root_Window.title("PiperTTS - Prototype GUI") # Sets the GUI Title # Setting up Window Starting Size and Position (can only be even numbers) Window_Width = 426 Window_Height = 576 # Getting Screen Width and Height Screen_Width = Root_Window.winfo_screenwidth() Screen_Height = Root_Window.winfo_screenheight() # Calculate Center of Screen for the window Window_PosX = (Screen_Width/2) - (Window_Width/2) Window_PosY = (Screen_Height/2) - (Window_Height/2) # Sets the GUI geometry and attempts to centers window on screen Root_Window.geometry(f'{Window_Width}x{Window_Height}+{int(Window_PosX)}+{int(Window_PosY)}') #Root_Window.minsize(Window_Width, Window_Height) # Attempts to create a Input Frame try: Input_Box_Frame = Frame(Root_Window) except: print("An exception occurred - when creating input Frame.") # Attempts to create a Controls Frame try: Controls_Box_Frame = Frame(Root_Window) except: print("An exception occurred - when creating Controls Frame.") # Attempts to create a Prefrences Frame try: Prefrences_Frame = Frame(Root_Window) except: print("An exception occurred - when creating Controls Frame.") # Attempts to Place Input and Controls frames try: Input_Box_Frame.place(x = 0, y = 0, relwidth = 1, relheight = 0.7) Controls_Box_Frame.place(x = 0, rely = 0.8, relwidth = 1, relheight = 0.7) except: print("An exception occurred - when placing Frames.") # Attempts to create a Input box try: Input_Box = Text(Input_Box_Frame, selectbackground="yellow", selectforeground="black", undo=True) Input_Box.pack(padx=5, pady=5, expand = True, fill = "both") except: print("An exception occurred - when creating input box.") # Attempts to create a scrollbar for the Input box try: Main_Text_Scrollbar = Scrollbar(Input_Box_Frame, command = Input_Box_Frame.yview) Input_Box_Frame.configure(yscrollcommand = Main_Text_Scrollbar.set) Main_Text_Scrollbar.place(relx = 1, rely = 0, relheight = 1, anchor = "ne") except: print("An exception occurred - when creating a scroll bar.") # def PiperTTS_GUI_Play(): try: My_Test_Label["text"] = "Playing?" C_Button_Pause["state"] == "normal" C_Button_Play["state"] = "disabled" except: print("An exception occurred - when pressing Play Button.") # def PiperTTS_GUI_Pause(): try: My_Test_Label["text"] = "Pause?" C_Button_Pause["state"] == "disabled" C_Button_Play["state"] = "normal" except: print("An exception occurred - when pressing Pause Button.") # def PiperTTS_GUI_Stop(): try: My_Test_Label["text"] = "Stop?" C_Button_Pause["state"] == "disabled" C_Button_Play["state"] = "normal" except: print("An exception occurred - when pressing Stop Button.") # def PiperTTS_GUI_Previous(): try: My_Test_Label["text"] = "Previous?" except: print("An exception occurred - when pressing Previous Button.") # def PiperTTS_GUI_Next(): try: My_Test_Label["text"] = "Next?" except: print("An exception occurred - when pressing Next Button.") # def PiperTTS_GUI_New_File(): try: My_Test_Label["text"] = "New File?" Input_Box.delete("1.0", "end-1c") except: print("An exception occurred - when pressing New File Button.") # def PiperTTS_GUI_Get_Selection(): try: Selected = Root_Window.selection_get() if not Selected: My_Test_Label["text"] = "No text Selected" else: Cursor_Position = Input_Box.index(INSERT) Input_Box.insert(Cursor_Position, Selected) except: print("An exception occurred - when grabbing Selection.") # def PiperTTS_GUI_Get_Clipboard(): try: Selected = Root_Window.clipboard_get() if not Selected: My_Test_Label["text"] = "No text in clipboard" else: Cursor_Position = Input_Box.index(INSERT) Input_Box.insert(Cursor_Position, Selected) except: print("An exception occurred - when grabbing Clipboard.") # def PiperTTS_GUI_TextFile_Open(): try: Root_Window.filename = filedialog.askopenfilename(initialdir = "./",title = "Select file",filetypes = (("Text files","*.txt"),("all files","*.*"))) if Root_Window.filename: with open(Root_Window.filename) as f: Cursor_Position = Input_Box.index(INSERT) Input_Box.insert(Cursor_Position, f.read()) else: print("Canceled file dialog.") except: print("An exception occurred - when Opening Text File.") # def PiperTTS_GUI_Reverse_Text(): try: TempText = Input_Box.get("1.0","end-1c") Input_Box.delete("1.0", "end-1c") Input_Box.insert("1.0", TempText[::-1]) except: print("An exception occurred - when reversing text.") # def PiperTTS_GUI_Randomize_Text(): try: TempText = Input_Box.get("1.0","end-1c") Input_Box.delete("1.0", "end-1c") TempList = list(TempText) random.shuffle(TempList) Input_Box.insert("1.0", ''.join(TempList)) except: print("An exception occurred - when Randomizing text.") # def PiperTTS_GUI_Set_Prefrences(): try: Input_Box_Frame.place_forget() Controls_Box_Frame.place_forget() Prefrences_Frame.place(x = 0, y = 0, relwidth = 1, relheight = 1) except: print("An exception occurred - when Setting prefrences.") ''' # def PiperTTS_GUI_Clipboard(): try: #PiperTTS_GUI_Hide_All_Labels() My_Label = Label(Controls_Box_Frame, text="Clipboard?").grid(row=3, column=0, columnspan=5) #global labels = [] labels.append(My_Label) except: print("An exception occurred - when pressing Clipboard Button.") # Deleting info messages def PiperTTS_GUI_Hide_All_Labels(): try: for label in labels: label.destroy() except: print("An exception occurred - when attempting to hide previous messages.") ''' # Creating Buttons #C_Button_Clipboard = Button(Controls_Box_Frame, text="📋", pady=5, padx=5, command=PiperTTS_GUI_Clipboard) C_Button_Play = Button(Controls_Box_Frame, text="▶", pady=5, padx=5, command=PiperTTS_GUI_Play) C_Button_Pause = Button(Controls_Box_Frame, text="⏸", pady=5, padx=5, command=PiperTTS_GUI_Pause) C_Button_Stop = Button(Controls_Box_Frame, text="⏹", pady=5, padx=5, command=PiperTTS_GUI_Stop) C_Button_previous = Button(Controls_Box_Frame, text="⏮", pady=5, padx=5, command=PiperTTS_GUI_Previous) C_Button_Next = Button(Controls_Box_Frame, text="⏭", pady=5, padx=5, command=PiperTTS_GUI_Next) # Creating a Test Text Label My_Test_Label = Label(Controls_Box_Frame, text="Test Text?") My_Test_Label.grid(row=0, column=0, columnspan=4) try: global MyTestText = "There are {} Lines of text".format(len(Input_Box.get("1.0","end-1c").readlines())) except: print("An exception occurred - trying to count like dracula.") My_Test_Labe2 = Label(Controls_Box_Frame, text=MyTestText) My_Test_Label.grid(row=2, column=0, columnspan=4) # Aligning Buttons to grid #C_Button_Clipboard.grid(row=1, column=4) C_Button_Play.grid(row=1, column=0) C_Button_Pause.grid(row=1, column=1) C_Button_Stop.grid(row=1, column=2) C_Button_previous.grid(row=1, column=3) C_Button_Next.grid(row=1, column=4) # Prefrences stuff GUI_Combobox_1_Label = Label(Prefrences_Frame, text="Language?") GUI_Combobox_1 = ttk.Combobox(Prefrences_Frame) GUI_Combobox_2_Label = Label(Prefrences_Frame, text="Voice?") GUI_Combobox_2 = ttk.Combobox(Prefrences_Frame) GUI_Spinbox_1_Label = Label(Prefrences_Frame, text="volume?") GUI_Spinbox_1 = ttk.Spinbox(Prefrences_Frame, from_ = 1, to = 100) GUI_Spinbox_2_Label = Label(Prefrences_Frame, text="length_scale?") GUI_Spinbox_2 = ttk.Spinbox(Prefrences_Frame, from_ = 1.0, to = 2.0) GUI_Spinbox_3_Label = Label(Prefrences_Frame, text="noise_scale?") GUI_Spinbox_3 = ttk.Spinbox(Prefrences_Frame, from_ = 1.0, to = 2.0) GUI_Spinbox_4_Label = Label(Prefrences_Frame, text="noise_w_scale?") GUI_Spinbox_4 = ttk.Spinbox(Prefrences_Frame, from_ = 1.0, to = 2.0) GUI_Checkbutton_1 = ttk.Checkbutton(Prefrences_Frame, text="normalize_audio?") # Prefrences placement GUI_Combobox_1_Label.pack() GUI_Combobox_1.pack() GUI_Combobox_2_Label.pack() GUI_Combobox_2.pack() GUI_Spinbox_1_Label.pack() GUI_Spinbox_1.pack() GUI_Spinbox_2_Label.pack() GUI_Spinbox_2.pack() GUI_Spinbox_3_Label.pack() GUI_Spinbox_3.pack() GUI_Spinbox_4_Label.pack() GUI_Spinbox_4.pack() GUI_Checkbutton_1.pack() #Creating Toolbar menu Root_Toolbar = Menu(Root_Window) Root_Window.configure(menu=Root_Toolbar) #Creating File menu for Toolbar File_Toolbar = Menu(Root_Toolbar, tearoff=False) Root_Toolbar.add_cascade(label="File", menu=File_Toolbar) File_Toolbar.add_command(label="New", command=PiperTTS_GUI_New_File) File_Toolbar.add_command(label="Open", command=PiperTTS_GUI_TextFile_Open) File_Toolbar.add_command(label="Save as Wave") File_Toolbar.add_separator() File_Toolbar.add_command(label="Exit", command=Root_Window.quit) #Creating Playback menu for Toolbar Playback_Toolbar = Menu(Root_Toolbar, tearoff=False) Root_Toolbar.add_cascade(label="Playback", menu=Playback_Toolbar) Playback_Toolbar.add_command(label="▶\tPlay", command=PiperTTS_GUI_Play) Playback_Toolbar.add_command(label="⏸\tPause", command=PiperTTS_GUI_Pause) Playback_Toolbar.add_command(label="⏹\tStop", command=PiperTTS_GUI_Stop) Playback_Toolbar.add_command(label="⏮\tPrevious", command=PiperTTS_GUI_Previous) Playback_Toolbar.add_command(label="⏭\tNext", command=PiperTTS_GUI_Next) #Creating Tools menu for Toolbar Tools_Toolbar = Menu(Root_Toolbar, tearoff=False) Root_Toolbar.add_cascade(label="Tools", menu=Tools_Toolbar) Tools_Toolbar.add_command(label="Insert Selection", command=PiperTTS_GUI_Get_Selection) Tools_Toolbar.add_command(label="Insert Clipboard", command=PiperTTS_GUI_Get_Clipboard) Tools_Toolbar.add_separator() Tools_Toolbar.add_command(label="Randomize Text", command=PiperTTS_GUI_Randomize_Text) Tools_Toolbar.add_command(label="Reverse Text", command=PiperTTS_GUI_Reverse_Text) Tools_Toolbar.add_separator() Tools_Toolbar.add_command(label="Prefrences", command=PiperTTS_GUI_Set_Prefrences) # End of Code - Emd of Tkinter loop Root_Window.mainloop() # Function called on Exit def Registered_Exit(): print("Goodbye!?") # Regestering Exit atexit.register(Registered_Exit)