195 lines
6.8 KiB
Python
195 lines
6.8 KiB
Python
from tkinter import *
|
|
import atexit
|
|
|
|
# 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 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)
|
|
except:
|
|
print("An exception occurred - when pressing New File Button.")
|
|
|
|
#
|
|
def PiperTTS_GUI_Get_Selection():
|
|
try:
|
|
Cursor_Position = Input_Box.index(INSERT)
|
|
Selected = Root_Window.selection_get()
|
|
Input_Box.insert(Cursor_Position, Selected)
|
|
except:
|
|
print("An exception occurred - when grabbing Selection.")
|
|
|
|
#
|
|
def PiperTTS_GUI_Get_Clipboard():
|
|
try:
|
|
Cursor_Position = Input_Box.index(INSERT)
|
|
Selected = Root_Window.clipboard_get()
|
|
Input_Box.insert(Cursor_Position, Selected)
|
|
except:
|
|
print("An exception occurred - when grabbing Clipboard.")
|
|
|
|
'''
|
|
#
|
|
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)
|
|
|
|
# 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)
|
|
|
|
#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")
|
|
File_Toolbar.add_command(label="Save")
|
|
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="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) |