<reponame>Xpliot/IDE
from tkinter import *
from tkinter.filedialog import asksaveasfilename, askopenfilename
import subprocess
import re
import idlelib.colorizer as ic
import idlelib.percolator as ip


cdg = ic.ColorDelegator()
cdg.prog = re.compile(r'\b(?P<MYGROUP>tkinter)\b|' + ic.make_pat(), re.S) 
cdg.idprog = re.compile(r'\s+(\w+)', re.S)
cdg.tagdefs['MYGROUP'] = {'foreground': '#E06C75', 'background': '#FFFFFF'}
cdg.tagdefs['COMMENT'] = {'foreground': '#ABB2BF', 'background': '#FFFFFF'}
cdg.tagdefs['KEYWORD'] = {'foreground': '#C678DD', 'background': '#FFFFFF'}
cdg.tagdefs['BUILTIN'] = {'foreground': '#56B6C2', 'background': '#FFFFFF'}
cdg.tagdefs['STRING'] = {'foreground': '#98C379', 'background': '#FFFFFF'}
cdg.tagdefs['DEFINITION'] = {'foreground': '#C678DD', 'background': '#FFFFFF'}

compiler = Tk()
compiler.title('Menta')
file_path = ''


def set_file_path(path):
    global file_path
    file_path = path


def open_file():
    path = askopenfilename(filetypes=[('Python Files', '*.py')])
    with open(path, 'r') as file:
        code = file.read()
        editor.delete('1.0', END)
        editor.insert('1.0', code)
        set_file_path(path)

def save_as():
    if file_path == '':
        path = asksaveasfilename(filetypes=[('Python Files', '*.py')])
    else:
        path = file_path
    with open(path, 'w') as file:
        code = editor.get('1.0', END)
        file.write(code)
        set_file_path(path)


def run():
    code_output.delete('1.0', END)
    if file_path == '':
        save_prompt = Toplevel()
        text = Label(save_prompt, text='Please save your code')
        text.pack()
        return
    command = f'python {file_path}'
    commandC = f'gcc {file_path}'
    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    processC = subprocess.Popen(commandC, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    outputC, errorC = processC.communicate()
    code_output.insert('1.0', output)
    code_output.insert('1.0',  error)
    code_output.insert('1.0', outputC)
    code_output.insert('1.0',  errorC)


menu_bar = Menu(compiler)

file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label='Open', command=open_file)
file_menu.add_command(label='Save', command=save_as)
file_menu.add_command(label='Save As', command=save_as)
file_menu.add_command(label='Exit', command=exit)
menu_bar.add_cascade(label='File', menu=file_menu)

run_bar = Menu(menu_bar, tearoff=0)
run_bar.add_command(label='Run', command=run)
menu_bar.add_cascade(label='Run', menu=run_bar)

compiler.config(menu=menu_bar)

editor = Text()
editor.pack()
code_output = Text(height=10)
code_output.pack()
ip.Percolator(editor).insertfilter(cdg)
compiler.mainloop()
from tkinter import *
from tkinter.filedialog import asksaveasfilename, askopenfilename
import subprocess
import re
import idlelib.colorizer as ic
import idlelib.percolator as ip


cdg = ic.ColorDelegator()
cdg.prog = re.compile(r'\b(?P<MYGROUP>tkinter)\b|' + ic.make_pat(), re.S) 
cdg.idprog = re.compile(r'\s+(\w+)', re.S)
cdg.tagdefs['MYGROUP'] = {'foreground': '#E06C75', 'background': '#FFFFFF'}
cdg.tagdefs['COMMENT'] = {'foreground': '#ABB2BF', 'background': '#FFFFFF'}
cdg.tagdefs['KEYWORD'] = {'foreground': '#C678DD', 'background': '#FFFFFF'}
cdg.tagdefs['BUILTIN'] = {'foreground': '#56B6C2', 'background': '#FFFFFF'}
cdg.tagdefs['STRING'] = {'foreground': '#98C379', 'background': '#FFFFFF'}
cdg.tagdefs['DEFINITION'] = {'foreground': '#C678DD', 'background': '#FFFFFF'}

compiler = Tk()
compiler.title('Menta')
file_path = ''


def set_file_path(path):
    global file_path
    file_path = path


def open_file():
    path = askopenfilename(filetypes=[('Python Files', '*.py')])
    with open(path, 'r') as file:
        code = file.read()
        editor.delete('1.0', END)
        editor.insert('1.0', code)
        set_file_path(path)

def save_as():
    if file_path == '':
        path = asksaveasfilename(filetypes=[('Python Files', '*.py')])
    else:
        path = file_path
    with open(path, 'w') as file:
        code = editor.get('1.0', END)
        file.write(code)
        set_file_path(path)


def run():
    code_output.delete('1.0', END)
    if file_path == '':
        save_prompt = Toplevel()
        text = Label(save_prompt, text='Please save your code')
        text.pack()
        return
    command = f'python {file_path}'
    commandC = f'gcc {file_path}'
    process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    processC = subprocess.Popen(commandC, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
    output, error = process.communicate()
    outputC, errorC = processC.communicate()
    code_output.insert('1.0', output)
    code_output.insert('1.0',  error)
    code_output.insert('1.0', outputC)
    code_output.insert('1.0',  errorC)


menu_bar = Menu(compiler)

file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label='Open', command=open_file)
file_menu.add_command(label='Save', command=save_as)
file_menu.add_command(label='Save As', command=save_as)
file_menu.add_command(label='Exit', command=exit)
menu_bar.add_cascade(label='File', menu=file_menu)

run_bar = Menu(menu_bar, tearoff=0)
run_bar.add_command(label='Run', command=run)
menu_bar.add_cascade(label='Run', menu=run_bar)

compiler.config(menu=menu_bar)

editor = Text()
editor.pack()
code_output = Text(height=10)
code_output.pack()
ip.Percolator(editor).insertfilter(cdg)
compiler.mainloop()