Skip to content

Commit 7e4a15b

Browse files
committed
More comments
1 parent c434831 commit 7e4a15b

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

blacs/plugins/virtual_device/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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()):

blacs/plugins/virtual_device/virtual_device_tab.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
class VirtualDeviceTab(PluginTab):
1010

1111
def create_widgets(self, blacs_tablist, AOs, DOs, DDSs):
12+
'''
13+
This function sets up the tab, and should be called as soon as the plugin is otherwise ready.
14+
Here, we create dictionaries of widgets (initially connecting them to outputs).
15+
'''
1216
self._blacs_tablist = blacs_tablist
1317
self._AOs = {(AO[0], AO[1]): None for AO in AOs}
1418
self._DOs = {(DO[0], DO[1], DO[2]): None for DO in DOs}
@@ -28,7 +32,7 @@ def create_widgets(self, blacs_tablist, AOs, DOs, DDSs):
2832
self._DOs[DO].setText('%s\n%s'%(DO[0]+'.'+orig_label[0], orig_label[1]))
2933
self._DOs[DO].last_DO = None
3034

31-
dds_widgets = []
35+
dds_widgets = [] # TODO
3236

3337
if len(self._AOs) > 0:
3438
self.place_widget_group('Analog Outputs', [v for k, v in self._AOs.items()])
@@ -38,6 +42,10 @@ def create_widgets(self, blacs_tablist, AOs, DOs, DDSs):
3842
return
3943

4044
def connect_widgets(self):
45+
'''
46+
For each of our widgets, check if it is connected to an output.
47+
If not, connect it.
48+
'''
4149
for AO in self._AOs.keys():
4250
if self._AOs[AO] is not None:
4351
new_AO = self._blacs_tablist[AO[0]].get_channel(AO[1])
@@ -50,6 +58,10 @@ def connect_widgets(self):
5058
self._DOs[DO].set_DO(new_DO)
5159

5260
def disconnect_widgets(self, closing_device_name):
61+
'''
62+
For each of our widgets, check if it connects to an output in 'closing_device_name'.
63+
If it is, disconnect it so that 'closing_device_name' can be safely closed.
64+
'''
5365
for AO in self._AOs.keys():
5466
if AO[0] == closing_device_name:
5567
self._AOs[AO].last_AO = self._AOs[AO].get_AO()

0 commit comments

Comments
 (0)