/
__init__.py
145 lines (128 loc) · 5.67 KB
/
__init__.py
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import os
import sys
from gi.repository import Gtk
from linker import Linker
from loader import Loader
from assembler import Assembler
from preprocessor import preprocess
from simulator import Simulator
class AllApp(Gtk.Application):
# constructor of the Gtk Application
def __init__(self):
Gtk.Application.__init__(self)
self.shell_ui = Gtk.Builder()
self.shell_ui.add_from_file("shell.glade")
self.handler_dict = {
"on_start_file_chooser_button_clicked": self.on_start_file_chooser_button_clicked,
"on_start_button_clicked": self.on_start_button_clicked,
"on_simulator_open_file_button_clicked": self.on_simulator_open_file_button_clicked,
"on_simulate_pass_button_clicked": self.on_simulate_pass_button_clicked,
"on_run_button_clicked": self.on_run_button_clicked,
"on_quit_image_menu_item_activate": self.on_quit_activate,
"on_offset_button_clicked": self.on_offset_button_clicked
}
self.shell_ui.connect_signals(self.handler_dict)
self.x = []
self.z = []
self.assembler_instance = None
self.loader_instance = None
self.linker_instance = None
self.simulator_instance = None
# self.simulator=Simulator()
def on_offset_button_clicked(self, widget):
self.loader_instance.loader2(self.x)
def do_activate(self):
window = self.shell_ui.get_object("all_window")
self.add_window(window)
window.show_all()
def on_start_file_chooser_button_clicked(self, widget):
window = self.shell_ui.get_object("all_window")
dialog = Gtk.FileChooserDialog(title="Please choose a file", parent=window, action=Gtk.FileChooserAction.OPEN,
buttons=(
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN,
Gtk.ResponseType.OK))
response = dialog.run()
if response == Gtk.ResponseType.OK:
selected_file_path = dialog.get_filename()
relative_path = os.path.basename(selected_file_path)
inputfile = open(relative_path, "r")
code = inputfile.read()
lines = code.split('\n')
finalfile = lines[0].split('.')[0] + '.8085'
print(lines[0].split('.')[0])
print(finalfile)
entries_box = self.shell_ui.get_object("start_entries_box")
wids = entries_box.get_children()
for widget in wids:
widget.destroy()
i = 0
print (lines)
for line in lines:
if line != '':
self.z.append(line)
label = Gtk.Label("Code" + str(i))
tv = Gtk.TextView()
tb = tv.get_buffer()
entries_box.add(label)
entries_box.add(tv)
i += 1
with open(line, "r") as file:
s = file.read()
tb.set_text(s)
print(s)
self.shell_ui.get_object("start_entry_number_entry").set_text(str(i))
entries_box.show_all()
self.x = preprocess(self.z)
processed_box = self.shell_ui.get_object("processed_box")
i = 0
for file_name in self.x:
if file_name != '':
label = Gtk.Label("Code" + str(i))
tv = Gtk.TextView()
tb = tv.get_buffer()
processed_box.add(label)
processed_box.add(tv)
i += 1
with open(file_name, "r") as file:
s = file.read()
tb.set_text(s)
print(s)
processed_box.show_all()
elif response == Gtk.ResponseType.CANCEL:
print("Cancel clicked")
dialog.destroy()
def on_start_button_clicked(self, widget):
finalfile = self.x[0].split('.')[0] + '.8085'
info = self.shell_ui.get_object("start_info_label")
# str1 = ''
# str1 += 'Interpreting...........\nRunning Assembler \n'
# info.set_text(str1)
self.assembler_instance = Assembler(self.shell_ui)
self.assembler_instance.test(self.x)
# str1 = str1 + 'Assembler Completed \n' + 'Running Linker \n'
# info.set_text(str1)
self.linker_instance = Linker(self.shell_ui, self.assembler_instance.symTable,
self.assembler_instance.globTable,
self.assembler_instance.filelen)
self.linker_instance.linker(self.x)
# str1 = str1 + 'Linker Completed \n' + 'Set offset and run loader\n'
# info.set_text(str1)
self.loader_instance = Loader(self.shell_ui)
self.loader_instance.loader(self.x)
# str1 = str1 + 'Loading Complete \n' + '\t\tFile ready to simulate.\n' + '\t\tFile name is : ' + finalfile + '\n'
# info.set_text(str1)
def on_simulator_open_file_button_clicked(self, widget):
pass
def on_simulate_pass_button_clicked(self, widget):
finalfile = self.x[0].split('.')[0] + '.8085'
self.simulator_instance = Simulator(self.shell_ui, self.shell_ui.get_object("all_window"))
self.simulator_instance.load(finalfile)
def on_run_button_clicked(self, widget):
self.simulator_instance.callbackf()
def do_startup(self):
Gtk.Application.do_startup(self)
def on_quit_activate(self, menu_item):
sys.exit()
app = AllApp()
exit_status = app.run(sys.argv)
sys.exit(exit_status)