wxWidgets / Phoenix

wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
http://wxpython.org/
2.21k stars 509 forks source link

PropertyGridManager does not handle the issue of parent property display disorder. #2533

Closed zerooneme closed 2 months ago

zerooneme commented 2 months ago

Operating system:windows11 wxPython version & source: 4.2.1 Python version & source: 3.10.11

Description of the problem: The subattributeAa2_1 is not displayed correctly under attributeB. "Aa11 is displayed within the parent attribute attributeA."

Code Example (click to expand) ```python import wx import wx.propgrid as wxpg class MyFrame(wx.Frame): def __init__(self, parent, title): super(MyFrame, self).__init__(parent, title=title, size=(400, 300)) panel = wx.Panel(self) propgrid_manager = wxpg.PropertyGridManager(panel, style=wxpg.PG_SPLITTER_AUTO_CENTER) propgrid_manager.SetExtraStyle(wxpg.PG_EX_MODE_BUTTONS) attributeA = propgrid_manager.Append(wxpg.PropertyCategory("A")) subattributeAa = propgrid_manager.AppendIn(attributeA, wxpg.PropertyCategory("Aa")) subattributeAa1 = propgrid_manager.AppendIn(subattributeAa, wxpg.IntProperty("Aa1", value=1)) attributeB = propgrid_manager.Append(wxpg.PropertyCategory("B")) subattributeBa = propgrid_manager.AppendIn(attributeB, wxpg.PropertyCategory("Ba")) subattributeAa2 = propgrid_manager.AppendIn(subattributeBa, wxpg.PropertyCategory("Aa")) subattributeAa2_1 = propgrid_manager.AppendIn(subattributeAa2, wxpg.IntProperty("Aa11", value=1)) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(propgrid_manager, 1, wx.EXPAND) panel.SetSizer(sizer) if __name__ == '__main__': app = wx.App() frame = MyFrame(None, "Property Grid Manager Example") frame.Show() app.MainLoop() ```
DietmarSchwertberger commented 2 months ago

I'm not familiar with PropertyGrid or PropertyGridManager. Therefore I don't know whether it's a bug or feature that items with the same category do get displayed next to each other. Anyway, this is wxWidgets, not wxPython.

I have taken your code an modified the wxWidgets sample from https://github.com/wxWidgets/wxWidgets/blob/master/samples/propgrid/propgrid_minimal.cpp Could you please check whether this matches your intentions? I've renamed some to make it clearer.

MyFrame::MyFrame(wxWindow* parent)
    : wxFrame(parent, wxID_ANY, "PropertyGrid Test")
{
    wxMenu *Menu = new wxMenu;
    Menu->Append(ID_ACTION, "Action");
    wxMenuBar *MenuBar = new wxMenuBar();
    MenuBar->Append(Menu, "Action");
    SetMenuBar(MenuBar);

    wxPropertyGrid* pg = new wxPropertyGrid(this,wxID_ANY,wxDefaultPosition,wxSize(400,400), wxPG_SPLITTER_AUTO_CENTER );
    m_pg = pg;

    pg->SetExtraStyle(wxPG_EX_MODE_BUTTONS);

    wxPGProperty* attributeA        = pg->Append(new wxPropertyCategory("A"));
    wxPGProperty* subattributeAa    = pg->AppendIn(attributeA, new wxPropertyCategory("Aa"));

    pg->AppendIn(subattributeAa, new wxIntProperty("Aa1", wxPG_LABEL, 1));

    wxPGProperty* attributeB        = pg->Append(new wxPropertyCategory("B"));
    wxPGProperty* subattributeBa    = pg->AppendIn(attributeB, new wxPropertyCategory("Ba"));
    wxPGProperty* subattributeBa2   = pg->AppendIn(subattributeBa, new wxPropertyCategory("Aa"));  // the same category value as above

    pg->AppendIn(subattributeBa2, new wxIntProperty("Ba2", wxPG_LABEL, 1));

}

When I run it, it looks like this: image

DietmarSchwertberger commented 2 months ago

In this call the previous category will be re-used: pg->AppendIn(subattributeBa, new wxPropertyCategory("Aa"));

That's the related comment in wxPropertyGridPageState::PrepareToAddItem:

// If we already have category with same name, delete given property
// and use it instead as most recent caption item.

Could you please check whether this should be considered a bug and what should be updated in the wxWidgets documentation?

DietmarSchwertberger commented 2 months ago

I would suggest to close the isssue. It's not clear whether it's a bug or the documentation should be updated. Also, the reporter seems to have lost interest.