控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ui_functions.py 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. # ///////////////////////////////////////////////////////////////
  2. #
  3. # BY: WANDERSON M.PIMENTA
  4. # PROJECT MADE WITH: Qt Designer and PySide6
  5. # V: 1.0.0
  6. #
  7. # This project can be used freely for all uses, as long as they maintain the
  8. # respective credits only in the Python scripts, any information in the visual
  9. # interface (GUI) can be modified without any implication.
  10. #
  11. # There are limitations on Qt licenses if you want to use your products
  12. # commercially, I recommend reading them on the official website:
  13. # https://doc.qt.io/qtforpython/licenses.html
  14. #
  15. # ///////////////////////////////////////////////////////////////
  16. # MAIN FILE
  17. # ///////////////////////////////////////////////////////////////
  18. from main import *
  19. import importlib
  20. from Back.GC import GC
  21. from Back.GS import GS
  22. from Back.WD import WD
  23. from Back.GC import GCcompute
  24. from Back.GS import GScompute
  25. from Back.WD import WDcompute
  26. from Back.GC import GCshow
  27. from Back.GS import GSshow
  28. from Back.WD import WDshow
  29. import os
  30. # GLOBALS
  31. # ///////////////////////////////////////////////////////////////
  32. GLOBAL_STATE = False
  33. GLOBAL_TITLE_BAR = True
  34. class UIFunctions(MainWindow):
  35. # MAXIMIZE/RESTORE
  36. # ///////////////////////////////////////////////////////////////
  37. def maximize_restore(self):
  38. global GLOBAL_STATE
  39. status = GLOBAL_STATE
  40. if status == False:
  41. self.showMaximized()
  42. GLOBAL_STATE = True
  43. self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
  44. self.ui.maximizeRestoreAppBtn.setToolTip("Restore")
  45. self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_restore.png"))
  46. self.ui.frame_size_grip.hide()
  47. self.left_grip.hide()
  48. self.right_grip.hide()
  49. self.top_grip.hide()
  50. self.bottom_grip.hide()
  51. else:
  52. GLOBAL_STATE = False
  53. self.showNormal()
  54. self.resize(self.width() + 1, self.height() + 1)
  55. self.ui.appMargins.setContentsMargins(10, 10, 10, 10)
  56. self.ui.maximizeRestoreAppBtn.setToolTip("Maximize")
  57. self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_maximize.png"))
  58. self.ui.frame_size_grip.show()
  59. self.left_grip.show()
  60. self.right_grip.show()
  61. self.top_grip.show()
  62. self.bottom_grip.show()
  63. # RETURN STATUS
  64. # ///////////////////////////////////////////////////////////////
  65. def returStatus(self):
  66. return GLOBAL_STATE
  67. # SET STATUS
  68. # ///////////////////////////////////////////////////////////////
  69. def setStatus(self, status):
  70. global GLOBAL_STATE
  71. GLOBAL_STATE = status
  72. # TOGGLE MENU
  73. # ///////////////////////////////////////////////////////////////
  74. def toggleMenu(self, enable):
  75. if enable:
  76. # GET WIDTH
  77. width = self.ui.leftMenuBg.width()
  78. maxExtend = Settings.MENU_WIDTH
  79. standard = 60
  80. # SET MAX WIDTH
  81. if width == 60:
  82. widthExtended = maxExtend
  83. else:
  84. widthExtended = standard
  85. # ANIMATION
  86. self.animation = QPropertyAnimation(self.ui.leftMenuBg, b"minimumWidth")
  87. self.animation.setDuration(Settings.TIME_ANIMATION)
  88. self.animation.setStartValue(width)
  89. self.animation.setEndValue(widthExtended)
  90. self.animation.setEasingCurve(QEasingCurve.InOutQuart)
  91. self.animation.start()
  92. # TOGGLE LEFT BOX
  93. # ///////////////////////////////////////////////////////////////
  94. def toggleLeftBox(self, enable):
  95. if enable:
  96. # GET WIDTH
  97. width = self.ui.extraLeftBox.width()
  98. widthRightBox = self.ui.extraRightBox.width()
  99. maxExtend = Settings.LEFT_BOX_WIDTH
  100. color = Settings.BTN_LEFT_BOX_COLOR
  101. standard = 0
  102. # GET BTN STYLE
  103. style = self.ui.toggleLeftBox.styleSheet()
  104. # SET MAX WIDTH
  105. if width == 0:
  106. widthExtended = maxExtend
  107. # SELECT BTN
  108. self.ui.toggleLeftBox.setStyleSheet(style + color)
  109. if widthRightBox != 0:
  110. style = self.ui.settingsTopBtn.styleSheet()
  111. self.ui.settingsTopBtn.setStyleSheet(style.replace(Settings.BTN_RIGHT_BOX_COLOR, ''))
  112. else:
  113. widthExtended = standard
  114. # RESET BTN
  115. self.ui.toggleLeftBox.setStyleSheet(style.replace(color, ''))
  116. UIFunctions.start_box_animation(self, width, widthRightBox, "left")
  117. # TOGGLE RIGHT BOX
  118. # ///////////////////////////////////////////////////////////////
  119. def toggleRightBox(self, enable):
  120. if enable:
  121. # GET WIDTH
  122. width = self.ui.extraRightBox.width()
  123. widthLeftBox = self.ui.extraLeftBox.width()
  124. maxExtend = Settings.RIGHT_BOX_WIDTH
  125. color = Settings.BTN_RIGHT_BOX_COLOR
  126. standard = 0
  127. # GET BTN STYLE
  128. style = self.ui.settingsTopBtn.styleSheet()
  129. # SET MAX WIDTH
  130. if width == 0:
  131. widthExtended = maxExtend
  132. # SELECT BTN
  133. self.ui.settingsTopBtn.setStyleSheet(style + color)
  134. if widthLeftBox != 0:
  135. style = self.ui.toggleLeftBox.styleSheet()
  136. self.ui.toggleLeftBox.setStyleSheet(style.replace(Settings.BTN_LEFT_BOX_COLOR, ''))
  137. else:
  138. widthExtended = standard
  139. # RESET BTN
  140. self.ui.settingsTopBtn.setStyleSheet(style.replace(color, ''))
  141. UIFunctions.start_box_animation(self, widthLeftBox, width, "right")
  142. def start_box_animation(self, left_box_width, right_box_width, direction):
  143. right_width = 0
  144. left_width = 0
  145. # Check values
  146. if left_box_width == 0 and direction == "left":
  147. left_width = 240
  148. else:
  149. left_width = 0
  150. # Check values
  151. if right_box_width == 0 and direction == "right":
  152. right_width = 240
  153. else:
  154. right_width = 0
  155. # ANIMATION LEFT BOX
  156. self.left_box = QPropertyAnimation(self.ui.extraLeftBox, b"minimumWidth")
  157. self.left_box.setDuration(Settings.TIME_ANIMATION)
  158. self.left_box.setStartValue(left_box_width)
  159. self.left_box.setEndValue(left_width)
  160. self.left_box.setEasingCurve(QEasingCurve.InOutQuart)
  161. # ANIMATION RIGHT BOX
  162. self.right_box = QPropertyAnimation(self.ui.extraRightBox, b"minimumWidth")
  163. self.right_box.setDuration(Settings.TIME_ANIMATION)
  164. self.right_box.setStartValue(right_box_width)
  165. self.right_box.setEndValue(right_width)
  166. self.right_box.setEasingCurve(QEasingCurve.InOutQuart)
  167. # GROUP ANIMATION
  168. self.group = QParallelAnimationGroup()
  169. self.group.addAnimation(self.left_box)
  170. self.group.addAnimation(self.right_box)
  171. self.group.start()
  172. # SELECT/DESELECT MENU
  173. # ///////////////////////////////////////////////////////////////
  174. # SELECT
  175. def selectMenu(getStyle):
  176. select = getStyle + Settings.MENU_SELECTED_STYLESHEET
  177. return select
  178. # DESELECT
  179. def deselectMenu(getStyle):
  180. deselect = getStyle.replace(Settings.MENU_SELECTED_STYLESHEET, "")
  181. return deselect
  182. # START SELECTION
  183. def selectStandardMenu(self, widget):
  184. for w in self.ui.topMenu.findChildren(QPushButton):
  185. if w.objectName() == widget:
  186. w.setStyleSheet(UIFunctions.selectMenu(w.styleSheet()))
  187. # RESET SELECTION
  188. def resetStyle(self, widget):
  189. for w in self.ui.topMenu.findChildren(QPushButton):
  190. if w.objectName() != widget:
  191. w.setStyleSheet(UIFunctions.deselectMenu(w.styleSheet()))
  192. # IMPORT THEMES FILES QSS/CSS
  193. # ///////////////////////////////////////////////////////////////
  194. def theme(self, file, useCustomTheme):
  195. if useCustomTheme:
  196. str = open(file, 'r').read()
  197. self.ui.styleSheet.setStyleSheet(str)
  198. # START - GUI DEFINITIONS
  199. # ///////////////////////////////////////////////////////////////
  200. def uiDefinitions(self):
  201. def dobleClickMaximizeRestore(event):
  202. # IF DOUBLE CLICK CHANGE STATUS
  203. if event.type() == QEvent.MouseButtonDblClick:
  204. QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self))
  205. self.ui.titleRightInfo.mouseDoubleClickEvent = dobleClickMaximizeRestore
  206. if Settings.ENABLE_CUSTOM_TITLE_BAR:
  207. # STANDARD TITLE BAR
  208. self.setWindowFlags(Qt.FramelessWindowHint)
  209. self.setAttribute(Qt.WA_TranslucentBackground)
  210. # MOVE WINDOW / MAXIMIZE / RESTORE
  211. def moveWindow(event):
  212. # IF MAXIMIZED CHANGE TO NORMAL
  213. if UIFunctions.returStatus(self):
  214. UIFunctions.maximize_restore(self)
  215. # MOVE WINDOW
  216. if event.buttons() == Qt.LeftButton:
  217. self.move(self.pos() + event.globalPos() - self.dragPos)
  218. self.dragPos = event.globalPos()
  219. event.accept()
  220. self.ui.titleRightInfo.mouseMoveEvent = moveWindow
  221. # CUSTOM GRIPS
  222. self.left_grip = CustomGrip(self, Qt.LeftEdge, True)
  223. self.right_grip = CustomGrip(self, Qt.RightEdge, True)
  224. self.top_grip = CustomGrip(self, Qt.TopEdge, True)
  225. self.bottom_grip = CustomGrip(self, Qt.BottomEdge, True)
  226. else:
  227. self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
  228. self.ui.minimizeAppBtn.hide()
  229. self.ui.maximizeRestoreAppBtn.hide()
  230. self.ui.closeAppBtn.hide()
  231. self.ui.frame_size_grip.hide()
  232. # DROP SHADOW
  233. self.shadow = QGraphicsDropShadowEffect(self)
  234. self.shadow.setBlurRadius(17)
  235. self.shadow.setXOffset(0)
  236. self.shadow.setYOffset(0)
  237. self.shadow.setColor(QColor(0, 0, 0, 150))
  238. self.ui.bgApp.setGraphicsEffect(self.shadow)
  239. # RESIZE WINDOW
  240. self.sizegrip = QSizeGrip(self.ui.frame_size_grip)
  241. self.sizegrip.setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;")
  242. # MINIMIZE
  243. self.ui.minimizeAppBtn.clicked.connect(lambda: self.showMinimized())
  244. # MAXIMIZE/RESTORE
  245. self.ui.maximizeRestoreAppBtn.clicked.connect(lambda: UIFunctions.maximize_restore(self))
  246. # CLOSE APPLICATION
  247. self.ui.closeAppBtn.clicked.connect(lambda: self.close())
  248. def resize_grips(self):
  249. if Settings.ENABLE_CUSTOM_TITLE_BAR:
  250. self.left_grip.setGeometry(0, 10, 10, self.height())
  251. self.right_grip.setGeometry(self.width() - 10, 10, 10, self.height())
  252. self.top_grip.setGeometry(0, 0, self.width(), 10)
  253. self.bottom_grip.setGeometry(0, self.height() - 10, self.width(), 10)
  254. # 上传文件的方法
  255. def execute_script_based_on_selection(self, file_path):
  256. current_text = self.ui.comboBox_2.currentText()
  257. # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
  258. # 获取当前脚本所在的目录
  259. current_dir = os.path.dirname(os.path.abspath(__file__))
  260. # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  261. sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  262. # 将相对路径转换为绝对路径
  263. sql_folder = os.path.abspath(sql_folder)
  264. db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
  265. file_path = file_path
  266. if current_text == "水准测段高差稳定计算":
  267. GC.main_function(file_path, db_path)
  268. # 添加水准执行代码
  269. elif current_text == "控制网复测平面基准计算":
  270. GS.main_function(file_path, db_path)
  271. # 添加控制网执行代码
  272. elif current_text == "平面控制网稳定性计算":
  273. WD.main_function(file_path, db_path)
  274. # 添加平面控制网执行代码
  275. # 计算与展示文件的方法
  276. def compute_show_process_excel_file(self, file_path):
  277. current_text = self.ui.comboBox_2.currentText()
  278. # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
  279. # 获取当前脚本所在的目录
  280. current_dir = os.path.dirname(os.path.abspath(__file__))
  281. # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  282. sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  283. # 将相对路径转换为绝对路径
  284. sql_folder = os.path.abspath(sql_folder)
  285. db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
  286. # 转换为utf-8
  287. excelname = os.path.basename(file_path)
  288. utf_en = excelname.encode('utf-8')
  289. if current_text == "水准测段高差稳定计算":
  290. GCcompute.main_function(file_path, db_path)
  291. GCshow.main_function(self.ui, db_path, utf_en)
  292. elif current_text == "控制网复测平面基准计算":
  293. # GScompute.main_function(file_path, db_path)
  294. GSshow.main_function(self.ui, db_path, utf_en)
  295. # GSshow.main_function(self.ui, file_path, db_path)
  296. elif current_text == "平面控制网稳定性计算":
  297. WDcompute.main_function(file_path, db_path)
  298. WDshow.main_function(self.ui, db_path, utf_en)
  299. # END - GUI DEFINITIONS