aboutsummaryrefslogtreecommitdiff
path: root/main.py
blob: 1da41ccd5dfc54c135177860832a454453674910 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import sys, getopt
from tkinter import *
from tkinter import ttk, filedialog
from lexer import *

class Main:
    input_file = None
    output_file = None

    # GUI widgets
    text = None
    msgarea = None
    symbols = None

    def abrir_archivo(self):
        self.input_file = filedialog.askopenfilename()
        with open(self.input_file) as f:
            data = f.read()
            self.text.insert(END, data)

    def guardar_archivo(self):
        data = self.text.get('1.0', 'end-1c')
        with open(self.input_file, "r+") as f:
            f.truncate(0)
            f.write(data)

    def compilar_programa(self):
        self.output_file = filedialog.asksaveasfilename()
        data = self.text.get('1.0', 'end-1c')
        inicio_lexer(data)

    def ejecutar_programa(self):
        print('ejecutar_programa()')

    def salir(self):
        exit(0)

    def main_gui(self, argv):
        root = Tk()
        root.title ("Javañol")
        root.columnconfigure(0, weight=1)
        root.rowconfigure(0, weight=1)
        root.option_add('*tearOff', FALSE)

        mainframe = ttk.Frame(root, padding="3 3 12 12")
        mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
        mainframe.columnconfigure(0, weight=1)
        mainframe.rowconfigure(0, weight=1)
        mainframe.rowconfigure(1, weight=0)

        # Menú
        menubar = Menu(root)
        root['menu'] = menubar

        menu_file = Menu(menubar)
        menubar.add_cascade(menu=menu_file, label='Archivo')
        menu_file.add_command(label='Abrir', command=self.abrir_archivo)
        menu_file.add_command(label='Guardar', command=self.guardar_archivo)
        menu_file.add_command(label='Salir', command=self.salir)

        menu_program = Menu(menubar)
        menubar.add_cascade(menu=menu_program, label='Programa')
        menu_program.add_command(label='Compilar', command=self.compilar_programa)
        menu_program.add_command(label='Ejecutar', command=self.ejecutar_programa)

        # Editor de código
        self.text = Text(mainframe)
        self.text.grid(column=0, row=0, sticky=(N, W, E, S))

        # Área de mensajes
        msgarealf = LabelFrame(mainframe, text='Área de mensajes', height=10)
        msgarealf.grid(column=0, row=1, sticky=(W, E, S))
        
        self.msgarea = Text(msgarealf, height=10)
        self.msgarea.grid(column=0, row=0, sticky=(N, W, E, S))
        self.msgarea.rowconfigure(0, weight=1)
        self.msgarea.columnconfigure(0, weight=1)

        # Tabla de símbolos
        symbolslf = LabelFrame(mainframe, text='Símbolos', width=100)
        symbolslf.grid(column=1, row=0, rowspan=2, sticky=(N, W, E, S))
        
        self.symbols = Text(symbolslf, width=20)
        self.symbols.grid(column=0, row=0, sticky=(N, W, E, S))
        self.msgarea.rowconfigure(0, weight=1)
        self.msgarea.columnconfigure(0, weight=1)

        root.mainloop()
        
if __name__ == "__main__":
    main = Main()
    main.main_gui(sys.argv)