控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ui_functions.py 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. from PySide6.QtWidgets import QMessageBox
  17. # MAIN FILE
  18. # ///////////////////////////////////////////////////////////////
  19. from main import *
  20. import importlib
  21. from Back.GC import GC, GCExport
  22. from Back.GS import GS, GSExport
  23. from Back.WD import WD, WDExport
  24. from Back.GC import GCcompute
  25. from Back.GS import GScompute
  26. from Back.WD import WDcompute
  27. from Back.GC import GCshow
  28. from Back.GS import GSshow
  29. from Back.WD import WDshow
  30. import os
  31. # GLOBALS
  32. # ///////////////////////////////////////////////////////////////
  33. GLOBAL_STATE = False
  34. GLOBAL_TITLE_BAR = True
  35. class UIFunctions(MainWindow):
  36. # MAXIMIZE/RESTORE
  37. # ///////////////////////////////////////////////////////////////
  38. def maximize_restore(self):
  39. global GLOBAL_STATE
  40. status = GLOBAL_STATE
  41. if status == False:
  42. self.showMaximized()
  43. GLOBAL_STATE = True
  44. self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
  45. self.ui.maximizeRestoreAppBtn.setToolTip("Restore")
  46. self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_restore.png"))
  47. self.ui.frame_size_grip.hide()
  48. self.left_grip.hide()
  49. self.right_grip.hide()
  50. self.top_grip.hide()
  51. self.bottom_grip.hide()
  52. else:
  53. GLOBAL_STATE = False
  54. self.showNormal()
  55. self.resize(self.width() + 1, self.height() + 1)
  56. self.ui.appMargins.setContentsMargins(10, 10, 10, 10)
  57. self.ui.maximizeRestoreAppBtn.setToolTip("Maximize")
  58. self.ui.maximizeRestoreAppBtn.setIcon(QIcon(u":/icons/images/icons/icon_maximize.png"))
  59. self.ui.frame_size_grip.show()
  60. self.left_grip.show()
  61. self.right_grip.show()
  62. self.top_grip.show()
  63. self.bottom_grip.show()
  64. # RETURN STATUS
  65. # ///////////////////////////////////////////////////////////////
  66. def returStatus(self):
  67. return GLOBAL_STATE
  68. # SET STATUS
  69. # ///////////////////////////////////////////////////////////////
  70. def setStatus(self, status):
  71. global GLOBAL_STATE
  72. GLOBAL_STATE = status
  73. # TOGGLE MENU
  74. # ///////////////////////////////////////////////////////////////
  75. def toggleMenu(self, enable):
  76. if enable:
  77. # GET WIDTH
  78. width = self.ui.leftMenuBg.width()
  79. maxExtend = Settings.MENU_WIDTH
  80. standard = 60
  81. # SET MAX WIDTH
  82. if width == 60:
  83. widthExtended = maxExtend
  84. else:
  85. widthExtended = standard
  86. # ANIMATION
  87. self.animation = QPropertyAnimation(self.ui.leftMenuBg, b"minimumWidth")
  88. self.animation.setDuration(Settings.TIME_ANIMATION)
  89. self.animation.setStartValue(width)
  90. self.animation.setEndValue(widthExtended)
  91. self.animation.setEasingCurve(QEasingCurve.InOutQuart)
  92. self.animation.start()
  93. # TOGGLE LEFT BOX
  94. # ///////////////////////////////////////////////////////////////
  95. def toggleLeftBox(self, enable):
  96. if enable:
  97. # GET WIDTH
  98. width = self.ui.extraLeftBox.width()
  99. widthRightBox = self.ui.extraRightBox.width()
  100. maxExtend = Settings.LEFT_BOX_WIDTH
  101. color = Settings.BTN_LEFT_BOX_COLOR
  102. standard = 0
  103. # GET BTN STYLE
  104. style = self.ui.toggleLeftBox.styleSheet()
  105. # SET MAX WIDTH
  106. if width == 0:
  107. widthExtended = maxExtend
  108. # SELECT BTN
  109. self.ui.toggleLeftBox.setStyleSheet(style + color)
  110. if widthRightBox != 0:
  111. style = self.ui.settingsTopBtn.styleSheet()
  112. self.ui.settingsTopBtn.setStyleSheet(style.replace(Settings.BTN_RIGHT_BOX_COLOR, ''))
  113. else:
  114. widthExtended = standard
  115. # RESET BTN
  116. self.ui.toggleLeftBox.setStyleSheet(style.replace(color, ''))
  117. UIFunctions.start_box_animation(self, width, widthRightBox, "left")
  118. # TOGGLE RIGHT BOX
  119. # ///////////////////////////////////////////////////////////////
  120. def toggleRightBox(self, enable):
  121. if enable:
  122. # GET WIDTH
  123. width = self.ui.extraRightBox.width()
  124. widthLeftBox = self.ui.extraLeftBox.width()
  125. maxExtend = Settings.RIGHT_BOX_WIDTH
  126. color = Settings.BTN_RIGHT_BOX_COLOR
  127. standard = 0
  128. # GET BTN STYLE
  129. style = self.ui.settingsTopBtn.styleSheet()
  130. # SET MAX WIDTH
  131. if width == 0:
  132. widthExtended = maxExtend
  133. # SELECT BTN
  134. self.ui.settingsTopBtn.setStyleSheet(style + color)
  135. if widthLeftBox != 0:
  136. style = self.ui.toggleLeftBox.styleSheet()
  137. self.ui.toggleLeftBox.setStyleSheet(style.replace(Settings.BTN_LEFT_BOX_COLOR, ''))
  138. else:
  139. widthExtended = standard
  140. # RESET BTN
  141. self.ui.settingsTopBtn.setStyleSheet(style.replace(color, ''))
  142. UIFunctions.start_box_animation(self, widthLeftBox, width, "right")
  143. def start_box_animation(self, left_box_width, right_box_width, direction):
  144. right_width = 0
  145. left_width = 0
  146. # Check values
  147. if left_box_width == 0 and direction == "left":
  148. left_width = 240
  149. else:
  150. left_width = 0
  151. # Check values
  152. if right_box_width == 0 and direction == "right":
  153. right_width = 240
  154. else:
  155. right_width = 0
  156. # ANIMATION LEFT BOX
  157. self.left_box = QPropertyAnimation(self.ui.extraLeftBox, b"minimumWidth")
  158. self.left_box.setDuration(Settings.TIME_ANIMATION)
  159. self.left_box.setStartValue(left_box_width)
  160. self.left_box.setEndValue(left_width)
  161. self.left_box.setEasingCurve(QEasingCurve.InOutQuart)
  162. # ANIMATION RIGHT BOX
  163. self.right_box = QPropertyAnimation(self.ui.extraRightBox, b"minimumWidth")
  164. self.right_box.setDuration(Settings.TIME_ANIMATION)
  165. self.right_box.setStartValue(right_box_width)
  166. self.right_box.setEndValue(right_width)
  167. self.right_box.setEasingCurve(QEasingCurve.InOutQuart)
  168. # GROUP ANIMATION
  169. self.group = QParallelAnimationGroup()
  170. self.group.addAnimation(self.left_box)
  171. self.group.addAnimation(self.right_box)
  172. self.group.start()
  173. # SELECT/DESELECT MENU
  174. # ///////////////////////////////////////////////////////////////
  175. # SELECT
  176. def selectMenu(getStyle):
  177. select = getStyle + Settings.MENU_SELECTED_STYLESHEET
  178. return select
  179. # DESELECT
  180. def deselectMenu(getStyle):
  181. deselect = getStyle.replace(Settings.MENU_SELECTED_STYLESHEET, "")
  182. return deselect
  183. # START SELECTION
  184. def selectStandardMenu(self, widget):
  185. for w in self.ui.topMenu.findChildren(QPushButton):
  186. if w.objectName() == widget:
  187. w.setStyleSheet(UIFunctions.selectMenu(w.styleSheet()))
  188. # RESET SELECTION
  189. def resetStyle(self, widget):
  190. for w in self.ui.topMenu.findChildren(QPushButton):
  191. if w.objectName() != widget:
  192. w.setStyleSheet(UIFunctions.deselectMenu(w.styleSheet()))
  193. # IMPORT THEMES FILES QSS/CSS
  194. # ///////////////////////////////////////////////////////////////
  195. def theme(self, file, useCustomTheme):
  196. if useCustomTheme:
  197. str = open(file, 'r').read()
  198. self.ui.styleSheet.setStyleSheet(str)
  199. # START - GUI DEFINITIONS
  200. # ///////////////////////////////////////////////////////////////
  201. def uiDefinitions(self):
  202. def dobleClickMaximizeRestore(event):
  203. # IF DOUBLE CLICK CHANGE STATUS
  204. if event.type() == QEvent.MouseButtonDblClick:
  205. QTimer.singleShot(250, lambda: UIFunctions.maximize_restore(self))
  206. self.ui.titleRightInfo.mouseDoubleClickEvent = dobleClickMaximizeRestore
  207. if Settings.ENABLE_CUSTOM_TITLE_BAR:
  208. # STANDARD TITLE BAR
  209. self.setWindowFlags(Qt.FramelessWindowHint)
  210. self.setAttribute(Qt.WA_TranslucentBackground)
  211. # MOVE WINDOW / MAXIMIZE / RESTORE
  212. def moveWindow(event):
  213. # IF MAXIMIZED CHANGE TO NORMAL
  214. if UIFunctions.returStatus(self):
  215. UIFunctions.maximize_restore(self)
  216. # MOVE WINDOW
  217. if event.buttons() == Qt.LeftButton:
  218. self.move(self.pos() + event.globalPos() - self.dragPos)
  219. self.dragPos = event.globalPos()
  220. event.accept()
  221. self.ui.titleRightInfo.mouseMoveEvent = moveWindow
  222. # CUSTOM GRIPS
  223. self.left_grip = CustomGrip(self, Qt.LeftEdge, True)
  224. self.right_grip = CustomGrip(self, Qt.RightEdge, True)
  225. self.top_grip = CustomGrip(self, Qt.TopEdge, True)
  226. self.bottom_grip = CustomGrip(self, Qt.BottomEdge, True)
  227. else:
  228. self.ui.appMargins.setContentsMargins(0, 0, 0, 0)
  229. self.ui.minimizeAppBtn.hide()
  230. self.ui.maximizeRestoreAppBtn.hide()
  231. self.ui.closeAppBtn.hide()
  232. self.ui.frame_size_grip.hide()
  233. # DROP SHADOW
  234. self.shadow = QGraphicsDropShadowEffect(self)
  235. self.shadow.setBlurRadius(17)
  236. self.shadow.setXOffset(0)
  237. self.shadow.setYOffset(0)
  238. self.shadow.setColor(QColor(0, 0, 0, 150))
  239. self.ui.bgApp.setGraphicsEffect(self.shadow)
  240. # RESIZE WINDOW
  241. self.sizegrip = QSizeGrip(self.ui.frame_size_grip)
  242. self.sizegrip.setStyleSheet("width: 20px; height: 20px; margin 0px; padding: 0px;")
  243. # MINIMIZE
  244. self.ui.minimizeAppBtn.clicked.connect(lambda: self.showMinimized())
  245. # MAXIMIZE/RESTORE
  246. self.ui.maximizeRestoreAppBtn.clicked.connect(lambda: UIFunctions.maximize_restore(self))
  247. # CLOSE APPLICATION
  248. self.ui.closeAppBtn.clicked.connect(lambda: self.close())
  249. def resize_grips(self):
  250. if Settings.ENABLE_CUSTOM_TITLE_BAR:
  251. self.left_grip.setGeometry(0, 10, 10, self.height())
  252. self.right_grip.setGeometry(self.width() - 10, 10, 10, self.height())
  253. self.top_grip.setGeometry(0, 0, self.width(), 10)
  254. self.bottom_grip.setGeometry(0, self.height() - 10, self.width(), 10)
  255. # 上传文件的方法
  256. def execute_script_based_on_selection(self, file_path):
  257. current_text = self.ui.comboBox_2.currentText()
  258. # db_path = r"D:/Code/ControlNetwork/UI/SQL/DataBase.db"
  259. # 获取当前脚本所在的目录
  260. current_dir = os.path.dirname(os.path.abspath(__file__))
  261. # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  262. sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  263. # 将相对路径转换为绝对路径
  264. sql_folder = os.path.abspath(sql_folder)
  265. db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
  266. file_path = file_path
  267. if current_text == "水准测段高差稳定计算":
  268. GC.main_function(file_path, db_path)
  269. # 添加水准执行代码
  270. elif current_text == "控制网复测平面基准计算":
  271. GS.main_function(file_path, db_path)
  272. # 添加控制网执行代码
  273. elif current_text == "平面控制网稳定性计算":
  274. WD.main_function(file_path, db_path)
  275. # 添加平面控制网执行代码
  276. # 计算与展示文件的方法
  277. def compute_show_process_excel_file(self, file_path):
  278. current_text = self.ui.comboBox_2.currentText()
  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') # 转换文件名为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(excelname, db_path)
  294. GSshow.main_function(self.ui, db_path, utf_en)
  295. elif current_text == "平面控制网稳定性计算":
  296. WDcompute.main_function(excelname, db_path)
  297. WDshow.main_function(self.ui, db_path, utf_en)
  298. # 文件导出的方法
  299. def export_database_to_excel(self, file_path):
  300. current_text = self.ui.comboBox_2.currentText()
  301. # 获取当前脚本所在的目录
  302. current_dir = os.path.dirname(os.path.abspath(__file__))
  303. # 构建 SQL 文件夹的相对路径(上一级的上一级中的 SQL 文件夹)
  304. sql_folder = os.path.join(current_dir, '..', '..', 'SQL')
  305. # 将相对路径转换为绝对路径
  306. sql_folder = os.path.abspath(sql_folder)
  307. db_path = os.path.join(sql_folder, f"{self.ui.comboBox.currentText()}.db")
  308. # 转换为utf-8
  309. excelname = os.path.basename(file_path) # 文件名
  310. utf_en = excelname.encode('utf-8') # 转换文件名为utf-8编码形式
  311. if current_text == "水准测段高差稳定计算":
  312. GCExport.main_function(self, file_path, utf_en, db_path)
  313. elif current_text == "控制网复测平面基准计算":
  314. GSExport.main_function(self, file_path, db_path, excelname)
  315. elif current_text == "平面控制网稳定性计算":
  316. WDExport.main_function(self, file_path, db_path, excelname)
  317. else:
  318. QMessageBox.warning(self, '警告', '请选择有效的计算类型')
  319. # 数据一览,点击查询
  320. def search_data_to_show(self, file_path, current_text, tablename):
  321. utf_en = tablename.encode('utf-8') # 转换文件名为utf-8编码形式
  322. # 高差部分我没改
  323. if current_text == "水准测段高差稳定计算":
  324. GCshow.main_function(self.ui, file_path, utf_en)
  325. elif current_text == "控制网复测平面基准计算":
  326. GSshow.main_function1(self.ui, file_path, utf_en)
  327. elif current_text == "平面控制网稳定性计算":
  328. WDshow.main_function1(self.ui, file_path, utf_en)
  329. # END - GUI DEFINITIONS