SOLVED Font Collection Custom Tool
Is there a safe way of adding tools to the font collection window, or is that not a good idea?
For example, if I wanted to add a button (say, next to Edit With…) that displayed the current font's notes in a new window, would that be possible?
that is easy
from mojo.UI import CurrentFontWindow from AppKit import NSImageNameAdvanced class AddToolBarButton(object): def __init__(self): # maybe subscribe to the "fontDidOpen" event # get the current window window = CurrentFontWindow() if window is None: return # get the current toolbar items toolbarItems = window.getToolbarItems() # make a new one, see the vanilla docs for more info newItem = dict(itemIdentifier="myNewButton", label="Button", imageNamed=NSImageNameAdvanced, callback=self.myCallback) # add the new item to the existing toolbars toolbarItems.append(newItem) # get the vanilla window object vanillaWindow = window.window() # set the new toolbaritems in the window window.toolbar = vanillaWindow.addToolbar(toolbarIdentifier="myCustomToolbar", toolbarItems=toolbarItems, addStandardItems=False) # done def myCallback(self, sender): print "hit, do something!" AddToolBarButton()
jack_jennings last edited by
Haha, it's easy if you say so, frederik.
Is there a list of the observable events that RoboFont supports? I assume that I can just read through the source of defcon to find its events...
There are several kinds of notification systems in RoboFont. There is one on font data, the defcon notifications. Another one is on app level, specific build for tools and extension to use and the last one is on cocoa level, UI only.
Not to let all of your tricks out of the bag, but is there a shortcut available to set the icons as PDFs like you're doing in other parts of the application?
My ObjC abilities are poor, and I'm not sure if this is a job for
Well, I've gotten past that hurdle by reading the the
NSImagedocs, now I just need to figure out how the "view" option works for the vanilla
addToolbarmethod (as I'm trying to match the style of the Glyph view buttons. I snooped around and found that the toolbar in the Glyph view is using a view called
ToolbarGlyphTools, and I think that I'm importing that module from
lib.UI.toolbarGlyphTools. Not sure how to get this hooked up because this doesn't seem to work. Maybe I'm barking up the wrong tree…
from lib.UI.toolbarGlyphTools import ToolbarGlyphTools newItem = dict(itemIdentifier="myNewButton", label="Button", imageObject=NSImage.alloc().initByReferencingFile_(imagePath), callback=self.myCallback, view = ToolbarGlyphTools.alloc().init() )
not sure how to do code tags either…
ToolbarGlyphToolsis an UI object that looks like a button that you can add in a toolbar dict item.
from AppKit import NSImage from lib.UI.toolbarGlyphTools import ToolbarGlyphTools ## create your image, best is that the image is only black and white ## so the image can be inverted when clicked myToolBarImage = NSImage.alloc().initByReferencingFile_(imagePath) ## a ToolbarGlyphTools is similar like the vanilla.SegmentedButton but has an extra toolbar item attributes ## if you want to add more items to the segmented button the item attributes just contains more dicts ## the size of the segmented button is atomically multiplied by the number of items. toolbarView = ToolbarGlyphTools((30, 25), [dict(image=myToolBarImage, toolTip="My ToolTip"], trackingMode="one") newItem = dict(itemIdentifier="myNewButton", label="Button", callback=self.myCallback, view=ToolbarGlyphTools.alloc().init())
</pre>to get the syntax highlighting in a post
I've written a proper vanilla patch which is already in the vanilla repo. This will be in the next update of RoboFont.
removeToolbarItemto a vanilla window object, able to manage toolbar items properly.