控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ui_functions.py 15KB

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