-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignals.py
148 lines (121 loc) · 4.6 KB
/
signals.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
146
147
148
from backend.interface import Interface
from PyQt5.QtWidgets import QTableWidgetItem, QFileDialog
from PyQt5.QtGui import QPixmap
import images
interface = Interface()
file_path = ''
def set_values(SC, PC, AR, IR, DR, AC, TR, INPR, OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT):
try:
result = interface.get_values()
SC.setText(result['SC'])
PC.setText(result['PC'])
AR.setText(result['AR'])
IR.setText(result['IR'])
DR.setText(result['DR'])
AC.setText(result['AC'])
TR.setText(result['TR'])
INPR.setText(result['INPR'])
OUTR.setText(result['OUTR'])
INST.setText(result['INST'])
INPUT.setText(result['INPUT'])
green = QPixmap(":/images/images/green.png")
red = QPixmap(":/images/images/red.png")
I.setPixmap(green if result['I'] else red)
S.setPixmap(green if result['S'] else red)
E.setPixmap(green if result['E'] else red)
R.setPixmap(green if result['R'] else red)
IEN.setPixmap(green if result['IEN'] else red)
FGI.setPixmap(green if result['FGI'] else red)
FGO.setPixmap(green if result['FGO'] else red)
except:
pass
def set_memory(memory):
try:
result = interface.get_memory()
for i in range(4096):
item0 = QTableWidgetItem(result[i][0])
item2 = QTableWidgetItem(result[i][1])
item0.setTextAlignment(4)
item2.setTextAlignment(4)
memory.setItem(i, 0, item0)
memory.setItem(i, 2, item2)
except:
for i in range(4096):
item0 = QTableWidgetItem('')
item2 = QTableWidgetItem('0000')
item0.setTextAlignment(4)
item2.setTextAlignment(4)
memory.setItem(i, 0, item0)
memory.setItem(i, 2, item2)
def text_changed(inp):
interface.update_input(inp.text())
def beautify_code(code):
text = interface.save(code.toPlainText())
code.setPlainText(text)
def save_code(code):
value = code.toPlainText()
code.setPlainText(interface.save(value))
def compile_code(console, code, microoperation, memory, SC, PC, AR, IR, DR, AC, TR, INPR, OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT):
try:
result = interface.compile(code.toPlainText())
console.setPlainText(result[1])
microoperation.setText('')
if result[0]:
I.setEnabled(True)
S.setEnabled(True)
E.setEnabled(True)
R.setEnabled(True)
IEN.setEnabled(True)
FGI.setEnabled(True)
FGO.setEnabled(True)
except:
pass
set_memory(memory)
set_values(SC, PC, AR, IR, DR, AC, TR, INPR,
OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT)
def next_step(console, code, microoperation, memory, SC, PC, AR, IR, DR, AC, TR, INPR, OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT):
message = interface.next_step(code.toPlainText())
if message == None:
console.setPlainText(
'Compile code first!')
microoperation.setText('')
else:
console.setPlainText('')
microoperation.setText(message)
set_memory(memory)
set_values(SC, PC, AR, IR, DR, AC, TR, INPR,
OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT)
def run(console, code, microoperation, memory, SC, PC, AR, IR, DR, AC, TR, INPR, OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT):
message = interface.run(code.toPlainText())
if message == False:
console.setPlainText(
'Compile code first!')
microoperation.setText('')
else:
console.setPlainText('')
microoperation.setText('[FINISHED PROGRAM]')
set_memory(memory)
set_values(SC, PC, AR, IR, DR, AC, TR, INPR,
OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT)
def reset(console, code, microoperation, memory, SC, PC, AR, IR, DR, AC, TR, INPR, OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT):
compile_code(console, code, microoperation, memory, SC, PC, AR,
IR, DR, AC, TR, INPR, OUTR, INST, I, S, E, R, IEN, FGI, FGO, INPUT)
console.setPlainText('Reset execution')
microoperation.setText('')
def save_code(code):
global file_path
if not file_path:
file_path = QFileDialog.getSaveFileName()[0]
if file_path:
file = open(file_path, 'w')
text = code.toPlainText()
file.write(text)
file.close()
def open_code(code):
global file_path
file_path = QFileDialog.getOpenFileName()[0]
if file_path:
file = open(file_path, 'r')
text = file.read()
code.setPlainText(text)
file.close()