Is there a way to know which tool is active in an edit tab?

Hey,

I’ve been looking in the documentation but can’t find something that would let me know what editor tool is currently active. I’d like my plugin to behave different (not trigger) for certain tools. I’m using the DRAWFOREGROUND callback.

Any pointers?

Cheers,
Johannes

Maybe something like this?

Thanks Jens,

this looks very much like what I need, but I’m not sure is it because I’m using a GeneralPlugin instead of a ReporterPlugin or because I am registering the callback differently that the self.controller seems to return something different.

I use Glyphs.addCallback(self.keepGlyphCenter, DRAWFOREGROUND) to listen for the updates, and in the callback “keepGlyphCenter” self.controller seems to be that very method itself.

How do you find out more about those under-the-surface bindings of Glyphs? I constantly seem to bang my head against a glass ceiling whenever I try anything past the documented API.

Okay, somehow found the right Object by trying…

This seems a more general way of getting the current tab’s selected tool without the correct “self” context Glyphs.fonts[0].currentTab.graphicView().window().windowController().toolDrawDelegate()

Also using print dir(whatever) in the Macro panel seems to expose some of the underlying bindings and methods of those black box objects.

The current tools classes seem to be:

<GlyphsToolSelect: 0x6080002b6c80>
<PenTool: 0x7fa77977a5c0>
<GlyphsToolRotate: 0x7fa779772500>
<GlyphsToolScale: 0x7fa779774570>
<GlyphsToolText: 0x60c000115720>
<AnnotationTool: 0x7fa779777e80>
<AnnotationTool: 0x7fa779777e80>
<GlyphsToolHand: 0x7fa779784a50>
<GlyphsToolTrueTypeInstructor: 0x7fa77977b890>

And with the Zoom or Ruler tool selected the toolDrawDelegate() will return the last used tool.

Furthermore, you can check against the Tool class name with type(tool).__name__ where tool is the return from the above toolDrawDelegate() call.

Suggestions to do this more smoothly are welcome of course :slight_smile:

Try this:

Glyphs.currentDocument.windowController().toolDrawDelegate()

and

Glyphs.currentDocument.windowController().toolEventDelegate()

This is the normal python way of doing it: tool.__class__.__name__ or use cocoa: tool.className()

1 Like

Perfect, once again thank you very much for those pointers.