123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- # ///////////////////////////////////////////////////////////////
- #
- # BY: WANDERSON M.PIMENTA
- # PROJECT MADE WITH: Qt Designer and PySide6
- # V: 1.0.0
- #
- # This project can be used freely for all uses, as long as they maintain the
- # respective credits only in the Python scripts, any information in the visual
- # interface (GUI) can be modified without any implication.
- #
- # There are limitations on Qt licenses if you want to use your products
- # commercially, I recommend reading them on the official website:
- # https://doc.qt.io/qtforpython/licenses.html
- #
- # ///////////////////////////////////////////////////////////////
- import time
-
- from PySide6.QtWidgets import QFileDialog
-
- import sys
- import os
- import platform
-
- import Back.Program_Run.database_operations
- # IMPORT / GUI AND MODULES AND WIDGETS
- # ///////////////////////////////////////////////////////////////
- from modules import *
- from widgets import *
-
- os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100%
-
- # SET AS GLOBAL WIDGETS
- # ///////////////////////////////////////////////////////////////
- widgets = None
-
-
- # 表格的模型
- class MyTableModel(QAbstractTableModel):
- def __init__(self, data):
- super().__init__()
- self._data = data
-
- # 重新定义行数
- def rowCount(self, parent=QModelIndex()):
- return len(self._data)
-
- # 重新定义列数
- def columnCount(self, parent=QModelIndex()):
- return len(self._data[0]) if self._data else 0
-
- # 重新定义数据
- def data(self, index, role=Qt.DisplayRole):
- if not index.isValid():
- return None
- if role == Qt.DisplayRole:
- return self._data[index.row()][index.column()]
- return None
-
-
- class MainWindow(QMainWindow):
-
- def __init__(self):
- QMainWindow.__init__(self)
- self.file_path = None # 初始化时文件路径设置为None
- # super().__init__()
- # SET AS GLOBAL WIDGETS
- # ///////////////////////////////////////////////////////////////
- self.ui = Ui_MainWindow()
- self.ui.setupUi(self)
- self.ui.createFile.clicked.connect(self.on_create_file_clicked)
- # self.comboBox_2 = QComboBox(self)
- # ...此处为省略代码...
- global widgets
- widgets = self.ui
-
- # 是否使用系统自带标题栏 True是不使用,False使用
- # ///////////////////////////////////////////////////////////////
- Settings.ENABLE_CUSTOM_TITLE_BAR = True
-
- # APP名称
- # ///////////////////////////////////////////////////////////////
- title = "控制网复测平面基准归算程序"
- description = "控制网复测平面基准归算程序"
- # APPLY TEXTS
- self.setWindowTitle(title)
- widgets.titleRightInfo.setText(description)
-
- # TOGGLE MENU
- # ///////////////////////////////////////////////////////////////
- widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True))
-
- # SET UI DEFINITIONS
- # ///////////////////////////////////////////////////////////////
- UIFunctions.uiDefinitions(self)
-
- # QTableWidget PARAMETERS
- # ///////////////////////////////////////////////////////////////
- # widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
-
- # 点击事件
- # ///////////////////////////////////////////////////////////////
-
- # 左边菜单
- # 首页
- widgets.btn_home.clicked.connect(self.buttonClick)
- # 输入表格
- widgets.btn_widgets.clicked.connect(self.buttonClick)
- # 成果预览
- widgets.btn_new.clicked.connect(self.buttonClick)
- # 数据一览
- widgets.btn_data.clicked.connect(self.buttonClick)
- # 皮肤切换
- widgets.btn_message.clicked.connect(self.buttonClick)
- # 打开上传文件夹
- widgets.upload.clicked.connect(self.buttonClick)
- # 文件计算
- widgets.compute.clicked.connect(self.buttonClick)
-
- # 拓展左侧栏
- # def openCloseLeftBox():
- # UIFunctions.toggleLeftBox(self, True)
- # widgets.toggleLeftBox.clicked.connect(openCloseLeftBox)
- # widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)
-
- # EXTRA RIGHT BOX
- def openCloseRightBox():
- UIFunctions.toggleRightBox(self, True)
-
- widgets.settingsTopBtn.clicked.connect(openCloseRightBox)
-
- # 展示APP
- # ///////////////////////////////////////////////////////////////
- self.show()
-
- # 设置主题
- # ///////////////////////////////////////////////////////////////
- if getattr(sys, 'frozen', False):
- absPath = os.path.dirname(os.path.abspath(sys.executable))
- elif __file__:
- absPath = os.path.dirname(os.path.abspath(__file__))
- useCustomTheme = True
- self.useCustomTheme = useCustomTheme
- self.absPath = absPath
- themeFile = r"themes\py_dracula_light.qss"
-
- # 设置主题和HACKS
- if useCustomTheme:
- # LOAD AND APPLY STYLE
- UIFunctions.theme(self, themeFile, True)
-
- # SET HACKS
- AppFunctions.setThemeHack(self)
-
- # 设置主页和选择菜单
- # ///////////////////////////////////////////////////////////////
- widgets.stackedWidget.setCurrentWidget(widgets.home)
- widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))
- # self.bind()
-
- # 绑定组件
- def bind(self):
- # 计算
- widgets.compute.clicked.connect(self.buttonClick)
-
- # 删除tableview
- def delete_table_view(table_view):
- table_view.setParent(None)
- table_view.deleteLater()
-
- # ///////////////////////////////////////////////////////////////
- def buttonClick(self):
- # GET BUTTON CLICKED
- btn = self.sender()
- btnName = btn.objectName()
-
- # 首页
- if btnName == "btn_home":
- widgets.stackedWidget.setCurrentWidget(widgets.home)
- UIFunctions.resetStyle(self, btnName)
- btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
-
- # 输入表格
- if btnName == "btn_widgets":
- widgets.stackedWidget.setCurrentWidget(widgets.widgets)
- UIFunctions.resetStyle(self, btnName)
- btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
-
- # 成果预览
- if btnName == "btn_new":
- widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
- UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
- btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
-
- # 数据一览
- if btnName == "btn_data":
- widgets.stackedWidget.setCurrentWidget(widgets.datainfo) # SET PAGE
- UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
- btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
-
- # 皮肤切换
- if btnName == "btn_message":
- if self.useCustomTheme:
- themeFile = os.path.abspath(os.path.join(self.absPath, "themes/py_dracula_dark.qss"))
- UIFunctions.theme(self, themeFile, True)
- # SET HACKS
- AppFunctions.setThemeHack(self)
- self.useCustomTheme = False
- else:
- themeFile = os.path.abspath(os.path.join(self.absPath, "themes/py_dracula_light.qss"))
- UIFunctions.theme(self, themeFile, True)
- # SET HACKS
- AppFunctions.setThemeHack(self)
- self.useCustomTheme = True
- # 文件上传
- if btnName == "upload":
- # 使用 QFileDialog 获取文件路径
- file_path, _ = QFileDialog.getOpenFileName(
- self,
- "选择文件",
- "",
- "表格文件 (*.xls *.xlsx)"
- # 水准后期添加支持.xls文件
- )
- if file_path:
- # 处理选中的文件
- self.file_path = file_path # 将获取的路径保存到类的属性中
- UIFunctions.execute_script_based_on_selection(self, file_path)
-
- # 文件计算
- if btnName == "compute":
- if self.file_path: # 确保有文件路径后再进行处理
- # 计算与展示的业务代码
- UIFunctions.compute_show_process_excel_file(self, self.file_path)
- # 1秒后自动跳转
- QTimer.singleShot(1000, lambda: self.simulateButtonClick("btn_new"))
- else:
- QMessageBox.warning(self, '警告', '请先选择项目并上传文件')
-
- # 输出点击回馈
- print(f'Button "{btnName}" pressed!')
-
- # 辅助函数,点击计算后自动跳转页面
- def simulateButtonClick(self, btnName):
- # 根据按钮名称找到对应的按钮
- btn = self.findChild(QObject, btnName)
- if btn:
- # 触发按钮点击事件
- btn.click()
-
-
- # 新增槽函数来调用 create_database_and_tables
- def on_create_file_clicked(self):
- Back.Program_Run.database_operations.create_database_and_tables(self.ui)
-
- # RESIZE EVENTS
- # ///////////////////////////////////////////////////////////////
- def resizeEvent(self, event):
- # Update Size Grips
- UIFunctions.resize_grips(self)
-
- # 鼠标点击事件
- # ///////////////////////////////////////////////////////////////
- def mousePressEvent(self, event):
- # SET DRAG POS WINDOW
- # self.dragPos = event.globalPos()
- self.dragPos = event.globalPosition().toPoint()
-
- # 输出鼠标事件
- if event.buttons() == Qt.LeftButton:
- print('Mouse click: LEFT CLICK')
- if event.buttons() == Qt.RightButton:
- print('Mouse click: RIGHT CLICK')
-
-
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- app.setWindowIcon(QIcon("icon.ico"))
- window = MainWindow()
- # window.resize(1440, 960) # 高宽
- sys.exit(app.exec())
|