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()
slider = dpg.add_slider_float(label=f'{s}', id=f'{s}', callback=update_param, user_data=s, min_value=p - 0.1, max_value=p + 0.1, width=200, default_value=p) draw_shelves(shelf, params, world, vis, steps=5) signal.signal(signal.SIGINT, handle_sigint) dpg.setup_viewport() dpg.set_viewport_width(300) dpg.set_viewport_height(200) dpg.set_viewport_title('Nobilia Test') dpg.start_dearpygui() # start = rospy.Time.now() # max_length_v = 0 # while not rospy.is_shutdown(): # state_range = shelf.joints['hinge'].limit_upper - shelf.joints['hinge'].limit_lower # state = {shelf_pos: shelf.joints['hinge'].limit_lower + (math.cos((rospy.Time.now() - start).to_sec()) + 1) * 0.5 * state_range } # world.update_world(state) # vis.begin_draw_cycle('world', 'poses', 'vectors') # vis.draw_world('world', world) # vis.draw_poses('poses', np.eye(4), 0.1, 0.01, [gm.subs(p, state) for p in debug.poses])
def configure_pygui(renderer, widgets, update=True): if not dearpygui_imported: raise RuntimeError( "Attempted to use DearPyGUI when it isn't imported.") if update: dpg.delete_item(window) else: dpg.setup_viewport() dpg.set_viewport_title(title=f"Manim Community v{__version__}") dpg.set_viewport_width(1015) dpg.set_viewport_height(540) def rerun_callback(sender, data): renderer.scene.queue.put(("rerun_gui", [], {})) def continue_callback(sender, data): renderer.scene.queue.put(("exit_gui", [], {})) def scene_selection_callback(sender, data): config["scene_names"] = (dpg.get_value(sender), ) renderer.scene.queue.put(("rerun_gui", [], {})) scene_classes = scene_classes_from_file(Path(config["input_file"]), full_list=True) scene_names = [scene_class.__name__ for scene_class in scene_classes] with dpg.window( id=window, label="Manim GUI", pos=[config["gui_location"][0], config["gui_location"][1]], width=1000, height=500, ): dpg.set_global_font_scale(2) dpg.add_button(label="Rerun", callback=rerun_callback) dpg.add_button(label="Continue", callback=continue_callback) dpg.add_combo( label="Selected scene", items=scene_names, callback=scene_selection_callback, default_value=config["scene_names"][0], ) dpg.add_separator() if len(widgets) != 0: with dpg.collapsing_header( label=f"{config['scene_names'][0]} widgets", default_open=True): for widget_config in widgets: widget_config_copy = widget_config.copy() name = widget_config_copy["name"] widget = widget_config_copy["widget"] if widget != "separator": del widget_config_copy["name"] del widget_config_copy["widget"] getattr(dpg, f"add_{widget}")(name, **widget_config_copy) else: dpg.add_separator() if not update: dpg.start_dearpygui()
def __init__(self, parent=None): self.DataPath = None self.DataStartDate = None self.StartDate = None self.WindowPositionX = None self.WindowPositionY = None self.nBeginYear = 2019 self.nBeginMonth = 1 self.nBeginDay = 1 self.nEndYear = 1970 self.nEndMonth = 1 self.nEndDay = 1 self.LoadInitFile() self.ExecuteTime = time.localtime() # TimeStr = str(self.ExecuteTime.tm_year) + "-" + str(self.ExecuteTime.tm_mon).zfill(2) + "-" + str(self.ExecuteTime.tm_mday).zfill( # 2) + " " + str(self.ExecuteTime.tm_hour).zfill(2) + ":" + str(self.ExecuteTime.tm_min).zfill(2) + ":" + str( # self.ExecuteTime.tm_sec).zfill(2) #================= UI =================. self.count = 0 if parent: self.window_id = parent else: self.window_id = dpg.add_window(label="MyApp") # print(self.window_id) dpg.set_primary_window(self.window_id, True) # window_id = dpg.window(label="MyApp") if not dpg.is_viewport_created(): vp = dpg.create_viewport(title="MyApp", width=430, height=750, x_pos=int(self.WindowPositionX), y_pos=int(self.WindowPositionY)) dpg.setup_dearpygui(viewport=vp) dpg.show_viewport(vp) dpg.set_viewport_height(950) dpg.set_viewport_width(950) # self.slider_float = dpg.add_slider_float(label="float", parent=self.window_id, width=100) # self.ID_GetWinSize = dpg.add_button(parent=self.window_id, label="GetWinSize", callback=self.callback_getwinsize ) # dpg.add_same_line(parent=self.window_id) dpg.add_text(parent=self.window_id, default_value="Time:") dpg.add_same_line(parent=self.window_id) self.ID_TimeText = dpg.add_button(parent=self.window_id, label="0", callback=self.callback_update_enddate) self.ID_BtnBeginDate = 0 self.ID_BeginDate = None self.ID_BeginDatePicker= None self.ID_BeginYear = None self.ID_BeginMonth = None self.ID_BeginDay = None self.ID_BtnEndDate = 0 self.ID_EndDate = None self.ID_EndDatePicker = None self.ID_EndYear = None self.ID_EndMonth = None self.ID_EndDay = None self.ShowInfo() self.UIBeginDate() self.UIEndDate() # dpg.add_same_line(parent=self.window_id) # self.ID_BeginDate = dpg.add_button(label="BeginDate", parent=self.window_id, callback=self.callback_begindate) self.BeginDate = datetime.strptime(self.StartDate, "%Y-%m-%d") self.EndDate = datetime.today() self.Stock = StockTool(self.DataPath, self.BeginDate, self.EndDate) self.ID_BtnDownloadData = dpg.add_button(parent=self.window_id, label="Download", callback=self.callback_downloaddata)