def get_attribute_id_from_label(label): all_editors_children = dpg.get_item_children(node_editor, 1) for node_id in all_editors_children: all_nodes_childern = dpg.get_item_children(node_id, slot=1) for child_id in all_nodes_childern: child_label = dpg.get_item_label(child_id) if child_label == label: return child_id
def clear_editor(): """ Clear the editor of all nodes and links :return: Nothing """ global nodes_list if dpg.get_item_children(node_editor, slot=1): for n in dpg.get_item_children(node_editor, slot=1): dpg.delete_item(n) for a in dpg.get_aliases(): dpg.remove_alias(a) nodes_list = []
def on_add_node(sender, data): """ The callback that creates a Heron.gui.node.Node in the node editor for the operation defined by the button calling the callback. :param sender: The button's node_name :param data: Not used :return: Nothing """ sender_name = dpg.get_item_label(sender) # Get corresponding operation operation = None for op in operations_list: if op.name == sender_name: operation = op break # Find how many other nodes there are already on the editor for the same operation num_of_same_nodes = 0 all_nodes = dpg.get_item_children(node_editor)[1] for n in all_nodes: name = dpg.get_item_label(n) if operation.name in name: num_of_same_nodes = num_of_same_nodes + 1 # Create the Node name = operation.name + '##{}'.format(num_of_same_nodes) n = Node(name=name, parent=node_editor) n.spawn_node_on_editor() n.starting_port = next(port_generator) nodes_list.append(n)
def iter_children(self) -> Iterable[ItemWidget]: """Iterates all of the item's children.""" children = dpgcore.get_item_children(self.id) if not children: return for child in children: yield get_item_by_id(child)
def _unregister_item(widget_id: int, unregister_children: bool = True) -> None: _ITEM_LOOKUP.pop(widget_id, None) if unregister_children: children = dpgcore.get_item_children(widget_id) if children is not None: for child_id in children: _unregister_item(child_id, True)
def test_moving_items(self): children = dpg.get_item_children(self.window_id, 1) dpg.move_item_down(self.item3) dpg.move_item_up(self.item2) dpg.move_item_up(self.item2) dpg.move_item_down(self.item5) children = dpg.get_item_children(self.window_id, 1) self.assertTrue(children[0] == self.item2) self.assertTrue(children[1] == self.item1) self.assertTrue(children[2] == self.item4) self.assertTrue(children[3] == self.item3) self.assertTrue(children[4] == self.item5) dpg.move_item(self.item5, before=self.item2) children = dpg.get_item_children(self.window_id, 1) self.assertTrue(children[0] == self.item5) self.assertTrue(children[1] == self.item2) self.assertTrue(children[2] == self.item1) self.assertTrue(children[3] == self.item4) self.assertTrue(children[4] == self.item3)
def resize_r(node, w, h): def _compute_value(input_value, total_size): if input_value < 0: return total_size + input_value if input_value > 1: return input_value return int(input_value * total_size) label = dpg.get_item_label(node) if label in layout: if layout[label][0] != 0: dpg.set_item_width(node, _compute_value(layout[label][0], w)) if layout[label][1] != 0: dpg.set_item_height(node, _compute_value(layout[label][1], h)) children = dpg.get_item_children(node) for item, value in children.items(): if len(value): for v in value: resize_r(v, w, h)
def _ticker_drop(sender, app_data, user_data): global window_data global prices # update data window_data.selected_ticker = app_data if app_data == '': return dpg.set_value(window_data.main_window_title, 'Ticker: ' + window_data.selected_ticker) # clean plots for i in dpg.get_item_children(window_data.candle_yaxis)[1]: dpg.delete_item(i) if window_data.volume_unit_yaxis != 0: dpg.delete_item(window_data.volume_unit_yaxis) for i in dpg.get_item_children(window_data.volume_yaxis)[1]: dpg.delete_item(i) # load data start_date = datetime(year=2021, month=6, day=29) end_date = datetime(year=2021, month=6, day=30) end_date = datetime.now() start_date = end_date - timedelta(days=7) if window_data.period == '1y': start_date = end_date - timedelta(days=365) elif window_data.period == '6m': start_date = end_date - timedelta(days=182) elif window_data.period == '1m': start_date = end_date - timedelta(days=30) elif window_data.period == '1w': start_date = end_date - timedelta(days=7) elif window_data.period == '1d': start_date = end_date - timedelta(days=1) # current price window_data.current_price = float( exchange.symbol_ticker(window_data.selected_ticker)[window_data.selected_ticker].current) # candle history prices = exchange.historical_candle_series([window_data.selected_ticker], start_date, end_date, window_data.interval) # compute ticker data new_dates = (prices[window_data.selected_ticker]['ta'].data['date'].astype('int64') // 1e9).to_list() new_closes = prices[window_data.selected_ticker]['ta'].data['close'].to_list() new_lows = prices[window_data.selected_ticker]['ta'].data['low'].to_list() new_highs = prices[window_data.selected_ticker]['ta'].data['high'].to_list() new_opens = prices[window_data.selected_ticker]['ta'].data['open'].to_list() # create candle stick graph dpg.add_candle_series(new_dates, new_opens, new_closes, new_lows, new_highs, label=app_data, parent=window_data.candle_yaxis) dpg.add_hline_series([window_data.current_price], label='cur price', parent=window_data.candle_yaxis) # add indicators indicators.add_sma_series(3, new_dates, window_data.candle_yaxis, prices[window_data.selected_ticker]['ta']) indicators.add_sma_series(7, new_dates, window_data.candle_yaxis, prices[window_data.selected_ticker]['ta']) indicators.add_sma_series(14, new_dates, window_data.candle_yaxis, prices[window_data.selected_ticker]['ta']) # create volume graph values = prices[window_data.selected_ticker]['ta'].data['volume'].to_list() dpg.add_bar_series(new_dates, values, parent=window_data.volume_yaxis, weight=500) # fit plot views dpg.fit_axis_data(window_data.candle_xaxis) dpg.fit_axis_data(window_data.candle_yaxis) dpg.fit_axis_data(window_data.volume_yaxis) dpg.fit_axis_data(window_data.volume_xaxis)
uv_min = dpg.add_slider_floatx(label="uv_min", default_value=[0, 0], max_value=3, min_value=-3, size=2) uv_max = dpg.add_slider_floatx(label="uv_max", default_value=[1, 1], max_value=3, min_value=-3, size=2) control_items = { "pmin": pmin, "pmax": pmax, "uv_min": uv_min, "uv_max": uv_max } drawing = dpg.add_drawlist(width=416, height=384) image = dpg.draw_image(image_id, dpg.get_value(pmin), dpg.get_value(pmax), uv_min=dpg.get_value(uv_min), uv_max=dpg.get_value(uv_max)) controls = dpg.get_item_children(control_group)[1] for item in controls: dpg.set_item_callback(item, update_image) dpg.set_item_user_data(item, (image, control_items)) dpg.start_dearpygui()
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()
def test_zelete_items(self): children = dpg.get_item_children(self.window_id, 1)
def clear_table(table_tag): for tag in get_item_children(table_tag)[1]: delete_item(tag)
def cb_table_result_selected(row_tag): children = get_item_children(row_tag) child_value = get_item_configuration(children[1][0])['label'] _load_record_from_id(_try_parse_int(child_value))