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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. self.selected_db = None # 新增属性来存储当前选中的数据库
  12. def on_modified(self, event):
  13. if event.is_directory:
  14. return
  15. if event.src_path.endswith('.db'):
  16. self.update_combo_box()
  17. def on_created(self, event):
  18. if event.is_directory:
  19. return
  20. if event.src_path.endswith('.db'):
  21. self.update_combo_box()
  22. def on_deleted(self, event):
  23. if event.is_directory:
  24. return
  25. if event.src_path.endswith('.db'):
  26. self.update_combo_box()
  27. def update_combo_box(self):
  28. # 保存当前选中的数据库
  29. self.selected_db = self.comboBox.currentText()
  30. # 清空现有的 comboBox 内容
  31. self.comboBox.clear()
  32. # 列出 SQL 文件夹中的所有 .db 文件
  33. db_files = [f for f in os.listdir(self.sql_folder) if f.endswith('.db')]
  34. # 将数据库文件名添加到 comboBox 中
  35. for db_file in db_files:
  36. db_name = os.path.splitext(db_file)[0] # 获取数据库名称并去掉.db后缀
  37. self.comboBox.addItem(QCoreApplication.translate("MainWindow", db_name, None))
  38. # 如果没有找到任何数据库文件,显示提示信息
  39. if not db_files:
  40. self.comboBox.addItem(QCoreApplication.translate("MainWindow", "未找到数据库文件", None))
  41. # 重新设置之前选中的数据库为选中状态
  42. if self.selected_db in [self.comboBox.itemText(i) for i in range(self.comboBox.count())]:
  43. self.comboBox.setCurrentText(self.selected_db)