控制网复测平面基准归算程序(包含控制网复测平面基准计算,平面控制网稳定性计算,水准测段高差稳定计算三个程序功能)
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

main.py 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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, QWidget, QVBoxLayout, QTreeWidget, QApplication, QTreeWidgetItem
  18. from PySide6.QtCore import Signal, Qt, Slot, QObject
  19. from PySide6.QtSql import QSqlTableModel, QSqlDatabase
  20. import sqlite3
  21. from PySide6.QtGui import QIcon
  22. import sys
  23. import os
  24. import platform
  25. import Back.Program_Run.database_operations
  26. # IMPORT / GUI AND MODULES AND WIDGETS
  27. # ///////////////////////////////////////////////////////////////
  28. from modules import *
  29. from widgets import *
  30. os.environ["QT_FONT_DPI"] = "96" # FIX Problem for High DPI and Scale above 100%
  31. # SET AS GLOBAL WIDGETS
  32. # ///////////////////////////////////////////////////////////////
  33. widgets = None
  34. excelname = ''
  35. # 获取项目根目录
  36. project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
  37. # 将项目根目录添加到 sys.path
  38. sys.path.append(project_root)
  39. # 表格的模型
  40. class MyTableModel(QAbstractTableModel):
  41. def __init__(self, data):
  42. super().__init__()
  43. self._data = data
  44. # 重新定义行数
  45. def rowCount(self, parent=QModelIndex()):
  46. return len(self._data)
  47. # 重新定义列数
  48. def columnCount(self, parent=QModelIndex()):
  49. return len(self._data[0]) if self._data else 0
  50. # 重新定义数据
  51. def data(self, index, role=Qt.DisplayRole):
  52. if not index.isValid():
  53. return None
  54. if role == Qt.DisplayRole:
  55. return self._data[index.row()][index.column()]
  56. return None
  57. # 数据一览树状
  58. class TreeWidgetItem:
  59. def __init__(self, id: any, parent_id: any, name: str, icon: QIcon = None, extend: object = None):
  60. """
  61. 菜单数据接口
  62. :param id: ID
  63. :param parent_id: 父ID
  64. :param name: 菜单名称
  65. :param icon: 图标
  66. :param extend: 扩展数据
  67. """
  68. self.id: any = id
  69. self.parent_id: any = parent_id
  70. self.name: str = name
  71. self.extend: object = extend
  72. # 实例化
  73. self.treeWidgetItem = QTreeWidgetItem([self.name])
  74. # 存储相关数据
  75. self.treeWidgetItem.setData(0, Qt.UserRole + 1, extend)
  76. self.treeWidgetItem.setIcon(0, QIcon(':/icons/default.png'))
  77. if icon is not None:
  78. self.treeWidgetItem.setIcon(0, icon)
  79. class ElTreeData(QObject):
  80. """
  81. Data Model
  82. """
  83. items_changed: Signal = Signal(str)
  84. styleSheet_changed: Signal = Signal(str)
  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. # 全数据库
  110. class ElTree(QWidget):
  111. """
  112. Control
  113. """
  114. itemClicked: Signal = Signal(object)
  115. itemDoubleClicked: Signal = Signal(object)
  116. def __init__(self, treeData: ElTreeData, parent=None):
  117. super(ElTree, self).__init__(parent=parent)
  118. self.data = treeData
  119. # 将按钮的点击信号绑定到当前类的点击信号
  120. widgets.allTreeWidget.itemClicked.connect(lambda item: self.itemClicked.emit(item.data(0, Qt.UserRole + 1)))
  121. widgets.allTreeWidget.itemDoubleClicked.connect(
  122. lambda item: self.itemDoubleClicked.emit(item.data(0, Qt.UserRole + 1)))
  123. self.__render_items(True)
  124. def __render_items(self, is_clear: bool):
  125. if is_clear:
  126. widgets.allTreeWidget.clear()
  127. widgets.qureyTreeWidget.clear()
  128. widgets.allTreeWidget.setColumnCount(1)
  129. widgets.allTreeWidget.setHeaderHidden(True)
  130. widgets.qureyTreeWidget.setColumnCount(1)
  131. widgets.qureyTreeWidget.setHeaderHidden(True)
  132. if self.data.items is not None:
  133. # 转为字典
  134. mapping: dict[any, TreeWidgetItem] = dict(zip([i.id for i in self.data.items], self.data.items))
  135. # 树容器
  136. treeWidgetItems: list[QTreeWidgetItem] = []
  137. for d in self.data.items:
  138. # 如果找不到父级项,则是根节点
  139. parent: TreeWidgetItem = mapping.get(d.parent_id)
  140. if parent is None:
  141. treeWidgetItems.append(d.treeWidgetItem)
  142. else:
  143. parent.treeWidgetItem.addChild(d.treeWidgetItem)
  144. # 挂载到树上
  145. widgets.allTreeWidget.insertTopLevelItems(0, treeWidgetItems)
  146. # 查询
  147. class ElTree1(QWidget):
  148. """
  149. Control
  150. """
  151. itemClicked: Signal = Signal(object)
  152. itemDoubleClicked: Signal = Signal(object)
  153. def __init__(self, treeData: ElTreeData, parent=None):
  154. super(ElTree1, self).__init__(parent=parent)
  155. self.data = treeData
  156. # 将按钮的点击信号绑定到当前类的点击信号
  157. widgets.qureyTreeWidget.itemClicked.connect(lambda item: self.itemClicked.emit(item.data(0, Qt.UserRole + 1)))
  158. widgets.qureyTreeWidget.itemDoubleClicked.connect(
  159. lambda item: self.itemDoubleClicked.emit(item.data(0, Qt.UserRole + 1)))
  160. self.__render_items(True)
  161. def __render_items(self, is_clear: bool):
  162. if is_clear:
  163. widgets.qureyTreeWidget.clear()
  164. widgets.qureyTreeWidget.setColumnCount(1)
  165. widgets.qureyTreeWidget.setHeaderHidden(True)
  166. if self.data.items is not None:
  167. # 转为字典
  168. mapping: dict[any, TreeWidgetItem] = dict(zip([i.id for i in self.data.items], self.data.items))
  169. # 树容器
  170. treeWidgetItems: list[QTreeWidgetItem] = []
  171. for d in self.data.items:
  172. # 如果找不到父级项,则是根节点
  173. parent: TreeWidgetItem = mapping.get(d.parent_id)
  174. if parent is None:
  175. treeWidgetItems.append(d.treeWidgetItem)
  176. else:
  177. parent.treeWidgetItem.addChild(d.treeWidgetItem)
  178. # 挂载到树上
  179. widgets.qureyTreeWidget.insertTopLevelItems(0, treeWidgetItems)
  180. class MainWindow(QMainWindow):
  181. def __init__(self):
  182. QMainWindow.__init__(self)
  183. self.file_path = None # 初始化时文件路径设置为None
  184. # super().__init__()
  185. # SET AS GLOBAL WIDGETS
  186. # ///////////////////////////////////////////////////////////////
  187. self.ui = Ui_MainWindow()
  188. self.ui.setupUi(self)
  189. # 连接信号与槽函数,实现点击操作
  190. self.ui.createFile.clicked.connect(self.on_create_file_clicked)
  191. self.ui.export_2.clicked.connect(self.on_export_2_clicked)
  192. # self.comboBox_2 = QComboBox(self)
  193. # ...此处为省略代码...
  194. global widgets
  195. widgets = self.ui
  196. widgets.search.clicked.connect(self.buttonClick)
  197. # 设置 datainfo 页面的焦点策略,使其能够捕获键盘事件
  198. widgets.datainfo.setFocusPolicy(Qt.StrongFocus)
  199. widgets.datainfo.keyPressEvent = self.datainfo_keyPressEvent
  200. # 是否使用系统自带标题栏 True是不使用,False使用
  201. # ///////////////////////////////////////////////////////////////
  202. Settings.ENABLE_CUSTOM_TITLE_BAR = True
  203. # APP名称
  204. # ///////////////////////////////////////////////////////////////
  205. title = "控制网复测平面基准归算程序"
  206. description = "控制网复测平面基准归算程序"
  207. # APPLY TEXTS
  208. self.setWindowTitle(title)
  209. widgets.titleRightInfo.setText(description)
  210. # TOGGLE MENU
  211. # ///////////////////////////////////////////////////////////////
  212. widgets.toggleButton.clicked.connect(lambda: UIFunctions.toggleMenu(self, True))
  213. # SET UI DEFINITIONS
  214. # ///////////////////////////////////////////////////////////////
  215. UIFunctions.uiDefinitions(self)
  216. # QTableWidget PARAMETERS
  217. # ///////////////////////////////////////////////////////////////
  218. # widgets.tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
  219. # 点击事件
  220. # ///////////////////////////////////////////////////////////////
  221. # 左边菜单
  222. # 首页
  223. widgets.btn_home.clicked.connect(self.buttonClick)
  224. # 输入表格
  225. widgets.btn_widgets.clicked.connect(self.buttonClick)
  226. # 成果预览
  227. widgets.btn_new.clicked.connect(self.buttonClick)
  228. # 数据一览
  229. widgets.btn_data.clicked.connect(self.buttonClick)
  230. # 皮肤切换
  231. widgets.btn_message.clicked.connect(self.buttonClick)
  232. # 打开上传文件夹
  233. widgets.upload.clicked.connect(self.buttonClick)
  234. # 文件计算
  235. widgets.compute.clicked.connect(self.buttonClick)
  236. # 数据一览的搜索键
  237. widgets.search.clicked.connect(self.buttonClick)
  238. # 拓展左侧栏
  239. # def openCloseLeftBox():
  240. # UIFunctions.toggleLeftBox(self, True)
  241. # widgets.toggleLeftBox.clicked.connect(openCloseLeftBox)
  242. # widgets.extraCloseColumnBtn.clicked.connect(openCloseLeftBox)
  243. # EXTRA RIGHT BOX
  244. def openCloseRightBox():
  245. UIFunctions.toggleRightBox(self, True)
  246. widgets.settingsTopBtn.clicked.connect(openCloseRightBox)
  247. # 展示APP
  248. # ///////////////////////////////////////////////////////////////
  249. self.show()
  250. # 设置主题
  251. # ///////////////////////////////////////////////////////////////
  252. if getattr(sys, 'frozen', False):
  253. absPath = os.path.dirname(os.path.abspath(sys.executable))
  254. elif __file__:
  255. absPath = os.path.dirname(os.path.abspath(__file__))
  256. useCustomTheme = True
  257. self.useCustomTheme = useCustomTheme
  258. self.absPath = absPath
  259. themeFile = r"themes\py_dracula_light.qss"
  260. # 设置主题和HACKS
  261. if useCustomTheme:
  262. # LOAD AND APPLY STYLE
  263. UIFunctions.theme(self, themeFile, True)
  264. # SET HACKS
  265. AppFunctions.setThemeHack(self)
  266. # 设置主页和选择菜单
  267. # ///////////////////////////////////////////////////////////////
  268. widgets.stackedWidget.setCurrentWidget(widgets.home)
  269. widgets.btn_home.setStyleSheet(UIFunctions.selectMenu(widgets.btn_home.styleSheet()))
  270. # self.bind()
  271. # 初始化树状数据库
  272. tree_button = self.sql_init()
  273. tree_button.itemClicked.connect(self.itembuttonClick)
  274. tree_button.itemDoubleClicked.connect(self.itembuttonClick)
  275. # 绑定组件
  276. def bind(self):
  277. # 计算
  278. widgets.compute.clicked.connect(self.buttonClick)
  279. # 删除tableview
  280. def delete_table_view(table_view):
  281. table_view.setParent(None)
  282. table_view.deleteLater()
  283. # ///////////////////////////////////////////////////////////////
  284. def buttonClick(self):
  285. # GET BUTTON CLICKED
  286. btn = self.sender()
  287. btnName = btn.objectName()
  288. # 首页
  289. if btnName == "btn_home":
  290. widgets.stackedWidget.setCurrentWidget(widgets.home)
  291. UIFunctions.resetStyle(self, btnName)
  292. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
  293. # 输入表格
  294. if btnName == "btn_widgets":
  295. widgets.stackedWidget.setCurrentWidget(widgets.widgets)
  296. UIFunctions.resetStyle(self, btnName)
  297. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet()))
  298. # 成果预览
  299. if btnName == "btn_new":
  300. widgets.stackedWidget.setCurrentWidget(widgets.new_page) # SET PAGE
  301. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  302. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  303. # 数据一览
  304. if btnName == "btn_data":
  305. widgets.stackedWidget.setCurrentWidget(widgets.datainfo) # SET PAGE
  306. UIFunctions.resetStyle(self, btnName) # RESET ANOTHERS BUTTONS SELECTED
  307. btn.setStyleSheet(UIFunctions.selectMenu(btn.styleSheet())) # SELECT MENU
  308. # 皮肤切换
  309. if btnName == "btn_message":
  310. if self.useCustomTheme:
  311. themeFile = os.path.abspath(os.path.join(self.absPath, "themes/py_dracula_dark.qss"))
  312. UIFunctions.theme(self, themeFile, True)
  313. # SET HACKS
  314. AppFunctions.setThemeHack(self)
  315. self.useCustomTheme = False
  316. else:
  317. themeFile = os.path.abspath(os.path.join(self.absPath, "themes/py_dracula_light.qss"))
  318. UIFunctions.theme(self, themeFile, True)
  319. # SET HACKS
  320. AppFunctions.setThemeHack(self)
  321. self.useCustomTheme = True
  322. # 文件上传
  323. if btnName == "upload":
  324. # 使用 QFileDialog 获取文件路径
  325. file_path, _ = QFileDialog.getOpenFileName(
  326. self,
  327. "选择文件",
  328. "",
  329. "表格文件 (*.xls *.xlsx)"
  330. # 水准后期添加支持.xls文件
  331. )
  332. if file_path:
  333. # 处理选中的文件
  334. self.file_path = file_path # 将获取的路径保存到类的属性中
  335. UIFunctions.execute_script_based_on_selection(self, file_path)
  336. # 文件计算
  337. if btnName == "compute":
  338. if self.file_path: # 确保有文件路径后再进行处理
  339. # 计算与展示的业务代码
  340. UIFunctions.compute_show_process_excel_file(self, self.file_path)
  341. # 1秒后自动跳转
  342. QTimer.singleShot(1000, lambda: self.simulateButtonClick("btn_new"))
  343. else:
  344. QMessageBox.warning(self, '警告', '请先选择项目并上传文件')
  345. # 树状查询
  346. if btnName == "search":
  347. self.searchClick()
  348. # 输出点击回馈
  349. print(f'Button "{btnName}" pressed!')
  350. # 辅助函数,点击计算后自动跳转页面
  351. def simulateButtonClick(self, btnName):
  352. # 根据按钮名称找到对应的按钮
  353. btn = self.findChild(QObject, btnName)
  354. if btn:
  355. # 触发按钮点击事件
  356. btn.click()
  357. # 新增槽函数来调用 create_database_and_tables
  358. def on_create_file_clicked(self):
  359. Back.Program_Run.database_operations.create_database_and_tables(self, self.ui)
  360. # 定义导出数据库的槽函数
  361. def on_export_2_clicked(self):
  362. if self.file_path:
  363. UIFunctions.export_database_to_excel(self, self.file_path)
  364. else:
  365. QMessageBox.warning(self, '警告', '请先选择项目并上传文件')
  366. # RESIZE EVENTS
  367. # ///////////////////////////////////////////////////////////////
  368. def resizeEvent(self, event):
  369. # Update Size Grips
  370. UIFunctions.resize_grips(self)
  371. # 鼠标点击事件
  372. # ///////////////////////////////////////////////////////////////
  373. def mousePressEvent(self, event):
  374. # SET DRAG POS WINDOW
  375. # self.dragPos = event.globalPos()
  376. self.dragPos = event.globalPosition().toPoint()
  377. # 输出鼠标事件
  378. if event.buttons() == Qt.LeftButton:
  379. print('Mouse click: LEFT CLICK')
  380. if event.buttons() == Qt.RightButton:
  381. print('Mouse click: RIGHT CLICK')
  382. # 设一个全局变量,存数据库中所有的包含内容(数据库-三种方法-表)
  383. dblist = []
  384. # 初始化数据一览(数据库全展示)
  385. def sql_init(self):
  386. # 初始化全部数据库
  387. # inpath = r'D:\4work_now\20240819GS\20241211\SQL'
  388. inpath = os.path.abspath('../SQL')
  389. # 读取所有的数据库名
  390. sqlitem = []
  391. id = 1
  392. for filename in os.listdir(inpath):
  393. # 数据库
  394. dbname = filename.split('.', -1)[0]
  395. dbpath = os.path.join(inpath, filename)
  396. sqlitem.append(TreeWidgetItem(id, 0, dbname, icon=QIcon(
  397. os.path.abspath(os.path.join(self.absPath, "images/icons/cil-clone.png")))))
  398. pid = id
  399. id = id + 1
  400. # 三种方法
  401. sqlitem.append(TreeWidgetItem(id, pid, '水准测段高差稳定计算', icon=QIcon(
  402. os.path.join(self.absPath, "images/icons/cil-description.png"))))
  403. gcid = id
  404. id = id + 1
  405. sqlitem.append(TreeWidgetItem(id, pid, '控制网复测平面基准计算', icon=QIcon(
  406. os.path.join(self.absPath, "images/icons/cil-description.png"))))
  407. gsid = id
  408. id = id + 1
  409. sqlitem.append(TreeWidgetItem(id, pid, '平面控制网稳定性计算', icon=QIcon(
  410. os.path.join(self.absPath, "images/icons/cil-description.png"))))
  411. wdid = id
  412. id = id + 1
  413. # 读取所有的表名(三种方式往下)
  414. db1 = sqlite3.connect(dbpath)
  415. # 获取游标
  416. cursor1 = db1.cursor()
  417. sqlstr1 = 'SELECT TableName FROM GC_Input_Param;'
  418. cursor1.execute(sqlstr1)
  419. result1 = cursor1.fetchall()
  420. for re1 in result1:
  421. str1 = re1[0].decode('utf-8')
  422. list1 = []
  423. list1.append(dbname)
  424. list1.append('水准测段高差稳定计算')
  425. list1.append(str1)
  426. self.dblist.append(list1)
  427. sqlitem.append(TreeWidgetItem(id, gcid, str1, icon=QIcon(
  428. os.path.join(self.absPath, "images/icons/cil-file.png")), extend={'listData': list1}))
  429. id = id + 1
  430. sqlstr2 = 'SELECT TableName FROM GS_Input_Param;'
  431. cursor1.execute(sqlstr2)
  432. result2 = cursor1.fetchall()
  433. for re2 in result2:
  434. str2 = re2[0].decode('utf-8')
  435. list2 = []
  436. list2.append(dbname)
  437. list2.append('控制网复测平面基准计算')
  438. list2.append(str2)
  439. self.dblist.append(list2)
  440. sqlitem.append(TreeWidgetItem(id, gsid, str2,
  441. icon=QIcon(os.path.join(self.absPath, "images/icons/cil-file.png")),
  442. extend={'listData': list2}))
  443. id = id + 1
  444. sqlstr3 = 'SELECT TableName FROM WD_Input_Param;'
  445. cursor1.execute(sqlstr3)
  446. result3 = cursor1.fetchall()
  447. for re3 in result3:
  448. str3 = re3[0].decode('utf-8')
  449. list3 = []
  450. list3.append(dbname)
  451. list3.append('平面控制网稳定性计算')
  452. list3.append(str3)
  453. self.dblist.append(list3)
  454. sqlitem.append(TreeWidgetItem(id, wdid, str3,
  455. icon=QIcon(os.path.join(self.absPath, "images/icons/cil-file.png")),
  456. extend={'listData': list3}))
  457. id = id + 1
  458. button = ElTree(ElTreeData(sqlitem))
  459. return button
  460. # 关键词查询
  461. def searchClick(self):
  462. # GET BUTTON CLICKED
  463. btn = self.sender()
  464. btnName = btn.objectName()
  465. # 获取文本
  466. text1 = self.ui.lineEdit_2.text()
  467. # 符合的list
  468. fhlist = []
  469. # 查询(待优化)
  470. for list1 in self.dblist:
  471. for li in list1:
  472. if text1 in li:
  473. fhlist.append(list1)
  474. break
  475. # 更新item值
  476. sqlitem = []
  477. # 前两层是否一致
  478. str1 = ''
  479. str2 = ''
  480. id = 1
  481. pid = 0
  482. fid = 0
  483. zdy = []
  484. for list2 in fhlist:
  485. dbname = list2[0]
  486. if dbname != str1:
  487. str1 = dbname
  488. pid = id
  489. str2 = ''
  490. sqlitem.append(TreeWidgetItem(id, 0, dbname, icon=QIcon(
  491. os.path.join(self.absPath, "images/icons/cil-clone.png"))))
  492. zdy1 = []
  493. zdy1.append(id)
  494. zdy1.append(0)
  495. zdy1.append(dbname)
  496. zdy.append(zdy1)
  497. id = id + 1
  498. mename = list2[1]
  499. if mename != str2:
  500. str2 = mename
  501. fid = id
  502. sqlitem.append(TreeWidgetItem(id, pid, mename, icon=QIcon(
  503. os.path.join(self.absPath, "images/icons/cil-description.png"))))
  504. zdy1 = []
  505. zdy1.append(id)
  506. zdy1.append(pid)
  507. zdy1.append(mename)
  508. zdy.append(zdy1)
  509. id = id + 1
  510. sqlitem.append(TreeWidgetItem(id, fid, list2[2], icon=QIcon(
  511. os.path.join(self.absPath, "images/icons/cil-file.png")), extend={'listData': list2}))
  512. zdy1 = []
  513. zdy1.append(id)
  514. zdy1.append(fid)
  515. zdy1.append(list2[2])
  516. zdy.append(zdy1)
  517. id = id + 1
  518. search_button = ElTree1(ElTreeData(sqlitem))
  519. search_button.itemClicked.connect(self.itembuttonClick1)
  520. search_button.itemDoubleClicked.connect(self.itembuttonClick1)
  521. # 隐藏默认label
  522. self.ui.defaultLabel.setVisible(False)
  523. # 全树的item展示
  524. def itembuttonClick(self):
  525. # 判定是否获取的是根节点
  526. pd = 1
  527. select_item = self.ui.allTreeWidget.currentItem()
  528. # 获取点击的item的text和它对应的上两个节点
  529. str1 = select_item.text(0)
  530. current_text = '' # 初始化 current_text
  531. str3 = '' # 初始化 str3
  532. try:
  533. pa_item = select_item.parent()
  534. current_text = pa_item.text(0)
  535. z_item = pa_item.parent()
  536. str3 = z_item.text(0)
  537. except:
  538. pd = -1
  539. if current_text == '':
  540. pd = -1
  541. if str3 == '':
  542. pd = -1
  543. if pd == -1:
  544. pass
  545. else:
  546. # 数据库目录
  547. inpath = os.path.abspath('../SQL')
  548. file_path = inpath + '/' + str3 + '.db'
  549. # 数据库路径,哪种方法,表名
  550. UIFunctions.search_data_to_show(self, file_path, current_text, str1)
  551. # 搜索的item展示
  552. def itembuttonClick1(self):
  553. # 判定是否获取的是根节点
  554. pd = 1
  555. select_item = self.ui.qureyTreeWidget.currentItem()
  556. # 获取点击的item的text和它对应的上两个节点
  557. str1 = select_item.text(0)
  558. current_text = '' # 初始化 current_text
  559. str3 = '' # 初始化 str3
  560. try:
  561. pa_item = select_item.parent()
  562. current_text = pa_item.text(0)
  563. z_item = pa_item.parent()
  564. str3 = z_item.text(0)
  565. except:
  566. pd = -1
  567. if current_text == '':
  568. pd = -1
  569. if str3 == '':
  570. pd = -1
  571. if pd == -1:
  572. pass
  573. else:
  574. # 数据库目录
  575. inpath = os.path.abspath('../SQL')
  576. file_path = inpath + '/' + str3 + '.db'
  577. # 数据库路径,哪种方法,表名
  578. UIFunctions.search_data_to_show(self, file_path, current_text, str1)
  579. # 键盘回车事件,目前用于搜索按钮
  580. def datainfo_keyPressEvent(self, event):
  581. if event.key() == Qt.Key_Return or event.key() == Qt.Key_Enter:
  582. # 检查 lineEdit_2 中是否有内容
  583. if widgets.lineEdit_2.text():
  584. # 模拟 search 按钮点击事件
  585. self.ui.search.click()
  586. else:
  587. # 调用默认的 keyPressEvent 处理其他按键事件
  588. super(widgets.datainfo.__class__, widgets.datainfo).keyPressEvent(event)
  589. if __name__ == "__main__":
  590. app = QApplication(sys.argv)
  591. app.setWindowIcon(QIcon("icon.ico"))
  592. window = MainWindow()
  593. # window.resize(1440, 960) # 高宽
  594. sys.exit(app.exec())