控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

main.py 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. import time
  17. from PySide6.QtWidgets import QFileDialog
  18. import sys
  19. import os
  20. import platform
  21. import Back.Program_Run.database_operations
  22. # IMPORT / GUI AND MODULES AND WIDGETS
  23. # ///////////////////////////////////////////////////////////////
  24. from modules import *
  25. from widgets import *
  26. os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100%
  27. # SET AS GLOBAL WIDGETS
  28. # ///////////////////////////////////////////////////////////////
  29. widgets = None
  30. # 表格的模型
  31. class MyTableModel(QAbstractTableModel):
  32. def __init__(self, data):
  33. super().__init__()
  34. self._data = data
  35. # 重新定义行数
  36. def rowCount(self, parent=QModelIndex()):
  37. return len(self._data)
  38. # 重新定义列数
  39. def columnCount(self, parent=QModelIndex()):
  40. return len(self._data[0]) if self._data else 0
  41. # 重新定义数据
  42. def data(self, index, role=Qt.DisplayRole):
  43. if not index.isValid():
  44. return None
  45. if role == Qt.DisplayRole:
  46. return self._data[index.row()][index.column()]
  47. return None
  48. class MainWindow(QMainWindow):
  49. def __init__(self):
  50. QMainWindow.__init__(self)
  51. self.file_path = None # 初始化时文件路径设置为None
  52. # super().__init__()
  53. # SET AS GLOBAL WIDGETS
  54. # ///////////////////////////////////////////////////////////////
  55. self.ui = Ui_MainWindow()
  56. self.ui.setupUi(self)
  57. # 连接信号与槽函数,实现点击操作
  58. self.ui.createFile.clicked.connect(self.on_create_file_clicked)
  59. self.ui.export_2.clicked.connect(self.on_export_2_clicked)
  60. # self.comboBox_2 = QComboBox(self)
  61. # ...此处为省略代码...
  62. global widgets
  63. widgets = self.ui
  64. # 是否使用系统自带标题栏 True是不使用,False使用
  65. # ///////////////////////////////////////////////////////////////
  66. Settings.ENABLE_CUSTOM_TITLE_BAR = True
  67. # APP名称
  68. # ///////////////////////////////////////////////////////////////
  69. title = "控制网复测平面基准归算程序"
  70. description = "控制网复测平面基准归算程序"
  71. # APPLY TEXTS
  72. self.setWindowTitle(title)
  73. widgets.titleRightInfo.setText(description)
  74. # TOGGLE MENU
  75. # ///////////////////////////////////////////////////////////////
  76. widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True))
  77. # SET UI DEFINITIONS
  78. # ///////////////////////////////////////////////////////////////
  79. UIFunctions.uiDefinitions(self)
  80. # QTableWidget PARAMETERS
  81. # ///////////////////////////////////////////////////////////////
  82. # widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  83. # 点击事件
  84. # ///////////////////////////////////////////////////////////////
  85. # 左边菜单
  86. # 首页
  87. widgets.btn_home.clicked.connect(self.buttonClick)
  88. # 输入表格
  89. widgets.btn_widgets.clicked.connect(self.buttonClick)
  90. # 成果预览
  91. widgets.btn_new.clicked.connect(self.buttonClick)
  92. # 数据一览
  93. widgets.btn_data.clicked.connect(self.buttonClick)
  94. # 皮肤切换
  95. widgets.btn_message.clicked.connect(self.buttonClick)
  96. # 打开上传文件夹
  97. widgets.upload.clicked.connect(self.buttonClick)
  98. # 文件计算
  99. widgets.compute.clicked.connect(self.buttonClick)
  100. # 拓展左侧栏
  101. # def openCloseLeftBox():
  102. # UIFunctions.toggleLeftBox(self, True)
  103. # widgets.toggleLeftBox.clicked.connect(openCloseLeftBox)
  104. # widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)
  105. # EXTRA RIGHT BOX
  106. def openCloseRightBox():
  107. UIFunctions.toggleRightBox(self, True)
  108. widgets.settingsTopBtn.clicked.connect(openCloseRightBox)
  109. # 展示APP
  110. # ///////////////////////////////////////////////////////////////
  111. self.show()
  112. # 设置主题
  113. # ///////////////////////////////////////////////////////////////
  114. if getattr(sys, 'frozen', False):
  115. absPath = os.path.dirname(os.path.abspath(sys.executable))
  116. elif __file__:
  117. absPath = os.path.dirname(os.path.abspath(__file__))
  118. useCustomTheme = True
  119. self.useCustomTheme = useCustomTheme
  120. self.absPath = absPath
  121. themeFile = r"themes\py_dracula_light.qss"
  122. # 设置主题和HACKS
  123. if useCustomTheme:
  124. # LOAD AND APPLY STYLE
  125. UIFunctions.theme(self, themeFile, True)
  126. # SET HACKS
  127. AppFunctions.setThemeHack(self)
  128. # 设置主页和选择菜单
  129. # ///////////////////////////////////////////////////////////////
  130. widgets.stackedWidget.setCurrentWidget(widgets.home)
  131. widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))
  132. # self.bind()
  133. # 绑定组件
  134. def bind(self):
  135. # 计算
  136. widgets.compute.clicked.connect(self.buttonClick)
  137. # 删除tableview
  138. def delete_table_view(table_view):
  139. table_view.setParent(None)
  140. table_view.deleteLater()
  141. # ///////////////////////////////////////////////////////////////
  142. def buttonClick(self):
  143. # GET BUTTON CLICKED
  144. btn = self.sender()
  145. btnName = btn.objectName()
  146. # 首页
  147. if btnName == "btn_home":
  148. widgets.stackedWidget.setCurrentWidget(widgets.home)
  149. UIFunctions.resetStyle(self, btnName)
  150. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
  151. # 输入表格
  152. if btnName == "btn_widgets":
  153. widgets.stackedWidget.setCurrentWidget(widgets.widgets)
  154. UIFunctions.resetStyle(self, btnName)
  155. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
  156. # 成果预览
  157. if btnName == "btn_new":
  158. widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
  159. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  160. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  161. # 数据一览
  162. if btnName == "btn_data":
  163. widgets.stackedWidget.setCurrentWidget(widgets.datainfo) # SET PAGE
  164. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  165. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  166. # 皮肤切换
  167. if btnName == "btn_message":
  168. if self.useCustomTheme:
  169. themeFile = os.path.abspath(os.path.join(self.absPath, "themes/py_dracula_dark.qss"))
  170. UIFunctions.theme(self, themeFile, True)
  171. # SET HACKS
  172. AppFunctions.setThemeHack(self)
  173. self.useCustomTheme = False
  174. else:
  175. themeFile = os.path.abspath(os.path.join(self.absPath, "themes/py_dracula_light.qss"))
  176. UIFunctions.theme(self, themeFile, True)
  177. # SET HACKS
  178. AppFunctions.setThemeHack(self)
  179. self.useCustomTheme = True
  180. # 文件上传
  181. if btnName == "upload":
  182. # 使用 QFileDialog 获取文件路径
  183. file_path, _ = QFileDialog.getOpenFileName(
  184. self,
  185. "选择文件",
  186. "",
  187. "表格文件 (*.xls *.xlsx)"
  188. # 水准后期添加支持.xls文件
  189. )
  190. if file_path:
  191. # 处理选中的文件
  192. self.file_path = file_path # 将获取的路径保存到类的属性中
  193. UIFunctions.execute_script_based_on_selection(self, file_path)
  194. # 文件计算
  195. if btnName == "compute":
  196. if self.file_path: # 确保有文件路径后再进行处理
  197. # 计算与展示的业务代码
  198. UIFunctions.compute_show_process_excel_file(self, self.file_path)
  199. # 1秒后自动跳转
  200. QTimer.singleShot(1000, lambda: self.simulateButtonClick("btn_new"))
  201. else:
  202. QMessageBox.warning(self, '警告', '请先选择项目并上传文件')
  203. # 输出点击回馈
  204. print(f'Button "{btnName}" pressed!')
  205. # 辅助函数,点击计算后自动跳转页面
  206. def simulateButtonClick(self, btnName):
  207. # 根据按钮名称找到对应的按钮
  208. btn = self.findChild(QObject, btnName)
  209. if btn:
  210. # 触发按钮点击事件
  211. btn.click()
  212. # 新增槽函数来调用 create_database_and_tables
  213. def on_create_file_clicked(self):
  214. Back.Program_Run.database_operations.create_database_and_tables(self, self.ui)
  215. # 定义导出数据库的槽函数
  216. def on_export_2_clicked(self):
  217. if self.file_path:
  218. UIFunctions.export_database_to_excel(self, self.file_path)
  219. else:
  220. QMessageBox.warning(self, '警告', '请先选择项目并上传文件')
  221. # RESIZE EVENTS
  222. # ///////////////////////////////////////////////////////////////
  223. def resizeEvent(self, event):
  224. # Update Size Grips
  225. UIFunctions.resize_grips(self)
  226. # 鼠标点击事件
  227. # ///////////////////////////////////////////////////////////////
  228. def mousePressEvent(self, event):
  229. # SET DRAG POS WINDOW
  230. # self.dragPos = event.globalPos()
  231. self.dragPos = event.globalPosition().toPoint()
  232. # 输出鼠标事件
  233. if event.buttons() == Qt.LeftButton:
  234. print('Mouse click: LEFT CLICK')
  235. if event.buttons() == Qt.RightButton:
  236. print('Mouse click: RIGHT CLICK')
  237. if __name__ == "__main__":
  238. app = QApplication(sys.argv)
  239. app.setWindowIcon(QIcon("icon.ico"))
  240. window = MainWindow()
  241. # window.resize(1440, 960) # 高宽
  242. sys.exit(app.exec())