|
1 | 1 | from PyQt5.QtWidgets import *
|
2 | 2 | from PyQt5.QtCore import *
|
3 | 3 | from PyQt5.QtGui import *
|
| 4 | +from lexer import * |
| 5 | +from sintactico import * |
4 | 6 |
|
5 | 7 |
|
6 | 8 | class RustEditor(QPlainTextEdit):
|
@@ -141,41 +143,84 @@ def __init__(self):
|
141 | 143 |
|
142 | 144 |
|
143 | 145 | class LabelExecution(QWidget):
|
| 146 | + vb = QVBoxLayout() |
| 147 | + hb_layout = QHBoxLayout() |
| 148 | + label_text = None |
| 149 | + plain_text = None |
144 | 150 | def __init__(self):
|
145 | 151 | super(LabelExecution, self).__init__()
|
146 |
| - layout = QHBoxLayout() |
147 |
| - label_text = QLabel() |
148 |
| - label_text.setText("<h4>Execution</h4>") |
149 |
| - label_text.setStyleSheet("color: #2D2D2D;") |
150 |
| - label_code = QLabel() |
| 152 | + self.label_text = QLabel() |
| 153 | + self.label_text.setText("<h4>Execution</h4>") |
| 154 | + self.label_text.setStyleSheet("color: #2D2D2D;") |
| 155 | + self.label_code = QLabel() |
151 | 156 | pixmap_code = QPixmap("./images/GUI/rs-exec.png")
|
152 | 157 | pixmap_code = pixmap_code.scaled(50, 100, Qt.KeepAspectRatio)
|
153 |
| - label_code.setPixmap(pixmap_code) |
| 158 | + self.label_code.setPixmap(pixmap_code) |
154 | 159 |
|
155 |
| - layout.addWidget(label_code) |
156 |
| - layout.addWidget(label_text) |
157 |
| - layout.addStretch(1) |
158 |
| - self.setLayout(layout) |
| 160 | + self.plain_text = QPlainTextEdit() |
| 161 | + self.plain_text.setReadOnly(True) |
| 162 | + self.plain_text.setStyleSheet("background-color: #E5E8ED;") |
| 163 | + |
| 164 | + self.hb_layout.addWidget(self.label_code) |
| 165 | + self.hb_layout.addWidget(self.label_text) |
| 166 | + self.hb_layout.addStretch(1) |
| 167 | + |
| 168 | + self.vb.addLayout(self.hb_layout) |
| 169 | + self.vb.addWidget(self.plain_text) |
| 170 | + self.setLayout(self.vb) |
159 | 171 |
|
160 | 172 |
|
161 | 173 | class Buttons(QWidget):
|
162 |
| - def __init__(self): |
| 174 | + def __init__(self, editor, execution_label): |
163 | 175 | super(Buttons, self).__init__()
|
164 | 176 | layout = QVBoxLayout()
|
165 |
| - button_run = QPushButton("Run") |
166 |
| - button_run.setIcon(QIcon("./images/GUI/play.png")) |
167 |
| - button_run.setFixedSize(100, 50) |
168 |
| - button_run.setCursor(QCursor(Qt.PointingHandCursor)) |
| 177 | + button_lexer = QPushButton("Run Lexer") |
| 178 | + button_lexer.setIcon(QIcon("./images/GUI/play.png")) |
| 179 | + button_lexer.setFixedSize(100, 40) |
| 180 | + button_lexer.setCursor(QCursor(Qt.PointingHandCursor)) |
| 181 | + button_lexer.clicked.connect(lambda: self.onClickedLexer(editor, execution_label)) |
| 182 | + |
| 183 | + layout = QVBoxLayout() |
| 184 | + button_parser = QPushButton("Run Parser") |
| 185 | + button_parser.setIcon(QIcon("./images/GUI/play.png")) |
| 186 | + button_parser.setFixedSize(100, 40) |
| 187 | + button_parser.setCursor(QCursor(Qt.PointingHandCursor)) |
| 188 | + button_parser.clicked.connect(lambda: self.onClickedParser(editor, execution_label)) |
169 | 189 |
|
170 | 190 | button_open = QPushButton("Open File")
|
171 | 191 | button_open.setIcon(QIcon("./images/GUI/open.png"))
|
172 |
| - button_open.setFixedSize(100, 50) |
| 192 | + button_open.setFixedSize(100, 40) |
173 | 193 | button_open.setCursor(QCursor(Qt.PointingHandCursor))
|
174 | 194 |
|
175 |
| - layout.addWidget(button_run) |
| 195 | + layout.addWidget(button_lexer) |
| 196 | + layout.addWidget(button_parser) |
176 | 197 | layout.addWidget(button_open)
|
177 | 198 | self.setLayout(layout)
|
178 | 199 |
|
| 200 | + def onClickedLexer(self,editor,execution_label): |
| 201 | + print("Clicked") |
| 202 | + print(editor.toPlainText()) |
| 203 | + tp = execution_label.plain_text |
| 204 | + tp.insertPlainText("") |
| 205 | + l_token = run_lexer(editor.toPlainText()) |
| 206 | + for tok in l_token: |
| 207 | + tp.insertPlainText("{:5} : {:5}".format(tok.value,tok.type)) |
| 208 | + tp.insertPlainText("\n") |
| 209 | + tp.insertPlainText("\n") |
| 210 | + tp.insertPlainText("\n") |
| 211 | + |
| 212 | + def onClickedParser(self,editor,execution_label): |
| 213 | + tp = execution_label.plain_text |
| 214 | + try: |
| 215 | + p_tree = run_parser(editor.toPlainText()) |
| 216 | + print(f'Este es el ptree: {p_tree}') |
| 217 | + tp.insertPlainText(str(p_tree)) |
| 218 | + tp.insertPlainText("\n") |
| 219 | + except Exception as e: |
| 220 | + tp.insertPlainText(str(e)) |
| 221 | + tp.insertPlainText("\n") |
| 222 | + tp.insertPlainText("\n") |
| 223 | + |
179 | 224 |
|
180 | 225 | class SyntaxHighlighter(QSyntaxHighlighter):
|
181 | 226 | def __init__(self, parent):
|
@@ -231,7 +276,7 @@ def UIComponents(self):
|
231 | 276 | editor = RustEditor(DISPLAY_LINE_NUMBERS=True,
|
232 | 277 | HIGHLIGHT_CURRENT_LINE=True)
|
233 | 278 |
|
234 |
| - buttons = Buttons() |
| 279 | + buttons = Buttons(editor,label_exec) |
235 | 280 |
|
236 | 281 | splitter = QFrame()
|
237 | 282 | splitter.setObjectName("splitter")
|
|
0 commit comments