Get Info panel position

Hi! I’m trying to add some info to go next to tab’s info view; can I ask what’s the best way to do that, how to get its position on the screen?

I use tab.viewPort.origin to calculate the position, but it seems like a long way around and the text is jumpy because of the rounding.

tab.graphicView().infoView().bounds.origin is always (0, 0), so that’s doesn’t help either. Am I overlooking something obvious?

What do you try to put there?

tab.graphicView().infoView().frame()

should work.

Or use the insectorView API to add your own info box.

1 Like

Thank you, that’s much better!
Almost there, just showing the angle:

However, in Glyphs 2 one can add a GSInspectorView to the panel with view method, but it doesn’t work in Glyphs 3. Is it different now?

def view(self):
    return self.window.group.getNSView()

Also, is there a way to change its position relative to the main panel? I’d put it above the width/height rather than on the right.

FYI that should be Font.currentTab.infoView().frame() (or with your tab variable tab.infoView().frame())

you need to return an NSViewController.

What class and superclass is self?

I found that in your comment from a couple of years ago. So, self is ReporterPlugin, pretty much the same code.

Any hints on how to return NSViewController, please? Can’t find it among properties of anything.

viewController = NSViewController.new()
viewController.setView_(self.window.group.getNSView())
return viewController

You should store that viewController in a local variable that you can reuse it.

Oh I see, thank you! But seems like that crashes Glyphs

Can you send me the full code (privately if needed)?

Sure, I was going to submit it for Plugin Manager anyway:

By the way, if you can explain how to position it at some coordinates above the default panel rather then next to it, I think it would look better :slight_smile:

You know that there is a plugin that does something similar: GitHub - Mark2Mark/Show-Distance-And-Angle-Of-Nodes

Of course, I just prefer such secondary info to blend with the interface rather than sit right on top of paths

That plugin has sadly been broken since 3.2, I miss it dearly :cry:

I fixed the Distance and Angle plugin.

1 Like

Any hints on that error, please?

The view method has to return a view, not a view controller. My code snippet would need to go into inspectorViewControllersForLayer_(). But your hack to return [self] works, too. I fixed the code but can’t push the changes. Can you add me to the repo?

1 Like

Hi! I’m trying to add a mouseUp callback to a vanilla TextBox via subclassing, but it removes the view’s background when its on the Info panel. Since I super() everything else, I don’t get where that change comes from. Any hints please?

image

try:
	ClickableTextBoxView
except NameError:    
	class ClickableTextBoxView(TextBox.nsTextFieldClass):
		def mouseUp_(self, event):
			if hasattr(self, 'mouseUpCallback') and self.mouseUpCallback:
				self.mouseUpCallback(event)

class ClickableTextBox(TextBox):
	nsTextFieldClass = ClickableTextBoxView
	def __init__(self, *args, **kwargs):
		self.mouseUpCallback = kwargs.pop('mouseUpCallback', None)
		super(ClickableTextBox, self).__init__(*args, **kwargs)
		self._nsObject.mouseUpCallback = self.mouseUpCallback

why do you need the try:/except:?

can you try not the subclass __init__ and set the callback in the script where you init the ClickableTextBox? Not a solution, just for debugging.

Right, I don’t, thank you! Copied that from a script.

Anyways, never mind, it turns out the error sneaked it somewhere else. Redid everything from scratch and it works.

Out of curiosity: why do you need the mouseUp on this textField? There is also the NSTextFieldDelegate with methods like textDidEndEditing: or textDidChange:, in case those could happen to be closer to what you want to do.
textDidEndEditing: is called any time the text object has finished editing (that it has resigned first responder status). So this is also, when the user hits the enter key, or tab, or clicks outside if the text field.