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

file_system_watching.py 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # file_system_watching.py 文件系统监控代码,用于监控comboBox的显示
  2. from watchdog.events import FileSystemEventHandler
  3. from PySide6.QtCore import QCoreApplication
  4. from watchdog.observers import Observer
  5. import os
  6. from Front.back.Program_Run.utils import resource_path
  7. class ComboBoxUpdater(FileSystemEventHandler):
  8. def __init__(self, comboBox, sql_folder):
  9. super().__init__()
  10. self.comboBox = comboBox
  11. self.sql_folder = resource_path(sql_folder)
  12. self.selected_db = None # 新增属性来存储当前选中的数据库
  13. def on_modified(self, event):
  14. if event.is_directory:
  15. return
  16. if event.src_path.endswith('.db'):
  17. self.update_combo_box()
  18. def on_created(self, event):
  19. if event.is_directory:
  20. return
  21. if event.src_path.endswith('.db'):
  22. self.update_combo_box()
  23. def on_deleted(self, event):
  24. if event.is_directory:
  25. return
  26. if event.src_path.endswith('.db'):
  27. self.update_combo_box()
  28. def update_combo_box(self):
  29. # 保存当前选中的数据库
  30. self.selected_db = self.comboBox.currentText()
  31. # 清空现有的 comboBox 内容
  32. self.comboBox.clear()
  33. # 列出 SQL 文件夹中的所有 .db 文件
  34. db_files = [f for f in os.listdir(self.sql_folder) if f.endswith('.db')]
  35. # 过滤掉以 'DataBase' 开头的文件
  36. filtered_db_files = [f for f in db_files if not f.startswith('DataBase')]
  37. # 将数据库文件名添加到 comboBox 中
  38. for db_file in filtered_db_files:
  39. db_name = os.path.splitext(db_file)[0] # 获取数据库名称并去掉.db后缀
  40. self.comboBox.addItem(QCoreApplication.translate("MainWindow", db_name, None))
  41. # 如果没有找到任何数据库文件,显示提示信息
  42. if not filtered_db_files:
  43. self.comboBox.addItem(QCoreApplication.translate("MainWindow", "未找到数据库文件", None))
  44. # 重新设置之前选中的数据库为选中状态
  45. if self.selected_db in [self.comboBox.itemText(i) for i in range(self.comboBox.count())]:
  46. self.comboBox.setCurrentText(self.selected_db)