@@ -56,13 +56,22 @@ def __init__(self, initial_settings):
5656
5757 self .setup_complete = False
5858 self .close_event = threading .Event ()
59+ # If the virtual device starts after a device starts, it needs to connect its widgets.
60+ # So we start a background thread to periodically check if we have any non-connected widgets and connect them.
5961 self .reconnect_thread = threading .Thread (target = self .reconnect , args = (self .close_event ,))
6062 self .reconnect_thread .daemon = True
6163
64+ # If a tab (device) is restarted, it recreates its outputs.
65+ # If the virtual device still has widgets referencing those outputs, they will fail.
66+ # So, we need to disconnect them.
6267 self .tab_restart_receiver = lambda dn , s = self : self .disconnect_widgets (dn )
6368
6469 @inmain_decorator (True )
6570 def connect_widgets (self ):
71+ '''
72+ For each of our tabs, tell connect its widgets to outputs.
73+ Also connect restart receivers so we can detect if new tabs start to close.
74+ '''
6675 if not self .setup_complete :
6776 return
6877 for name , vd_tab in self .tab_dict .items ():
@@ -73,6 +82,9 @@ def connect_widgets(self):
7382
7483 @inmain_decorator (True )
7584 def disconnect_widgets (self , closing_device_name ):
85+ '''
86+ For each of our tabs, disconnect it from closing_device_name
87+ '''
7688 if not self .setup_complete :
7789 return
7890 self .BLACS ['ui' ].blacs .tablist [closing_device_name ].disconnect_restart_receiver (self .tab_restart_receiver )
@@ -163,6 +175,12 @@ def _get_root_parent(item):
163175 return item
164176
165177 def _get_child_outputs (self , conn_table , root_devs , dev_name , tab ):
178+ '''
179+ Get all child outputs of a device.
180+
181+ This is more complex than simply accessing `child_list` for the device
182+ as some devices have structures between themselves and their ultimate outputs.
183+ '''
166184 AOs = []
167185 DOs = []
168186 DDSs = []
@@ -420,6 +438,9 @@ def on_edit_virtual_devices(self, *args, **kwargs):
420438 return
421439
422440 def _encode_virtual_devices (self ):
441+ '''
442+ Convert data in model to a simple dictionary that can be saved.
443+ '''
423444 virtual_device_data = {}
424445 root = self .virtual_device_model .invisibleRootItem ()
425446 for i in range (root .rowCount ()):
0 commit comments