Remove client_watcher global

This commit is contained in:
atse 2023-07-05 16:02:35 +08:00
parent 9cf33abe06
commit e33f8430f2
1 changed files with 9 additions and 10 deletions

View File

@ -16,8 +16,6 @@ from ui_tec_qt import Ui_MainWindow
tec_client: Client = None tec_client: Client = None
client_watcher = None
def get_argparser(): def get_argparser():
parser = argparse.ArgumentParser(description="ARTIQ master") parser = argparse.ArgumentParser(description="ARTIQ master")
@ -72,6 +70,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self.fan_power_slider.valueChanged.connect(self.fan_set) self.fan_power_slider.valueChanged.connect(self.fan_set)
self.fan_auto_box.stateChanged.connect(self.fan_auto_set) self.fan_auto_box.stateChanged.connect(self.fan_auto_set)
self.client_watcher: ClientWatcher = None
self.client_watcher_task = None self.client_watcher_task = None
if args.connect: if args.connect:
@ -136,7 +135,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
@asyncSlot() @asyncSlot()
async def connect(self): async def connect(self):
global tec_client, client_watcher global tec_client
ip, port = self.ip_set_line.text(), self.port_set_spin.value() ip, port = self.ip_set_line.text(), self.port_set_spin.value()
try: try:
@ -148,20 +147,20 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self._hw_rev(await tec_client.hw_rev()) self._hw_rev(await tec_client.hw_rev())
# self.fan_update(await tec_client.fan()) # self.fan_update(await tec_client.fan())
client_watcher = ClientWatcher(self.main_widget, self.report_refresh_spin.value()) self.client_watcher = ClientWatcher(self.main_widget, self.report_refresh_spin.value())
client_watcher.fan_update.connect(self.fan_update) self.client_watcher.fan_update.connect(self.fan_update)
self.report_apply_btn.clicked.connect( self.report_apply_btn.clicked.connect(
lambda: client_watcher.set_update_s(self.report_refresh_spin.value()) lambda: self.client_watcher.set_update_s(self.report_refresh_spin.value())
) )
QtWidgets.QApplication.instance().aboutToQuit.connect(client_watcher.stop_watching) QtWidgets.QApplication.instance().aboutToQuit.connect(self.client_watcher.stop_watching)
self.client_watcher_task = asyncio.create_task(client_watcher.run()) self.client_watcher_task = asyncio.create_task(self.client_watcher.run())
else: else:
await tec_client.disconnect() await tec_client.disconnect()
tec_client = None tec_client = None
self._on_connection_changed(False) self._on_connection_changed(False)
client_watcher.stop_watching() self.client_watcher.stop_watching()
client_watcher = None self.client_watcher = None
await self.client_watcher_task await self.client_watcher_task
self.client_watcher_task = None self.client_watcher_task = None
except Exception as e: except Exception as e: