Palette refresh on document change

Hi all,

I’m wondering if anyone can point me in the right direction with something:

I’m working on a palette plugin that reads data from a plaintext file next to the source, and am trying to figure out how to change the displayed text to reflect this when a source in a different directory (with a different text file) is activated. At the moment I have to close all files before the change is pulled in.

I’m guessing it’s to the with the callbacks? I currently have this set in start(self): Glyphs.addCallback(self.updatetext, DOCUMENTACTIVATED), where updatetext is the function that reads the textfile. Where would I likely be going wrong?

many thanks

The palette plugin is instantiated for each document. So each plugin can read its own text file and does not need to update when another document is activated.

Ok, thanks Georg. This means I must have an issue somewhere else as the information isn’t changing at present.

Do you have the information in a single floating window or in the sidebar?
If you are doing a floating window, you should not start with a palette plugin but use a general plugin plus callbacks.

It is indeed a palette so sits in the sidebar. After some modifications part of it is working, but I think what i’m trying to achieve is not possible in the way that I have currently gone about it.

Maybe you can show me on Skype what you are trying to do?

I’m doing something similar and had pretty much the same issue, but I haven’t had time to look into it.

In testing I also noticed that DOCUMENTACTIVATED gets called twice when I switch documents. If I have them opened side by side and just click on another font it gets called once usually, but if I select a different font from the Window menu it gets called twice. I made a simple test of GeneralPlugin without a window or palette just to test the callback. I also just tried this in the Macro window to see what happens and the results are inconsistent. Sometimes it just says currentFont or currentDocument is the previous font, not the one that has just been activated. So Font #1 is selected and then I select Font #2 and what I see printed is Font #1.

def changeDocument(sender):
	print('doc changed', GlyphsApp.currentFont())

Glyphs.addCallback(changeDocument, DOCUMENTACTIVATED)

Currently testing with 2.4.2 (998)

the callback only works for the one observer at a time. That is a bug and I’ll try to fix it.