aboutsummaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2021-12-14 19:53:52 +0100
committerNao Pross <np@0hm.ch>2021-12-14 19:53:52 +0100
commit1a0dfb03aaa7f609e041122807617d8427847272 (patch)
treeefa0d1096f3fa11c26054120904364fb82d7a1ae /src/gui
parentAttempt to use UNIX sockets for better performance (diff)
parentImplement network_value to show BER (diff)
downloadFading-1a0dfb03aaa7f609e041122807617d8427847272.tar.gz
Fading-1a0dfb03aaa7f609e041122807617d8427847272.zip
Merge branch 'ber-gui'
Diffstat (limited to 'src/gui')
-rwxr-xr-xsrc/gui/gui.py15
-rw-r--r--src/gui/net.py25
2 files changed, 33 insertions, 7 deletions
diff --git a/src/gui/gui.py b/src/gui/gui.py
index b298fd8..7e2357b 100755
--- a/src/gui/gui.py
+++ b/src/gui/gui.py
@@ -249,12 +249,18 @@ with window(label="Bit Error Rate ", width=300, height=150, pos=(200,875)) as be
add_theme_color(mvThemeCol_Text,(0,0,0)) #Schwarz
add_theme_style(mvStyleVar_FrameRounding, 5)
- add_button(label="BER", height=60, width=150,pos=(75,60))
- bind_item_theme(last_item(),"button_ber")
+ add_button(label="BER", height=60, width=-1, tag="ber_value")
+ bind_item_theme(last_item(), "button_ber")
# bind_item_theme(ber_window, "ber_window")
# bind_item_font(ber_window, test)
+def set_ber(values):
+ ber_curr, ber_max, ber_avg = values
+ configure_item("ber_value", label=f"Current: {ber_curr}, Max: {ber_max}, Avg: {ber_avg}")
+
+ber_value = net.network_value(url="udp://localhost:31420", dtype=float, refresh_func=set_ber)
+
#================================================
# Picture Window
@@ -278,8 +284,9 @@ set_primary_window("primary_window", True)
# Main loop
while is_dearpygui_running():
- for plt in network_plots:
- plt.refresh_series(plt.series_tag)
+ for plt, tag in network_plots.items():
+ plt.refresh_series(tag)
+ ber_value.refresh()
render_dearpygui_frame()
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.