def add_rsi_series(iw, ws, dates, ta, parent): values = ta.rsi(iw, ws) dpg.add_line_series(dates, values, label='RSI', parent=parent) dpg.add_button(label="Delete Series", user_data=dpg.last_item(), parent=dpg.last_item(), callback=lambda s, a, u: dpg.delete_item(u))
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 submit(self, parent): dpg.add_button(label=self.label, parent=parent, width=-1) dpg.set_item_theme(dpg.last_item(), _source_theme) with dpg.drag_payload(parent=dpg.last_item(), drag_data=(self, self._generator, self._data)): dpg.add_text(f"Name: {self.label}")
def create_error_window(error_text, spacer): with dpg.window(label="Error Window", modal=True, show=True, id="modal_error_id", no_title_bar=True, popup=True): dpg.add_text(error_text) dpg.add_separator() with dpg.group(horizontal=True): dpg.add_spacer(width=spacer) dpg.add_button(label="OK", width=75, callback=delete_error_popup_aliases)
def setUp(self): 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 add_ema_series(n, dates, parent, ta): ema_dates = dates[n - 1:] ema_values = ta.ema(n).to_list()[n - 1:] dpg.add_line_series(ema_dates, ema_values, label='EMA-' + str(n), parent=parent) dpg.add_button(label="Delete Series", user_data=dpg.last_item(), parent=dpg.last_item(), callback=lambda s, a, u: dpg.delete_item(u))
def setupconfig(): dpg.set_main_window_size(600, 300) dpg.set_main_window_title("Sudoku Config") dpg.add_text(name="Sudoku Config") dpg.add_slider_int(name="Basesize", default_value=c.basesize, min_value=2, max_value=5, callback="updateconfig") dpg.add_slider_float(name="Delay in ms", default_value=c.sleeptime * 1000, min_value=0, max_value=400, callback="updateconfig") # dpg.add_button(name="Print Values",callback="butcallback") dpg.add_button(name="Start Solver", callback="startPygame") dpg.add_same_line() dpg.add_button(name="Stop Pygame", callback="stopSudoku") dpg.add_button(name="Reset Grid", callback="resetGrid") dpg.add_same_line() dpg.add_button(name="Set a Grid", callback="setGridone")
def __init__(self, parent=None): self.log_level = 0 self._auto_scroll = True self.filter_id = None if parent: self.window_id = parent else: self.window_id = dpg.add_window(label="mvLogger", pos=(10, 150), width=800, height=200) self.count = 0 self.flush_count = 1000 with dpg.group(horizontal=True, parent=self.window_id): dpg.add_checkbox(label="Auto-scroll", default_value=True, callback=lambda sender: self.auto_scroll( dpg.get_value(sender))) dpg.add_button(label="Clear", callback=lambda: dpg.delete_item( self.filter_id, children_only=True)) dpg.add_input_text(label="Filter", callback=lambda sender: dpg.set_value( self.filter_id, dpg.get_value(sender)), parent=self.window_id) self.child_id = dpg.add_child(parent=self.window_id, autosize_x=True, autosize_y=True) self.filter_id = dpg.add_filter_set(parent=self.child_id) with dpg.theme() as self.trace_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (0, 255, 0, 255)) with dpg.theme() as self.debug_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (64, 128, 255, 255)) with dpg.theme() as self.info_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 255, 255)) with dpg.theme() as self.warning_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 0, 255)) with dpg.theme() as self.error_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255)) with dpg.theme() as self.critical_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255))
def _candle_plot_drop(sender, app_data, user_data): global prices global window_data if window_data.selected_ticker == '': return ta = prices[window_data.selected_ticker]['ta'] dates = (ta.data['date'].astype('int64') // 1e9).to_list() # indicator comes in app_data logger.log('adding indicator ' + app_data[0]) if app_data[0] == 'RLINES': current_price = float(exchange.symbol_ticker(window_data.selected_ticker)[window_data.selected_ticker].current) threshold = dpg.get_value(app_data[1]) / 100 min_strength = dpg.get_value(app_data[2]) resistance_lines = ta.resistance_lines_for_price(current_price, min_strength, threshold) resistance_levels = [v[0] for v in resistance_lines] resistance_strengths = [v[1] for v in resistance_lines] resistance_lines = ta.support_lines_for_price(current_price, min_strength, threshold) resistance_levels += [v[0] for v in resistance_lines] resistance_strengths += [v[1] for v in resistance_lines] logger.log(str(resistance_levels)) hlid = dpg.add_hline_series(resistance_levels, label='RLINES', parent=window_data.candle_yaxis) def delete_hl_series(s, a, u): dpg.delete_item(u) for an in window_data.rlines_annotation_ids[u]: dpg.delete_item(an) window_data.rlines_annotation_ids[u] = [] dpg.add_button(label="Delete", user_data=dpg.last_item(), parent=dpg.last_item(), callback=delete_hl_series) window_data.rlines_annotation_ids[hlid] = [] # add annotations for ri in range(len(resistance_levels)): dpg.add_plot_annotation(label=str(resistance_strengths[ri]), default_value=(dates[-1], resistance_levels[ri]), offset=(10, 0), clamped=False, parent=window_data.candle_plot) window_data.rlines_annotation_ids[hlid].append(dpg.last_item()) elif app_data[0] == 'SMA': indicators.add_sma_series(app_data[1], dates, window_data.candle_yaxis, ta) elif app_data[0] == 'EMA': indicators.add_ema_series(app_data[1], dates, window_data.candle_yaxis, ta) elif app_data[0] == 'BOLLINGER_BANDS': indicators.add_bbands_series(app_data[1], app_data[2], dates, ta, window_data.candle_yaxis) dpg.add_button(label="Delete", user_data=dpg.last_item(), parent=dpg.last_item(), callback=lambda s, a, u: dpg.delete_item(u))
def _show_gui(self): with dpg.window( tag=PRIMARY_WINDOW, width=MAIN_WINDOW_WIDTH, height=MAIN_WINDOW_HEIGHT, ): with dpg.group(horizontal=True): with dpg.child_window( width=CONTACT_LIST_WIDTH, height=MAIN_WINDOW_HEIGHT ): dpg.add_listbox( tag=CONTACT_LIST, items=self.data.histories, width=-1, num_items=len(self.data.contacts), callback=self.call_list, ) with dpg.group(horizontal=False): with dpg.group(width=-1, horizontal=True): with dpg.child_window( tag=MESSAGE_GROUP, width=-1, height=MESSAGE_WINDOW_HEIGHT ): dpg.add_text("No message yet") dpg.add_text(tag=STATUS_LABEL, label="", color=COLOR_ACCENT) dpg.add_input_text( default_value="", multiline=True, label="", tag=MESSAGE_INPUT, width=-1, height=MESSAGE_INPUT_HEIGHT, hint="Write...", callback=self.call_write, ) with dpg.group(horizontal=True): dpg.add_button( label="Send", width=100, callback=self.call_send_button, user_data=False, ) dpg.add_button( label="Send To All", width=100, callback=self.call_send_button, user_data=True, # send all )
def submit(self, parent): with dpg.node(parent=parent, label=self.label, id=self.uuid): with dpg.node_attribute(attribute_type=dpg.mvNode_Attr_Static): dpg.add_button(label="Execute", user_data=self, callback=lambda s, a, u: u.execute()) for attribute in self._input_attributes: attribute.submit(self.uuid) with dpg.node_attribute(parent=self.uuid, attribute_type=dpg.mvNode_Attr_Static, user_data=self, id=self.static_uuid): self.custom() for attribute in self._output_attributes: attribute.submit(self.uuid)
def _ticker_list(parent_id): # dpg.add_text("TICKER LIST") with dpg.filter_set(parent=parent_id) as filter_id: filter_container = dpg.last_container() for ticker in tickers: with dpg.group(filter_key=ticker, horizontal=True): item = dpg.last_item() dpg.add_button(label=ticker, user_data=ticker, callback=lambda s, a, u: logger.log_info(u)) dpg.set_item_theme(dpg.last_item(), button_themes[2]) tick = exchange.symbol_ticker(ticker)[ticker] dpg.add_text("%.2f %s" % (float(tick.current), tick.currency)) with dpg.drag_payload(parent=item, drag_data=ticker, payload_type='main_window'): dpg.add_text('asdfasf') dpg.add_input_text(parent=parent_id, label="", before=filter_container, user_data=filter_container, callback=lambda s, a, u: dpg.set_value(u, a))
def edit_ssh_info(): global ssh_table global parent_id with dpg.window(label='ssh info editor', width=800, height=500, on_close=on_close): with dpg.group(horizontal=True): dpg.add_button(label='Add ssh server', callback=add_ssh_server_row) dpg.add_button(label='Remove ssh server', callback=remove_ssh_server_rows) ssh_table = Table( 'ssh info editor', ['', 'ID', 'Name', 'IP', 'Port', 'username', 'password'], parent_id)
def sma(): with dpg.child(width=200, height=70): item = dpg.add_button(label='SMA') dpg.set_item_theme(dpg.last_item(), button_themes[5]) dpg.add_same_line() i = dpg.add_input_int(default_value=3, label='', width=70) dpg.add_button(label='SMA200') dpg.set_item_theme(dpg.last_item(), button_themes[4]) with dpg.tooltip(dpg.last_item()): dpg.add_text('Media Movel de 200 dias') with dpg.drag_payload(parent=dpg.last_item(), drag_data=('SMA', 200), payload_type='candle_plot'): dpg.add_text('SMA200') dpg.add_same_line() dpg.add_button(label='SMA50') dpg.set_item_theme(dpg.last_item(), button_themes[3]) with dpg.drag_payload(parent=dpg.last_item(), drag_data=('SMA', 50), payload_type='candle_plot'): dpg.add_text('SMA50') dpg.add_same_line() dpg.add_button(label='SMA7') dpg.set_item_theme(dpg.last_item(), button_themes[2]) with dpg.drag_payload(parent=dpg.last_item(), drag_data=('SMA', 7), payload_type='candle_plot'): dpg.add_text('SMA7') with dpg.drag_payload(parent=item, drag_data=('SMA', dpg.get_value(i)), payload_type='candle_plot'): dpg.add_text('SMA')
def add_bbands_series(w, s, dates, ta, parent): values = ta.bollinger_bands(w, s) bbdates = dates[w - 1:] upper_band = values[1].to_list()[w - 1:] lower_band = values[2].to_list()[w - 1:] with dpg.theme() as b_theme: dpg.add_theme_color(dpg.mvPlotCol_Fill, (100, 100, 150, 64), category=dpg.mvThemeCat_Plots) dpg.add_shade_series(bbdates, upper_band, y2=lower_band, label="BBANDS", parent=parent) dpg.set_item_theme(dpg.last_item(), b_theme) dpg.add_button(label="Delete Series", user_data=dpg.last_item(), parent=dpg.last_item(), callback=lambda s, a, u: dpg.delete_item(u))
def set_table_data(tag, data): clear_table(tag) for i, record in enumerate(data): with table_row(parent=tag, tag=f'row_{i}'): add_button(label=record[0], callback=lambda: cb_table_result_selected(f'row_{i}')) add_button(label=', '.join(load_tags_from_id_database(record[0])), callback=lambda: cb_table_result_selected(f'row_{i}')) add_button(label=record[2], callback=lambda: cb_table_result_selected(f'row_{i}')) add_button(label=record[3], callback=lambda: cb_table_result_selected(f'row_{i}'))
def init(self, parent): self.window_id = parent with dpg.group(horizontal=True, parent=self.window_id): dpg.add_checkbox(label="Auto-scroll", default_value=True, callback=lambda sender: self.auto_scroll( dpg.get_value(sender))) dpg.add_same_line() dpg.add_button(label="Clear", callback=lambda: dpg.delete_item( self.filter_id, children_only=True)) dpg.add_same_line() dpg.add_input_text(label="Filter", callback=lambda sender: dpg.set_value( self.filter_id, dpg.get_value(sender))) self.child_id = dpg.add_child(parent=self.window_id, autosize_x=True, autosize_y=True) self.filter_id = dpg.add_filter_set(parent=self.child_id)
def __init__(self): self.log_level = 0 self._auto_scroll = True self.filter_id = None self.window_id = dpg.add_window(label="mvLogger", pos=(200, 200), width=500, height=500) self.count = 0 self.flush_count = 1000 self.level_options = {"Trace": 0, "Debug": 1, "Info": 2, "Warning": 3, "Error": 4, "Critical": 5} with dpg.group(horizontal=True, parent=self.window_id): dpg.add_checkbox(label="Auto-scroll", default_value=True, callback=lambda sender: self.auto_scroll(dpg.get_value(sender))) dpg.add_button(label="Clear", callback=lambda: dpg.delete_item(self.filter_id, children_only=True)) dpg.add_input_text(label="Filter", callback=lambda sender: dpg.set_value(self.filter_id, dpg.get_value(sender)), parent=self.window_id) dpg.add_radio_button(list(self.level_options.keys()), parent=self.window_id, callback=lambda sender: self.set_level(self.level_options[dpg.get_value(sender)])) dpg.add_same_line(parent=self.window_id) self.child_id = dpg.add_child(parent=self.window_id, autosize_x=True, autosize_y=True) self.filter_id = dpg.add_filter_set(parent=self.child_id) with dpg.theme() as self.trace_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (0, 255, 0, 255)) with dpg.theme() as self.debug_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (64, 128, 255, 255)) with dpg.theme() as self.info_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 255, 255)) with dpg.theme() as self.warning_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 255, 0, 255)) with dpg.theme() as self.error_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255)) with dpg.theme() as self.critical_theme: dpg.add_theme_color(dpg.mvThemeCol_Text, (255, 0, 0, 255))
def rlines(): with dpg.child(width=200, height=90): item = dpg.add_button(label='RLINES') dpg.set_item_theme(dpg.last_item(), button_themes[5]) with dpg.tooltip(dpg.last_item()): dpg.add_text('Linhas de Resistencia') s = dpg.add_slider_float(label='%', default_value=2, min_value=0.1, max_value=5) i = dpg.add_input_int(default_value=0, label='') with dpg.drag_payload(parent=item, drag_data=('RLINES', s, i), payload_type='candle_plot'): dpg.add_text('RLINES')
def rsi(): with dpg.child(width=200, height=90): item = dpg.add_button(label='RSI') dpg.set_item_theme(dpg.last_item(), button_themes[5]) i = dpg.add_slider_int(default_value=14, label='', min_value=3, max_value=200) j = dpg.add_slider_float(default_value=24, label='', min_value=3, max_value=200) with dpg.drag_payload(parent=item, drag_data=('RSI', i, j), payload_type='volume_plot'): dpg.add_text('RSI')
def bbands(): with dpg.child(width=200, height=95): item = dpg.add_button(label='BOLLINGER BANDS') dpg.set_item_theme(dpg.last_item(), button_themes[5]) i = dpg.add_slider_int(default_value=10, label='', min_value=3, max_value=200) j = dpg.add_slider_float(default_value=5, label='', min_value=1, max_value=5) with dpg.drag_payload(parent=item, drag_data=('BOLLINGER_BANDS', dpg.get_value(i), dpg.get_value(j)), payload_type='candle_plot'): dpg.add_text('BOLLINGER BANDS')
def UIBeginDate(self): # dpg.add_text("BeginDate(yyyy/mm/dd):", parent=self.window_id ) self.ID_BtnBeginDate = dpg.add_button(parent=self.window_id, label="BeginDate(yyyy/mm/dd):", callback=self.callback_begindate) dpg.add_same_line(parent=self.window_id) dpg.add_text(" ", parent=self.window_id) dpg.add_same_line(parent=self.window_id) self.ID_BeginYear = dpg.add_input_text(parent=self.window_id, label="", decimal=True, width=40, callback=self.callback_inputtext) dpg.add_same_line(parent=self.window_id) dpg.add_text("/", parent=self.window_id) dpg.add_same_line(parent=self.window_id) self.ID_BeginMonth = dpg.add_input_text(parent=self.window_id, label="", decimal=True, width=20, callback=self.callback_inputtext) dpg.add_same_line(parent=self.window_id) dpg.add_text("/", parent=self.window_id) dpg.add_same_line(parent=self.window_id) self.ID_BeginDay = dpg.add_input_text(parent=self.window_id, label="", decimal=True, width=20, callback=self.callback_inputtext) dpg.set_value(self.ID_BeginYear, self.nBeginYear) dpg.set_value(self.ID_BeginMonth, self.nBeginMonth) dpg.set_value(self.ID_BeginDay, self.nBeginDay)
def UIEndDate(self): # dpg.add_text("EndDate(yyyy/mm/dd): ", parent=self.window_id ) # 取得當前時間. self.ID_BtnEndDate = dpg.add_button(parent=self.window_id, label="EndDate (yyyy/mm/dd):", callback=self.callback_enddate) dpg.add_same_line(parent=self.window_id) dpg.add_text(" ", parent=self.window_id) dpg.add_same_line(parent=self.window_id) self.ID_EndYear = dpg.add_input_text(parent=self.window_id, label="", decimal=True, width=40, callback=self.callback_inputtext) dpg.add_same_line(parent=self.window_id) dpg.add_text("/", parent=self.window_id) dpg.add_same_line(parent=self.window_id) self.ID_EndMonth = dpg.add_input_text(parent=self.window_id, label="", decimal=True, width=20, callback=self.callback_inputtext) dpg.add_same_line(parent=self.window_id) dpg.add_text("/", parent=self.window_id) dpg.add_same_line(parent=self.window_id) self.ID_EndDay = dpg.add_input_text(parent=self.window_id, label="", decimal=True, width=20, callback=self.callback_inputtext) dpg.set_value(self.ID_EndYear, self.ExecuteTime.tm_year) dpg.set_value(self.ID_EndMonth, self.ExecuteTime.tm_mon) dpg.set_value(self.ID_EndDay, self.ExecuteTime.tm_mday)
def file_dialog(self, tag, bind): with dpg.file_dialog( label="Demo File Dialog", width=800, height=600, show=False, callback=callback_file, tag="__demo_filedialog", user_data=bind, ): dpg.add_file_extension(".*", color=(255, 255, 255, 255)) dpg.add_file_extension( "Source files (*.cpp *.h *.hpp){.cpp,.h,.hpp}", color=(0, 255, 255, 255)) dpg.add_file_extension(".txt", color=(255, 255, 0, 255)) dpg.add_file_extension(".gif", color=(255, 0, 255, 255), custom_text="header") dpg.add_file_extension(".py", color=(0, 255, 0, 255)) item = dpg.add_button(label="Show File Selector", user_data=dpg.last_container(), callback=callback_dvd) self.item[tag] = item
def create_node_selector_window(): with dpg.window(label='Node Selector', pos=[10, 60], width=300, height=890) as node_selector: # Create the window of the Node selector node_tree = generate_node_tree() base_id = node_tree[0][0] base_name = node_tree[0][1] with dpg.tree_node(label=base_name, parent=node_selector, default_open=True, id=base_id, open_on_arrow=True): # Read what *_com files exist in the Heron/Operations dir and sub dirs and create the correct # tree_node widget for parent_id, parent, node_id, node in node_tree: with dpg.tree_node(label=node, parent=parent_id, default_open=True, id=node_id): for op in operations_list: if node == op.parent_dir: colour = gu.choose_color_according_to_operations_type(node) button = dpg.add_button(label=op.name, width=200, height=30, callback=on_add_node) with dpg.theme() as theme_id: with dpg.theme_component(0): dpg.add_theme_color(dpg.mvThemeCol_Button, colour, category=dpg.mvThemeCat_Core) dpg.add_theme_style(dpg.mvStyleVar_FrameRounding, 5, category=dpg.mvThemeCat_Core) dpg.bind_item_theme(button, theme_id) return node_selector
https://hub.fastgit.org/Pcothren/DearPyGui-Examples """ dpg.show_style_editor() def save_callback(sender, app_data, user_data): print(dpg) print("Save Clicked") for i in dpg.get_all_items(): print(i) print(sender, app_data, user_data, dpg.get_value(2)) print(sender, app_data, user_data, dpg.get_value(3)) print(sender, app_data, user_data, dpg.get_value(4)) print(sender, app_data, user_data, dpg.get_value(21)) with dpg.window(id=0, label="Example Window By LC", width=500, height=500): dpg.add_text(id=1, label="Hello world Hello LC", show_label=True) # label – 覆盖“name”作为标签。 # id – 用于以编程方式引用项目的唯一 id。如果标签未使用,这将是标签 text_input = dpg.add_input_text(id=2, label="MyInput") text_slider = dpg.add_slider_float(id=3, label="MySlider") text_input2 = dpg.add_input_text(id=4, label="name", default_value="LC") dpg.add_button(id=5, label="Save", callback=save_callback, user_data=text_input) dpg.setup_viewport() dpg.start_dearpygui()
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 log_warning(self, message): self._log(message, 3) def log_error(self, message): self._log(message, 4) def log_critical(self, message): self._log(message, 5) def clear_log(self): dpg.delete_item(self.filter_id, children_only=True) self.count = 0 def set_level(self, level): self.log_level = level def log_things(sender, app_data, user_data): user_data.log("We can log to a trace level.") user_data.log_debug("We can log to a debug level.") user_data.log_info("We can log to an info level.") user_data.log_warning("We can log to a warning level.") user_data.log_error("We can log to a error level.") user_data.log_critical("We can log to a critical level.") with dpg.window(): logger = MyCustomLogger() logger.log("This is my logger. Just like an onion it has many levels.") dpg.add_button(label="Log to logger", callback=log_things, user_data=logger) dpg.start_dearpygui()
import dearpygui.dearpygui as dpg dpg.create_context() with dpg.window(label="Tutorial"): dpg.add_button(label="Button 1") dpg.add_button(label="Button 2") with dpg.group(): dpg.add_button(label="Button 3") dpg.add_button(label="Button 4") with dpg.group() as group1: pass dpg.add_button(label="Button 6", parent=group1) dpg.add_button(label="Button 5", parent=group1) dpg.create_viewport(title='Custom Title', width=600, height=400) dpg.setup_dearpygui() dpg.show_viewport() dpg.start_dearpygui() dpg.destroy_context()
def __setup_add_widget__(self, dpg_args) -> None: dpgcore.add_button(self.id, **dpg_args)