RoboFont › Forums › Help / General › Font Collection Custom Tool
This topic contains 9 replies, has 3 voices, and was last updated by asaumierdemers 6 years, 6 months ago.
-
AuthorPosts
-
March 7, 2013 at 18:29 #5458
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?
March 7, 2013 at 20:11 #5459he,
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.myCallack, ) # 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 myCallack(self, sender): print "hit, do something!" AddToolBarButton()
good luck!
March 8, 2013 at 14:12 #5460Haha, 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…
March 8, 2013 at 15:05 #5461There 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.
see:
http://doc.robofont.com/api/custom-observers/
http://doc.robofont.com/api/custom-tools/March 9, 2013 at 14:29 #5462Not 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 NSPDFImageRef or…?
March 9, 2013 at 16:06 #5463Well, I’ve gotten past that hurdle by reading the the NSImage docs, now I just need to figure out how the “view” option works for the vanilla addToolbar method (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…
March 9, 2013 at 19:42 #5464Hi
The
ToolbarGlyphTools
is an UI object that looks like a button that you can add in a toolbar dict item.usage:
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() )
good luck
use <pre> your code </pre> to get the syntax highlighting in a post
April 15, 2014 at 11:57 #5846Hello!
There is one problem when trying to add an item to the toolbar: if there is another custom toolbarItem, it gets removed…
toolbarItems = window.getToolbarItems()
this doesn’t contain the other items, but the vanilla window seems to have them
vanillaWindow = window.window() vanillaWindow._toolbarItems
So how can I add another item to a custom toolbar?
(example: I have RoboToDo and I want another extension that adds an item to the toolbar)
I hope this is clear…
Thanks!
April 16, 2014 at 11:49 #5857He
Ive written a proper vanilla patch which is already in the vanilla repo. This will be in the next update of RoboFont.
It adds
addToolBarItem
andremoveToolbarItem
to a vanilla window object, able to manage toolbar items properly.see https://github.com/typesupply/vanilla/blob/master/Lib/vanilla/vanillaWindows.py#L631
April 16, 2014 at 12:18 #5859Great, thanks!
It’s exactly what I need.
-
AuthorPosts
You must be logged in to reply to this topic.