TargetBox

The widget that displays restoration target options is an instance of a class named TargetBox, defined in widgets.py. It has a set of two tabs that display different options for specifying targets.

The restoration targets are shown in a matrix with a selection widget next to each target name. The TargetBox widget has two tabs showing different types of selection widgets, either simple checkboxes (shown by a BasicTargetBox) or text entry widgets (shown by WeightedTargetBox).

Source code in src/tidegates/widgets.py
285
286
287
288
289
290
291
def __init__(self):
    super(TargetBox, self).__init__(margin=(10,0,10,5))
    self.tabs = pn.Tabs(
        ('Basic', BasicTargetBox()),
        ('Weighted', WeightedTargetBox()),
    )
    self.append(self.tabs)

selection()

Get a list of IDs of selected targets from the current target widget.

src/tidegates/widgets.py
293
294
295
296
297
def selection(self) -> list[str]:
    """
    Get a list of IDs of selected targets from the current target widget.
    """
    return self.tabs[self.tabs.active].selection()

weights()

Get target weights from the current target widget.

src/tidegates/widgets.py
299
300
301
302
303
def weights(self):
    """
    Get target weights from the current target widget.
    """
    return self.tabs[self.tabs.active].weights()

BasicTargetBox

The BasicTargetBox widget displays a checkbox next to each target name.

Source code in src/tidegates/widgets.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
def __init__(self):
    """
    Make the grid of checkboxes.  The IDs and descriptions of targets are
    fetched by calling the make_layout function in the Target class.
    """
    super(BasicTargetBox, self).__init__(margin=(10,0,10,5))
    self.grid = pn.GridBox(ncols=2)
    self.boxes = { }
    for row in make_layout():
        lst = [ ]
        for t in row:
            b = pn.widgets.Checkbox(name=t, styles=box_styles, stylesheets=[box_style_sheet])
            lst.append(b)
            self.boxes[t] = b
        self.grid.objects.extend(lst)
    self.append(self.grid)

selection()

Return a list of IDs of selected targets.

src/tidegates/widgets.py
232
233
234
235
236
def selection(self) -> list[str]:
    """
    Return a list of IDs of selected targets.
    """
    return [t for t in self.boxes if self.boxes[t].value ]

weights()

There are no weights (all targets considered equally) so return an empty list.

src/tidegates/widgets.py
238
239
240
241
242
def weights(self):
    """
    There are no weights (all targets considered equally) so return an empty list.
    """
    return []

WeightedTargetBox

A WeightedTargetBox shows a text entry widget next to each target to allow users to enter a numeric weight for the target.

Source code in src/tidegates/widgets.py
250
251
252
253
254
255
256
257
258
259
260
261
262
263
def __init__(self):
    """
    Make the grid of text entry widgets.  The IDs and descriptions of targets are
    fetched by calling the make_layout function in the Target class.
    """
    super(WeightedTargetBox, self).__init__(margin=(10,0,10,5))
    self.grid = pn.GridBox(ncols=2)
    for tnames in make_layout():
        for t in tnames:
            w = pn.Row()
            w.append(pn.widgets.TextInput(name='', placeholder='', width=25, stylesheets=[input_style_sheet]))
            w.append(t)
            self.grid.objects.append(w)
    self.append(self.grid)

selection()

Return a list of IDs of selected targets.

src/tidegates/widgets.py
265
266
267
268
269
def selection(self) -> list[str]:
    """
    Return a list of IDs of selected targets.
    """
    return [w[1].object for w in self.grid.objects if w[0].value]

weights()

Return the text content of each non-empty text entry box.

src/tidegates/widgets.py
271
272
273
274
275
def weights(self) -> list[str]:
    """
    Return the text content of each non-empty text entry box.
    """
    return [w[0].value for w in self.grid.objects if w[0].value]