Submenu creation

Hello, everyone, is there a way to make submenus using panda3d?

Hmm… I don’t think that Panda has a widget that conveniently implements that feature. I think that it may call for a custom class of your own.

What I might suggest is that you compose your menus of DirectScrolledFrames, with menu-items that spawn sub-menus each spawning their own DirectScrolledFrame-menu. Perhaps the menus might be encapsulated in some custom menu-class, allowing their functionality to be nested where sub-menuing occurs.

What exact kind of menus are you talking about? If it’s those menu bar type menus, I already created a special widget which can handle submenus. It’s in my DirectGuiExtensions set. Here’s the documentation for the menu class.

1 Like

Oh, that’s good to know! :slight_smile:

I really ought to look at those extensions someday!

There is also this code to generate menu bar and popup menu (that’s what I’m using in my app) : Popup Menu & Drop-down Menu Bar

I updated it to be compatible with Panda3D 1.10, cosmonium/third-party/pandamenu at develop · cosmonium/cosmonium · GitHub

I should move it to its own repository (or switch to Wolf’s implementation :wink: )

1 Like

How can I align the file menu to the left corner?

Here follows my code:

class UserInterface:
    """ Class holding all elements at the Graphical User Interface """

    def __init__(self, showbase):
        self.showbase = showbase
        self.mainBox = DirectBoxSizer(orientation=DGG.VERTICAL, autoUpdateFrameSize=False)
        DirectAutoSizer(child=self.mainBox,extendHorizontal=False, childUpdateSizeFunc=self.mainBox.refresh)
        """Let the GUI system create the layout"""
        self.file = ''

    def menu(self):
        """Configuring the menu file and architecture"""
        # create menu structure
        # MENU ITEMS
        itemList = [
            DirectMenuItemEntry("Save", print, [False]),
            DirectMenuItemEntry("Load", print, [True]),
            DirectMenuItemSubMenu("Recent >", [
                DirectMenuItemEntry("Item A", print, ["Item A"]),
                DirectMenuItemEntry("Item B", print, ["Item B"]),
                DirectMenuItemEntry("Item C", print, ["Item C"])
            DirectMenuItemEntry("Quit", quit, [])]
        fileMenu = DirectMenuItem(text="File", scale=0.05, item_relief=0, items=itemList)

        boxSizer = DirectBoxSizer(itemAlign=DirectBoxSizer.A_Left)


If extendHorizontal=False is not set, it covers my 3D drawing like this and goes to the right corner.

Sorry for the late reply.

If you want to have it over there in the left corner but don’t want the background to block your screen, you can use what you have and simply set the relief of the self.mainBox and the DirectAutoSizer to None by passing relief=None to both of them. That will make the background disappear.

I’m also working on an integration of those widgets into my DirectGuiDesigner which should make it simpler to use and create UIs with them. But that’ll take some more time until it’s ready and fully functional.

Thanks for the response, it remains transparent and at the correct place but I can’t manipulate the scene.

Ah, that’s probably because DirectGui is catching all the mouse events by default. That should be solved by simply passing state=DGG.DISABLED to your DirectBoxSizer mainBox.