Skip to content

Commit 7ba50d4

Browse files
committed
slider added
1 parent bdfc157 commit 7ba50d4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

roboticstoolbox/backends/Swift/Swift.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import spatialmath as sm
1010
import time
1111
from queue import Queue
12+
import json
1213

1314
_sw = None
1415
sw = None
@@ -72,6 +73,12 @@ def __init__(self, realtime=True, display=True):
7273
self.outq = Queue()
7374
self.inq = Queue()
7475

76+
# Number of custom html elements added to page for id purposes
77+
self.elementid = 0
78+
79+
# Element dict which holds the callback functions for form updates
80+
self.elements = {}
81+
7582
self.realtime = realtime
7683
self.display = display
7784

@@ -383,6 +390,46 @@ def stop_recording(self):
383390
"You must call swift.start_recording(file_name) before trying"
384391
" to stop the recording")
385392

393+
def add_slider(
394+
self, cb, min=0, max=100, step=1, value=0, desc='', unit=''):
395+
"""
396+
Add a range-slider to the page
397+
398+
:param cb: A callback function which is executed when the value of the
399+
slider changes. The callback should accept one argument which
400+
represents the new value of the slider
401+
:type cb: function
402+
:param min: the minimum value of the slider, optional
403+
:type min: float
404+
:param max: the maximum value of the slider, optional
405+
:type max: float
406+
:param step: the step size of the slider, optional
407+
:type step: float
408+
:param desc: add a description of the slider, optional
409+
:type desc: str
410+
:param unit: add a unit to the slider value, optional
411+
:type unit: str
412+
413+
``env.add_slider()`` adds a slider to the graphical
414+
environment.
415+
416+
"""
417+
418+
id = 'customelement' + str(self.elementid)
419+
self.elementid += 1
420+
self.elements[id] = cb
421+
422+
self._send_socket(
423+
'add_element',
424+
['slider', id, min, max, step, value, desc, unit])
425+
426+
def process_events(self):
427+
events = self._send_socket('check_elements')
428+
events = json.loads(events)
429+
430+
for event in events:
431+
self.elements[event](events[event])
432+
386433
def _step_robots(self, dt):
387434

388435
for robot_object in self.robots:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy