# /////////////////////////////////////////////////////////////// # # 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 # # /////////////////////////////////////////////////////////////// from PySide6.QtWidgets import QMessageBox # MAIN FILE # /////////////////////////////////////////////////////////////// from main import * import importlib from Back.GC import GC, GCExport from Back.GS import GS, GSExport from Back.WD import WD, WDExport from Back.GC import GCcompute from Back.GS import GScompute from Back.WD import WDcompute from Back.GC import GCshow from Back.GS import GSshow from Back.WD import WDshow import os # GLOBALS # /////////////////////////////////////////////////////////////// GLOBAL_STATE = False GLOBAL_TITLE_BAR = True class UIFunctions(MainWindow): # MAXIMIZE/RESTORE # /////////////////////////////////////////////////////////////// def maximize_restore(self): global GLOBAL_STATE status = GLOBAL_STATE if status == False: self.showMaximized() GLOBAL_STATE = True self.ui.appMargins.setContentsMargins(0, 0, 0, 0) self.ui.maximizeRestoreAppBtn.setToolTip("Restore") self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_restore.png")) self.ui.frame_size_grip.hide() self.left_grip.hide() self.right_grip.hide() self.top_grip.hide() self.bottom_grip.hide() else: GLOBAL_STATE = False self.showNormal() self.resize(self.width() + 1, self.height() + 1) self.ui.appMargins.setContentsMargins(10, 10, 10, 10) self.ui.maximizeRestoreAppBtn.setToolTip("Maximize") self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_maximize.png")) self.ui.frame_size_grip.show() self.left_grip.show() self.right_grip.show() self.top_grip.show() self.bottom_grip.show() # RETURN STATUS # /////////////////////////////////////////////////////////////// def returStatus(self): return GLOBAL_STATE # SET STATUS # /////////////////////////////////////////////////////////////// def setStatus(self, status): global GLOBAL_STATE GLOBAL_STATE = status # TOGGLE MENU # /////////////////////////////////////////////////////////////// def toggleMenu(self, enable): if enable: # GET WIDTH width = self.ui.leftMenuBg.width() maxExtend = Settings.MENU_WIDTH standard = 60 # SET MAX WIDTH if width == 60: widthExtended = maxExtend else: widthExtended = standard # ANIMATION self.animation = QPropertyAnimation(self.ui.leftMenuBg, b"minimumWidth") self.animation.setDuration(Settings.TIME_ANIMATION) self.animation.setStartValue(width) self.animation.setEndValue(widthExtended) self.animation.setEasingCurve(QEasingCurve.InOutQuart) self.animation.start() # TOGGLE LEFT BOX # /////////////////////////////////////////////////////////////// def toggleLeftBox(self, enable): if enable: # GET WIDTH width = self.ui.extraLeftBox.width() widthRightBox = self.ui.extraRightBox.width() maxExtend = Settings.LEFT_BOX_WIDTH color = Settings.BTN_LEFT_BOX_COLOR standard = 0 # GET BTN STYLE style = self.ui.toggleLeftBox.styleSheet() # SET MAX WIDTH if width == 0: widthExtended = maxExtend # SELECT BTN self.ui.toggleLeftBox.setStyleSheet(style + color) if widthRightBox != 0: style = self.ui.settingsTopBtn.styleSheet() self.ui.settingsTopBtn.setStyleSheet(style.replace(Settings.BTN_RIGHT_BOX_COLOR, '')) else: widthExtended = standard # RESET BTN self.ui.toggleLeftBox.setStyleSheet(style.replace(color, '')) UIFunctions.start_box_animation(self, width, widthRightBox, "left") # TOGGLE RIGHT BOX # /////////////////////////////////////////////////////////////// def toggleRightBox(self, enable): if enable: # GET WIDTH width = self.ui.extraRightBox.width() widthLeftBox = self.ui.extraLeftBox.width() maxExtend = Settings.RIGHT_BOX_WIDTH color = Settings.BTN_RIGHT_BOX_COLOR standard = 0 # GET BTN STYLE style = self.ui.settingsTopBtn.styleSheet() # SET MAX WIDTH if width == 0: widthExtended = maxExtend # SELECT BTN self.ui.settingsTopBtn.setStyleSheet(style + color) if widthLeftBox != 0: style = self.ui.toggleLeftBox.styleSheet() self.ui.toggleLeftBox.setStyleSheet(style.replace(Settings.BTN_LEFT_BOX_COLOR, '')) else: widthExtended = standard # RESET BTN self.ui.settingsTopBtn.setStyleSheet(style.replace(color, '')) UIFunctions.start_box_animation(self, widthLeftBox, width, "right") def start_box_animation(self, left_box_width, right_box_width, direction): right_width = 0 left_width = 0 # Check values if left_box_width == 0 and direction == "left": left_width = 240 else: left_width = 0 # Check values if right_box_width == 0 and direction == "right": right_width = 240 else: right_width = 0 # ANIMATION LEFT BOX self.left_box = QPropertyAnimation(self.ui.extraLeftBox, b"minimumWidth") self.left_box.setDuration(Settings.TIME_ANIMATION) self.left_box.setStartValue(left_box_width) self.left_box.setEndValue(left_width) self.left_box.setEasingCurve(QEasingCurve.InOutQuart) # ANIMATION RIGHT BOX self.right_box = QPropertyAnimation(self.ui.extraRightBox, b"minimumWidth") self.right_box.setDuration(Settings.TIME_ANIMATION) self.right_box.setStartValue(right_box_width) self.right_box.setEndValue(right_width) self.right_box.setEasingCurve(QEasingCurve.InOutQuart) # GROUP ANIMATION self.group = QParallelAnimationGroup() self.group.addAnimation(self.left_box) self.group.addAnimation(self.right_box) self.group.start() # SELECT/DESELECT MENU # /////////////////////////////////////////////////////////////// # SELECT def selectMenu(getStyle): select = getStyle + Settings.MENU_SELECTED_STYLESHEET return select # DESELECT def deselectMenu(getStyle): deselect = getStyle.replace(Settings.MENU_SELECTED_STYLESHEET, "") return deselect # START SELECTION def selectStandardMenu(self, widget): for w in self.ui.topMenu.findChildren(QPushButton): if w.objectName() == widget: w.setStyleSheet(UIFunctions.selectMenu(w.styleSheet())) # RESET SELECTION def resetStyle(self, widget): for w in self.ui.topMenu.findChildren(QPushButton): if w.objectName() != widget: w.setStyleSheet(UIFunctions.deselectMenu(w.styleSheet())) # IMPORT THEMES FILES QSS/CSS # /////////////////////////////////////////////////////////////// def theme(self, file, useCustomTheme): if useCustomTheme: str = open(file, 'r').read() self.ui.styleSheet.setStyleSheet(str) # START - GUI DEFINITIONS # /////////////////////////////////////////////////////////////// def uiDefinitions(self): def dobleClickMaximizeRestore(event): # IF DOUBLE CLICK CHANGE STATUS if event.type() == QEvent.MouseButtonDblClick: QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self)) self.ui.titleRightInfo.mouseDoubleClickEvent = dobleClickMaximizeRestore if Settings.ENABLE_CUSTOM_TITLE_BAR: # STANDARD TITLE BAR self.setWindowFlags(Qt.FramelessWindowHint) self.setAttribute(Qt.WA_TranslucentBackground) # MOVE WINDOW / MAXIMIZE / RESTORE def moveWindow(event): # IF MAXIMIZED CHANGE TO NORMAL if UIFunctions.returStatus(self): UIFunctions.maximize_restore(self) # MOVE WINDOW if event.buttons() == Qt.LeftButton: self.move(self.pos() + event.globalPos() - self.dragPos) self.dragPos = event.globalPos() event.accept() self.ui.titleRightInfo.mouseMoveEvent = moveWindow # CUSTOM GRIPS self.left_grip = CustomGrip(self, Qt.LeftEdge, True) self.right_grip = CustomGrip(self, Qt.RightEdge, True) self.top_grip = CustomGrip(self, Qt.TopEdge, True) self.bottom_grip = CustomGrip(self, Qt.BottomEdge, True) else: self.ui.appMargins.setContentsMargins(0, 0, 0, 0) self.ui.minimizeAppBtn.hide() self.ui.maximizeRestoreAppBtn.hide() self.ui.closeAppBtn.hide() self.ui.frame_size_grip.hide() # DROP SHADOW self.shadow = QGraphicsDropShadowEffect(self) self.shadow.setBlurRadius(17) self.shadow.setXOffset(0) self.shadow.setYOffset(0) self.shadow.setColor(QColor(0, 0, 0, 150)) self.ui.bgApp.setGraphicsEffect(self.shadow) # RESIZE WINDOW self.sizegrip = QSizeGrip(self.ui.frame_size_grip) self.sizegrip.setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;") # MINIMIZE self.ui.minimizeAppBtn.clicked.connect(lambda: self.showMinimized()) # MAXIMIZE/RESTORE self.ui.maximizeRestoreAppBtn.clicked.connect(lambda: UIFunctions.maximize_restore(self)) # CLOSE APPLICATION self.ui.closeAppBtn.clicked.connect(lambda: self.close()) def resize_grips(self): if Settings.ENABLE_CUSTOM_TITLE_BAR: self.left_grip.setGeometry(0, 10, 10, self.height()) self.right_grip.setGeometry(self.width() - 10, 10, 10, self.height()) self.top_grip.setGeometry(0, 0, self.width(), 10) self.bottom_grip.setGeometry(0, self.height() - 10, self.width(), 10) # 上传文件的方法 def execute_script_based_on_selection(self, file_path): current_text = self.ui.comboBox_2.currentText() # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db" # 获取当前脚本所在的目录 current_dir = os.path.dirname(os.path.abspath(__file__)) # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹) sql_folder = os.path.join(current_dir, '..', '..', 'SQL') # 将相对路径转换为绝对路径 sql_folder = os.path.abspath(sql_folder) db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db") file_path = file_path if current_text == "水准测段高差稳定计算": GC.main_function(file_path, db_path) # 添加水准执行代码 elif current_text == "控制网复测平面基准计算": GS.main_function(file_path, db_path) # 添加控制网执行代码 elif current_text == "平面控制网稳定性计算": WD.main_function(file_path, db_path) # 添加平面控制网执行代码 # 计算与展示文件的方法 def compute_show_process_excel_file(self, file_path): current_text = self.ui.comboBox_2.currentText() # 获取当前脚本所在的目录 current_dir = os.path.dirname(os.path.abspath(__file__)) # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹) sql_folder = os.path.join(current_dir, '..', '..', 'SQL') # 将相对路径转换为绝对路径 sql_folder = os.path.abspath(sql_folder) db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db") # 转换为utf-8 excelname = os.path.basename(file_path) # 文件名 utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式 if current_text == "水准测段高差稳定计算": GCcompute.main_function(file_path, db_path) GCshow.main_function(self.ui, db_path, utf_en) elif current_text == "控制网复测平面基准计算": GScompute.main_function(excelname, db_path) GSshow.main_function(self.ui, db_path, utf_en) elif current_text == "平面控制网稳定性计算": WDcompute.main_function(excelname, db_path) WDshow.main_function(self.ui, db_path, utf_en) # 文件导出的方法 def export_database_to_excel(self, file_path): current_text = self.ui.comboBox_2.currentText() # 获取当前脚本所在的目录 current_dir = os.path.dirname(os.path.abspath(__file__)) # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹) sql_folder = os.path.join(current_dir, '..', '..', 'SQL') # 将相对路径转换为绝对路径 sql_folder = os.path.abspath(sql_folder) db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db") # 转换为utf-8 excelname = os.path.basename(file_path) # 文件名 utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式 if current_text == "水准测段高差稳定计算": GCExport.main_function(self, file_path, utf_en, db_path) elif current_text == "控制网复测平面基准计算": GSExport.main_function(self, db_path, file_path) elif current_text == "平面控制网稳定性计算": # WDExport.main_function(self, file_path) pass else: QMessageBox.warning(self, '警告', '请选择有效的计算类型') # END - GUI DEFINITIONS