Build single one-time operation tool/button in glyph window, like RemoveOverlap



  • Hi,

    I'm working on an extension that I'm hooking into the toolbar of the glyph window.

    For now I have subclassed BaseEventTool, which adds one button to the bar of drawing tools on the left.
    Since my extension performs a one-time operation, it's somewhat unsatisfactory and odd that the tool stays selected after the operation has been performed, and I manually have to select another/the tool I was using previously.

    What I'd want is to have it as a tool that behaves basically like the RemoveOverlap tool: One single button, it does what it does, and the current drwaing/editing tool remains selected/active during the operation.

    I can't seem to get my head round if this can be done for an extension at all, or what tool to subclass.

    Maybe I was looking at it too long but not hard enough, but any lead in the right direction would be much appreciated.

    thanks,
    franz




  • For now, I haven't found a way to directly insert my toolbarItem into the toolbar as I couldn't get insertItemWithItemIdentifier:()atIndex:() to work in the context of my script/extension, but probably I'm just being daft here.

    So currently I read all the items in the glyph window toolbar, add my item, and use vanilla's addToolbar method to replace the toolbar. That's looking good so far, all the previously present items are there, glyph tools work, and my item shows up (not as a button yet, that's lined up next). RemoveOverlap in the replaced toolbar crashes right now when clicked (I guess I'm somehow breaking the delegate or something), but I hope to get that sorted, too.



  • Aarghh. Facepalm. I owe you a beer.


  • admin

    use

    ## this returns the vanilla window object
    info["window"].window()
    


  • Hi Frederik,

    again many thanks, esp. for the link to the vanilla docu.

    Now I got the observer working, I have the button and the actual functionality, but I can't seem to get hold of the window properly to perform all the additional steps to add a toolbar item:

    def glyphWindowDidOpenCallback(self,info):
            gwin = info["window"]
            nswin = gwin.getNSWindow() # or whatever I try here…
    

    … gives me:

    AttributeError: 'DoodleGlyphWindow' object has no attribute 'getNSWindow'
    

    (or whatever I try to get from the window)

    I feel it's just a simple but crucial bit I'm missing here, any leads come greatly appreciated!

    Franz

    p.s. ain't it funny that the actual functionality mostly comes easy peasy, hooking the thing in the UI doesn't exactly… :-/


  • admin

    from mojo.events import addObserver
    
    class test:
        
        def __init__(self):
            addObserver(self, "myCallback", "glyphWindowDidOpen")
    
        def myCallback(self, info):
            print(info["window"])
            print(info["glyph"])
            print("a new glyph window did open")
    
    test()
    

    and use vanilla to add a toolbar item see http://code.typesupply.com/browser/packages/vanilla/trunk/Lib/vanilla/vanillaWindows.py#L449

    good luck



  • Ouch, i was hoping it was a tad easier than that.
    Many thanks Frederik, I will give it a try.
    So my extension would need to live as an object independent from BaseEventTool, observe if a glyph win opens and then add an NSButton object to it, correct?


  • admin

    You can add your script to the scripting folder see http://doc.robofont.com/documentation/workspace/preferences/python/ and assign a short key.
    Or make an observer to a key down and perform an action when the user hit a key.
    Or if you know enough about vanilla you could add it to the glyph window: observe when a glyph window opens and add/insert your button in the toolbar.

    good luck