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

main_new.py 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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 QFileDialog,QWidget, QVBoxLayout, QTreeWidget, QApplication, QTreeWidgetItem
  17. from PySide6.QtCore import Signal, Slot,Qt,QObject
  18. from PySide6.QtSql import QSqlTableModel,QSqlDatabase
  19. import sqlite3
  20. from PySide6.QtGui import QIcon
  21. import sys
  22. import os
  23. import platform
  24. from tkinter import messagebox
  25. # IMPORT / GUI AND MODULES AND WIDGETS
  26. # ///////////////////////////////////////////////////////////////
  27. from modules import *
  28. from widgets import *
  29. os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100%
  30. # SET AS GLOBAL WIDGETS
  31. # ///////////////////////////////////////////////////////////////
  32. widgets = None
  33. excelname = ''
  34. # 获取项目根目录
  35. project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
  36. # 将项目根目录添加到 sys.path
  37. sys.path.append(project_root)
  38. # 表格的模型
  39. class MyTableModel(QAbstractTableModel):
  40. def __init__(self, data):
  41. super().__init__()
  42. self._data = data
  43. # 重新定义行数
  44. def rowCount(self, parent=QModelIndex()):
  45. return len(self._data)
  46. # 重新定义列数
  47. def columnCount(self, parent=QModelIndex()):
  48. return len(self._data[0]) if self._data else 0
  49. # 重新定义数据
  50. def data(self, index, role=Qt.DisplayRole):
  51. if not index.isValid():
  52. return None
  53. if role == Qt.DisplayRole:
  54. return self._data[index.row()][index.column()]
  55. return None
  56. class TreeWidgetItem:
  57. def __init__(self, id: any, parent_id: any, name: str, icon: QIcon = None, extend: object = None):
  58. """
  59. 菜单数据接口
  60. :param id: ID
  61. :param parent_id: 父ID
  62. :param name: 菜单名称
  63. :param icon: 图标
  64. :param extend: 扩展数据
  65. """
  66. self.id: any = id
  67. self.parent_id: any = parent_id
  68. self.name: str = name
  69. self.extend: object = extend
  70. # 实例化
  71. self.treeWidgetItem = QTreeWidgetItem([self.name])
  72. # 存储相关数据
  73. self.treeWidgetItem.setData(0, Qt.UserRole + 1, extend)
  74. self.treeWidgetItem.setIcon(0, QIcon(':/icons/default.png'))
  75. if icon is not None:
  76. self.treeWidgetItem.setIcon(0, icon)
  77. class ElTreeData(QObject):
  78. """
  79. Data Model
  80. """
  81. items_changed: Signal = Signal(str)
  82. styleSheet_changed: Signal = Signal(str)
  83. itemClicked: Signal = Signal(object)
  84. itemDoubleClicked: Signal = Signal(object)
  85. def __init__(self, items: list[TreeWidgetItem] = None, styleSheet: str = None):
  86. super(ElTreeData, self).__init__()
  87. # 定义数据
  88. self._items: list[TreeWidgetItem]
  89. self._styleSheet: str
  90. # 初始化数据
  91. self.items = items
  92. self.styleSheet = styleSheet
  93. @property
  94. def items(self):
  95. return self._items
  96. @items.setter
  97. def items(self, value):
  98. self._items = value
  99. # 数据改变时发出信号
  100. self.items_changed.emit(self.items)
  101. @property
  102. def styleSheet(self):
  103. return self._styleSheet
  104. @styleSheet.setter
  105. def styleSheet(self, value):
  106. self._styleSheet = value
  107. # 数据改变时发出信号
  108. self.styleSheet_changed.emit(self.styleSheet)
  109. class MainWindow(QMainWindow):
  110. def __init__(self):
  111. QMainWindow.__init__(self)
  112. # super().__init__()
  113. # SET AS GLOBAL WIDGETS
  114. # ///////////////////////////////////////////////////////////////
  115. self.ui = Ui_MainWindow()
  116. self.ui.setupUi(self)
  117. # self.comboBox_2 = QComboBox(self)
  118. # ...此处为省略代码...
  119. global widgets
  120. widgets = self.ui
  121. # 是否使用系统自带标题栏 True是不使用,False使用
  122. # ///////////////////////////////////////////////////////////////
  123. Settings.ENABLE_CUSTOM_TITLE_BAR = True
  124. # APP名称
  125. # ///////////////////////////////////////////////////////////////
  126. title = "控制网复测平面基准归算程序"
  127. description = "控制网复测平面基准归算程序"
  128. # APPLY TEXTS
  129. self.setWindowTitle(title)
  130. widgets.titleRightInfo.setText(description)
  131. # TOGGLE MENU
  132. # ///////////////////////////////////////////////////////////////
  133. widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True))
  134. # SET UI DEFINITIONS
  135. # ///////////////////////////////////////////////////////////////
  136. UIFunctions.uiDefinitions(self)
  137. # QTableWidget PARAMETERS
  138. # ///////////////////////////////////////////////////////////////
  139. # widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  140. # 点击事件
  141. # ///////////////////////////////////////////////////////////////
  142. # 左边菜单
  143. # 首页
  144. widgets.btn_home.clicked.connect(self.buttonClick)
  145. # 输入表格
  146. widgets.btn_widgets.clicked.connect(self.buttonClick)
  147. # 成果预览
  148. widgets.btn_new.clicked.connect(self.buttonClick)
  149. # 数据一览
  150. # 皮肤切换
  151. widgets.btn_message.clicked.connect(self.buttonClick)
  152. # 打开上传文件夹
  153. widgets.upload.clicked.connect(self.buttonClick)
  154. # 拓展左侧栏
  155. # def openCloseLeftBox():
  156. # UIFunctions.toggleLeftBox(self, True)
  157. # widgets.toggleLeftBox.clicked.connect(openCloseLeftBox)
  158. # widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)
  159. # EXTRA RIGHT BOX
  160. def openCloseRightBox():
  161. UIFunctions.toggleRightBox(self, True)
  162. widgets.settingsTopBtn.clicked.connect(openCloseRightBox)
  163. # 展示APP
  164. # ///////////////////////////////////////////////////////////////
  165. self.show()
  166. # 设置主题
  167. # ///////////////////////////////////////////////////////////////
  168. if getattr(sys, 'frozen', False):
  169. absPath = os.path.dirname(os.path.abspath(sys.executable))
  170. elif __file__:
  171. absPath = os.path.dirname(os.path.abspath(__file__))
  172. useCustomTheme = True
  173. self.useCustomTheme = useCustomTheme
  174. self.absPath = absPath
  175. # themeFile = r"Front\themes\py_dracula_light.qss"
  176. themeFile = r"D:\4work_now\20240819GS\20241211\Front\themes\py_dracula_light.qss"
  177. # 设置主题和HACKS
  178. if useCustomTheme:
  179. # LOAD AND APPLY STYLE
  180. UIFunctions.theme(self, themeFile, True)
  181. # SET HACKS
  182. AppFunctions.setThemeHack(self)
  183. # 设置主页和选择菜单
  184. # ///////////////////////////////////////////////////////////////
  185. widgets.stackedWidget.setCurrentWidget(widgets.home)
  186. widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))
  187. self.bind()
  188. #treewidget
  189. self.data = ElTreeData
  190. widgets.allTreeWidget.itemClicked.connect(lambda item: self.itemClicked.emit(item.data(0, Qt.UserRole + 1)))
  191. widgets.allTreeWidget.itemDoubleClicked.connect(lambda item: self.itemDoubleClicked.emit(item.data(0, Qt.UserRole + 1)))
  192. # self.__render_items(True)
  193. def __render_items(self, is_clear: bool):
  194. if is_clear:
  195. widgets.allTreeWidget.clear()
  196. widgets.allTreeWidget.setColumnCount(1)
  197. widgets.allTreeWidget.setHeaderHidden(True)
  198. if self.data.items is not None:
  199. # 转为字典
  200. mapping: dict[any, TreeWidgetItem] = dict(zip([i.id for i in self.data.items], self.data.items))
  201. # 树容器
  202. treeWidgetItems: list[QTreeWidgetItem] = []
  203. for d in self.data.items:
  204. # 如果找不到父级项,则是根节点
  205. parent: TreeWidgetItem = mapping.get(d.parent_id)
  206. if parent is None:
  207. treeWidgetItems.append(d.treeWidgetItem)
  208. else:
  209. parent.treeWidgetItem.addChild(d.treeWidgetItem)
  210. # 挂载到树上
  211. widgets.allTreeWidget.insertTopLevelItems(0, treeWidgetItems)
  212. #绑定组件
  213. def bind(self):
  214. # 计算
  215. widgets.compute.clicked.connect(self.computeClick)
  216. #数据库展示(初始化)
  217. widgets.btn_data.clicked.connect(self.dataClick)
  218. #删除tableview
  219. def delete_table_view(table_view):
  220. table_view.setParent(None)
  221. table_view.deleteLater()
  222. #默认第一个参数是self,所以使用时只有一个参数
  223. #稳定性成果表
  224. def Arrange_Data(self,list1):
  225. #最终return的
  226. list2 = []
  227. #点号部分
  228. nlist = []
  229. for data1 in list1:
  230. #点名
  231. #存每一行的数据
  232. resultlist = []
  233. pn = data1[0].decode('utf-8')
  234. resultlist.append(pn)
  235. nlist.append(pn)
  236. resultlist.append(data1[1])
  237. resultlist.append(data1[2])
  238. resultlist.append(data1[3])
  239. resultlist.append(data1[4])
  240. resultlist.append(data1[5])
  241. resultlist.append(data1[6])
  242. resultlist.append(data1[7])
  243. resultlist.append(data1[8])
  244. resultlist.append(data1[9])
  245. resultlist.append(data1[10])
  246. resultlist.append(data1[11])
  247. #判定1
  248. an1 = data1[12].decode('utf-8')
  249. resultlist.append(an1)
  250. resultlist.append(data1[13])
  251. resultlist.append(data1[14])
  252. resultlist.append(data1[15])
  253. #判定2
  254. an2 = data1[16].decode('utf-8')
  255. resultlist.append(an2)
  256. list2.append(resultlist)
  257. return nlist,list2
  258. #复测成果表
  259. def Arrange_Data1(self,list1):
  260. #最终return的
  261. list2 = []
  262. #点号部分
  263. nlist = []
  264. for data1 in list1:
  265. #点名
  266. #存每一行的数据
  267. resultlist = []
  268. pn = data1[0].decode('utf-8')
  269. resultlist.append(pn)
  270. nlist.append(pn)
  271. resultlist.append(data1[1])
  272. resultlist.append(data1[2])
  273. resultlist.append(data1[3])
  274. resultlist.append(data1[4])
  275. resultlist.append(data1[5])
  276. resultlist.append(data1[6])
  277. resultlist.append(data1[7])
  278. #判定
  279. an1 = data1[8].decode('utf-8')
  280. resultlist.append(an1)
  281. list2.append(resultlist)
  282. return nlist,list2
  283. #基准归算表
  284. def Arrange_Data2(self,list1):
  285. #最终return的
  286. list2 = []
  287. #点号部分
  288. nlist = []
  289. for data1 in list1:
  290. #点名
  291. #存每一行的数据
  292. resultlist = []
  293. pn = data1[0].decode('utf-8')
  294. resultlist.append(pn)
  295. nlist.append(pn)
  296. resultlist.append(data1[1])
  297. resultlist.append(data1[2])
  298. resultlist.append(data1[3])
  299. resultlist.append(data1[4])
  300. resultlist.append(data1[5])
  301. #判定
  302. an1 = data1[6].decode('utf-8')
  303. resultlist.append(an1)
  304. list2.append(resultlist)
  305. return nlist,list2
  306. #稳定性成果表
  307. def Data_in_Cell(self,list1):
  308. model = QStandardItemModel()
  309. xx = 0
  310. while xx < len(list1):
  311. data1 = list1[xx]
  312. #点号
  313. cell1 = str(data1[0])
  314. item = QStandardItem(cell1)
  315. model.setItem(xx, 0, item)
  316. #首期
  317. cell1 = str(round(data1[1],4))
  318. item = QStandardItem(cell1)
  319. model.setItem(xx, 1, item)
  320. cell1 = str(round(data1[2],4))
  321. item = QStandardItem(cell1)
  322. model.setItem(xx, 2, item)
  323. #上期
  324. cell1 = str(round(data1[3],4))
  325. item = QStandardItem(cell1)
  326. model.setItem(xx, 3, item)
  327. cell1 = str(round(data1[4],4))
  328. item = QStandardItem(cell1)
  329. model.setItem(xx, 4, item)
  330. #权
  331. cell1 = str(int(data1[5]))
  332. item = QStandardItem(cell1)
  333. model.setItem(xx, 5, item)
  334. #本期
  335. cell1 = str(round(data1[6],4))
  336. item = QStandardItem(cell1)
  337. model.setItem(xx, 6, item)
  338. cell1 = str(round(data1[7],4))
  339. item = QStandardItem(cell1)
  340. model.setItem(xx, 7, item)
  341. #权
  342. cell1 = str(int(data1[8]))
  343. item = QStandardItem(cell1)
  344. model.setItem(xx, 8, item)
  345. #本-首
  346. cell1 = str(round(data1[9],1))
  347. item = QStandardItem(cell1)
  348. model.setItem(xx, 9, item)
  349. cell1 = str(round(data1[10],1))
  350. item = QStandardItem(cell1)
  351. model.setItem(xx, 10, item)
  352. cell1 = str(round(data1[11],1))
  353. item = QStandardItem(cell1)
  354. model.setItem(xx, 11, item)
  355. #判定(如果是稳定则不显示)
  356. cell1 = str(data1[12])
  357. if cell1 == '稳定':
  358. cell1 = ''
  359. item = QStandardItem(cell1)
  360. model.setItem(xx, 12, item)
  361. #本-上
  362. cell1 = str(round(data1[13],1))
  363. item = QStandardItem(cell1)
  364. model.setItem(xx, 13, item)
  365. cell1 = str(round(data1[14],1))
  366. item = QStandardItem(cell1)
  367. model.setItem(xx, 14, item)
  368. cell1 = str(round(data1[15],1))
  369. item = QStandardItem(cell1)
  370. model.setItem(xx, 15, item)
  371. #判定
  372. cell1 = str(data1[16])
  373. if cell1 == '稳定':
  374. cell1 = ''
  375. item = QStandardItem(cell1)
  376. model.setItem(xx, 16, item)
  377. xx = xx + 1
  378. return model
  379. #复测成果表
  380. def Data_in_Cell1(self,list1):
  381. model = QStandardItemModel()
  382. xx = 0
  383. while xx < len(list1):
  384. data1 = list1[xx]
  385. #点号
  386. cell1 = str(data1[0])
  387. item = QStandardItem(cell1)
  388. model.setItem(xx, 0, item)
  389. #上期
  390. cell1 = str(round(data1[1],4))
  391. item = QStandardItem(cell1)
  392. model.setItem(xx, 1, item)
  393. cell1 = str(round(data1[2],4))
  394. item = QStandardItem(cell1)
  395. model.setItem(xx, 2, item)
  396. #本期
  397. cell1 = str(round(data1[3],4))
  398. item = QStandardItem(cell1)
  399. model.setItem(xx, 3, item)
  400. cell1 = str(round(data1[4],4))
  401. item = QStandardItem(cell1)
  402. model.setItem(xx, 4, item)
  403. #上-本
  404. cell1 = str(round(data1[5],1))
  405. item = QStandardItem(cell1)
  406. model.setItem(xx, 5, item)
  407. cell1 = str(round(data1[6],1))
  408. item = QStandardItem(cell1)
  409. model.setItem(xx, 6, item)
  410. cell1 = str(round(data1[7],1))
  411. item = QStandardItem(cell1)
  412. model.setItem(xx, 7, item)
  413. #判定(如果是稳定则不显示)
  414. cell1 = str(data1[8])
  415. if cell1 == '稳定':
  416. cell1 = ''
  417. item = QStandardItem(cell1)
  418. model.setItem(xx, 8, item)
  419. xx = xx + 1
  420. return model
  421. #基准归算表
  422. def Data_in_Cell2(self,list1):
  423. model = QStandardItemModel()
  424. xx = 0
  425. while xx < len(list1):
  426. data1 = list1[xx]
  427. #点号
  428. cell1 = str(data1[0])
  429. item = QStandardItem(cell1)
  430. model.setItem(xx, 0, item)
  431. #计算
  432. cell1 = str(round(data1[1],4))
  433. item = QStandardItem(cell1)
  434. model.setItem(xx, 1, item)
  435. cell1 = str(round(data1[2],4))
  436. item = QStandardItem(cell1)
  437. model.setItem(xx, 2, item)
  438. #上-计
  439. cell1 = str(round(data1[3],1))
  440. item = QStandardItem(cell1)
  441. model.setItem(xx, 3, item)
  442. cell1 = str(round(data1[4],1))
  443. item = QStandardItem(cell1)
  444. model.setItem(xx, 4, item)
  445. cell1 = str(round(data1[5],1))
  446. item = QStandardItem(cell1)
  447. model.setItem(xx, 5, item)
  448. #判定(如果是稳定则不显示)
  449. cell1 = str(data1[6])
  450. if cell1 == '稳定':
  451. cell1 = ''
  452. item = QStandardItem(cell1)
  453. model.setItem(xx, 6, item)
  454. xx = xx + 1
  455. return model
  456. def dataClick(self):
  457. # GET BUTTON CLICKED
  458. btn = self.sender()
  459. btnName = btn.objectName()
  460. #初始化全部数据库
  461. inpath = r'D:\4work_now\20240819GS\20241211\SQL'
  462. #读取所有的数据库名
  463. list1 = []
  464. for filename in os.listdir(inpath):
  465. dbname = filename.split('.',-1)[0]
  466. dbpath = os.path.join(inpath,filename)
  467. lista = []
  468. lista.append(dbname)
  469. lista.append(dbpath)
  470. list1.append(lista)
  471. #读取所有的表名(三种方式往下)
  472. db1 = sqlite3.connect(dbpath)
  473. #获取游标
  474. cursor1 = db1.cursor()
  475. sqlstr1 = 'SELECT TableName FROM GC_Input_Param;'
  476. cursor1.execute(sqlstr1)
  477. result1 = cursor1.fetchall()
  478. sqlstr2 = 'SELECT TableName FROM GS_Input_Param;'
  479. cursor1.execute(sqlstr2)
  480. result2 = cursor1.fetchall()
  481. sqlstr3 = 'SELECT TableName FROM WD_Input_Param;'
  482. cursor1.execute(sqlstr3)
  483. result3 = cursor1.fetchall()
  484. atw_button = ElTreeData(items=[
  485. TreeWidgetItem(1, 0, "User", icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil_file.png"), extend={'id': 1}),
  486. TreeWidgetItem(2, 1, "Child", icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil_file.png"), extend={'id': 2}),
  487. TreeWidgetItem(3, 1, "Child", icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil_file.png"), extend={'id': 3}),
  488. TreeWidgetItem(4, 2, "Child", icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil_file.png"), extend={'id': 4}),
  489. TreeWidgetItem(5, 2, "Child", icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil_file.png"), extend={'id': 5}),
  490. TreeWidgetItem(6, 5, "Child", icon=QIcon("D:/4work_now/20240819GS/20241211/Front/images/icons/cil_file.png"), extend={'id': 6}),
  491. TreeWidgetItem(7, 5, "Child", extend={'id': 7}),
  492. TreeWidgetItem(8, 5, "Child", extend={'id': 8}),
  493. TreeWidgetItem(9, 8, "Child", extend={'id': 9}),
  494. ])
  495. # atw_button.itemClicked.connect(lambda extend: print("单击->扩展数据为:", extend))
  496. # atw_button.itemDoubleClicked.connect(lambda extend: print("双击->扩展数据为:", extend))
  497. # atw_button.show()
  498. widgets.stackedWidget.setCurrentWidget(widgets.datainfo)
  499. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  500. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
  501. def computeClick(self):
  502. # GET BUTTON CLICKED
  503. btn = self.sender()
  504. btnName = btn.objectName()
  505. #处理选中的文件
  506. # print(file_path)
  507. UIFunctions.compute_show_process_excel_file(self, file_path)
  508. current_text = self.ui.comboBox_2.currentText()
  509. db_path = r"D:\4work_now\20240819GS\ControlNetwork\ControlNetwork\UI\SQL\DataBase.db"
  510. #转换下
  511. excelname = os.path.basename(file_path)
  512. utf_en = excelname.encode('utf-8')
  513. # file_path = file_path
  514. if current_text == "水准测段高差稳定计算":
  515. #只显示一个tab
  516. self.ui.tabWidget.setTabVisible(0,True)
  517. self.ui.tabWidget.setTabVisible(1,False)
  518. self.ui.tabWidget.setTabVisible(2,False)
  519. #重新设置文字名称
  520. self.ui.tabWidget.setTabText(0,'测段高差计算表')
  521. # 计算结束自动跳转结果页面,并保留查询内容,以便输出
  522. widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
  523. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  524. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  525. elif current_text == "控制网复测平面基准计算":
  526. #就用已有的选项卡
  527. self.ui.tabWidget.setTabVisible(0,True)
  528. self.ui.tabWidget.setTabVisible(1,True)
  529. self.ui.tabWidget.setTabVisible(2,True)
  530. #重新设置文字名称
  531. self.ui.tabWidget.setTabText(0,'复测成果表')
  532. self.ui.tabWidget.setTabText(1,'基准归算模型')
  533. self.ui.tabWidget.setTabText(2,'复测基准归算表')
  534. #链接数据库并显示
  535. # 连接到数据库
  536. #将结果输出到数据库
  537. db1 = sqlite3.connect(db_path)
  538. #获取游标
  539. cursor1 = db1.cursor()
  540. #查询表内符合的所有数据(分成两个结果分别显示)
  541. #复测成果表
  542. sqlstr1 = 'select PointName,Last_X,Last_Y,Result_X,Result_Y,Last_ResultX,Last_ResultY,Last_ResultP,Dis_Ass from GS_Result_Point WHERE TableName = ?'
  543. cursor1.execute(sqlstr1,(utf_en,))
  544. #获取结果集
  545. result1 = cursor1.fetchall()
  546. #基准归算表
  547. sqlstr11 = 'select PointName,Cal_X,Cal_Y,Last_CalX,Last_CalY,Last_CalP,Dis_Ass from GS_Result_Point WHERE TableName = ?'
  548. cursor1.execute(sqlstr11,(utf_en,))
  549. #获取结果集
  550. result2 = cursor1.fetchall()
  551. #对结果集进行处理,把汉字转换过来,添加表头部分
  552. nlist1,plist1 = self.Arrange_Data1(result1)
  553. nlist2,plist2 = self.Arrange_Data2(result2)
  554. # 创建一个数据模型(复测成果表)
  555. self.model1 = QStandardItemModel()
  556. #把数据放进去
  557. model1 = self.Data_in_Cell1(plist1)
  558. model2 = self.Data_in_Cell2(plist2)
  559. #设置表头
  560. model1.setHorizontalHeaderLabels(['点名', '前期X','前期Y','本期X', '本期Y','前期-本期X','前期-本期Y','前期-本期P','位移判定'])
  561. model1.setVerticalHeaderLabels(nlist1)
  562. #QTableView并将数据模型与之关联
  563. self.ui.resultTableView.setModel(model1)
  564. self.ui.resultTableView.show()
  565. #设置表头
  566. model2.setHorizontalHeaderLabels(['点名', '基准归算X','基准归算Y','前期-归算X','前期-归算Y','前期-归算P','位移判定'])
  567. model2.setVerticalHeaderLabels(nlist2)
  568. #QTableView并将数据模型与之关联
  569. self.ui.reconTableView.setModel(model2)
  570. self.ui.reconTableView.show()
  571. #富文本的html
  572. sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from GS_Trans_Param WHERE TableName = ?'
  573. cursor1.execute(sqlstr2,(utf_en,))
  574. #获取结果集
  575. result1 = cursor1.fetchall()
  576. str1 = result1[0][0].decode('utf-8')
  577. str2 = result1[0][1].decode('utf-8')
  578. n1 = result1[0][2]
  579. n2 = result1[0][3]
  580. n3 = result1[0][4]
  581. n4 = result1[0][5]
  582. n5 = result1[0][6]
  583. n6 = result1[0][7]
  584. str0 = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
  585. <html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
  586. p, li { white-space: pre-wrap; }
  587. hr { height: 1px; border-width: 0; }
  588. li.unchecked::marker { content: "\2610"; }
  589. li.checked::marker { content: "\2612"; }
  590. </style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
  591. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#000000;">"""+str2+"""--"""+str1+"""</span><span style=" font-size:14pt;">已知系统转换公式:</span></p>
  592. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">X</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">"""+str(n1)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">"""+str(n2)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">"""+str(n3)+"""</span><span style=" font-size:14pt;">)</span></p>
  593. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">Y</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">"""+str(n4)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">"""+str(n5)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">"""+str(n6)+"""</span><span style=" font-size:14pt;">)</span></p>
  594. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">式中:</span><span style=" font-size:14pt; font-weight:700; color:#000000;">x、y</span><span style=" font-size:14pt;">为</span><span style=" font-size:14pt; color:#000000;">"""+str2+"""</span><span style=" font-size:14pt;">坐标;</span></p>
  595. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;"> </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为"""+str1+"""已知系统的"""+str2+"""归算坐标。</span></p></body></html>"""
  596. self.ui.printTableView.setHtml(str0)
  597. # 计算结束自动跳转结果页面,并保留查询内容,以便输出
  598. widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
  599. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  600. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  601. # GS.main_function(file_path, db_path)
  602. # 添加控制网执行代码
  603. elif current_text=="平面控制网稳定性计算":
  604. #只显示头两个tab
  605. self.ui.tabWidget.setTabVisible(0,True)
  606. self.ui.tabWidget.setTabVisible(1,True)
  607. self.ui.tabWidget.setTabVisible(2,False)
  608. #重新设置文字名称
  609. self.ui.tabWidget.setTabText(0,'稳定性分析成果表')
  610. self.ui.tabWidget.setTabText(1,'自由网成果归算模型')
  611. #链接数据库并显示
  612. # 连接到数据库
  613. #将结果输出到数据库
  614. db1 = sqlite3.connect(db_path)
  615. #获取游标
  616. cursor1 = db1.cursor()
  617. #查询表内符合的所有数据
  618. sqlstr1 = 'select PointName,First_X,First_Y,Last_X,Last_Y,Last_Wight,Result_X,Result_Y,New_Wight,New_FirstX,New_FirstY,New_FirstP,NFDis_Ass,New_LastX,New_LastY,New_LastP,NLDis_Ass from WD_Result_Point WHERE TableName = ?'
  619. cursor1.execute(sqlstr1,(utf_en,))
  620. #获取结果集
  621. result = cursor1.fetchall()
  622. #对结果集进行处理,把汉字转换过来,添加表头部分
  623. nlist,plist = self.Arrange_Data(result)
  624. # 创建一个数据模型
  625. self.model = QStandardItemModel()
  626. #把数据放进去
  627. model1 = self.Data_in_Cell(plist)
  628. #设置表头
  629. model1.setHorizontalHeaderLabels(['点名', '首期X','首期Y','上期X', '上期Y','权','本期X','本期Y','权','本期-首期X','本期-首期Y','本期-首期P','位移判定', '本期-上期X','本期-上期Y','本期-上期P','位移判定'])
  630. model1.setVerticalHeaderLabels(nlist)
  631. #QTableView并将数据模型与之关联
  632. self.ui.resultTableView.setModel(model1)
  633. self.ui.resultTableView.show()
  634. #富文本的html
  635. sqlstr2 = 'select Last_ResultName,New_ResultName,Formula_X1,Formula_X2,Formula_X3,Formula_Y1,Formula_Y2,Formula_Y3 from WD_Result_Param WHERE TableName = ?'
  636. cursor1.execute(sqlstr2,(utf_en,))
  637. #获取结果集
  638. result1 = cursor1.fetchall()
  639. str1 = result1[0][0].decode('utf-8')
  640. str2 = result1[0][1].decode('utf-8')
  641. n1 = result1[0][2]
  642. n2 = result1[0][3]
  643. n3 = result1[0][4]
  644. n4 = result1[0][5]
  645. n5 = result1[0][6]
  646. n6 = result1[0][7]
  647. str0 = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
  648. <html><head><meta name="qrichtext" content="1" /><meta charset="utf-8" /><style type="text/css">
  649. p, li { white-space: pre-wrap; }
  650. hr { height: 1px; border-width: 0; }
  651. li.unchecked::marker { content: "\2610"; }
  652. li.checked::marker { content: "\2612"; }
  653. </style></head><body style=" font-family:'Microsoft YaHei UI'; font-size:9pt; font-weight:400; font-style:normal;">
  654. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; color:#000000;">"""+str2+"""--"""+str1+"""</span><span style=" font-size:14pt;">已知系统转换公式:</span></p>
  655. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">X</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">"""+str(n1)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">"""+str(n2)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">"""+str(n3)+"""</span><span style=" font-size:14pt;">)</span></p>
  656. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt; font-weight:700;">Y</span><span style=" font-size:14pt;">=(</span><span style=" font-size:14pt; color:#aa0000;">"""+str(n4)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">x</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00aa00;">"""+str(n5)+"""</span><span style=" font-size:14pt;">)</span><span style=" font-size:14pt; font-weight:700;">y</span><span style=" font-size:14pt;">+(</span><span style=" font-size:14pt; color:#00007f;">"""+str(n6)+"""</span><span style=" font-size:14pt;">)</span></p>
  657. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;">式中:</span><span style=" font-size:14pt; font-weight:700; color:#000000;">x、y</span><span style=" font-size:14pt;">为</span><span style=" font-size:14pt; color:#000000;">"""+str2+"""</span><span style=" font-size:14pt;">坐标;</span></p>
  658. <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:14pt;"> </span><span style=" font-size:14pt; font-weight:700;">X、Y</span><span style=" font-size:14pt;">为"""+str1+"""已知系统的"""+str2+"""归算坐标。</span></p></body></html>"""
  659. self.ui.printTableView.setHtml(str0)
  660. #----------------------------------------------------------
  661. # 计算结束自动跳转结果页面,并保留查询内容,以便输出
  662. widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
  663. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  664. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  665. # 点击事件
  666. # 在这里添加点击事件的方法
  667. # ///////////////////////////////////////////////////////////////
  668. def buttonClick(self):
  669. # GET BUTTON CLICKED
  670. btn = self.sender()
  671. btnName = btn.objectName()
  672. # 首页
  673. if btnName == "btn_home":
  674. widgets.stackedWidget.setCurrentWidget(widgets.home)
  675. UIFunctions.resetStyle(self, btnName)
  676. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
  677. # 输入表格
  678. if btnName == "btn_widgets":
  679. widgets.stackedWidget.setCurrentWidget(widgets.widgets)
  680. UIFunctions.resetStyle(self, btnName)
  681. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
  682. # 成果预览
  683. if btnName == "btn_new":
  684. widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
  685. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  686. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  687. # 数据一览
  688. if btnName == "btn_data":
  689. widgets.stackedWidget.setCurrentWidget(widgets.datainfo) # SET PAGE
  690. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  691. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  692. # 皮肤切换
  693. if btnName == "btn_message":
  694. if self.useCustomTheme:
  695. themeFile = os.path.abspath(os.path.join(self.absPath, "themes/py_dracula_dark.qss"))
  696. UIFunctions.theme(self, themeFile, True)
  697. # SET HACKS
  698. AppFunctions.setThemeHack(self)
  699. self.useCustomTheme = False
  700. else:
  701. themeFile = os.path.abspath(os.path.join(self.absPath, "themes/py_dracula_light.qss"))
  702. UIFunctions.theme(self, themeFile, True)
  703. # SET HACKS
  704. AppFunctions.setThemeHack(self)
  705. self.useCustomTheme = True
  706. # 文件上传
  707. if btnName == "upload":
  708. global file_path
  709. # options = QFileDialog.Options()
  710. # 使用 QFileDialog 获取文件路径
  711. file_path, _ = QFileDialog.getOpenFileName(
  712. self,
  713. "选择文件",
  714. "",
  715. "表格文件 (*.xls *.xlsx)"
  716. )
  717. if file_path:
  718. # 处理选中的文件
  719. # print(file_path)
  720. UIFunctions.execute_script_based_on_selection(self, file_path)
  721. # messagebox.showinfo("提示",f"文件 '{file_name}' 跳转成功!")
  722. # 输出点击回馈
  723. print(f'Button "{btnName}" pressed!')
  724. # RESIZE EVENTS
  725. # ///////////////////////////////////////////////////////////////
  726. def resizeEvent(self, event):
  727. # Update Size Grips
  728. UIFunctions.resize_grips(self)
  729. # 鼠标点击事件
  730. # ///////////////////////////////////////////////////////////////
  731. def mousePressEvent(self, event):
  732. # SET DRAG POS WINDOW
  733. self.dragPos = event.globalPos()
  734. # 输出鼠标事件
  735. if event.buttons() == Qt.LeftButton:
  736. print('Mouse click: LEFT CLICK')
  737. if event.buttons() == Qt.RightButton:
  738. print('Mouse click: RIGHT CLICK')
  739. if __name__ == "__main__":
  740. app = QApplication(sys.argv)
  741. app.setWindowIcon(QIcon("icon.ico"))
  742. window = MainWindow()
  743. # window.resize(1440, 960) # 高宽
  744. sys.exit(app.exec())