How do I see help of activeEditViewController()?

I am trying to learn what I can do with activeEditViewController() and graphicView() but I have no idea how to see the help of them. I saw Core section of Glyphs reference but it didn’t help much. How should I do it?

I specifically want to know how to display text in an edit view with different layers. I know how to set a plain text, but don’t know how to change the layer in each glyph.

We are working on improving the python documentation and the editviewcontroller and graphicView will be covered a bit.

Here is an example. It is a small piece of code from Glyphs I just ported to python:

graphicView = Font.parent.windowControllers()[0].activeEditViewController().graphicView()

Attributes = { "GSLayerIdAttrib" : Font.masters[1].id }
selectedRange = graphicView.textStorage().selectedRange()
if selectedRange.length == 0: # only a cursor
	selectedRange.length = 1

graphicView.textStorage().willChangeValueForKey_("text")
graphicView.textStorage().text().addAttributes_range_(Attributes, selectedRange)
graphicView.textStorage().didChangeValueForKey_("text")

The .text() is a NSMutableAttributedString
We will see if we can make that a bit friendlier for scripts.

Thanks. Wow, this is complicated. It seems that it depends on the cursor position?

What I want to do is to throw a new text in a tab; textA in the first master/layer and textB in the second, in the same tab. Like line 1 in Regular and line 2 in Bold. How can I do that?

Te examle happens to use the cursor position. But you can iterate over the string and set the layerID for each glyph.

Thanks. What are the will/didChangeValueForKey_(“text”) doing? What’s “text” referring to?

At least I got my stuff done though, by removing those two lines.

Hi Tosche.
Could you please post the entire code of your solution?
I’m currently working on improving the Python documentation, and maybe I can even make some form of a shortcut for your problem. Seems like a good idea.
Thanks.

Thanks for the interest, Yanone. I want to post it on Github next week but the script contains other person’s work, which I am waiting for approval. So, please wait for a little while.

Okay.
Meanwhile Georg has agreed on a completely new implementation of something like font.tabs, something which was missing for a while, and which we’ll cover in the Python API, of course, as soon as possible.

Congratulations on the update to 2.1 and the Python wrapper! Unfortunately I have a problem using tabs the new way. When I run a code like this ( print font.tabs[0].text ), it says “AttributeError: ‘NSKVONotifying_GSFont’ object has no attribute ‘tabs’”. I’m using build 267. Can you help?

I hope you are using 767. :smile:
Perhaps, in your Scripts folder, delete outdated .pyc files. Does that help?

Yes I’m using 767. I had .pyc files indeed, but still the same. I only need to delete them from the Scripts folder, right?

If you have a .pyc file, you might have an glyphsapp.py file, too?

And did you restart after deleting the files?

Thanks, after deleting glyphsapp.py it started to work. I have some other py files (GSPen.py, objectsGS.py). I have my problem solved, but do they need to be thrown away too?

Actually it accepts the code but all sorts of weird things are happening around the tab.
font.tabs[-1].text=“abc” correctly displays abc in the last tab. I can print the tabs[-1].text too.
font.newTab(“abc”) results in instant crash.
font.newTab("") sometimes opens a new tab, but opens a grey blank tab, not white, where you can do nothing until you change zoom size. Other times it crashes (seems to depend on what tool you are using at the moment?)

Other times it makes the entire window grey blank, or UI keep extending rapidly in horizontal, slowly in vertical direction, or causes all sorts of weird stuff, so much so it’s rather entertaining.

I can’t reproduce your problems.

Problem identified after some chat with Georg. It was happening only in Macro window.

Hey @Tosche did you ever upload this script? I thought it was available for a while but I can’t find it anymore.

I think this was about “Display Unlocked Kerning Pairs”.

1 Like