When the user clicks the Run Optimizer button in the Start panel
the GUI displays a message by calling one of the methods in
this class. Messages are displayed in the modal dialog area
defined by the GUI template.
| Parameters: |
-
template
–
the application template (which contains the modal dialog area to use)
-
run_cb
–
a callback function to invoke after the user reviews settings and clicks "Continue"
|
Source code in src/tidegates/widgets.py
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355 | def __init__(self, template, run_cb):
"""
Initialize the module.
Arguments:
template: the application template (which contains the modal dialog area to use)
run_cb: a callback function to invoke after the user reviews settings and clicks "Continue"
"""
super(InfoBox, self).__init__()
self.template = template
self.continue_button = pn.widgets.Button(name='Continue')
self.continue_button.on_click(run_cb)
self.cancel_button = pn.widgets.Button(name='Cancel')
self.cancel_button.on_click(self._cancel_cb)
|
Method called if OptiPass failed.
| Parameters: |
-
reason
–
string containing the error message
|
src/tidegates/widgets.py
433
434
435
436
437
438
439
440
441
442
443
444
445 | def show_fail(self, reason):
"""
Method called if OptiPass failed.
Arguments:
reason: string containing the error message
"""
self.clear()
text = self.fail_text.format(reason)
if str(reason) == 'No solution':
text += '\n * try increasing the maximum budget'
self.append(pn.pane.Alert(text, alert_type = 'danger'))
self.template.open_modal()
|
Method called when weighted targets are being used and one of the
text boxes does not have a valid entry (must be a number between 1 and 5).
| Parameters: |
-
w
(list[str])
–
the list of strings read from the text entry widgets
|
src/tidegates/widgets.py
379
380
381
382
383
384
385
386
387
388
389
390 | def show_invalid_weights(self, w: list[str]):
"""
Method called when weighted targets are being used and one of the
text boxes does not have a valid entry (must be a number between 1 and 5).
Arguments:
w: the list of strings read from the text entry widgets
"""
text = self.invalid_weights_text.format(w)
self.clear()
self.append(pn.pane.Alert(text, alert_type = 'warning'))
self.template.open_modal()
|
Method called by the OP class when it detects missing parameters (e.g.
if the user did not select a region or a target).
src/tidegates/widgets.py
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377 | def show_missing(self, rlist, bmax, tlist):
"""
Method called by the OP class when it detects missing parameters (e.g.
if the user did not select a region or a target).
"""
text = self.missing_params_text
if len(rlist) == 0:
text += ' * one or more geographic regions\n'
if bmax == 0:
text += ' * a maximum budget\n'
if len(tlist) == 0:
text += ' * one or more targets\n'
self.clear()
self.append(pn.pane.Alert(text, alert_type = 'warning'))
self.template.open_modal()
|
Method called to allow the user to review the optimization parameters read from the
various widgets. Displays each parameter and two buttons ("Cancel" and "Continue").
| Parameters: |
-
regions
–
-
bmax
–
-
bstep
–
incremwnt in budget amounts
-
targets
–
list of restoration target names
-
weights
–
-
climate
–
|
src/tidegates/widgets.py
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422 | def show_params(self, regions, bmax, bstep, targets, weights, climate):
"""
Method called to allow the user to review the optimization parameters read from the
various widgets. Displays each parameter and two buttons ("Cancel" and "Continue").
Arguments:
regions: list of region names
bmax: maximum budget amount
bstep: incremwnt in budget amounts
targets: list of restoration target names
weights: list of target weights
climate: climate scenario
"""
n = bmax // bstep
fbmax = OP.format_budget_amount(bmax)
fbstep = OP.format_budget_amount(bstep)
text = self.preview_message_text
text += f' * Regions: {", ".join(regions)}\n\n'
if n > 1:
text += f' * {n} budget levels from {fbstep} up to {fbmax} in increments of {fbstep}\n\n'
else:
text += f' * a single budget of {fbmax}\n\n'
targets = [t.split(':')[-1] for t in targets]
if weights:
targets = [f'{targets[i]} ⨉ {weights[i]}' for i in range(len(targets))]
text += f' * Targets: {", ".join(targets)}\n'
text += f' * Climate: {climate}\n\n'
self.clear()
self.append(pn.pane.Alert(text, alert_type = 'secondary'))
self.append(pn.Row(self.cancel_button, self.continue_button))
self.template.open_modal()
|
Method called after OptiPass has finished running and the results have been
parsed successfully.
src/tidegates/widgets.py
424
425
426
427
428
429
430
431 | def show_success(self):
"""
Method called after OptiPass has finished running and the results have been
parsed successfully.
"""
self.clear()
self.append(pn.pane.Alert(self.success_text, alert_type = 'success'))
self.template.open_modal()
|