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 --- tests/dearpygui/test.py | 57 ++++++++++++++++++++++++++ tests/dearpygui/test10.py | 53 ++++++++++++++++++++++++ tests/dearpygui/test1_updating_series_data.py | 30 ++++++++++++++ tests/dearpygui/test2_axis_limis.py | 40 ++++++++++++++++++ tests/dearpygui/test3_custom_axis_labels.py | 34 +++++++++++++++ tests/dearpygui/test4_multiple_y_axes.py | 25 +++++++++++ tests/dearpygui/test5_annotations.py | 32 +++++++++++++++ tests/dearpygui/test6_drag_points_and_lines.py | 26 ++++++++++++ tests/dearpygui/test7_querying.py | 37 +++++++++++++++++ tests/dearpygui/test8_custom_context_menus.py | 33 +++++++++++++++ tests/dearpygui/test9_colors_and_styles.py | 50 ++++++++++++++++++++++ 11 files changed, 417 insertions(+) create mode 100644 tests/dearpygui/test.py create mode 100644 tests/dearpygui/test10.py create mode 100644 tests/dearpygui/test1_updating_series_data.py create mode 100644 tests/dearpygui/test2_axis_limis.py create mode 100644 tests/dearpygui/test3_custom_axis_labels.py create mode 100644 tests/dearpygui/test4_multiple_y_axes.py create mode 100644 tests/dearpygui/test5_annotations.py create mode 100644 tests/dearpygui/test6_drag_points_and_lines.py create mode 100644 tests/dearpygui/test7_querying.py create mode 100644 tests/dearpygui/test8_custom_context_menus.py create mode 100644 tests/dearpygui/test9_colors_and_styles.py (limited to 'tests') diff --git a/tests/dearpygui/test.py b/tests/dearpygui/test.py new file mode 100644 index 0000000..3fb0d51 --- /dev/null +++ b/tests/dearpygui/test.py @@ -0,0 +1,57 @@ +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/tests/dearpygui/test10.py b/tests/dearpygui/test10.py new file mode 100644 index 0000000..d478d9a --- /dev/null +++ b/tests/dearpygui/test10.py @@ -0,0 +1,53 @@ +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/tests/dearpygui/test1_updating_series_data.py b/tests/dearpygui/test1_updating_series_data.py new file mode 100644 index 0000000..1371008 --- /dev/null +++ b/tests/dearpygui/test1_updating_series_data.py @@ -0,0 +1,30 @@ +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/tests/dearpygui/test2_axis_limis.py b/tests/dearpygui/test2_axis_limis.py new file mode 100644 index 0000000..bdfeda1 --- /dev/null +++ b/tests/dearpygui/test2_axis_limis.py @@ -0,0 +1,40 @@ +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/tests/dearpygui/test3_custom_axis_labels.py b/tests/dearpygui/test3_custom_axis_labels.py new file mode 100644 index 0000000..be6b80b --- /dev/null +++ b/tests/dearpygui/test3_custom_axis_labels.py @@ -0,0 +1,34 @@ +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/tests/dearpygui/test4_multiple_y_axes.py b/tests/dearpygui/test4_multiple_y_axes.py new file mode 100644 index 0000000..ebaac7e --- /dev/null +++ b/tests/dearpygui/test4_multiple_y_axes.py @@ -0,0 +1,25 @@ +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/tests/dearpygui/test5_annotations.py b/tests/dearpygui/test5_annotations.py new file mode 100644 index 0000000..9deff6b --- /dev/null +++ b/tests/dearpygui/test5_annotations.py @@ -0,0 +1,32 @@ +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/tests/dearpygui/test6_drag_points_and_lines.py b/tests/dearpygui/test6_drag_points_and_lines.py new file mode 100644 index 0000000..c6d8862 --- /dev/null +++ b/tests/dearpygui/test6_drag_points_and_lines.py @@ -0,0 +1,26 @@ +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/tests/dearpygui/test7_querying.py b/tests/dearpygui/test7_querying.py new file mode 100644 index 0000000..06f3ceb --- /dev/null +++ b/tests/dearpygui/test7_querying.py @@ -0,0 +1,37 @@ +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/tests/dearpygui/test8_custom_context_menus.py b/tests/dearpygui/test8_custom_context_menus.py new file mode 100644 index 0000000..b459d15 --- /dev/null +++ b/tests/dearpygui/test8_custom_context_menus.py @@ -0,0 +1,33 @@ +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/tests/dearpygui/test9_colors_and_styles.py b/tests/dearpygui/test9_colors_and_styles.py new file mode 100644 index 0000000..2f1c7ef --- /dev/null +++ b/tests/dearpygui/test9_colors_and_styles.py @@ -0,0 +1,50 @@ +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() -- cgit v1.2.1 From bf41ed4934742edf85e9973286b04f023f660c2f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 11 Nov 2021 19:45:58 +0100 Subject: Create ZMQ test --- tests/zmq/lena512color.tiff | Bin 0 -> 786572 bytes tests/zmq/server.py | 4 ++ tests/zmq/zmqtest.grc | 112 ++++++++++++++++++++++++++++++++++++++++++++ tests/zmq/zmqtest.py | 85 +++++++++++++++++++++++++++++++++ 4 files changed, 201 insertions(+) create mode 100644 tests/zmq/lena512color.tiff create mode 100644 tests/zmq/server.py create mode 100644 tests/zmq/zmqtest.grc create mode 100755 tests/zmq/zmqtest.py (limited to 'tests') diff --git a/tests/zmq/lena512color.tiff b/tests/zmq/lena512color.tiff new file mode 100644 index 0000000..ffe5c83 Binary files /dev/null and b/tests/zmq/lena512color.tiff differ diff --git a/tests/zmq/server.py b/tests/zmq/server.py new file mode 100644 index 0000000..be4bede --- /dev/null +++ b/tests/zmq/server.py @@ -0,0 +1,4 @@ +import zmq +import pmt + +import numpy as np diff --git a/tests/zmq/zmqtest.grc b/tests/zmq/zmqtest.grc new file mode 100644 index 0000000..ad1729d --- /dev/null +++ b/tests/zmq/zmqtest.grc @@ -0,0 +1,112 @@ +options: + parameters: + author: Naoki Pross + category: '[GRC Hier Blocks]' + cmake_opt: '' + comment: '' + copyright: '' + description: '' + gen_cmake: 'On' + gen_linking: dynamic + generate_options: no_gui + hier_block_src_path: '.:' + id: zmqtest + max_nouts: '0' + output_language: python + placement: (0,0) + qt_qss_theme: '' + realtime_scheduling: '1' + run: 'True' + run_command: '{python} -u {filename}' + run_options: prompt + sizing_mode: fixed + thread_safe_setters: '' + title: ZMQ test + window_size: '' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [8, 8] + rotation: 0 + state: enabled + +blocks: +- name: samp_rate + id: variable + parameters: + comment: '' + value: '32000' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [184, 12] + rotation: 0 + state: enabled +- name: blocks_throttle_0 + id: blocks_throttle + parameters: + affinity: '' + alias: '' + comment: '' + ignoretag: 'True' + maxoutbuf: '0' + minoutbuf: '0' + samples_per_second: samp_rate + type: complex + vlen: '1' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [440, 324.0] + rotation: 0 + state: true +- name: zeromq_rep_sink_0 + id: zeromq_rep_sink + parameters: + address: '' + affinity: '' + alias: '' + comment: '' + hwm: '-1' + pass_tags: 'False' + timeout: '100' + type: complex + vlen: '1' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [664, 308.0] + rotation: 0 + state: true +- name: zeromq_req_source_0 + id: zeromq_req_source + parameters: + address: '' + affinity: '' + alias: '' + comment: '' + hwm: '-1' + maxoutbuf: '0' + minoutbuf: '0' + pass_tags: 'False' + timeout: '100' + type: complex + vlen: '1' + states: + bus_sink: false + bus_source: false + bus_structure: null + coordinate: [216, 308.0] + rotation: 0 + state: true + +connections: +- [blocks_throttle_0, '0', zeromq_rep_sink_0, '0'] +- [zeromq_req_source_0, '0', blocks_throttle_0, '0'] + +metadata: + file_format: 1 diff --git a/tests/zmq/zmqtest.py b/tests/zmq/zmqtest.py new file mode 100755 index 0000000..a046c13 --- /dev/null +++ b/tests/zmq/zmqtest.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# +# SPDX-License-Identifier: GPL-3.0 +# +# GNU Radio Python Flow Graph +# Title: ZMQ test +# Author: Naoki Pross +# GNU Radio version: 3.8.2.0 + +from gnuradio import blocks +from gnuradio import gr +from gnuradio.filter import firdes +import sys +import signal +from argparse import ArgumentParser +from gnuradio.eng_arg import eng_float, intx +from gnuradio import eng_notation +from gnuradio import zeromq + + +class zmqtest(gr.top_block): + + def __init__(self): + gr.top_block.__init__(self, "ZMQ test") + + ################################################## + # Variables + ################################################## + self.samp_rate = samp_rate = 32000 + + ################################################## + # Blocks + ################################################## + self.zeromq_req_source_0 = zeromq.req_source(gr.sizeof_gr_complex, 1, '', 100, False, -1) + self.zeromq_rep_sink_0 = zeromq.rep_sink(gr.sizeof_gr_complex, 1, '', 100, False, -1) + self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) + + + + ################################################## + # Connections + ################################################## + self.connect((self.blocks_throttle_0, 0), (self.zeromq_rep_sink_0, 0)) + self.connect((self.zeromq_req_source_0, 0), (self.blocks_throttle_0, 0)) + + + def get_samp_rate(self): + return self.samp_rate + + def set_samp_rate(self, samp_rate): + self.samp_rate = samp_rate + self.blocks_throttle_0.set_sample_rate(self.samp_rate) + + + + + +def main(top_block_cls=zmqtest, options=None): + if gr.enable_realtime_scheduling() != gr.RT_OK: + print("Error: failed to enable real-time scheduling.") + tb = top_block_cls() + + def sig_handler(sig=None, frame=None): + tb.stop() + tb.wait() + + sys.exit(0) + + signal.signal(signal.SIGINT, sig_handler) + signal.signal(signal.SIGTERM, sig_handler) + + tb.start() + + try: + input('Press Enter to quit: ') + except EOFError: + pass + tb.stop() + tb.wait() + + +if __name__ == '__main__': + main() -- cgit v1.2.1