Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better ui #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>
Here are some steps on how to install it:
* Download Python 3.8.x or higher<br>
* Download Python 3.10.x or higher<br>
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<br>
Expand Down
98 changes: 62 additions & 36 deletions main/compiler.py
Original file line number Diff line number Diff line change
@@ -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()

3 changes: 2 additions & 1 deletion main/transpile_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -78,3 +78,4 @@
"""Optional to write file directly in dir."""
#newFile = open("result.txtl", "+w")
#newFile.write('\n'.join(result_array))