@ -0,0 +1,137 @@
|
||||
### pycharm template
|
||||
### Your template template
|
||||
# Byte-compiled / optimized / DLL files
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# C extensions
|
||||
*.so
|
||||
|
||||
# Distribution / packaging
|
||||
.idea/
|
||||
.Python
|
||||
build/
|
||||
develop-eggs/
|
||||
dist/
|
||||
downloads/
|
||||
eggs/
|
||||
.eggs/
|
||||
lib/
|
||||
lib64/
|
||||
parts/
|
||||
sdist/
|
||||
var/
|
||||
wheels/
|
||||
pip-wheel-metadata/
|
||||
share/python-wheels/
|
||||
*.egg-info/
|
||||
.installed.cfg
|
||||
*.egg
|
||||
MANIFEST
|
||||
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
pip-delete-this-directory.txt
|
||||
|
||||
# Unit test / coverage reports
|
||||
htmlcov/
|
||||
.tox/
|
||||
.coverage
|
||||
.coverage.*
|
||||
.cache
|
||||
nosetests.xml
|
||||
coverage.xml
|
||||
*.cover
|
||||
*.py,cover
|
||||
.hypothesis/
|
||||
.pytest_cache/
|
||||
|
||||
# Translations
|
||||
*.mo
|
||||
*.pot
|
||||
|
||||
# Django stuff:
|
||||
*.log
|
||||
local_settings.py
|
||||
db.sqlite3
|
||||
db.sqlite3-journal
|
||||
media
|
||||
|
||||
# Flask stuff:
|
||||
instance/
|
||||
.webassets-cache
|
||||
|
||||
# Scrapy stuff:
|
||||
.scrapy
|
||||
|
||||
# Sphinx documentation
|
||||
docs/_build/
|
||||
|
||||
# PyBuilder
|
||||
target/
|
||||
|
||||
# Jupyter Notebook
|
||||
.ipynb_checkpoints
|
||||
|
||||
# IPython
|
||||
profile_default/
|
||||
ipython_config.py
|
||||
|
||||
# pyenv
|
||||
.python-version
|
||||
|
||||
# celery beat schedule file
|
||||
celerybeat-schedule
|
||||
|
||||
# SageMath parsed files
|
||||
*.sage.py
|
||||
|
||||
# Environments
|
||||
.env
|
||||
.venv
|
||||
env/
|
||||
venv/
|
||||
ENV/
|
||||
|
||||
# Python profiling files
|
||||
profiling/
|
||||
*.pyc
|
||||
|
||||
# virtualenv
|
||||
VENV/
|
||||
|
||||
# Spyder project settings
|
||||
.spyderproject
|
||||
.spyproject
|
||||
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
# Sublime Text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
*.sublime-workspace
|
||||
*.sublime-project
|
||||
|
||||
# PyCharm files
|
||||
.idea/
|
||||
|
||||
# Visual Studio Code
|
||||
.vscode/
|
||||
|
||||
# Windows directories
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# macOS directories
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Linux directories
|
||||
*~
|
||||
|
||||
# Python Jupyter Notebooks
|
||||
.ipynb_checkpoints
|
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 8.0 KiB |
After Width: | Height: | Size: 8.7 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 19 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 24 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 7.5 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 18 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 27 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 57 KiB |
After Width: | Height: | Size: 56 KiB |
After Width: | Height: | Size: 56 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 5.8 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 8.9 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 52 KiB |
After Width: | Height: | Size: 51 KiB |
After Width: | Height: | Size: 54 KiB |
@ -0,0 +1,69 @@
|
||||
from PySide6.QtCore import Qt, QRectF, Signal, QObject
|
||||
from PySide6.QtGui import QPainter, QPen, QColor, QFontMetricsF, QPainterPath
|
||||
from PySide6.QtWidgets import QGraphicsItem
|
||||
|
||||
|
||||
class RoundedRectangleItem(QGraphicsItem, QObject):
|
||||
selected = Signal(int)
|
||||
unselected = Signal(int)
|
||||
def __init__(self, x, y, text, id):
|
||||
QGraphicsItem.__init__(self)
|
||||
QObject.__init__(self)
|
||||
self.rect = QRectF(x, y, 70, 70)
|
||||
self.radius = 10
|
||||
self.text = text
|
||||
self.id = id
|
||||
self.isSelected = False # 是否被选中
|
||||
|
||||
def boundingRect(self):
|
||||
return self.rect
|
||||
|
||||
def shape(self):
|
||||
path = QPainterPath()
|
||||
path.addRoundedRect(self.rect, self.radius, self.radius)
|
||||
return path
|
||||
|
||||
def paint(self, painter, option, widget):
|
||||
painter.setRenderHint(QPainter.Antialiasing) # 设置抗锯齿
|
||||
pen = QPen(Qt.black)
|
||||
painter.setPen(pen)
|
||||
|
||||
if self.isSelected:
|
||||
# 如果被选中,设置不同的填充颜色和边框样式
|
||||
painter.setBrush(QColor(255, 0, 0, 255)) # 设置选中时的填充颜色
|
||||
pen.setWidth(2) # 设置边框宽度
|
||||
pen.setStyle(Qt.DashLine) # 设置虚线边框样式
|
||||
painter.setPen(pen)
|
||||
else:
|
||||
painter.setBrush(QColor(0, 255, 0, 255)) # 设置默认的填充颜色
|
||||
|
||||
# 绘制圆角矩形
|
||||
painter.drawRoundedRect(self.rect, self.radius, self.radius)
|
||||
|
||||
# 计算文本的位置
|
||||
font = painter.font()
|
||||
font.setPointSize(36)
|
||||
painter.setFont(font)
|
||||
metrics = QFontMetricsF(font)
|
||||
text_bounding_rect = metrics.boundingRect(str(self.text))
|
||||
text_width = text_bounding_rect.width()
|
||||
text_height = text_bounding_rect.height()
|
||||
text_x = self.rect.center().x() - text_width / 2
|
||||
text_y = self.rect.center().y() + text_height / 4
|
||||
|
||||
# 绘制文本
|
||||
painter.drawText(text_x, text_y, str(self.text))
|
||||
|
||||
def mousePressEvent(self, event):
|
||||
# 鼠标点击时切换选中状态
|
||||
self.isSelected = not self.isSelected
|
||||
self.update()
|
||||
|
||||
# 发射选中信号
|
||||
if self.isSelected:
|
||||
self.selected.emit(self.id)
|
||||
else:
|
||||
self.unselected.emit(self.id)
|
||||
|
||||
|
||||
super().mousePressEvent(event)
|
@ -0,0 +1,267 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
################################################################################
|
||||
## Form generated from reading UI file 'main_ui.ui'
|
||||
##
|
||||
## Created by: Qt User Interface Compiler version 6.6.1
|
||||
##
|
||||
## WARNING! All changes made in this file will be lost when recompiling UI file!
|
||||
################################################################################
|
||||
|
||||
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
|
||||
QMetaObject, QObject, QPoint, QRect,
|
||||
QSize, QTime, QUrl, Qt)
|
||||
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
|
||||
QFont, QFontDatabase, QGradient, QIcon,
|
||||
QImage, QKeySequence, QLinearGradient, QPainter,
|
||||
QPalette, QPixmap, QRadialGradient, QTransform)
|
||||
from PySide6.QtWidgets import (QApplication, QFrame, QGraphicsView, QHBoxLayout,
|
||||
QLabel, QLineEdit, QMainWindow, QMenuBar,
|
||||
QPushButton, QSizePolicy, QStatusBar, QVBoxLayout,
|
||||
QWidget)
|
||||
|
||||
class Ui_MainWindow(object):
|
||||
def setupUi(self, MainWindow):
|
||||
if not MainWindow.objectName():
|
||||
MainWindow.setObjectName(u"MainWindow")
|
||||
MainWindow.resize(1190, 923)
|
||||
font = QFont()
|
||||
font.setPointSize(16)
|
||||
MainWindow.setFont(font)
|
||||
MainWindow.setStyleSheet(u"")
|
||||
self.centralwidget = QWidget(MainWindow)
|
||||
self.centralwidget.setObjectName(u"centralwidget")
|
||||
self.centralwidget.setStyleSheet(u"")
|
||||
self.verticalLayout = QVBoxLayout(self.centralwidget)
|
||||
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||
self.frame = QFrame(self.centralwidget)
|
||||
self.frame.setObjectName(u"frame")
|
||||
self.frame.setFrameShape(QFrame.StyledPanel)
|
||||
self.frame.setFrameShadow(QFrame.Raised)
|
||||
self.horizontalLayoutWidget = QWidget(self.frame)
|
||||
self.horizontalLayoutWidget.setObjectName(u"horizontalLayoutWidget")
|
||||
self.horizontalLayoutWidget.setGeometry(QRect(40, 10, 651, 222))
|
||||
self.horizontalLayout = QHBoxLayout(self.horizontalLayoutWidget)
|
||||
self.horizontalLayout.setObjectName(u"horizontalLayout")
|
||||
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.p4 = QPushButton(self.horizontalLayoutWidget)
|
||||
self.p4.setObjectName(u"p4")
|
||||
self.p4.setMinimumSize(QSize(148, 220))
|
||||
self.p4.setMaximumSize(QSize(148, 16777215))
|
||||
|
||||
self.horizontalLayout.addWidget(self.p4)
|
||||
|
||||
self.p3 = QPushButton(self.horizontalLayoutWidget)
|
||||
self.p3.setObjectName(u"p3")
|
||||
self.p3.setMinimumSize(QSize(148, 220))
|
||||
self.p3.setMaximumSize(QSize(148, 16777215))
|
||||
|
||||
self.horizontalLayout.addWidget(self.p3)
|
||||
|
||||
self.p2 = QPushButton(self.horizontalLayoutWidget)
|
||||
self.p2.setObjectName(u"p2")
|
||||
self.p2.setMinimumSize(QSize(148, 220))
|
||||
self.p2.setMaximumSize(QSize(148, 16777215))
|
||||
|
||||
self.horizontalLayout.addWidget(self.p2)
|
||||
|
||||
self.p1 = QPushButton(self.horizontalLayoutWidget)
|
||||
self.p1.setObjectName(u"p1")
|
||||
self.p1.setMinimumSize(QSize(148, 220))
|
||||
self.p1.setMaximumSize(QSize(148, 16777215))
|
||||
|
||||
self.horizontalLayout.addWidget(self.p1)
|
||||
|
||||
self.lineEdit = QLineEdit(self.frame)
|
||||
self.lineEdit.setObjectName(u"lineEdit")
|
||||
self.lineEdit.setGeometry(QRect(40, 230, 821, 31))
|
||||
self.label_result = QLabel(self.frame)
|
||||
self.label_result.setObjectName(u"label_result")
|
||||
self.label_result.setGeometry(QRect(880, 230, 141, 31))
|
||||
self.label_result.setStyleSheet(u"background-color:rgb(74, 203, 105)")
|
||||
self.label_result.setAlignment(Qt.AlignCenter)
|
||||
self.label_TF = QLabel(self.frame)
|
||||
self.label_TF.setObjectName(u"label_TF")
|
||||
self.label_TF.setGeometry(QRect(1030, 230, 31, 31))
|
||||
self.label_TF.setStyleSheet(u"background-color:rgb(219, 205, 166)")
|
||||
self.label_TF.setAlignment(Qt.AlignCenter)
|
||||
self.pushButton = QPushButton(self.frame)
|
||||
self.pushButton.setObjectName(u"pushButton")
|
||||
self.pushButton.setGeometry(QRect(1080, 220, 81, 51))
|
||||
font1 = QFont()
|
||||
font1.setPointSize(16)
|
||||
font1.setBold(True)
|
||||
self.pushButton.setFont(font1)
|
||||
self.pushButton.setStyleSheet(u"")
|
||||
self.pushButton_q = QPushButton(self.frame)
|
||||
self.pushButton_q.setObjectName(u"pushButton_q")
|
||||
self.pushButton_q.setGeometry(QRect(950, 50, 151, 51))
|
||||
self.pushButton_q.setFont(font1)
|
||||
self.pushButton_ex = QPushButton(self.frame)
|
||||
self.pushButton_ex.setObjectName(u"pushButton_ex")
|
||||
self.pushButton_ex.setGeometry(QRect(950, 130, 151, 51))
|
||||
self.pushButton_ex.setFont(font1)
|
||||
self.pushButton_autosv = QPushButton(self.frame)
|
||||
self.pushButton_autosv.setObjectName(u"pushButton_autosv")
|
||||
self.pushButton_autosv.setGeometry(QRect(40, 270, 141, 41))
|
||||
self.pushButton_autosv.setFont(font1)
|
||||
self.pushButton_dtree = QPushButton(self.frame)
|
||||
self.pushButton_dtree.setObjectName(u"pushButton_dtree")
|
||||
self.pushButton_dtree.setGeometry(QRect(200, 270, 141, 41))
|
||||
self.pushButton_dtree.setFont(font1)
|
||||
self.pushButton_allan = QPushButton(self.frame)
|
||||
self.pushButton_allan.setObjectName(u"pushButton_allan")
|
||||
self.pushButton_allan.setGeometry(QRect(360, 270, 141, 41))
|
||||
self.pushButton_allan.setFont(font1)
|
||||
self.pushButton_exp = QPushButton(self.frame)
|
||||
self.pushButton_exp.setObjectName(u"pushButton_exp")
|
||||
self.pushButton_exp.setGeometry(QRect(520, 270, 141, 41))
|
||||
self.pushButton_exp.setFont(font1)
|
||||
self.pushButton_ast = QPushButton(self.frame)
|
||||
self.pushButton_ast.setObjectName(u"pushButton_ast")
|
||||
self.pushButton_ast.setGeometry(QRect(690, 270, 141, 41))
|
||||
self.pushButton_ast.setFont(font1)
|
||||
self.pushButton_9 = QPushButton(self.frame)
|
||||
self.pushButton_9.setObjectName(u"pushButton_9")
|
||||
self.pushButton_9.setGeometry(QRect(860, 270, 141, 41))
|
||||
self.pushButton_9.setFont(font1)
|
||||
self.label = QLabel(self.frame)
|
||||
self.label.setObjectName(u"label")
|
||||
self.label.setGeometry(QRect(760, 170, 101, 31))
|
||||
self.p1_selected = QPushButton(self.frame)
|
||||
self.p1_selected.setObjectName(u"p1_selected")
|
||||
self.p1_selected.setGeometry(QRect(750, 20, 100, 150))
|
||||
self.p1_selected.setMinimumSize(QSize(100, 150))
|
||||
self.p1_selected.setMaximumSize(QSize(100, 150))
|
||||
|
||||
self.verticalLayout.addWidget(self.frame)
|
||||
|
||||
self.line = QFrame(self.centralwidget)
|
||||
self.line.setObjectName(u"line")
|
||||
self.line.setMinimumSize(QSize(0, 0))
|
||||
self.line.setFrameShape(QFrame.HLine)
|
||||
self.line.setFrameShadow(QFrame.Sunken)
|
||||
|
||||
self.verticalLayout.addWidget(self.line)
|
||||
|
||||
self.frame_2 = QFrame(self.centralwidget)
|
||||
self.frame_2.setObjectName(u"frame_2")
|
||||
self.frame_2.setFrameShape(QFrame.StyledPanel)
|
||||
self.frame_2.setFrameShadow(QFrame.Raised)
|
||||
self.graphicsView = QGraphicsView(self.frame_2)
|
||||
self.graphicsView.setObjectName(u"graphicsView")
|
||||
self.graphicsView.setGeometry(QRect(0, 0, 1000, 541))
|
||||
self.pushButton_add = QPushButton(self.frame_2)
|
||||
self.pushButton_add.setObjectName(u"pushButton_add")
|
||||
self.pushButton_add.setGeometry(QRect(1040, 120, 41, 41))
|
||||
font2 = QFont()
|
||||
font2.setPointSize(24)
|
||||
font2.setBold(False)
|
||||
self.pushButton_add.setFont(font2)
|
||||
self.pushButton_add.setStyleSheet(u"")
|
||||
self.pushButton_sub = QPushButton(self.frame_2)
|
||||
self.pushButton_sub.setObjectName(u"pushButton_sub")
|
||||
self.pushButton_sub.setGeometry(QRect(1090, 120, 41, 41))
|
||||
self.pushButton_sub.setFont(font2)
|
||||
self.pushButton_sub.setStyleSheet(u"")
|
||||
self.pushButton_div = QPushButton(self.frame_2)
|
||||
self.pushButton_div.setObjectName(u"pushButton_div")
|
||||
self.pushButton_div.setGeometry(QRect(1090, 170, 41, 41))
|
||||
self.pushButton_div.setFont(font2)
|
||||
self.pushButton_div.setStyleSheet(u"")
|
||||
self.pushButton_mul = QPushButton(self.frame_2)
|
||||
self.pushButton_mul.setObjectName(u"pushButton_mul")
|
||||
self.pushButton_mul.setGeometry(QRect(1040, 170, 41, 41))
|
||||
self.pushButton_mul.setFont(font2)
|
||||
self.pushButton_mul.setStyleSheet(u"")
|
||||
self.add_ops_node = QPushButton(self.frame_2)
|
||||
self.add_ops_node.setObjectName(u"add_ops_node")
|
||||
self.add_ops_node.setGeometry(QRect(1020, 220, 141, 41))
|
||||
font3 = QFont()
|
||||
font3.setPointSize(14)
|
||||
font3.setBold(False)
|
||||
self.add_ops_node.setFont(font3)
|
||||
self.add_val_node = QPushButton(self.frame_2)
|
||||
self.add_val_node.setObjectName(u"add_val_node")
|
||||
self.add_val_node.setGeometry(QRect(1020, 270, 141, 41))
|
||||
self.add_val_node.setFont(font3)
|
||||
self.ex_node_value = QPushButton(self.frame_2)
|
||||
self.ex_node_value.setObjectName(u"ex_node_value")
|
||||
self.ex_node_value.setGeometry(QRect(1020, 320, 141, 41))
|
||||
self.ex_node_value.setFont(font3)
|
||||
self.ex_node_ops = QPushButton(self.frame_2)
|
||||
self.ex_node_ops.setObjectName(u"ex_node_ops")
|
||||
self.ex_node_ops.setGeometry(QRect(1020, 370, 141, 41))
|
||||
self.ex_node_ops.setFont(font3)
|
||||
self.ex_node_self = QPushButton(self.frame_2)
|
||||
self.ex_node_self.setObjectName(u"ex_node_self")
|
||||
self.ex_node_self.setGeometry(QRect(1020, 420, 141, 41))
|
||||
self.ex_node_self.setFont(font3)
|
||||
self.label_2 = QLabel(self.frame_2)
|
||||
self.label_2.setObjectName(u"label_2")
|
||||
self.label_2.setGeometry(QRect(1030, 70, 121, 41))
|
||||
self.lb_ops_selected = QLabel(self.frame_2)
|
||||
self.lb_ops_selected.setObjectName(u"lb_ops_selected")
|
||||
self.lb_ops_selected.setGeometry(QRect(1060, 10, 53, 51))
|
||||
font4 = QFont()
|
||||
font4.setPointSize(18)
|
||||
font4.setBold(True)
|
||||
self.lb_ops_selected.setFont(font4)
|
||||
self.lb_ops_selected.setStyleSheet(u"background-color:rgb(255, 255, 255)")
|
||||
self.lb_ops_selected.setAlignment(Qt.AlignCenter)
|
||||
self.clear_button = QPushButton(self.frame_2)
|
||||
self.clear_button.setObjectName(u"clear_button")
|
||||
self.clear_button.setGeometry(QRect(1020, 470, 141, 41))
|
||||
self.clear_button.setFont(font3)
|
||||
|
||||
self.verticalLayout.addWidget(self.frame_2)
|
||||
|
||||
self.verticalLayout.setStretch(0, 3)
|
||||
self.verticalLayout.setStretch(2, 5)
|
||||
MainWindow.setCentralWidget(self.centralwidget)
|
||||
self.menubar = QMenuBar(MainWindow)
|
||||
self.menubar.setObjectName(u"menubar")
|
||||
self.menubar.setGeometry(QRect(0, 0, 1190, 32))
|
||||
MainWindow.setMenuBar(self.menubar)
|
||||
self.statusbar = QStatusBar(MainWindow)
|
||||
self.statusbar.setObjectName(u"statusbar")
|
||||
MainWindow.setStatusBar(self.statusbar)
|
||||
|
||||
self.retranslateUi(MainWindow)
|
||||
|
||||
QMetaObject.connectSlotsByName(MainWindow)
|
||||
# setupUi
|
||||
|
||||
def retranslateUi(self, MainWindow):
|
||||
MainWindow.setWindowTitle(QCoreApplication.translate("MainWindow", u"\u8ba1\u7b97\u601d\u7ef424\u70b9", None))
|
||||
self.p4.setText("")
|
||||
self.p3.setText("")
|
||||
self.p2.setText("")
|
||||
self.p1.setText("")
|
||||
self.label_result.setText(QCoreApplication.translate("MainWindow", u" = \uff1f", None))
|
||||
self.label_TF.setText("")
|
||||
self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u8ba1\u7b97", None))
|
||||
self.pushButton_q.setText(QCoreApplication.translate("MainWindow", u"\u51fa\u9898", None))
|
||||
self.pushButton_ex.setText(QCoreApplication.translate("MainWindow", u"\u6362\u724c", None))
|
||||
self.pushButton_autosv.setText(QCoreApplication.translate("MainWindow", u"\u81ea\u52a8\u6c42\u89e3", None))
|
||||
self.pushButton_dtree.setText(QCoreApplication.translate("MainWindow", u"\u753b\u6811", None))
|
||||
self.pushButton_allan.setText(QCoreApplication.translate("MainWindow", u"\u6240\u6709\u7b54\u6848", None))
|
||||
self.pushButton_exp.setText(QCoreApplication.translate("MainWindow", u"\u751f\u6210\u8868\u8fbe\u5f0f", None))
|
||||
self.pushButton_ast.setText(QCoreApplication.translate("MainWindow", u"\u751f\u6210\u8bed\u6cd5\u6811", None))
|
||||
self.pushButton_9.setText(QCoreApplication.translate("MainWindow", u"\u4e00\u81f4\u6027\u68c0\u67e5", None))
|
||||
self.label.setText(QCoreApplication.translate("MainWindow", u"\u5df2\u9009\u724c\u9762", None))
|
||||
self.p1_selected.setText("")
|
||||
self.pushButton_add.setText(QCoreApplication.translate("MainWindow", u"+", None))
|
||||
self.pushButton_sub.setText(QCoreApplication.translate("MainWindow", u"-", None))
|
||||
self.pushButton_div.setText(QCoreApplication.translate("MainWindow", u"/", None))
|
||||
self.pushButton_mul.setText(QCoreApplication.translate("MainWindow", u"*", None))
|
||||
self.add_ops_node.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u8fd0\u7b97\u8282\u70b9", None))
|
||||
self.add_val_node.setText(QCoreApplication.translate("MainWindow", u"\u6dfb\u52a0\u6570\u503c\u8282\u70b9", None))
|
||||
self.ex_node_value.setText(QCoreApplication.translate("MainWindow", u"\u6539\u53d8\u8fd0\u7b97\u8f93\u5165", None))
|
||||
self.ex_node_ops.setText(QCoreApplication.translate("MainWindow", u"\u6539\u53d8\u8282\u70b9\u8fd0\u7b97", None))
|
||||
self.ex_node_self.setText(QCoreApplication.translate("MainWindow", u"\u6570\u503c\u8282\u70b9\u4ea4\u6362", None))
|
||||
self.label_2.setText(QCoreApplication.translate("MainWindow", u"\u5df2\u9009\u8fd0\u7b97\u7b26", None))
|
||||
self.lb_ops_selected.setText("")
|
||||
self.clear_button.setText(QCoreApplication.translate("MainWindow", u"\u6e05\u7a7a\u753b\u5e03", None))
|
||||
# retranslateUi
|
||||
|
@ -0,0 +1,71 @@
|
||||
import math
|
||||
|
||||
def split_exp(expression): # 将表达式拆分为数字、运算符和三角函数
|
||||
stack = []
|
||||
current_item = ''
|
||||
for char in expression:
|
||||
if char.isdigit() or char == '.':
|
||||
current_item += char
|
||||
elif char.isalpha(): # 识别字母表示的函数名
|
||||
current_item += char
|
||||
elif char == '(':
|
||||
if current_item:
|
||||
stack.append(current_item)
|
||||
current_item = ''
|
||||
stack.append(char)
|
||||
elif char == ')' and current_item:
|
||||
stack.append(current_item)
|
||||
stack.append(char)
|
||||
current_item = ''
|
||||
elif char in OPS:
|
||||
if current_item:
|
||||
stack.append(current_item)
|
||||
current_item = ''
|
||||
stack.append(char)
|
||||
if current_item:
|
||||
stack.append(current_item)
|
||||
return stack
|
||||
|
||||
def get_postfix_expression(expression):
|
||||
# 多位数拆分
|
||||
expression = split_exp(expression)
|
||||
precedence = {'+': 1, '-': 1, '*': 2, '/': 2, '^': 3,"sin":4,"cos":4,"tan":4}
|
||||
postfix = []
|
||||
stack = []
|
||||
def is_number(char):
|
||||
try:
|
||||
float(char)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
for char in expression:
|
||||
if is_number(char):
|
||||
postfix.append(char)
|
||||
elif char == '(':
|
||||
stack.append(char)
|
||||
elif char == ')':
|
||||
while stack and stack[-1] != '(':
|
||||
postfix.append(stack.pop())
|
||||
stack.pop() # 弹出 '('
|
||||
elif char in precedence:
|
||||
while stack and stack[-1] != '(' and precedence.get(stack[-1], 0) >= precedence.get(char, 0):
|
||||
postfix.append(stack.pop())
|
||||
stack.append(char)
|
||||
# elif char in ('sin', 'cos', 'tan'): # 处理三角函数
|
||||
# stack.append(char)
|
||||
|
||||
while stack:
|
||||
postfix.append(stack.pop())
|
||||
|
||||
return postfix
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
exp = 'sin(3.3)^2+cos(3.3)^2'
|
||||
OPS = ['+', '-', '*', '/', '^']
|
||||
|
||||
exp_ls = split_exp(exp)
|
||||
print(exp_ls)
|
||||
print(get_postfix_expression(exp)) # ['3.3', 'sin', '2', '^', '3.3', 'cos', '2', '^', '+']
|