From 723103628ccb1679fc7e94022f5a97176442544d Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 13 Dec 2021 18:31:05 +0100 Subject: Clean up GUI code, set up network constellation plots --- src/gui/gui.py | 328 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 177 insertions(+), 151 deletions(-) (limited to 'src/gui/gui.py') diff --git a/src/gui/gui.py b/src/gui/gui.py index 3f5b986..d3ada9c 100755 --- a/src/gui/gui.py +++ b/src/gui/gui.py @@ -30,21 +30,38 @@ logger = logging.getLogger(__name__) #================================================ # Initialize DearPyGUI - - create_context() -create_viewport(title="Fading Demonstrator") +create_viewport(title="Fading Demonstrator",width=1920, height=1200) setup_dearpygui() - # Show demo for dev show_demo() -show_documentation() +show_debug() + +#================================================ +# Set up theme and looks + +# Font +# with font_registry(): +# # first argument ids the path to the .ttf or .otf file +# default_font = add_font("NotoSerifCJKjp-Medium.otf", 20) +# second_font = add_font("NotoSerifCJKjp-Medium.otf", 10) +# test = add_font("NotoSerifCJKjp-Medium.otf", 30) + +# Constellation diagrams +with theme(tag="constellation_series_theme"): + with theme_component(mvScatterSeries): + # add_theme_style(mvPlotStyleVar_Marker, mvPlotMarker_Asterisk, category=mvThemeCat_Plots) + add_theme_style(mvPlotStyleVar_MarkerSize, 3, category=mvThemeCat_Plots) #================================================ # GUI Callback functions +# Menu Bar +def exit(sender, data): + stop_dearpygui() + # Flow graph window def on_rx_node_link(sender, app_data): link_id_1, link_id_2 = app_data @@ -52,193 +69,202 @@ def on_rx_node_link(sender, app_data): def on_rx_node_delink(sender, app_data): link_id = app_data - delete_item(link_id) + # do nothing + # delete_item(link_id) -#================================================ -#Setting Window Test -# with window(label="Dear", width=800, height=800, on_close=_on_demo_close, pos=(100, 100)): - - with menu_bar(): - with menu(label="Settings"): - add_menu_item(label="Option 1", callback=_log) - add_menu_item(label="Option 2", check=True, callback=_log) - add_menu_item(label="Option 3", check=True, default_value=True, callback=_log) +# add and load images +def add_and_load_image(image_path): + width, height, channels, data = load_image(image_path) + with texture_registry() as reg_id: + texture_id = add_static_texture(width, height, data, parent=reg_id) + return add_image(texture_id) +#================================================ +# Primary Window -# Settings Window -def exit(sender, data): - stop_dearpygui() +with window(tag="primary_window"): + # Grössere Schrifftart/ Grösse für das ganze Dokument definiert + # bind_font(default_font) -# def _hsv_to_rgb(h, s, v): -# if s == 0.0: return (v, v, v) -# i = int(h*6.) # XXX assume int() truncates! -# f = (h*6.)-i; p,q,t = v*(1.-s), v*(1.-s*f), v*(1.-s*(1.-f)); i%=6 -# if i == 0: return (255*v, 255*t, 255*p) -# if i == 1: return (255*q, 255*v, 255*p) -# if i == 2: return (255*p, 255*v, 255*t) -# if i == 3: return (255*p, 255*q, 255*v) -# if i == 4: return (255*t, 255*p, 255*v) -# if i == 5: return (255*v, 255*p, 255*q) - -with window(label="Settings", width=200, height=400, pos=(25, 25), tag="sim_win", - no_close=True,no_background= True): with menu_bar(): with menu(label="Settings"): - add_menu_item(label="Option 1") - add_menu_item(label="Option 2", check=True) - add_menu_item(label="Option 3", check=True, default_value=True) + add_menu_item(label="Toggle Fullscreen",callback=toggle_viewport_fullscreen) + add_menu_item(label="Minimize",callback=minimize_viewport) + add_menu_item(label="Close", callback=exit) - #Farbwahl in schleife und mit def? - with theme(tag= "button_window"): - with theme_component(mvButton): - add_theme_color(mvThemeCol_Button,(135, 206, 255))#Blau - add_theme_color(mvThemeCol_Text,(0,0,0))#Schwarz - add_theme_style(mvStyleVar_FrameRounding, 5) + with theme(tag="close"): + with theme_component(): + add_theme_color(mvThemeCol_Text,(255, 64, 64)) + add_theme_style(mvStyleVar_Alpha, 5) + bind_item_theme(last_item(),"close") - add_button(label="Toggle Fullscreen", height=50, width=150,callback= toggle_viewport_fullscreen) - bind_item_theme(last_item(),"button_window") - - with theme(tag= "button_minimize"): - with theme_component(mvButton): - #add_theme_color(mvThemeCol_Button,(135, 206, 255))#Blau - #add_theme_color(mvThemeCol_Text,(0,0,0))#Schwarz - add_theme_style(mvStyleVar_FrameRounding, 5) - add_button(label="Minimize",height=50, width=150, callback= minimize_viewport) - bind_item_theme(last_item(),"button_minimize") - - #with child_window(autosize_x=True, height=100)as close: - add_button(label="Maximize",height=50, width=150, callback= maximize_viewport) #Befehl nötig ? - - with theme(tag= "button_close"): - with theme_component(mvButton): - add_theme_color(mvThemeCol_Button,(255, 64, 64))#Rot - add_theme_color(mvThemeCol_Text,(0,0,0))#Schwarz - add_theme_style(mvStyleVar_FrameRounding, 5) - - add_button(label="Close", height=50, width=150, callback= exit) - bind_item_theme(last_item(),"button_close") - - - - -# #================================================ -# # Flow Graph Window - -# with window(label="RX DSP Flow Graph", width=800, height=400, pos=(25,25), tag="rx_win"): -# with node_editor(callback=on_rx_node_link, delink_callback=on_rx_node_delink): -# with node(label="USRP Source", pos=(20,100)): -# with node_attribute(tag="src_out", attribute_type=mvNode_Attr_Output): -# add_text("Signal from antenna") - -# with node(label="Clock Sync", pos=(200,200)): -# with node_attribute(tag="clksync_in", attribute_type=mvNode_Attr_Input): -# add_text("Input") - -# with node_attribute(tag="clksync_out", attribute_type=mvNode_Attr_Output): -# add_text("Synchronized") +#================================================ +# Flow Graph Window -# with node(label="Equalizer", pos=(350,100)): -# with node_attribute(tag="eq_in", attribute_type=mvNode_Attr_Input): -# add_text("Input") +with window(label="RX DSP Flow Graph", width=800, height=400, pos=(0,25), tag="rx_win"): + with node_editor(callback=on_rx_node_link, delink_callback=on_rx_node_delink): + with node(label="USRP Source", pos=(20,100)): + with node_attribute(tag="src_out", attribute_type=mvNode_Attr_Output): + add_text("Signal from antenna") -# with node_attribute(attribute_type=mvNode_Attr_Static): -# add_knob_float(label="Gain") + with node(label="Clock Sync", pos=(200,200)): + with node_attribute(tag="clksync_in", attribute_type=mvNode_Attr_Input): + add_text("Input") -# with node_attribute(tag="eq_out", attribute_type=mvNode_Attr_Output): -# add_text("Equalized") + with node_attribute(tag="clksync_out", attribute_type=mvNode_Attr_Output): + add_text("Synchronized") -# with node(label="Phase Locked Loop", pos=(600, 200)): -# with node_attribute(tag="pll_in", attribute_type=mvNode_Attr_Input): -# add_text("Input") + with node(label="Equalizer", pos=(350,100)): + with node_attribute(tag="eq_in", attribute_type=mvNode_Attr_Input): + add_text("Input") -# with node_attribute(tag="pll_out", attribute_type=mvNode_Attr_Output): -# add_text("Locked") -# add_knob_float(label="Loop BW") + with node_attribute(tag="eq_out", attribute_type=mvNode_Attr_Output): + add_text("Equalized") + with node(label="Phase Locked Loop", pos=(600, 200)): + with node_attribute(tag="pll_in", attribute_type=mvNode_Attr_Input): + add_text("Input") -# add_node_link(get_alias_id("src_out"), get_alias_id("clksync_in")) -# add_node_link(get_alias_id("clksync_out"), get_alias_id("eq_in")) -# add_node_link(get_alias_id("eq_out"), get_alias_id("pll_in")) + with node_attribute(tag="pll_out", attribute_type=mvNode_Attr_Output): + add_text("Locked") -# #================================================ -# Network plots Window -recv_plot = net.network_plot(url="udp://localhost:31415", dtype=float, nsamples=100, \ - label="Test", height=300, width=800) + add_node_link(get_alias_id("src_out"), get_alias_id("clksync_in")) + add_node_link(get_alias_id("clksync_out"), get_alias_id("eq_in")) + add_node_link(get_alias_id("eq_out"), get_alias_id("pll_in")) -plots = { - # recv_plot: "plt_ampl" +#================================================ +# Network plots + +time_plot = net.network_plot(url="udp://localhost:31415", dtype=float, \ + nsamples=100, tag="time_plot", label="Time plot") +channel_plot = net.network_constellation_plot(url="udp://localhost:31416", \ + nsamples=80, tag="channel_plot", label="Channel") +synchronized_plot = net.network_constellation_plot(url="udp://localhost:31417", \ + nsamples=100, tag="synchronized_plot", label="Synchronized") +equalized_plot = net.network_constellation_plot(url="udp://localhost:31418", \ + nsamples=100, tag="equalized_plot", label="Equalized") +locked_plot = net.network_constellation_plot(url="udp://localhost:31419", \ + nsamples=100, tag="locked_plot", label="Locked") + +network_plots = { + time_plot: "time_plot_series", + channel_plot: "channel_plot_series", + synchronized_plot: "synchronized_plot_series", + equalized_plot: "equalized_plot_series", + locked_plot: "locked_plot_series", } -with window(label="Time domain plots", width=800, height=350, pos=(25,450)): - with recv_plot: - add_plot_axis(mvXAxis, label="Time") - add_plot_axis(mvYAxis, label="Amplitude", tag="axis") - - add_line_series(recv_plot.xdata, recv_plot.ydata, parent="axis", tag="plt_ampl") +with window(label="Time domain", width=800, height=350, pos=(0,425)): + with time_plot: + add_plot_axis(mvXAxis, label="Time", tag="xaxis_time") + add_plot_axis(mvYAxis, label="Amplitude", tag="yaxis_time") + add_line_series(time_plot.xdata, time_plot.ydata, parent="yaxis_time", tag=network_plots[time_plot]) + +with window(label="Channel", width=560, height=400, pos=(800,25)): + with channel_plot: + add_plot_axis(mvXAxis, label="In-Phase", tag="inphase_channel") + add_plot_axis(mvYAxis, label="Quadrature", tag="quadrature_channel") + + add_plot_legend() + set_axis_limits("inphase_channel", -2.5, 2.5) + set_axis_limits("quadrature_channel", -2.5, 2.5) + + series_tag = network_plots[channel_plot] + add_scatter_series(channel_plot.xdata, channel_plot.ydata, \ + label = "Channel", parent="inphase_channel", tag=series_tag) + bind_item_theme(series_tag, "constellation_series_theme") + # bind_colormap("channel_plot", mvPlotColormap_Spectral) + +with window(label="Synchronized", width=560, height=400, pos=(1360,25)): + with synchronized_plot: + add_plot_axis(mvXAxis, label="In-Phase", tag="inphase_synchronized") + add_plot_axis(mvYAxis, label="Quadrature", tag="quadrature_synchronized") + + add_plot_legend() + set_axis_limits("inphase_synchronized", -2.5, 2.5) + set_axis_limits("quadrature_synchronized", -2.5, 2.5) + + series_tag = network_plots[synchronized_plot] + add_scatter_series(synchronized_plot.xdata, synchronized_plot.ydata, \ + label="Synchronized", parent="inphase_synchronized", tag=series_tag) + bind_item_theme(series_tag, "constellation_series_theme") + +with window(label="Equalized", width=560, height=400, pos=(800,425)): + with equalized_plot: + add_plot_legend() + add_plot_axis(mvXAxis, label="In-Phase", tag="inphase_equalized") + add_plot_axis(mvYAxis, label="Quadrature", tag="quadrature_equalized") + + add_plot_legend() + set_axis_limits("inphase_equalized", -1.5, 1.5) + set_axis_limits("quadrature_equalized", -1.5, 1.5) + + series_tag = network_plots[equalized_plot] + add_scatter_series(equalized_plot.xdata, equalized_plot.ydata, \ + label="Equalized", parent="inphase_equalized", tag=series_tag) + bind_item_theme(series_tag, "constellation_series_theme") + +with window(label="Locked", width=560, height=400, pos=(1360,425)): + with locked_plot: + add_plot_legend() + add_plot_axis(mvXAxis, label="In-Phase", tag="inphase_locked") + add_plot_axis(mvYAxis, label="Quadrature", tag="quadrature_locked") + + add_plot_legend() + set_axis_limits("inphase_locked", -1.5, 1.5) + set_axis_limits("quadrature_locked", -1.5, 1.5) + + series_tag = network_plots[locked_plot] + add_scatter_series(locked_plot.xdata, locked_plot.ydata, \ + label="Locked", parent="inphase_locked", tag=series_tag) + bind_item_theme(series_tag, "constellation_series_theme") #================================================ -# Byte Error Rate Window -#TO DO: +# Bit Error Rate Window -with window(label="Byte Error Rate ", width=300, height=150, pos=(850,25),tag="__ber_id",no_move=True, no_collapse= True): - add_text("The Byte Error Rate is:") +#TO DO:BER von GNU Radio anzeigen +with theme(tag= "ber_window"): + with theme_component(mvAll): + add_theme_style(mvStyleVar_WindowTitleAlign, 0.5) + add_theme_style(mvStyleVar_WindowRounding, 5) + add_theme_style(mvStyleVar_WindowBorderSize, 1)#Rad ein und aus Schalten -#================================================ -# Channel Window -#TO DO: -# recv_plot = net.network_plot(url="udp://localhost:31415", nsamples=100, label="Test", height=300, width=800) - -# plots = { -# recv_plot: "plt_ampl" -# } - -# with window(label="Channel ", width=600, height=600, pos=(850,25)): -# with child_window(autosize_x=True, height=100): -# add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen) -# with recv_plot: -# add_plot_axis(mvXAxis, label="In-phase") -# add_plot_axis(mvYAxis, label="Quadrature", tag="plt_ampl") - -# add_scatter_series(recv_plot.x_data, recv_plot.y_data, parent="plt_ampl") -# #================================================ -# # Synchronized Window -# #TO DO: -# with window(label="Synchronized ", width=600, height=600, pos=(850,25)): -# with child_window(autosize_x=True, height=100): -# add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen) - -# #================================================ -# # Equalized Window -# #TO DO: -# with window(label="Equalized ", width=600, height=600, pos=(850,25)): -# with child_window(autosize_x=True, height=100): -# add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen) - -# #================================================ -# # Locked Window -# #TO DO: -# with window(label="Locked ", width=600, height=600, pos=(850,25)): -# with child_window(autosize_x=True, height=100): -# add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen) +with window(label="Bit Error Rate ", width=300, height=150, pos=(1200,875), no_title_bar = True, no_move=True, no_collapse= True) as ber_window : + + add_text("The Bit Error Rate is:", pos=(35,10)) + with theme(tag= "button_ber"): + with theme_component(mvButton): + add_theme_color(mvThemeCol_Button,(135, 206, 255))#Blau + 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") +# bind_item_theme(ber_window, "ber_window") +# bind_item_font(ber_window, test) #================================================ +# Picture Window +with window(label="Picture", width=400, height=300, pos=(0,825)) as picture_window : + add_and_load_image("lena512color.png") #TO DO Problem lösen +#================================================ # Start GUI and main loop # Start window and main loop show_viewport() +set_primary_window("primary_window", True) # Main loop while is_dearpygui_running(): - for plt, tag in plots.items(): + for plt, tag in network_plots.items(): plt.refresh_series(tag) render_dearpygui_frame() -- cgit v1.2.1