SOLVED Contextual Menu in Glyph View



  • Is there any way to build my own contextual menu in the Glyph View?

    I'm looking for similar solution as the one given in the example:
    link

    Thanks in advance for your help.


  • admin

    A tool can have his own contextual menu item:

    from mojo.events import EditingTool, installTool
    
    
    class MyTool(EditingTool):
        
        def additionContextualMenuItems(self):
            return [
                ("Hello", self.sayHello), 
                ("World", self.sayWorld),
                ("submenu", [("an item", self.sayAnItem)])
            ]
        
        def sayHello(self, sender):
            print("Hello")
        
        def sayWorld(self, sender):
            print("World")
        
        def sayAnItem(self, sender):
            print("an item")
    
        
    installTool(MyTool())
    

    0_1517341664440_Screen Shot 2018-01-30 at 20.47.05.png

    It not possible to directly inject menu item into the each menu for each tool. I will think about this and take it with me of the upcoming release.


  • admin

    mmm, RF could use the changes I’ve committed to vanilla.

    see https://github.com/typesupply/vanilla/blob/master/Lib/vanilla/vanillaList.py#L196

    for vanilla you can also provide the state, image and if the menu item is enabled.



  • Hey @frederik, Is it possible to add additional-contextual-menu-item that will look/work like a checkbox to the BaseEventTool? (like the "lock image" checkbox in the example-screenshot that you shared?)

    (I know I can easily go around it and do it without a check sign. But I consider the check sign more practical)



  • Thanks for the response. I will wait for new solutions then :)


  • admin

    A tool can have his own contextual menu item:

    from mojo.events import EditingTool, installTool
    
    
    class MyTool(EditingTool):
        
        def additionContextualMenuItems(self):
            return [
                ("Hello", self.sayHello), 
                ("World", self.sayWorld),
                ("submenu", [("an item", self.sayAnItem)])
            ]
        
        def sayHello(self, sender):
            print("Hello")
        
        def sayWorld(self, sender):
            print("World")
        
        def sayAnItem(self, sender):
            print("an item")
    
        
    installTool(MyTool())
    

    0_1517341664440_Screen Shot 2018-01-30 at 20.47.05.png

    It not possible to directly inject menu item into the each menu for each tool. I will think about this and take it with me of the upcoming release.


Log in to reply