diff --git a/README.md b/README.md index 8a472f5..cbb7930 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Discord: https://discord.gg/5zGVZ6f # Installation Installing this transpiler is simple, and any device that can run Python can install it, so macOS, Linux, and Windows are all probably able to do it, Windows has been tested and works successfully.
Here are some steps on how to install it: -* Download Python 3.8.x or higher
+* Download Python 3.10.x or higher
Other Python versions (such as 3.5, 3.4, etc) may work, but have not been tested if you already have an older version, use that. If an error occurs, upgrade. * Download the scripts
diff --git a/main/compiler.py b/main/compiler.py index 0fce838..3dd0c10 100644 --- a/main/compiler.py +++ b/main/compiler.py @@ -1,43 +1,69 @@ - +import PySimpleGUI as sg from tkinter import * from tkinter.scrolledtext import ScrolledText from tkinter import messagebox as tkmsg from tkinter import filedialog; import time -window = Tk() - -window.title("Python-Lua Compiler") -window.configure(bg="#000000") -window.tk.call('tk', 'scaling', 3.0) # Fix resolution +from os import path -# Func def msgbox(title, desc): - tkmsg.showinfo(title, desc) -def openDialog(): - openableTypes = [("All Files", "*"), ("Python Files", "*.py"), ("Text Files", "*.txt")] - openedPath = filedialog.askopenfilename(filetypes=openableTypes) - opened = open(openedPath) - readOpened = opened.read() - opened.close() - text_box.delete(1.0, END) - text_box.insert(1.0, readOpened) - msgbox("Opened", "File opened successfully.") - - -# widgets -text_box = ScrolledText(background="#000000", foreground="#FFFFFF") -# Operations -class to: - result = [] -def operations(): - openOperations = open("transpile_operations.py", "r") + tkmsg.showinfo(title, desc) + + +def openDialog() -> str: + readOpened = '' + openableTypes = [("All Files", "*"), ("Python Files", "*.py"), ("Text Files", "*.txt")] + openedPath = filedialog.askopenfilename(filetypes=openableTypes) + if type(openedPath) is str: + with open(openedPath) as opened: + readOpened = opened.read() + msgbox("Opened", "File opened successfully.") + return readOpened + + +def operations(window, values): + text_box = ScrolledText(background="#000000", foreground="#FFFFFF") + text_box.delete(1.0, END) + text_box.insert(1.0, values['-text_box-']) + + i_path = "transpile_operations.py" + + if not path.exists(i_path): + i_path = "main/transpile_operations.py" + + openOperations = open(i_path, "r") exec(openOperations.read()); openOperations.close() -# menus -_menu = Menu() -mainMenu = Menu(_menu, tearoff=0) -mainMenu.add_command(label="Open", command=openDialog) -mainMenu.add_command(label="Help", command= lambda: tkmsg.showinfo("Help", "Check repository for details.")) -mainMenu.add_command(label="Compile", command=operations) -_menu.add_cascade(label="Menu", menu=mainMenu) -window.config(menu=_menu) -text_box.pack() -window.mainloop() + window['-text_box-'].update(text_box.get(1.0, END)) + +def defaultWindow() -> None: + lenght = 500 + height = 470 + menu = [['&menu', ['&Open', '&Help', '&Compile', ], ], ] + layout = [ + [sg.MenubarCustom(menu, k='-menu-')], + [sg.Multiline(size = (lenght, 28), k='-text_box-', background_color='#000000', text_color='#808080')], + [sg.Button('Quit', size = (5, 1))], + #[sg.Button('Ok',size = (5, 1)), sg.Button('Quit', size = (5, 1))], + ] + window = sg.Window('Python-Lua Compiler', layout, size = (lenght, height)) + + while True: + event, values = window.read() + # See if user wants to quit or window was closed + match event: + case sg.WINDOW_CLOSED | 'Quit': + break + case 'Open': + window['-text_box-'].update(openDialog()) + case 'Help': + sg.Popup('Check repository for details.') + case 'Compile': + if values['-text_box-'] != '': + operations(window, values) + else: + sg.Popup('Input text cannot be empty') + + +if __name__ == '__main__': + sg.theme('graygraygray') + defaultWindow() + diff --git a/main/transpile_operations.py b/main/transpile_operations.py index 36616d5..f4412d6 100644 --- a/main/transpile_operations.py +++ b/main/transpile_operations.py @@ -6,7 +6,7 @@ """ tkmsg.showinfo("Compile", "Compiling. This may take some time.") -toParse = text_box.get(1.0, END) +toParse = text_box.get(END) lineBreak = """ """ # This functions. parse_dict = { @@ -78,3 +78,4 @@ """Optional to write file directly in dir.""" #newFile = open("result.txtl", "+w") #newFile.write('\n'.join(result_array)) +