Skip to content

Commit 603d3cc

Browse files
committed
More function documentation of virtual device plugin
1 parent 790bd1e commit 603d3cc

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

blacs/plugins/virtual_device/__init__.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def disconnect_widgets(self, closing_device_name):
9292
vd_tab.disconnect_widgets(closing_device_name)
9393

9494
def reconnect(self, stop_event):
95+
'''
96+
Runs constantly in a second thread to reconnect widgets in virtual devices
97+
to hardware devices after the hardware device tabs restart.
98+
'''
9599
while not stop_event.wait(CONNECT_CHECK_INTERVAL):
96100
self.connect_widgets()
97101

@@ -155,6 +159,15 @@ def close(self):
155159
pass
156160

157161
class Menu(object):
162+
'''
163+
The virtual device adding/editing menu.
164+
165+
Reads the connection table to determine what hardware is available,
166+
then allows adding or removing hardware from virtual devices.
167+
168+
Stores new virtual devices in the Plugin object,
169+
which does not reload them until a BLACS restart.
170+
'''
158171
VD_TREE_DUMMY_ROW_TEXT = '<Click to add virtual device>'
159172

160173
CT_TREE_COL_NAME = 0
@@ -211,6 +224,12 @@ def _get_child_outputs(self, conn_table, root_devs, dev_name, tab):
211224
return AOs, DOs, DDSs
212225

213226
def __init__(self, BLACS):
227+
'''
228+
Some small preparation for the menu.
229+
230+
Parses the connection table immediately,
231+
defers parsing of current virtual devices so that they can be edited multiple times.
232+
'''
214233
self.BLACS = BLACS
215234

216235
self.connection_table_model = QStandardItemModel()
@@ -292,6 +311,12 @@ def make_virtual_device_output_row(self, name_item):
292311
return [name_item, up_item, dn_item, remove_item]
293312

294313
def on_treeView_connection_table_clicked(self, index):
314+
'''
315+
Processes user clicking on an item in the connection table tree.
316+
317+
The only column we respond to is the "add" column.
318+
This adds a hardware output to the currently selected virtual device
319+
'''
295320
item = self.connection_table_model.itemFromIndex(index)
296321
if item.column() == self.CT_TREE_COL_ADD:
297322
# Add this output to the currently selected virtual devices
@@ -352,6 +377,15 @@ def on_virtual_devices_item_changed(self, item):
352377
item.setText(self.VD_TREE_DUMMY_ROW_TEXT)
353378

354379
def on_treeView_virtual_devices_clicked(self, index):
380+
'''
381+
Processes user clicking on an item in the virtual device tree.
382+
383+
Options are:
384+
-Dummy row clicked: add new device
385+
-Up or down arrow clicked: reorder hardware output
386+
-Remove virtual device clicked: remove virtual device
387+
-Remove hardware output clicked: remove hardware output from virtual device
388+
'''
355389
item = self.virtual_device_model.itemFromIndex(index)
356390
if item.data(self.VD_TREE_ROLE_IS_DUMMY_ROW):
357391
name_index = index.sibling(index.row(), self.VD_TREE_COL_NAME)
@@ -371,8 +405,11 @@ def on_treeView_virtual_devices_clicked(self, index):
371405
item.parent().removeRow(index.row())
372406

373407
def on_edit_virtual_devices(self, *args, **kwargs):
374-
# Construct tree of virtual devices
375-
# This happens here so that the tree is up to date
408+
'''
409+
Open the editing menu.
410+
411+
At this point, virtual devices are parsed and GUI objects are instantiated.
412+
'''
376413
for vd_name, vd in self.BLACS['plugins'][module].get_save_virtual_devices().items():
377414
device_item = QStandardItem(vd_name)
378415
remove_item = QStandardItem()
@@ -497,13 +534,20 @@ def _encode_virtual_devices(self):
497534
return virtual_device_data
498535

499536
def on_save(self):
537+
'''
538+
Pass new virtual devices back to the plugin.
539+
Instructs the user to restart BLACS to reload virtual devices.
540+
'''
500541
self.BLACS['plugins'][module].set_save_virtual_devices(self._encode_virtual_devices())
501542
# Cleanup model in case editing window is reopened.
502543
self.virtual_device_model.removeRows(0, self.virtual_device_model.rowCount())
503544
QMessageBox.information(self.BLACS['ui'], 'Virtual Devices Saved',
504545
'New virtual devices saved. Please restart BLACS to load new devices.')
505546

506547
def on_cancel(self):
548+
'''
549+
Inform the user that nothing has happened.
550+
'''
507551
self.virtual_device_model.removeRows(0, self.virtual_device_model.rowCount())
508552
QMessageBox.information(self.BLACS['ui'], 'Virtual Devices Not Saved',
509553
'Editing of virtual devices canceled.')

0 commit comments

Comments
 (0)