def run_gui(csr_csv, port): import dearpygui.dearpygui as dpg bus = RemoteClient(csr_csv=csr_csv, port=port) bus.open() def reboot_callback(): bus.regs.ctrl_reset.write(1) bus.regs.ctrl_reset.write(0) dpg.create_context() dpg.create_viewport(title="LiteX CLI GUI", max_width=800, always_on_top=True) dpg.setup_dearpygui() with dpg.window(autosize=True): dpg.add_text("Control/Status") dpg.add_button(label="Reboot", callback=reboot_callback) def filter_callback(sender, filter_str): dpg.set_value("csr_filter", filter_str) dpg.add_input_text(label="CSR Filter (inc, -exc)", callback=filter_callback) dpg.add_text("CSR Registers:") with dpg.filter_set(id="csr_filter"): def reg_callback(tag, data): for name, reg in bus.regs.__dict__.items(): if (tag == name): try: reg.write(int(data, 0)) except: pass for name, reg in bus.regs.__dict__.items(): dpg.add_input_text(indent=16, label=f"0x{reg.addr:08x} - {name}", tag=name, filter_key=name, callback=reg_callback, on_enter=True, width=200) def timer_callback(refresh=1e-1): while True: for name, reg in bus.regs.__dict__.items(): value = reg.read() dpg.set_value(item=name, value=f"0x{reg.read():x}") time.sleep(refresh) timer_thread = threading.Thread(target=timer_callback) timer_thread.start() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() bus.close()
def run(self, app): title = "celestine - PyPI" dpg.create_context() dpg.create_viewport(title=title, small_icon="celestine_small.ico", large_icon="celestine_large.ico", width=1920, height=1080, x_pos=256, y_pos=256, min_width=640, max_width=3840, min_height=480, max_height=2160, resizable=True, vsync=True, always_on_top=False, decorated=True, clear_color=(0, 0, 0)) with dpg.texture_registry(show=False): app.setup(self) with dpg.window(tag="primary_window"): app.view(self) dpg.setup_dearpygui() dpg.show_viewport(minimized=False, maximized=False) dpg.set_primary_window("primary_window", True) dpg.start_dearpygui() dpg.destroy_context()
def start_dpg(): """ The outside loop runs forever and blocks when the dpg.start_dearpygui() is called. When the plot_callback() calls dpg.stop_dearpygui() then it continues running forever until the visualisation_on turns on at which point the start_dearpygui is called again and this blocks :return: Nothing """ global visualisation_type global visualiser_showing global is_dearpygui_running global dpg_ids global initialised_plots is_dearpygui_running = True initialised_plots = False dpg.create_context() dpg.create_viewport(title='Visualising', width=330, height=280) with dpg.window(label="Visualisation", show=True) as dpg_ids['Visualisation']: if visualisation_type == 'Value': dpg_ids['Text'] = dpg.add_text(default_value='__start__', label='Value') dpg.set_item_width(dpg_ids['Visualisation'], 300) dpg.set_item_height(dpg_ids['Visualisation'], 250) elif visualisation_type == 'Single Pane Plot': dpg.set_viewport_width(1050) dpg.set_viewport_height(770) dpg.set_item_width(dpg_ids['Visualisation'], 1050) dpg.set_item_height(dpg_ids['Visualisation'], 770) with dpg.plot(label="Plot", height=700, width=1000, show=True, pan_button=True, fit_button=True) as dpg_ids['Plot 0']: dpg_ids['x_axis'] = dpg.add_plot_axis(dpg.mvXAxis, label="Data index") dpg_ids['y_axis'] = dpg.add_plot_axis(dpg.mvYAxis, label="Data") elif visualisation_type == 'Multi Pane Plot': dpg.set_viewport_width(1050) dpg.set_viewport_height(850) dpg.set_item_width(dpg_ids['Visualisation'], 1050) dpg.set_item_height(dpg_ids['Visualisation'], 820) dpg.set_viewport_resize_callback(on_resize_viewport) dpg.setup_dearpygui() dpg.show_viewport() visualiser_showing = True if data is not None: update_dpg_gui() dpg.start_dearpygui() dpg.destroy_context()
def setUp(self): dpg.create_context() with dpg.window() as self.window_id: self.item1 = dpg.add_button(label="item1") self.item2 = dpg.add_button(label="item2") self.item3 = dpg.add_button(label="item3") self.item4 = dpg.add_button(label="item4") self.item5 = dpg.add_button(label="item5") dpg.setup_dearpygui()
def show(self): dpg.create_context() dpg.create_viewport( title="MQTT Message Chat (me: " + self.data.myself + ")", width=MAIN_WINDOW_WIDTH, height=MAIN_WINDOW_HEIGHT, ) dpg.setup_dearpygui() self._show_gui() dpg.show_viewport() dpg.set_primary_window(PRIMARY_WINDOW, True) while dpg.is_dearpygui_running(): self.main_callback() dpg.render_dearpygui_frame() dpg.destroy_context()
def run(self): # -------------------------------------------------- 01 # make sure if was already called if self.internal.has("is_run_called"): raise e.code.NotAllowed( msgs=[ f"You can run only once ..." ] ) # -------------------------------------------------- 02 # setup dpg _pyc_debug = settings.PYC_DEBUGGING dpg.create_context() dpg.configure_app(manual_callback_management=_pyc_debug) dpg.create_viewport() dpg.setup_dearpygui() # -------------------------------------------------- 03 # setup and layout _LOGGER.info(msg="Setup and layout dashboard ...") self.setup() self.layout() # -------------------------------------------------- 04 # call build and indicate build is done _LOGGER.info(msg="Building dashboard ...") self.build() self.internal.is_run_called = True # -------------------------------------------------- 05 # dpg related dpg.show_viewport() if _pyc_debug: if not internal_dpg.is_viewport_ok(): raise RuntimeError("Viewport was not created and shown.") while internal_dpg.is_dearpygui_running(): # add this extra line for callback debug # https://pythonrepo.com/repo/hoffstadt-DearPyGui-python-graphical-user-interface-applications dpg.run_callbacks(dpg.get_callback_queue()) internal_dpg.render_dearpygui_frame() else: dpg.start_dearpygui() dpg.destroy_context()
def demo(): """ Refer >>> from dearpygui import demo """ dpg.create_context() dpg.create_viewport() dpg.setup_dearpygui() _demo.show_demo() # with dpg.window(label="Dear PyGui Demo", width=800, height=800, # pos=(100, 100), tag="__demo_id"): # with dpg.collapsing_header(label="some label", default_open=True,): # dpg.add_text(default_value="Some text") dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context()
def try_dpg_children(_dpg_def: DpgDef, _all_dpg_defs: t.List[DpgDef]): dpg.create_context() dpg.create_viewport() dpg.setup_dearpygui() with dpg.window(label="Dear PyGui Demo", width=800, height=800, pos=(100, 100), tag="__demo_id") as w1: _ret = [] if _dpg_def.is_container: with _dpg_def.fn() as _dpg_id: for _child_dpg_def in _all_dpg_defs: try: _child_dpg_def.fn_fake_call(parent=_dpg_id) _ret.append(_child_dpg_def) except Exception: ... dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context() return _ret
import dearpygui.dearpygui as dpg import dearpygui.demo as demo from dearpygui_ext.logger import mvLogger dpg.create_context() #dpg.configure_app(manual_callback_management=True) dpg.create_viewport() dpg.setup_dearpygui() log = mvLogger() log.log("log") log.log_debug("log debug") log.log_info("log info") log.log_warning("log warning") log.log_error("log error") log.log_critical("log critical") with dpg.font_registry(): with dpg.font("../../Resources/NotoSerifCJKjp-Medium.otf", 20, tag="custom font"): dpg.add_font_range_hint(dpg.mvFontRangeHint_Default) dpg.bind_font(dpg.last_container()) demo.show_demo() # main loop dpg.show_viewport() while dpg.is_dearpygui_running(): #dpg.run_callbacks(dpg.get_callback_queue()) dpg.render_dearpygui_frame()
def main(port): # Should be configurable or whatever, for the other pad protocols serial = SerialProtoGF('/dev/ttyACM0') # Fetch the pad config / base settings # [panel no] = list[sensor indices] panel_mapping = get_panel_mapping(serial) trigger_values = serial.command_get_trigger_values() schmitt_values = serial.command_get_trigger_schmitt_values() dpg.create_context() dpg.create_viewport(title="ITGaz's Awesome Pad GUI", width=800, height=600, resizable=False, decorated=True) dpg.setup_dearpygui() vals_raw = [0 for x in trigger_values] with dpg.window(label="", width=800, height=600, no_resize=True, no_title_bar=True, no_move=True): dpg.add_text("LEFT:") with dpg.group(horizontal=True): for s in panel_mapping[PANEL_P1LEFT]: dpg.add_slider_float(no_input=True, vertical=False, tag=f"sensorbar_{s}", width=300) dpg.add_checkbox(tag=f"sensortriggered_{s}") dpg.add_text("DOWN:") with dpg.group(horizontal=True): for s in panel_mapping[PANEL_P1DOWN]: dpg.add_slider_float(no_input=True, vertical=False, tag=f"sensorbar_{s}", width=300) dpg.add_checkbox(tag=f"sensortriggered_{s}") dpg.add_text("UP:") with dpg.group(horizontal=True): for s in panel_mapping[PANEL_P1UP]: dpg.add_slider_float(no_input=True, vertical=False, tag=f"sensorbar_{s}", width=300) dpg.add_checkbox(tag=f"sensortriggered_{s}") dpg.add_text("RIGHT:") with dpg.group(horizontal=True): for s in panel_mapping[PANEL_P1RIGHT]: dpg.add_slider_float(no_input=True, vertical=False, tag=f"sensorbar_{s}", width=300) dpg.add_checkbox(tag=f"sensortriggered_{s}") dpg.show_viewport() # dpg.start_dearpygui() while dpg.is_dearpygui_running(): vals_raw = serial.command_get_values_raw() vals_raw_min = serial.command_get_values_raw_min() vals_filtered = serial.command_get_values_filtered() triggered = serial.command_get_triggered() for s, v in enumerate(vals_filtered): slider_tag = f"sensorbar_{s}" triggered_tag = f"sensortriggered_{s}" # slider_config = dpg.get_item_configuration(tag) slider_min = 0 slider_max = 1024 # slider_min = min(slider_config['min_value'], vals_raw_min[s]) # slider_max = max(slider_config['max_value'], vals_raw[s]) dpg.configure_item(slider_tag, min_value=slider_min, max_value=slider_max) dpg.set_value(slider_tag, v) dpg.set_value(triggered_tag, triggered[s]) # render_ui(panel_mapping, trigger_values, schmitt_values, vals_raw, vals_raw_min, vals_filtered, triggered) dpg.render_dearpygui_frame() time.sleep(0.05) dpg.destroy_context()
def setUp(self): dpg.create_context() with dpg.window() as self.window_id: def testy(sender, app, user): print(f"Sender: {dpg.get_item_type(sender)} {sender}, App Data: {app}, User Data:{user}") # Menus with dpg.menu_bar() as menu_bar: dpg.add_menu_item(label="menu item", payload_type="str", drop_callback=testy) with dpg.menu(label="menu", payload_type="str", drop_callback=testy): dpg.add_menu_item(label="menu item") # basic with dpg.collapsing_header(label="basic") as basic: dpg.add_image(dpg.mvFontAtlas) dpg.add_image_button(dpg.mvFontAtlas) dpg.add_text("this is a text widget") dpg.add_checkbox(label="checkbox") dpg.add_button(label="button") dpg.add_input_float(label="input float") dpg.add_input_floatx(label="input floatx") dpg.add_drag_int(label="drag int") dpg.add_drag_intx(label="drag intx") dpg.add_input_text(label="input text") dpg.add_slider_float(label="slider float") dpg.add_slider_floatx(label="slider floatx") dpg.add_listbox(label="listbox") dpg.add_selectable(label="selectable") dpg.add_radio_button(["item 1", "item 2"],label="radio button") # color with dpg.collapsing_header(label="color") as color: with dpg.group() as color: dpg.add_color_button([255,0,0,255]) dpg.add_color_edit([255,0,0,255]) dpg.add_colormap_button(label="Colormap Button 1") dpg.add_color_picker((255, 0, 255, 255), label="Color Picker", width=200) dpg.add_colormap_slider(label="Colormap Slider 1", default_value=0.5, payload_type="str", drop_callback=testy) dpg.add_colormap_scale(label="Colormap Spectral", min_scale=-100, max_scale=150, payload_type="str", drop_callback=testy) # containers with dpg.collapsing_header(label="containers"): with dpg.group() as containers: with dpg.collapsing_header(): btn = dpg.add_button() with dpg.group(width=150): dpg.add_button() with dpg.tree_node(): dpg.add_button() with dpg.child_window(width=150, height=100, payload_type="str", drop_callback=testy): pass # tab stuff with dpg.collapsing_header(label="tab bars"): with dpg.tab_bar(): with dpg.tab(label="tab", payload_type="str", drop_callback=testy): pass dpg.add_tab_button(label="tab button", payload_type="str", drop_callback=testy, drag_callback=testy) with dpg.drag_payload(parent=dpg.last_item(), drop_data="dropped", drag_data="dragged", user_data="user data", payload_type="str"): dpg.add_text(dpg.get_item_type(dpg.last_item())) dpg.add_text(f"Item ID: {dpg.last_item()}") # custom with dpg.collapsing_header(label="custom"): with dpg.group() as custom: dpg.add_date_picker() dpg.add_knob_float() dpg.add_3d_slider() dpg.add_time_picker() dpg.add_loading_indicator(payload_type="str", drop_callback=testy) # misc with dpg.collapsing_header(label="misc"): with dpg.group() as misc: dpg.add_progress_bar(label="progress bar", default_value=.5) # node with dpg.collapsing_header(label="node"): with dpg.node_editor() as node: with dpg.node(pos=[20,20], draggable=False): pass with dpg.node(pos=[100,100], draggable=False): pass # plots with dpg.collapsing_header(label="plot") as plot: with dpg.plot(): dpg.add_plot_legend(payload_type="str", drop_callback=testy) dpg.add_plot_axis(dpg.mvXAxis, label="x", payload_type="str", drop_callback=testy) with dpg.plot_axis(dpg.mvYAxis, label="y", payload_type="str", drop_callback=testy): dpg.add_line_series([0,1,2,3,4,5], [0,1,2,3,4,5], label="data") self.test_bind_items = dpg.get_item_children(basic, slot=1) self.test_bind_items += dpg.get_item_children(color, slot=1) self.test_bind_items += dpg.get_item_children(containers, slot=1) self.test_bind_items += dpg.get_item_children(custom, slot=1) self.test_bind_items += dpg.get_item_children(misc, slot=1) self.test_bind_items += dpg.get_item_children(node, slot=1) self.test_bind_items += dpg.get_item_children(plot, slot=1) dpg.setup_dearpygui()