checkbox or slider in additionContextualMenuItems?

  • Hi Guys,
    As in the topic: I'm creating tool based on BaseEventTool. is it possible to add checkbox and slider objects to the right click menu?
    If yes, then how?

    any help would be great :)

  • admin

    you need to provide a NSMenuItem with a view, which will be the controller: a checkBox or slider.

    I can make an example next week, as I’m on the road!

  • Hi @frederik,
    I've been trying to have fun with AppKit etc, but I wasn't able to build those NSMenuItems. Could you show an example? It would be super nice of you.

  • admin

    hope this makes sense

    import AppKit
    import vanilla
    from mojo.UI import MenuBuilder
    def callback(sender):
    def sliderCallback(sender):
    sliderMenuItem = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_("slider", '', '')
    slider = vanilla.Slider((0, 0, 100, 30), callback=sliderCallback) 
    view = slider.getNSSlider()
    view.setFrame_(((0, 0), (100, 30)))
    builder = MenuBuilder([
        ("test", callback), 
        ("test 2", callback),
        ("test 3", callback),
    menu = builder.getMenu()
    name = "My Menu With Slider"
    # get the menu bar
    menubar = AppKit.NSApp().mainMenu()
    newItem = menubar.itemWithTitle_(name)
    if not newItem:
        # if not, create one and append it before `Help`
        newItem = AppKit.NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(name, '', '')
        menubar.insertItem_atIndex_(newItem, menubar.numberOfItems()-1)
    # set the menu as submenu

  • Sweet! it is clear, looks like it works. Thank you so much.

    question a bit off topic: is it possible to add custom menu items to default RF tools, like edit tool?

    I was thinking about creating the one functionality in right-click menu, and I think that it would be waste of space in the glyph window toolbar If I would create additional tool only to have this small function build into right click menu.

  • admin

    yes there is a notification for that :)

    subscribe to:

    • for glyphs glyphAdditionContextualMenuItems
    • for guides guideAdditionContextualMenuItems
    • for images imageAdditionContextualMenuItems
    • in the glyph cell view fontOverviewAdditionContextualMenuItems

    good luck!

  • This post is deleted!