控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
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

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