Hello, is there a function to reload a Glyphs document? Let’s say I make an edit in an external application to something in the current document. Is there a way to force a refresh, without having to close and reopen the document? Thanks!
You can check the documentation of NSDocument.
If someone is also interested :
from AppKit import NSDocumentController
def refresh_document():
doc_controller = NSDocumentController.sharedDocumentController()
doc = doc_controller.currentDocument()
if doc:
file_url = doc.fileURL()
file_type = doc.fileType()
success, error = doc.readFromURL_ofType_error_(file_url, file_type, None)
if not success:
print(f"Error reading document: {error}")
else:
print("Document refreshed.")
merci bg
I would try this (not on my Mac right now):
font.parent().revertdocumenttosaved()
That’s nice as well. It triggers a dialogue if the file is unsaved. Thanks!
Btw it’s
Font.parent.revertDocumentToSaved_(None)`
Although I’m not sure what argument to pass, I just passed None and it works. Apparently, it is expecting an id?
Whenever you see …:(id)sender
, you can just pass None
.
Note that not all plugins expect the underlying GSFont of the document to get replaced and thus can act in unexpected ways. Use these methods with caution.
Thanks for the explanation. Yes, I only intend to use this in a very specific case.