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

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. class ComboBoxUpdater(FileSystemEventHandler):
  7. def __init__(self, comboBox, sql_folder):
  8. super().__init__()
  9. self.comboBox = comboBox
  10. self.sql_folder = sql_folder
  11. def on_modified(self, event):
  12. if event.is_directory:
  13. return
  14. if event.src_path.endswith('.db'):
  15. self.update_combo_box()
  16. def on_created(self, event):
  17. if event.is_directory:
  18. return
  19. if event.src_path.endswith('.db'):
  20. self.update_combo_box()
  21. def on_deleted(self, event):
  22. if event.is_directory:
  23. return
  24. if event.src_path.endswith('.db'):
  25. self.update_combo_box()
  26. def update_combo_box(self):
  27. # 清空现有的 comboBox 内容
  28. self.comboBox.clear()
  29. # 列出 SQL 文件夹中的所有 .db 文件
  30. db_files = [f for f in os.listdir(self.sql_folder) if f.endswith('.db')]
  31. # 将数据库文件名添加到 comboBox 中
  32. for db_file in db_files:
  33. db_name = os.path.splitext(db_file)[0] # 获取数据库名称并去掉.db后缀
  34. self.comboBox.addItem(QCoreApplication.translate("MainWindow", db_name, None))
  35. # 如果没有找到任何数据库文件,显示提示信息
  36. if not db_files:
  37. self.comboBox.addItem(QCoreApplication.translate("MainWindow", "未找到数据库文件", None))