Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GlyphConstruction.roboFontExt/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
<key>requiresVersionMinor</key>
<string>5</string>
<key>timeStamp</key>
<real>1594285837.2753458</real>
<real>1594289843.4766321</real>
<key>version</key>
<string>0.8.4</string>
<string>0.8.5</string>
</dict>
</plist>
18 changes: 16 additions & 2 deletions GlyphConstruction.roboFontExt/lib/glyphConstructionController.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from fontTools.misc.py23 import *
from AppKit import *
import re
Expand Down Expand Up @@ -32,6 +33,15 @@
from lib.scripting.codeEditor import CodeEditor
import os


def asyncTask(func):

def wrapper(*args, **kwargs):
task = asyncio.create_task(func(*args, **kwargs))

return wrapper


defaultKey = "com.typemytype.glyphBuilder"

constructions = """# capitals
Expand Down Expand Up @@ -622,8 +632,12 @@ def unsubscribeFont(self):
self.preview.set([])
self.font.removeObserver(self, notification="Font.Changed")
self.font = None

def constructionsCallback(self, sender, update=True):

@asyncTask
async def constructionsCallback(self, sender, update=True):
await asyncio.gather(self._constructionsCallback(sender, update))

async def _constructionsCallback(self, sender, update=True):
if self.font is None:
return

Expand Down
28 changes: 26 additions & 2 deletions LibExtension/glyphConstructionController.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import asyncio
import functools

from fontTools.misc.py23 import *
from AppKit import *
import re
Expand Down Expand Up @@ -32,6 +35,23 @@
from lib.scripting.codeEditor import CodeEditor
import os


def asyncTask(func):

taskAttributeName = f"_{func.__name__}_autoCancelTask"
@functools.wraps(func)
def createFuncTask(self, *args, **kwargs):
oldTask = getattr(self, taskAttributeName, None)
if oldTask is not None:
oldTask.cancel()
coro = func(self, *args, **kwargs)
task = asyncio.create_task(coro)
setattr(self, taskAttributeName, task)
return task

return createFuncTask


defaultKey = "com.typemytype.glyphBuilder"

constructions = """# capitals
Expand Down Expand Up @@ -622,8 +642,12 @@ def unsubscribeFont(self):
self.preview.set([])
self.font.removeObserver(self, notification="Font.Changed")
self.font = None

def constructionsCallback(self, sender, update=True):

@asyncTask
async def constructionsCallback(self, sender, update=True):
await asyncio.gather(self._constructionsCallback(sender, update))

async def _constructionsCallback(self, sender, update=True):
if self.font is None:
return

Expand Down
2 changes: 1 addition & 1 deletion build-extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
B.name = "Glyph Construction"
B.developer = 'Frederk Berlaen'
B.developerURL = 'http://typemytype.com/'
B.version = '0.8.4'
B.version = '0.8.5'
B.launchAtStartUp = True
B.mainScript = 'glyphConstructionUIStartUp.py'
B.html = True
Expand Down