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.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/gui/net.py b/src/gui/net.py
index f836f42..820bc84 100644
--- a/src/gui/net.py
+++ b/src/gui/net.py
@@ -1,3 +1,4 @@
+import os
import select
import socket
from urllib.parse import urlparse
@@ -19,13 +20,30 @@ class udpsource:
self.timeout = timeout
self.blocksize = blocksize
+ if self.url.scheme == "udp":
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ elif self.url.scheme == "file":
+ try:
+ os.unlink(self.url.path)
+ except OSError:
+ if os.path.exists(self.url.path):
+ raise
+
+ self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
+ else:
+ raise NotImplemented
+
def __del__(self):
self.sock.close()
def bind(self):
self.sock.setblocking(False)
- self.sock.bind((self.url.hostname, self.url.port))
- # self.sock.listen()
+ if self.url.scheme == "udp":
+ self.sock.bind((self.url.hostname, self.url.port))
+ elif self.url.scheme == "file":
+ self.sock.bind(self.url.path)
+
+ # self.sock.listen(1)
def read(self, nblocks):
# TODO: run in a separate thread (it will be painful to implement)
@@ -77,7 +95,7 @@ class network_plot(udpsource):
"""
Wraps a udpsource while at the same time intefacing with DearPyGUI as a plot element.
"""
- def __init__(self, url, dtype, nsamples , **kwargs):
+ def __init__(self, url, dtype, nsamples, **kwargs):
udpsource.__init__(self, url, dtype)
self.nsamples = nsamples
@@ -96,6 +114,14 @@ class network_plot(udpsource):
self.yvalues.extend(np.zeros(self.nsamples))
def _init_dpg_plot(self, **kwargs):
+ if "tag" in kwargs:
+ self.tag = kwargs["tag"]
+
+ self.series_tag = f"{self.tag}_series"
+ self.xaxis_tag = f"{self.tag}_xaxis"
+ self.yaxis_tag = f"{self.tag}_yaxis"
+ self.window_tag = f"window_{self.tag}"
+
self.plot = dpg.plot(**kwargs)
# Map `with' expressions to the underlying plot