aboutsummaryrefslogtreecommitdiffstats
path: root/src/gui/net.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/net.py')
-rw-r--r--src/gui/net.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/src/gui/net.py b/src/gui/net.py
index 1ddb1d0..820bc84 100644
--- a/src/gui/net.py
+++ b/src/gui/net.py
@@ -13,10 +13,12 @@ class udpsource:
"""
Creates an UDP listening socket
"""
- def __init__(self, url, dtype, timeout=0.05):
+ def __init__(self, url, dtype, timeout=0.05, blocksize=1024):
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.url = urlparse(url)
self.dtype = dtype
self.timeout = timeout
+ self.blocksize = blocksize
if self.url.scheme == "udp":
self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -50,8 +52,7 @@ class udpsource:
return None
# read from socket
- blocksize = 1024
- string = ready[0].recv(nblocks * blocksize).decode("ascii")
+ string = ready[0].recv(nblocks * self.blocksize).decode("ascii")
# decode string, remove empty values
chunks = filter(None, re.split(r"\[(.+?)\]", string))
@@ -72,6 +73,24 @@ class udpsource:
return values
+class network_value(udpsource):
+ def __init__(self, url, dtype, refresh_func):
+ udpsource.__init__(self, url, dtype, blocksize=16)
+
+ self._refresh = refresh_func
+ self.value = None
+
+ self.bind()
+
+ def read(self):
+ return udpsource.read(self, 1)
+
+ def refresh(self):
+ self.value = self.read()
+ if self.value:
+ self._refresh(self.value)
+
+
class network_plot(udpsource):
"""
Wraps a udpsource while at the same time intefacing with DearPyGUI as a plot element.