GetHMenu fwom wx.Menu()?

In wxWindows, there’s a method, wxMenu->GetHMenu()
I don’t see this in wxPython. How can I pass a wxMenu from Python to C++?

Thanks : )

context, I’m trying to add a context menu to AutoCAD

import PyRx as Rx
import PyGe as Ge
import PyGi as Gi
import PyDb as Db
import PyAp as Ap
import PyEd as Ed
import wx

class MyMenu(Ed.UIContext):
    def __init__(self):
        Ed.UIContext.__init__(self)
        self.contextMenu = wx.Menu()
        self.contextMenu.Append(10001, "doCommand1", "doCommand1")
        self.contextMenu.Append(10002, "doCommand2", "doCommand2")
        self.HMENU = self.contextMenu.GetHMenu() #need this <<<<-------------
       
    def getMenuContext(self, classType, ids):
        #return the menu
        return self.HMENU

    def onCommand(self, cmd):
        print(cmd)
        
    def OnUpdateMenu(self):
        print("update")
        
menu = MyMenu()
        
def PyRxCmd_pydoit():
    try:
        Ed.UIContext.addObjectContextMenu(Db.Line.desc(),menu)
    except Exception as err:
        print(err)

def PyRxCmd_pydoit2():
    try:
        Ed.UIContext.removeObjectContextMenu(Db.Line.desc(),menu)
    except Exception as err:
        print(err)

got it from the C++ side

 if (wxPyWrappedPtr_TypeCheck(obj.ptr(), _T("wxMenu")))
    {
        wxMenu* ptr = nullptr;
        wxPyConvertWrappedPtr(obj.ptr(), (void**)&ptr, wxT("wxMenu"));
        if (ptr != nullptr)
        {
            m_hmenu = ptr->GetHMenu();
            return &m_hmenu;
        }
    }

Yes, that method isn’t exposed in wxPython. It’s also not documented in wxWidgets, so it’s unclear whether it’s supposed to be used by end users? If you’d like to get it added to wxPython officially, I’d suggest filing a wxWidgets issue asking them if it can/should be documented.

1 Like