forked from YanShulinjj/Sample-Compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoMata_Ui.py
188 lines (163 loc) · 7.55 KB
/
AutoMata_Ui.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'nfa.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from AutoFA import *
class Ui_NFA(object):
def setupUi(self, NFA, name=""):
from PIL import Image
file_path = './image/{}.gv.png'.format(name)
img = Image.open(file_path)
w = img.width # 图片的宽
h = img.height # 图片的高
NFA.setObjectName("NFA")
NFA.resize(w*1.2, h*1.5)
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(NFA)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.groupBox = QtWidgets.QGroupBox(NFA)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.groupBox)
self.horizontalLayout.setObjectName("horizontalLayout")
self.graphicsView = QtWidgets.QGraphicsView(self.groupBox)
self.graphicsView.setObjectName("graphicsView")
self.horizontalLayout.addWidget(self.graphicsView)
self.horizontalLayout_2.addWidget(self.groupBox)
self.graphicsView.scene_img = QGraphicsScene()
self.imgShow = QPixmap()
self.imgShow.load(file_path)
self.imgShowItem = QGraphicsPixmapItem()
self.imgShowItem.setPixmap(QPixmap(self.imgShow))
self.imgShowItem.setPixmap(QPixmap(self.imgShow).scaled(w, h)) # //自己设定尺寸
self.graphicsView.scene_img.addItem(self.imgShowItem)
self.graphicsView.setScene(self.graphicsView.scene_img)
self.retranslateUi(NFA, name.upper())
QtCore.QMetaObject.connectSlotsByName(NFA)
def retranslateUi(self, NFA, name=""):
_translate = QtCore.QCoreApplication.translate
NFA.setWindowTitle(_translate("NFA", name))
class Auto_Mata(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.setEnabled(True)
Form.resize(701, 160)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Form.sizePolicy().hasHeightForWidth())
Form.setSizePolicy(sizePolicy)
Form.setMaximumSize(QtCore.QSize(701, 160))
self.groupBox = QtWidgets.QGroupBox(Form)
self.groupBox.setGeometry(QtCore.QRect(10, 10, 681, 80))
self.groupBox.setLayoutDirection(QtCore.Qt.LeftToRight)
self.groupBox.setAutoFillBackground(True)
self.groupBox.setTitle("")
self.groupBox.setObjectName("groupBox")
self.textEdit = QtWidgets.QTextEdit(self.groupBox)
self.textEdit.setGeometry(QtCore.QRect(300, 20, 371, 41))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(14)
self.textEdit.setFont(font)
self.textEdit.setObjectName("textEdit")
self.label = QtWidgets.QLabel(self.groupBox)
self.label.setGeometry(QtCore.QRect(20, 20, 271, 41))
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(14)
self.label.setFont(font)
self.label.setObjectName("label")
self.groupBox_2 = QtWidgets.QGroupBox(Form)
self.groupBox_2.setGeometry(QtCore.QRect(10, 90, 681, 61))
self.groupBox_2.setTitle("")
self.groupBox_2.setObjectName("groupBox_2")
self.widget = QtWidgets.QWidget(self.groupBox_2)
self.widget.setGeometry(QtCore.QRect(130, 20, 397, 31))
self.widget.setObjectName("widget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.widget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.pushButton_4 = QtWidgets.QPushButton(self.widget)
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(12)
self.pushButton_4.setFont(font)
self.pushButton_4.setObjectName("pushButton_4")
self.horizontalLayout.addWidget(self.pushButton_4)
self.pushButton = QtWidgets.QPushButton(self.widget)
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(12)
self.pushButton.setFont(font)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.widget)
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(12)
self.pushButton_2.setFont(font)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout.addWidget(self.pushButton_2)
self.pushButton_3 = QtWidgets.QPushButton(self.widget)
font = QtGui.QFont()
font.setFamily("Microsoft YaHei UI")
font.setPointSize(12)
self.pushButton_3.setFont(font)
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout.addWidget(self.pushButton_3)
self.pushButton_4.setEnabled(True)
self.pushButton.setEnabled(False)
self.pushButton_2.setEnabled(False)
self.pushButton_3.setEnabled(False)
self.pushButton_4.clicked.connect(self.botton_display)
self.pushButton_4.clicked.connect(lambda : self.generate_auto_mata())
self.pushButton.clicked.connect(lambda : self.png_display("nfa"))
self.pushButton_2.clicked.connect(lambda : self.png_display("dfa"))
self.pushButton_3.clicked.connect(lambda : self.png_display("mfa"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def botton_display(self):
self.pushButton_4.setEnabled(False)
self.pushButton.setEnabled(True)
self.pushButton_2.setEnabled(True)
self.pushButton_3.setEnabled(True)
def png_display(self, name=""):
self.png_widget = QWidget()
self.png_window = Ui_NFA()
self.png_window.setupUi(self.png_widget, name)
self.png_widget.show()
def generate_auto_mata(self):
exp = self.textEdit.toPlainText()
if exp:
ss = Auto_FA(exp)
ss.exp_to_nfa()
ss.show()
ss.trans_dfa()
ss.simplify_dfa()
ss.draw_png()
else:
self.pushButton_4.setEnabled(True)
self.pushButton.setEnabled(False)
self.pushButton_2.setEnabled(False)
self.pushButton_3.setEnabled(False)
def refresh(self):
self.pushButton_4.setEnabled(True)
self.pushButton_3.setEnabled(False)
self.pushButton_2.setEnabled(False)
self.pushButton.setEnabled(False)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Auto_Mata"))
self.label.setText(_translate("Form", "input the Regular Expression:"))
self.pushButton_4.setText(_translate("Form", "Start"))
self.pushButton.setText(_translate("Form", "NFA Display"))
self.pushButton_2.setText(_translate("Form", "DFA Display"))
self.pushButton_3.setText(_translate("Form", "MFA Display"))
# 当内容改变时
self.textEdit.textChanged.connect(self.refresh)