robotools / vanilla

A Pythonic wrapper around Cocoa.
MIT License
78 stars 28 forks source link

toolbaritems could have a menuFormRepresentation option #191

Closed typemytype closed 1 year ago

typemytype commented 1 year ago

add new key menuFormRepresentation to build a NSMenuItem from either a NSMenuItem or a single menu item dict as described in VanillaMenuBuilder

https://github.com/robotools/vanilla/blob/master/Lib/vanilla/vanillaWindows.py#L705-L732

see https://developer.apple.com/documentation/appkit/nstoolbaritem/1532562-menuformrepresentation?language=objc

typemytype commented 1 year ago
import vanilla

class Test:

    def __init__(self):
        self.w = vanilla.Window((200, 200), minSize=(100, 100))
        self.w.addToolbar(
            "com.identifier",
            [
                dict(
                    itemIdentifier="foo",
                    label="Foo",
                    callback=self.fooCallback
                    ),
                dict(
                    itemIdentifier="bar",
                    label="bar",
                    callback=self.barCallback,
                    menuRepresentation=dict(
                        title="menu bar", 

                        items=[
                            dict(title="hello", callback=self.menuBarCallback)
                        ]
                    )
                )
            ]
        )
        self.w.open()

    def fooCallback(self, sender):
        print("foo", sender)

    def barCallback(self, sender):
        print("bar", sender)

    def menuBarCallback(self, sender):
        print("menuBarCallback", sender)

Test()
image