hoffstadt / DearPyGui

Dear PyGui: A fast and powerful Graphical User Interface Toolkit for Python with minimal dependencies
https://dearpygui.readthedocs.io/en/latest/
MIT License
12.94k stars 676 forks source link

Image series' "show" state failed to switch #1962

Open SymExp opened 1 year ago

SymExp commented 1 year ago

Version of Dear PyGui

Version: 1.6.2. Operating System: Windows 11

My Issue/Question

Plot legend with build-in toggle handles didn't change the image series' 'show' state during switching.

To Reproduce

use the code below to see there isn't any change during switching.

Expected behavior

image serie's 'show' configuration is True when it is rendered and False otherwise.

Screenshots/Video

None

Additional context

Linked with issue #1961

Standalone, minimal, complete and verifiable example

import dearpygui.dearpygui as dpg

def _on_demo_close(sender, app_data, user_data): dpg.delete_item(sender) dpg.delete_item("__demo_texture_container")

if name == "main": dpg.create_context()

plot_area_size = 800
ref_ratio = .75
dpg.create_viewport(title='Radiation Calculation', width=1080, height=720)
with dpg.window(label="Test", width=1300, height=1000, on_close=_on_demo_close, pos=(100, 100), tag="Primary"):
    with dpg.plot(label="Image Plot", height= plot_area_size*ref_ratio, width= plot_area_size, tag = "Plot_Plot0",):
        X_axis = dpg.add_plot_axis(dpg.mvXAxis, label="x axis", tag = "Plot_Xaxis")
        Y_axis = dpg.add_plot_axis(dpg.mvYAxis, label="y axis", tag = "Plot_Yaxis")
        # you may use the build-in legend and see their behavior
        dpg.add_plot_legend(tag = "Plot_Legendtest_0")

texture_data1 = []
for i in range(100*100):
    texture_data1.append(125/255)
    texture_data1.append(100/255)
    texture_data1.append(255/255)
    texture_data1.append(255/255)

dpg.add_texture_registry(tag="__demo_texture_container")
dpg.add_static_texture(100, 100, texture_data1, parent="__demo_texture_container", tag="__demo_static_texture_1", label="Static Texture 1")
dpg.add_image_series("__demo_static_texture_1", [0, 0], [100, 100], label="static 1", parent = "Plot_Yaxis", tag = "Plot_Imtest_0")
last_config = dpg.get_item_configuration("Plot_Imtest_0")

dpg.setup_dearpygui()
dpg.show_viewport()
dpg.set_primary_window("Primary", True)

count = 0
while dpg.is_dearpygui_running():
    present_config = dpg.get_item_configuration("Plot_Imtest_0")
    if count%1000 == 0:
        print(f"regular configure\npresent config = {str(present_config)}\n*******************\n\n")
        count = 0

    for i in present_config:
        if present_config[i] != last_config[i]:
            print(f"diff at config {i} with last value{last_config[i]} and present value{present_config[i]}")

    if dpg.is_key_pressed(dpg.mvKey_Escape):
        break

    children = dpg.get_item_children("Plot_Legendtest_0")
    for i in children:
        for ii in children[i]:
            print(dpg.get_item_alias(children[1][i]))
    children = dpg.get_item_children( "Plot_Imtest_0")
    for i in children:
        for ii in children[i]:
            print(dpg.get_item_alias(children[1][i]))

    dpg.render_dearpygui_frame()
    last_config = present_config
    count += 1

dpg.destroy_context()
SymExp commented 1 year ago

notice: the code area is not complete. copy the whole code since secssion Standalone, minimal, complete and verifiable example

my1e5 commented 1 year ago

Really minimal example using dpg.plot

import dearpygui.dearpygui as dpg
dpg.create_context()

with dpg.window():
    with dpg.plot():
        legend = dpg.add_plot_legend()
        dpg.add_plot_axis(dpg.mvXAxis)
        dpg.add_plot_axis(dpg.mvYAxis)
        dpg.add_line_series([0, 1], [0, 1], parent=dpg.last_item(), label="line1")
    dpg.add_button(label="Print legend config", callback=lambda: print(dpg.get_item_configuration(legend)))

dpg.create_viewport(width=800, height=600)
dpg.setup_dearpygui()
dpg.show_viewport()
dpg.start_dearpygui()
dpg.destroy_context()

I've found this only happens when you show/hide the legend using the plot context menu (i.e. right-clicking on the plot). The show key in the legend item configuration doesn't update to the new state.