dswidgets is a collection of panel
derived widgets commonly used in
airborne datasytems.
- Toggle
- Folder_Button
- FolderSelector
- CPU_WIDGET()
- Shutdown
- Reboot
- Mount a drive (May use auto-mounts)
- unMount a drive
- Disk
- drive info, size,
- size
- remaining space
- Memory
- IO operations
- network
pip install dswidgets
pip install -e .
import panel as pn
import sys
sys.path
['/home/jovyan/work/github-projects/dswidgets/nbs',
'/opt/conda/lib/python311.zip',
'/opt/conda/lib/python3.11',
'/opt/conda/lib/python3.11/lib-dynload',
'',
'/opt/conda/lib/python3.11/site-packages',
'/home/jovyan/work/github-projects/nbdev_learn']
Be sure to install dswidgets via make install, make dev-install
import dswidgets as ds
dir(ds)
['Buttons',
'FileSystem',
'__all__',
'__builtins__',
'__cached__',
'__doc__',
'__file__',
'__loader__',
'__name__',
'__package__',
'__path__',
'__spec__',
'__version__',
'dswidgets']
We need to load the panel extension
so we can view the widgets in the
notebook output. The floatpanel
parameter is required to show the
FileBroswer in a floating pop-up widget.
pn.extension('floatpanel')
Unable to display output for mime type(s): application/javascript, application/vnd.holoviews_load.v0+json
Unable to display output for mime type(s): application/javascript, application/vnd.holoviews_load.v0+json
Below are some of the variables we can access.
print(f' __version__ = {ds.__version__}\n'
f'__package__ = {ds.__package__}\n'
f'File = {ds.__file__}')
__version__ = 0.0.3
__package__ = dswidgets
File = /opt/conda/lib/python3.11/site-packages/dswidgets/__init__.py
b = ds.Buttons.Toggle()
b.button
b.value
1
def button_changed(v):
debug_w.value = v
#print(v)
debug_w = pn.widgets.StaticText(
name="Debug_w.value:",
value = 'Push the button to set this value.')
b2 = ds.Buttons.Toggle(id='b2_id', change_cb = button_changed )
w = pn.Row(b2.button, debug_w)
w.servable()
b2.value
0
The Toggle()
button contains an ‘id’ element that you can
b2.id
'b2_id'
Folder_Button
creates a button that triggers a pop-up Folder-Selector
widget
allowing the user to select a folder on the server system. Once the
folder is selected, a user defined call back function is called with the
selected folder as a parameter.
Below we define a call back cb()
which will be called with the string
value of the selected folder, and then create the
Folder_Button
.
Click the Folder button to trigger the Folder_Selector dialog.
def cb(v):
print(f'{v=} ')
Fsb = ds.FileSystem.Folder_Button( name = "Folder", call_back=cb )
Fsb.folder_button
After you select a folder, the result will also be in Fsb.value
.
Fsb.value
'/proc/37987'
This widget provides a snapshot of the CPU utilization for each core RAM utilization, disk drive information at a user specified interval. The widget starts a thread which automatically updates widget values.
Below is instantiate the widget which also starts the internal thread which updates the widget.
cw = ds.FileSystem.CPU_WIDGET()
cw.cpu_status_widget.servable()
None
For debugging, you can check the status of the widget with
show_status()
.
cw.show_status()
Thread Name Run Alive Loops Interval
Thread-5 (system_status_thread) True True 4 1.0 Sec
You can also change the visibilty of the widget. Let’s hide it.
cw.cpu_status_widget.visible = False
Now lets redisplay it.
cw.cpu_status_widget.visible = True