From 8b73e03472222fc7e12ebe9e85a80f3432bc1de3 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 11 Nov 2021 15:18:22 +0100 Subject: Minor changes to sketch.py --- src/sketch.py | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/sketch.py b/src/sketch.py index 5f170b2..58e36a3 100755 --- a/src/sketch.py +++ b/src/sketch.py @@ -36,7 +36,7 @@ create_viewport() setup_dearpygui() # Show demo for dev -# show_demo() +show_demo() #================================================ # Custom GNURadio blocks @@ -122,25 +122,40 @@ sim.connect((sim.digital_costas_loop_cc_0, 0), (locked_time_plot, 0)) # Settings Window with window(label="Settings", width=200, height=400, pos=(25, 450), tag="sim_win"): - add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen) + with child_window(autosize_x=True, height=100): + add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen) - add_text("Simulation running:") - add_text("false", tag="sim_running_lbl") + with child_window(autosize_x=True): + with group(horizontal=True): + add_text("Simulation running:") + add_text("false", tag="sim_running_lbl") - with group(horizontal=True): - def on_sim_start_btn_clicked(): - sim.start() - sim_runnig = True - logger.debug("Started simulation") + with group(tag="sim_grp", horizontal=True): + def on_sim_start_btn_clicked(): + global sim_running - def on_sim_stop_btn_clicked(): - sim.stop() - sim.wait() - sim_running = False - logger.debug("Stopped simulation") + if sim_running: + logger.error("Simulation is already running") + return - add_button(label="Start", tag="sim_start_btn", callback=on_sim_start_btn_clicked) - add_button(label="Stop", tag="sim_stop_btn", callback=on_sim_stop_btn_clicked) + sim.start() + sim_running = True + logger.debug("Started simulation") + + def on_sim_stop_btn_clicked(): + global sim_running + + if not sim_running: + logger.error("Simulation not running") + return + + sim.stop() + sim.wait() + sim_running = False + logger.debug("Stopped simulation") + + add_button(label="Start", tag="sim_start_btn", callback=on_sim_start_btn_clicked) + add_button(label="Stop", tag="sim_stop_btn", callback=on_sim_stop_btn_clicked) #================================================ # Flow Graph Window @@ -196,8 +211,3 @@ start_dearpygui() # clean up gui destroy_context() - -# Stop GNURadio -if sim_running: - sim.stop() - sim.wait() -- cgit v1.2.1 From 0ad4b5f2b78e199dae017fdb6cb80fca39102e5a Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 11 Nov 2021 19:21:33 +0100 Subject: Rename sketch.py to gui.py, move tests in test/ directory --- src/Test_Plots/test.py | 57 ------- src/Test_Plots/test10.py | 53 ------- src/Test_Plots/test1_updating_series_data.py | 30 ---- src/Test_Plots/test2_axis_limis.py | 40 ----- src/Test_Plots/test3_custom_axis_labels.py | 34 ---- src/Test_Plots/test4_multiple_y_axes.py | 25 --- src/Test_Plots/test5_annotations.py | 32 ---- src/Test_Plots/test6_drag_points_and_lines.py | 26 ---- src/Test_Plots/test7_querying.py | 37 ----- src/Test_Plots/test8_custom_context_menus.py | 33 ---- src/Test_Plots/test9_colors_and_styles.py | 50 ------ src/gui.py | 213 ++++++++++++++++++++++++++ src/sketch.py | 213 -------------------------- 13 files changed, 213 insertions(+), 630 deletions(-) delete mode 100644 src/Test_Plots/test.py delete mode 100644 src/Test_Plots/test10.py delete mode 100644 src/Test_Plots/test1_updating_series_data.py delete mode 100644 src/Test_Plots/test2_axis_limis.py delete mode 100644 src/Test_Plots/test3_custom_axis_labels.py delete mode 100644 src/Test_Plots/test4_multiple_y_axes.py delete mode 100644 src/Test_Plots/test5_annotations.py delete mode 100644 src/Test_Plots/test6_drag_points_and_lines.py delete mode 100644 src/Test_Plots/test7_querying.py delete mode 100644 src/Test_Plots/test8_custom_context_menus.py delete mode 100644 src/Test_Plots/test9_colors_and_styles.py create mode 100755 src/gui.py delete mode 100755 src/sketch.py (limited to 'src') diff --git a/src/Test_Plots/test.py b/src/Test_Plots/test.py deleted file mode 100644 index 3fb0d51..0000000 --- a/src/Test_Plots/test.py +++ /dev/null @@ -1,57 +0,0 @@ -import dearpygui.dearpygui as dpg -from math import sin - -import qpks as qp - -q = qp.qpsk_nogui() - -dpg.create_context() - -# data = q.analog_random_source_x_0 - -sindatax = [] -sindatay = [] -for i in range(0, 100): - sindatax.append(i / 100) - sindatay.append(0.5 + 0.5 * sin(50 * i / 100)) -sindatay2 = [] -for i in range(0, 100): - sindatay2.append(2 + 0.5 * sin(50 * i / 100)) - -with dpg.window(label="Tutorial", width=500, height=400): - # create a theme for the plot - with dpg.theme(tag="plot_theme"): - with dpg.theme_component(dpg.mvStemSeries): - dpg.add_theme_color(dpg.mvPlotCol_Line, (150, 255, 0), category=dpg.mvThemeCat_Plots) - dpg.add_theme_style(dpg.mvPlotStyleVar_Marker, dpg.mvPlotMarker_Diamond, category=dpg.mvThemeCat_Plots) - dpg.add_theme_style(dpg.mvPlotStyleVar_MarkerSize, 7, category=dpg.mvThemeCat_Plots) - - with dpg.theme_component(dpg.mvScatterSeries): - dpg.add_theme_color(dpg.mvPlotCol_Line, (60, 150, 200), category=dpg.mvThemeCat_Plots) - dpg.add_theme_style(dpg.mvPlotStyleVar_Marker, dpg.mvPlotMarker_Square, category=dpg.mvThemeCat_Plots) - dpg.add_theme_style(dpg.mvPlotStyleVar_MarkerSize, 4, category=dpg.mvThemeCat_Plots) - - # create plot - with dpg.plot(tag="plot", label="Line Series", height=-1, width=-1): - - # optionally create legend - dpg.add_plot_legend() - - # REQUIRED: create x and y axes - dpg.add_plot_axis(dpg.mvXAxis, label="x") - dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis") - - # series belong to a y axis - # dpg.add_stem_series(data, sindatay, label="Source", parent="yaxis", tag="series_data") - dpg.add_stem_series(sindatax, sindatay, label="0.5 + 0.5 * sin(x)", parent="yaxis", tag="series_data") - dpg.add_scatter_series(sindatax, sindatay2, label="2 + 0.5 * sin(x)", parent="yaxis", tag="series_data2") - - # apply theme to series - dpg.bind_item_theme("series_data", "plot_theme") - dpg.bind_item_theme("series_data2", "plot_theme") - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() \ No newline at end of file diff --git a/src/Test_Plots/test10.py b/src/Test_Plots/test10.py deleted file mode 100644 index d478d9a..0000000 --- a/src/Test_Plots/test10.py +++ /dev/null @@ -1,53 +0,0 @@ -from dearpygui.core import * -from dearpygui.simple import * -from math import cos - -def plot_callback(sender, data): - # keeping track of frames - frame_count = get_data("frame_count") - frame_count += 1 - add_data("frame_count", frame_count) - - # updating plot data - plot_datax = get_data("plot_datax") - plot_datay = get_data("plot_datay") - if len(plot_datax) > 2000: - frame_count = 0 - plot_datax.clear() - plot_datay.clear() - plot_datax.append(3.14 * frame_count / 180) - plot_datay.append(cos(3 * 3.14 * frame_count / 180)) - add_data("plot_datax", plot_datax) - add_data("plot_datay", plot_datay) - - # plotting new data - add_line_series("Plot", "Cos", plot_datax, plot_datay, weight=2) - -with window("Tutorial", width=500, height=500): - add_plot("Plot", height=-1) - add_data("plot_datax", []) - add_data("plot_datay", []) - add_data("frame_count", 0) - add_input_text("freq") - with menu_bar("Main Menu Bar"): - with menu("File"): - add_menu_item("test") - set_render_callback(plot_callback) - -with window("Heat", width=500, height=500): - add_plot("HeatPlot", show_color_scale=False, scale_min=0.0, scale_max=6.0, - scale_height=400, no_legend=True, - no_mouse_pos=True, xaxis_lock_min=True, xaxis_lock_max=True, xaxis_no_gridlines=True, xaxis_no_tick_marks=True, - yaxis_no_gridlines=True, yaxis_no_tick_marks=True, yaxis_lock_min=True, yaxis_lock_max=True, height=400) - set_color_map("HeatPlot", 6) - values = [0.8, 2.4, 2.5, 3.9, 0.0, 4.0, 0.0, - 2.4, 0.0, 4.0, 1.0, 2.7, 0.0, 0.0, - 1.1, 2.4, 0.8, 4.3, 1.9, 4.4, 0.0, - 0.6, 0.0, 0.3, 0.0, 3.1, 0.0, 0.0, - 0.7, 1.7, 0.6, 2.6, 2.2, 6.2, 0.0, - 1.3, 1.2, 0.0, 0.0, 0.0, 3.2, 5.1, - 0.1, 2.0, 0.0, 1.4, 0.0, 1.9, 6.3] - add_heat_series("HeatPlot", "heat data", values, 7, 7, 0, 6, format='') - - -start_dearpygui() \ No newline at end of file diff --git a/src/Test_Plots/test1_updating_series_data.py b/src/Test_Plots/test1_updating_series_data.py deleted file mode 100644 index 1371008..0000000 --- a/src/Test_Plots/test1_updating_series_data.py +++ /dev/null @@ -1,30 +0,0 @@ -import dearpygui.dearpygui as dpg -from math import sin - -dpg.create_context() - -# creating data -sindatax = [] -sindatay = [] -for i in range(0, 500): - sindatax.append(i / 1000) - sindatay.append(0.5 + 0.5 * sin(50 * i / 1000)) - -with dpg.window(label="Tutorial"): - # create plot - with dpg.plot(label="Line Series", height=400, width=400): - # optionally create legend - dpg.add_plot_legend() - - # REQUIRED: create x and y axes - dpg.add_plot_axis(dpg.mvXAxis, label="x") - dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="y_axis") - - # series belong to a y axis - dpg.add_line_series(sindatax, sindatay, label="0.5 + 0.5 * sin(x)", parent="y_axis") - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() \ No newline at end of file diff --git a/src/Test_Plots/test2_axis_limis.py b/src/Test_Plots/test2_axis_limis.py deleted file mode 100644 index bdfeda1..0000000 --- a/src/Test_Plots/test2_axis_limis.py +++ /dev/null @@ -1,40 +0,0 @@ -import dearpygui.dearpygui as dpg -from math import sin, cos - -dpg.create_context() - -sindatax = [] -sindatay = [] -for i in range(0, 500): - sindatax.append(i / 1000) - sindatay.append(0.5 + 0.5 * sin(50 * i / 1000)) - -def update_series(): - - cosdatax = [] - cosdatay = [] - for i in range(0, 500): - cosdatax.append(i / 1000) - cosdatay.append(0.5 + 0.5 * cos(50 * i / 1000)) - dpg.set_value('series_tag', [cosdatax, cosdatay]) - dpg.set_item_label('series_tag', "0.5 + 0.5 * cos(x)") - -with dpg.window(label="Tutorial", tag="win"): - dpg.add_button(label="Update Series", callback=update_series) - # create plot - with dpg.plot(label="Line Series", height=400, width=400): - # optionally create legend - dpg.add_plot_legend() - - # REQUIRED: create x and y axes - dpg.add_plot_axis(dpg.mvXAxis, label="x") - dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="y_axis") - - # series belong to a y axis - dpg.add_line_series(sindatax, sindatay, label="0.5 + 0.5 * sin(x)", parent="y_axis", tag="series_tag") - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() diff --git a/src/Test_Plots/test3_custom_axis_labels.py b/src/Test_Plots/test3_custom_axis_labels.py deleted file mode 100644 index be6b80b..0000000 --- a/src/Test_Plots/test3_custom_axis_labels.py +++ /dev/null @@ -1,34 +0,0 @@ -import dearpygui.dearpygui as dpg - -dpg.create_context() - -with dpg.window(label="Tutorial", width=400, height=400): - with dpg.group(horizontal=True): - dpg.add_button(label="fit y", callback=lambda: dpg.fit_axis_data("y_axis")) - dpg.add_button(label="unlock x limits", callback=lambda: dpg.set_axis_limits_auto("x_axis")) - dpg.add_button(label="unlock y limits", callback=lambda: dpg.set_axis_limits_auto("y_axis")) - dpg.add_button(label="print limits x", callback=lambda: print(dpg.get_axis_limits("x_axis"))) - dpg.add_button(label="print limits y", callback=lambda: print(dpg.get_axis_limits("y_axis"))) - - with dpg.plot(label="Bar Series", height=-1, width=-1): - dpg.add_plot_legend() - - # create x axis - dpg.add_plot_axis(dpg.mvXAxis, label="Student", no_gridlines=True, tag="x_axis") - dpg.set_axis_limits(dpg.last_item(), 9, 33) - dpg.set_axis_ticks(dpg.last_item(), (("S1", 11), ("S2", 21), ("S3", 31))) - - # create y axis - dpg.add_plot_axis(dpg.mvYAxis, label="Score", tag="y_axis") - dpg.set_axis_limits("y_axis", 0, 110) - - # add series to y axis - dpg.add_bar_series([10, 20, 30], [100, 75, 90], label="Final Exam", weight=1, parent="y_axis") - dpg.add_bar_series([11, 21, 31], [83, 75, 72], label="Midterm Exam", weight=1, parent="y_axis") - dpg.add_bar_series([12, 22, 32], [42, 68, 23], label="Course Grade", weight=1, parent="y_axis") - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() \ No newline at end of file diff --git a/src/Test_Plots/test4_multiple_y_axes.py b/src/Test_Plots/test4_multiple_y_axes.py deleted file mode 100644 index ebaac7e..0000000 --- a/src/Test_Plots/test4_multiple_y_axes.py +++ /dev/null @@ -1,25 +0,0 @@ -import dearpygui.dearpygui as dpg - -dpg.create_context() - -with dpg.window(label="Tutorial", width=400, height=400): - with dpg.plot(label="Bar Series", height=-1, width=-1): - dpg.add_plot_legend() - - # create x axis - dpg.add_plot_axis(dpg.mvXAxis, label="Student", no_gridlines=True) - dpg.set_axis_ticks(dpg.last_item(), (("S1", 11), ("S2", 21), ("S3", 31))) - - # create y axis - dpg.add_plot_axis(dpg.mvYAxis, label="Score", tag="yaxis_tag") - - # add series to y axis - dpg.add_bar_series([10, 20, 30], [100, 75, 90], label="Final Exam", weight=1, parent="yaxis_tag") - dpg.add_bar_series([11, 21, 31], [83, 75, 72], label="Midterm Exam", weight=1, parent="yaxis_tag") - dpg.add_bar_series([12, 22, 32], [42, 68, 23], label="Course Grade", weight=1, parent="yaxis_tag") - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() \ No newline at end of file diff --git a/src/Test_Plots/test5_annotations.py b/src/Test_Plots/test5_annotations.py deleted file mode 100644 index 9deff6b..0000000 --- a/src/Test_Plots/test5_annotations.py +++ /dev/null @@ -1,32 +0,0 @@ -import dearpygui.dearpygui as dpg -from math import sin - -dpg.create_context() - - -sindatax = [] -sindatay = [] -for i in range(0, 100): - sindatax.append(i / 100) - sindatay.append(0.5 + 0.5 * sin(50 * i / 100)) - -with dpg.window(label="Tutorial", width=400, height=400): - with dpg.plot(label="Annotations", height=-1, width=-1): - dpg.add_plot_legend() - dpg.add_plot_axis(dpg.mvXAxis, label="x") - dpg.add_plot_axis(dpg.mvYAxis, label="y") - dpg.add_line_series(sindatax, sindatay, label="0.5 + 0.5 * sin(x)", parent=dpg.last_item()) - - # annotations belong to the plot NOT axis - dpg.add_plot_annotation(label="BL", default_value=(0.25, 0.25), offset=(-15, 15), color=[255, 255, 0, 255]) - dpg.add_plot_annotation(label="BR", default_value=(0.75, 0.25), offset=(15, 15), color=[255, 255, 0, 255]) - dpg.add_plot_annotation(label="TR not clampled", default_value=(0.75, 0.75), offset=(-15, -15), - color=[255, 255, 0, 255], clamped=False) - dpg.add_plot_annotation(label="TL", default_value=(0.25, 0.75), offset=(-15, -15), color=[255, 255, 0, 255]) - dpg.add_plot_annotation(label="Center", default_value=(0.5, 0.5), color=[255, 255, 0, 255]) - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() diff --git a/src/Test_Plots/test6_drag_points_and_lines.py b/src/Test_Plots/test6_drag_points_and_lines.py deleted file mode 100644 index c6d8862..0000000 --- a/src/Test_Plots/test6_drag_points_and_lines.py +++ /dev/null @@ -1,26 +0,0 @@ -import dearpygui.dearpygui as dpg - -dpg.create_context() - -def print_val(sender): - print(dpg.get_value(sender)) - -with dpg.window(label="Tutorial", width=400, height=400): - with dpg.plot(label="Drag Lines/Points", height=-1, width=-1): - dpg.add_plot_legend() - dpg.add_plot_axis(dpg.mvXAxis, label="x") - dpg.set_axis_limits(dpg.last_item(), -5, 5) - dpg.add_plot_axis(dpg.mvYAxis, label="y") - dpg.set_axis_limits(dpg.last_item(), -5, 5) - - # drag lines/points belong to the plot NOT axis - dpg.add_drag_line(label="dline1", color=[255, 0, 0, 255], default_value=2.0, callback=print_val) - dpg.add_drag_line(label="dline2", color=[255, 255, 0, 255], vertical=False, default_value=-2, callback=print_val) - dpg.add_drag_point(label="dpoint1", color=[255, 0, 255, 255], default_value=(1.0, 1.0), callback=print_val) - dpg.add_drag_point(label="dpoint2", color=[255, 0, 255, 255], default_value=(-1.0, 1.0), callback=print_val) - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() \ No newline at end of file diff --git a/src/Test_Plots/test7_querying.py b/src/Test_Plots/test7_querying.py deleted file mode 100644 index 06f3ceb..0000000 --- a/src/Test_Plots/test7_querying.py +++ /dev/null @@ -1,37 +0,0 @@ -import dearpygui.dearpygui as dpg -from math import sin - -dpg.create_context() - -sindatax = [] -sindatay = [] -for i in range(0, 100): - sindatax.append(i / 100) - sindatay.append(0.5 + 0.5 * sin(50 * i / 100)) - -with dpg.window(label="Tutorial", width=400, height=600): - dpg.add_text("Click and drag the middle mouse button over the top plot!") - - - def query(sender, app_data, user_data): - dpg.set_axis_limits("xaxis_tag2", app_data[0], app_data[1]) - dpg.set_axis_limits("yaxis_tag2", app_data[2], app_data[3]) - - - # plot 1 - with dpg.plot(no_title=True, height=200, callback=query, query=True, no_menus=True, width=-1): - dpg.add_plot_axis(dpg.mvXAxis, label="x") - dpg.add_plot_axis(dpg.mvYAxis, label="y") - dpg.add_line_series(sindatax, sindatay, parent=dpg.last_item()) - - # plot 2 - with dpg.plot(no_title=True, height=200, no_menus=True, width=-1): - dpg.add_plot_axis(dpg.mvXAxis, label="x1", tag="xaxis_tag2") - dpg.add_plot_axis(dpg.mvYAxis, label="y1", tag="yaxis_tag2") - dpg.add_line_series(sindatax, sindatay, parent="yaxis_tag2") - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() \ No newline at end of file diff --git a/src/Test_Plots/test8_custom_context_menus.py b/src/Test_Plots/test8_custom_context_menus.py deleted file mode 100644 index b459d15..0000000 --- a/src/Test_Plots/test8_custom_context_menus.py +++ /dev/null @@ -1,33 +0,0 @@ -import dearpygui.dearpygui as dpg -from math import sin - -dpg.create_context() - -sindatax = [] -sindatay = [] -for i in range(0, 100): - sindatax.append(i / 100) - sindatay.append(0.5 + 0.5 * sin(50 * i / 100)) - -with dpg.window(label="Tutorial", width=400, height=400): - # create plot - dpg.add_text("Right click a series in the legend!") - with dpg.plot(label="Line Series", height=-1, width=-1): - dpg.add_plot_legend() - - dpg.add_plot_axis(dpg.mvXAxis, label="x") - dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis") - - # series 1 - dpg.add_line_series(sindatax, sindatay, label="series 1", parent="yaxis", tag="series_1") - dpg.add_button(label="Delete Series 1", parent=dpg.last_item(), callback=lambda: dpg.delete_item("series_1")) - - # series 2 - dpg.add_line_series(sindatax, sindatay, label="series 2", parent="yaxis", tag="series_2") - dpg.add_button(label="Delete Series 2", parent=dpg.last_item(), callback=lambda: dpg.delete_item("series_2")) - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() diff --git a/src/Test_Plots/test9_colors_and_styles.py b/src/Test_Plots/test9_colors_and_styles.py deleted file mode 100644 index 2f1c7ef..0000000 --- a/src/Test_Plots/test9_colors_and_styles.py +++ /dev/null @@ -1,50 +0,0 @@ -import dearpygui.dearpygui as dpg -from math import sin - -dpg.create_context() - -sindatax = [] -sindatay = [] -for i in range(0, 100): - sindatax.append(i / 100) - sindatay.append(0.5 + 0.5 * sin(50 * i / 100)) -sindatay2 = [] -for i in range(0, 100): - sindatay2.append(2 + 0.5 * sin(50 * i / 100)) - -with dpg.window(label="Tutorial", width=500, height=400): - # create a theme for the plot - with dpg.theme(tag="plot_theme"): - with dpg.theme_component(dpg.mvStemSeries): - dpg.add_theme_color(dpg.mvPlotCol_Line, (150, 255, 0), category=dpg.mvThemeCat_Plots) - dpg.add_theme_style(dpg.mvPlotStyleVar_Marker, dpg.mvPlotMarker_Diamond, category=dpg.mvThemeCat_Plots) - dpg.add_theme_style(dpg.mvPlotStyleVar_MarkerSize, 7, category=dpg.mvThemeCat_Plots) - - with dpg.theme_component(dpg.mvScatterSeries): - dpg.add_theme_color(dpg.mvPlotCol_Line, (60, 150, 200), category=dpg.mvThemeCat_Plots) - dpg.add_theme_style(dpg.mvPlotStyleVar_Marker, dpg.mvPlotMarker_Square, category=dpg.mvThemeCat_Plots) - dpg.add_theme_style(dpg.mvPlotStyleVar_MarkerSize, 4, category=dpg.mvThemeCat_Plots) - - # create plot - with dpg.plot(tag="plot", label="Line Series", height=-1, width=-1): - - # optionally create legend - dpg.add_plot_legend() - - # REQUIRED: create x and y axes - dpg.add_plot_axis(dpg.mvXAxis, label="x") - dpg.add_plot_axis(dpg.mvYAxis, label="y", tag="yaxis") - - # series belong to a y axis - dpg.add_stem_series(sindatax, sindatay, label="0.5 + 0.5 * sin(x)", parent="yaxis", tag="series_data") - dpg.add_scatter_series(sindatax, sindatay2, label="2 + 0.5 * sin(x)", parent="yaxis", tag="series_data2") - - # apply theme to series - dpg.bind_item_theme("series_data", "plot_theme") - dpg.bind_item_theme("series_data2", "plot_theme") - -dpg.create_viewport(title='Custom Title', width=800, height=600) -dpg.setup_dearpygui() -dpg.show_viewport() -dpg.start_dearpygui() -dpg.destroy_context() diff --git a/src/gui.py b/src/gui.py new file mode 100755 index 0000000..58e36a3 --- /dev/null +++ b/src/gui.py @@ -0,0 +1,213 @@ +#!/usr/bin/env python3 + +# Python stdlib +import sys + +# Grahical libraries +from dearpygui.dearpygui import * +from dearpygui.demo import show_demo + +# Detect (unix) signals +import signal + +# GNURadio tools +from gnuradio import gr + +# Mathematics +import numpy as np + +# Our interface for simulation / hardware +import qpsk + +# For debugging +import logging + +#================================================ +# Debugging tools + +logging.basicConfig(format="[%(levelname)s] %(asctime)s %(message)s", level=logging.DEBUG) +logger = logging.getLogger(__name__) + +#================================================ +# Initialize DearPyGUI + +create_context() +create_viewport() +setup_dearpygui() + +# Show demo for dev +show_demo() + +#================================================ +# Custom GNURadio blocks + +class pygui_plot_block(gr.sync_block): + def __init__(self, title="Plot", xlabel="x", ylabel="y"): + gr.sync_block.__init__(self, name="PyGUI Plot", + in_sig=[np.complex64], out_sig=None) + + self.title = title + self.xlabel = xlabel + self.ylabel = ylabel + + # TODO: parametrize with nsamples + self.buffer = np.linspace(0, 1, 1000) + + def construct_gui(self, width, height, **kwargs): + # Create plot + with plot(label=self.title, height=height, width=width, **kwargs): + add_plot_legend() + add_plot_axis(mvXAxis, label=self.xlabel) + add_plot_axis(mvYAxis, label=self.ylabel) + + def work(self, input_items, output_items): + # This is a sink (no output) + # TODO: add samples to display buffer + return 0 + + +class pygui_constellation_block(gr.sync_block): + def __init__(self, title="Constellation", xlabel="In-Phase", ylabel="Quadrature"): + gr.sync_block.__init__(self, name="PyGUI Constellation Diagram", + in_sig=[np.complex64], out_sig=None) + + self.title = title + self.xlabel = xlabel + selt.ylabel = ylabel + + def construct_gui(self, width, height, **kwargs): + # TODO: Create a widget based ons scatter plot + pass + + def work(self, input_items, output_items): + # This is a sink (no output) + # TODO: add samples to display buffer + return 0 + + +#================================================ +# GUI Callback functions + +# Flow graph window +def on_rx_node_link(sender, app_data): + link_id_1, link_id_2 = app_data + add_node_link(link_id_1, link_id_2, parent=sender) + +def on_rx_node_delink(sender, app_data): + link_id = app_data + delete_item(link_id) + +#================================================ +# Set up GNURadio simulation + +# Global variables, yes I know they are ugly +sim = qpsk.qpsk_nogui() +sim_running = False + +# Catch signals +def sim_sig_handler(sig=None, frame=None): + sim.stop() + sim.wait() + sys.exit(0) + +# TODO: create GUI handlers +signal.signal(signal.SIGINT, sim_sig_handler) +signal.signal(signal.SIGTERM, sim_sig_handler); + +# Add GUI blocks +locked_time_plot = pygui_plot_block(title="Locked signal", ylabel="Amplitude", xlabel="Time") +sim.connect((sim.digital_costas_loop_cc_0, 0), (locked_time_plot, 0)) + +#================================================ +# Settings Window + +with window(label="Settings", width=200, height=400, pos=(25, 450), tag="sim_win"): + with child_window(autosize_x=True, height=100): + add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen) + + with child_window(autosize_x=True): + with group(horizontal=True): + add_text("Simulation running:") + add_text("false", tag="sim_running_lbl") + + with group(tag="sim_grp", horizontal=True): + def on_sim_start_btn_clicked(): + global sim_running + + if sim_running: + logger.error("Simulation is already running") + return + + sim.start() + sim_running = True + logger.debug("Started simulation") + + def on_sim_stop_btn_clicked(): + global sim_running + + if not sim_running: + logger.error("Simulation not running") + return + + sim.stop() + sim.wait() + sim_running = False + logger.debug("Stopped simulation") + + add_button(label="Start", tag="sim_start_btn", callback=on_sim_start_btn_clicked) + add_button(label="Stop", tag="sim_stop_btn", callback=on_sim_stop_btn_clicked) + +#================================================ +# 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") + + with node(label="Equalizer", pos=(350,100)): + with node_attribute(tag="eq_in", attribute_type=mvNode_Attr_Input): + add_text("Input") + + with node_attribute(attribute_type=mvNode_Attr_Static): + add_knob_float(label="Gain") + + 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") + + with node_attribute(tag="pll_out", attribute_type=mvNode_Attr_Output): + add_text("Locked") + add_knob_float(label="Loop BW") + + + 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")) + +#================================================ +# Time plots Window + +with window(label="Time domain plots", width=800, height=400, pos=(850,25), tag="time_plots_win"): + locked_time_plot.construct_gui(width=780, height=300) + +#================================================ +# Start GUI + +# Start window and main loop +show_viewport() +start_dearpygui() + +# clean up gui +destroy_context() diff --git a/src/sketch.py b/src/sketch.py deleted file mode 100755 index 58e36a3..0000000 --- a/src/sketch.py +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/env python3 - -# Python stdlib -import sys - -# Grahical libraries -from dearpygui.dearpygui import * -from dearpygui.demo import show_demo - -# Detect (unix) signals -import signal - -# GNURadio tools -from gnuradio import gr - -# Mathematics -import numpy as np - -# Our interface for simulation / hardware -import qpsk - -# For debugging -import logging - -#================================================ -# Debugging tools - -logging.basicConfig(format="[%(levelname)s] %(asctime)s %(message)s", level=logging.DEBUG) -logger = logging.getLogger(__name__) - -#================================================ -# Initialize DearPyGUI - -create_context() -create_viewport() -setup_dearpygui() - -# Show demo for dev -show_demo() - -#================================================ -# Custom GNURadio blocks - -class pygui_plot_block(gr.sync_block): - def __init__(self, title="Plot", xlabel="x", ylabel="y"): - gr.sync_block.__init__(self, name="PyGUI Plot", - in_sig=[np.complex64], out_sig=None) - - self.title = title - self.xlabel = xlabel - self.ylabel = ylabel - - # TODO: parametrize with nsamples - self.buffer = np.linspace(0, 1, 1000) - - def construct_gui(self, width, height, **kwargs): - # Create plot - with plot(label=self.title, height=height, width=width, **kwargs): - add_plot_legend() - add_plot_axis(mvXAxis, label=self.xlabel) - add_plot_axis(mvYAxis, label=self.ylabel) - - def work(self, input_items, output_items): - # This is a sink (no output) - # TODO: add samples to display buffer - return 0 - - -class pygui_constellation_block(gr.sync_block): - def __init__(self, title="Constellation", xlabel="In-Phase", ylabel="Quadrature"): - gr.sync_block.__init__(self, name="PyGUI Constellation Diagram", - in_sig=[np.complex64], out_sig=None) - - self.title = title - self.xlabel = xlabel - selt.ylabel = ylabel - - def construct_gui(self, width, height, **kwargs): - # TODO: Create a widget based ons scatter plot - pass - - def work(self, input_items, output_items): - # This is a sink (no output) - # TODO: add samples to display buffer - return 0 - - -#================================================ -# GUI Callback functions - -# Flow graph window -def on_rx_node_link(sender, app_data): - link_id_1, link_id_2 = app_data - add_node_link(link_id_1, link_id_2, parent=sender) - -def on_rx_node_delink(sender, app_data): - link_id = app_data - delete_item(link_id) - -#================================================ -# Set up GNURadio simulation - -# Global variables, yes I know they are ugly -sim = qpsk.qpsk_nogui() -sim_running = False - -# Catch signals -def sim_sig_handler(sig=None, frame=None): - sim.stop() - sim.wait() - sys.exit(0) - -# TODO: create GUI handlers -signal.signal(signal.SIGINT, sim_sig_handler) -signal.signal(signal.SIGTERM, sim_sig_handler); - -# Add GUI blocks -locked_time_plot = pygui_plot_block(title="Locked signal", ylabel="Amplitude", xlabel="Time") -sim.connect((sim.digital_costas_loop_cc_0, 0), (locked_time_plot, 0)) - -#================================================ -# Settings Window - -with window(label="Settings", width=200, height=400, pos=(25, 450), tag="sim_win"): - with child_window(autosize_x=True, height=100): - add_button(label="Toggle Fullscreen", callback= toggle_viewport_fullscreen) - - with child_window(autosize_x=True): - with group(horizontal=True): - add_text("Simulation running:") - add_text("false", tag="sim_running_lbl") - - with group(tag="sim_grp", horizontal=True): - def on_sim_start_btn_clicked(): - global sim_running - - if sim_running: - logger.error("Simulation is already running") - return - - sim.start() - sim_running = True - logger.debug("Started simulation") - - def on_sim_stop_btn_clicked(): - global sim_running - - if not sim_running: - logger.error("Simulation not running") - return - - sim.stop() - sim.wait() - sim_running = False - logger.debug("Stopped simulation") - - add_button(label="Start", tag="sim_start_btn", callback=on_sim_start_btn_clicked) - add_button(label="Stop", tag="sim_stop_btn", callback=on_sim_stop_btn_clicked) - -#================================================ -# 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") - - with node(label="Equalizer", pos=(350,100)): - with node_attribute(tag="eq_in", attribute_type=mvNode_Attr_Input): - add_text("Input") - - with node_attribute(attribute_type=mvNode_Attr_Static): - add_knob_float(label="Gain") - - 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") - - with node_attribute(tag="pll_out", attribute_type=mvNode_Attr_Output): - add_text("Locked") - add_knob_float(label="Loop BW") - - - 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")) - -#================================================ -# Time plots Window - -with window(label="Time domain plots", width=800, height=400, pos=(850,25), tag="time_plots_win"): - locked_time_plot.construct_gui(width=780, height=300) - -#================================================ -# Start GUI - -# Start window and main loop -show_viewport() -start_dearpygui() - -# clean up gui -destroy_context() -- cgit v1.2.1 From b0db2314e0d43c528e4797c6f329d49742578531 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 11 Nov 2021 19:32:38 +0100 Subject: Create QAM without gui --- src/qam.py | 1 + 1 file changed, 1 insertion(+) create mode 120000 src/qam.py (limited to 'src') diff --git a/src/qam.py b/src/qam.py new file mode 120000 index 0000000..a59366b --- /dev/null +++ b/src/qam.py @@ -0,0 +1 @@ +../simulation/QAM/qam_nogui.py \ No newline at end of file -- cgit v1.2.1