@@ -51,22 +51,38 @@ for all Widgets (defaults shown below):
5151 _run_frequency = " every-frame"
5252 _run_mode = " serial"
5353
54- ``_run_frequency `` specifies how often the widget is run. It takes one of two values:
55- ``every-frame `` or ``batch ``.
54+ * ``_run_frequency `` specifies how often the widget is run. It takes one of two values:
5655
57- ``_run_mode `` specifies how the widget code is run. It takes one of two values:
58- ``serial `` or ``parallel ``.
56+ * ``every-frame ``
57+ * ``batch ``.
58+
59+ * ``_run_mode `` specifies how the widget code is run. It takes one of two values:
60+
61+ * ``serial ``
62+ * ``parallel ``.
5963
6064By default, all Widgets run every frame serially (due to defaults above) unless the above
6165attributes are customized.
6266
63- Both these attributes can be configured independent of each other. Which method(s) in
64- the Widget class gets invoked depend on both these attributes as described below.
67+ Both these attributes can be configured independent of each other. Which run method(s)
68+ in the Widget class gets invoked depend on both these attributes as described in the
69+ following sections.
70+
71+ These available run methods are:
72+
73+ * :meth: `~mdadash.backend.widgets.base.WidgetBase.run_every_frame `
74+ * :meth: `~mdadash.backend.widgets.base.WidgetBase.run_batch `
75+ * :meth: `~mdadash.backend.widgets.base.WidgetBase.get_parallel_job `
76+ * :meth: `~mdadash.backend.widgets.base.WidgetBase.apply_parallel_results `
6577
6678.. note ::
6779
68- A Widget can make these attributes dynamically changeable at runtime as well by making
69- them as `Inputs `_, which then show corresponding options in the UI.
80+ One of :meth: `~mdadash.backend.widgets.base.WidgetBase.run_every_frame ` or
81+ :meth: `~mdadash.backend.widgets.base.WidgetBase.run_batch ` must be implemented by
82+ the Widget class.
83+
84+ A Widget can make the ``_run_frequency `` and ``_run_mode `` attributes dynamically
85+ changeable at runtime as well by making them as `Inputs `_.
7086
7187_run_frequency
7288~~~~~~~~~~~~~~
@@ -86,10 +102,10 @@ If the ``_run_mode`` is ``parallel``, see the next section to see what gets invo
86102
87103If the ``_run_mode `` is ``serial ``:
88104
89- * When ``_run_frequency `` is ``every-frame ``,
105+ * and ``_run_frequency `` is ``every-frame ``,
90106 :meth: `~mdadash.backend.widgets.base.WidgetBase.run_every_frame ` method is invoked.
91107
92- * When ``_run_frequency `` is ``batch ``,
108+ * and ``_run_frequency `` is ``batch ``,
93109 :meth: `~mdadash.backend.widgets.base.WidgetBase.run_batch ` method is invoked.
94110
95111_run_mode
@@ -124,6 +140,9 @@ invoked by the dashboard framework at those stages.
124140* :meth: `~mdadash.backend.widgets.base.WidgetBase.on_pre_resume `
125141* :meth: `~mdadash.backend.widgets.base.WidgetBase.on_input_change `
126142
143+ All the lifecycle methods are optional and the Widget class can choose to implement them
144+ as they see fit.
145+
127146Inputs
128147------
129148
@@ -212,10 +231,18 @@ shown below:
212231 " type" : " cell" ,
213232 },
214233
234+ Here is an example of how the different inputs show up in the UI based on their type:
235+
236+ .. image :: _static/images/custom-widget-inputs.png
237+ :alt: Custom Widget Inputs
238+
215239The :meth: `~mdadash.backend.widgets.base.WidgetBase.on_input_change ` handler gets invoked
216240for any input change made from the dasboard UI. Any validation errors raised by the
217241handler will show up as errors in the UI as well.
218242
243+ Having inputs for the Widget is optional and the Widget class can choose to add them as
244+ they see fit.
245+
219246.. caution ::
220247
221248 Widgets will not be run as long as there are input errors as shown in the dasboard UI.
@@ -231,6 +258,19 @@ if required when any custom conditions are met in their code.
231258* :meth: `~mdadash.backend.widgets.base.WidgetBase.pause_simulation `
232259
233260
261+ Notes and Docs link
262+ -------------------
263+
264+ Widget classes can add an optional ``_notes `` string attibute that will display the given
265+ string as Notes in the Widget details page as shown below:
266+
267+ .. image :: _static/images/widget-notes.png
268+ :alt: Widget Notes
269+
270+ An optional ``_doclink `` string attribute can be provided with a link to the Widget class
271+ documentation and if present, it will be available as a button in the Widget details page
272+ as shown above (book icon).
273+
234274Automatic refresh
235275-----------------
236276
@@ -240,6 +280,48 @@ All existing inputs are retained as is. This allows updates to the Widget class
240280immediately in existing Widget outputs.
241281
242282
283+ Examples
284+ --------
285+
286+ Here is a simple Widget that has a single input made available in the UI to customize the
287+ MDAnalysis selection phrase and displays the center-of-mass of that selection every frame:
288+
289+ .. code-block :: python
290+
291+ from mdadash.backend.widgets.base import WidgetBase
292+
293+ class CustomWidget (WidgetBase ):
294+ name = " Custom Widget"
295+ _override_name = True
296+
297+ _inputs = [
298+ {
299+ " attribute" : " selection" ,
300+ " name" : " Selection" ,
301+ " description" : " MDAnalysis selection phrase" ,
302+ " type" : " str" ,
303+ },
304+ ]
305+
306+ def __init__ (self ):
307+ super ().__init__ ()
308+ self .selection = " protein"
309+
310+ def run_every_frame (self ):
311+ com = self .u.select_atoms(self .selection).center_of_mass()
312+ print (f " COM of { self .selection} is " , com)
313+
314+ The ``_override_name `` attribute set to ``True `` is added in the class above to make any
315+ code changes to the above class update in real-time.
316+
317+ Here is an example of how this Widget shows up in the UI along with its output:
318+
319+ .. image :: _static/images/custom-widget-output.png
320+ :alt: Custom Widget Output
321+
322+ All the :doc: `built_in_widgets ` use the exact same framework described here and the sources
323+ for these are examples of more complex use cases.
324+
243325----
244326
245327.. tip ::
0 commit comments