typemytype / drawbot

http://www.drawbot.com
Other
402 stars 63 forks source link

"tracking" works in DrawBot app, but not when used in DrawBot module #442

Closed arrowtype closed 2 years ago

arrowtype commented 2 years ago

I can get tracking to work in the DrawBot app, but it is failing for me when I try to use DrawBot as a Python module, in a separate code editor.

I’ve tried to use it both in the simple way and in a FormattedString. In each case, I get a similar traceback.

I can’t remember having any similar problems recently – this stands out as an unexpected issue, whereas basically everything else works as expected.

Let me know if I can provide any more information, here! Thanks.

Test case

# set up to use drawbot as a module in an external code editor
from drawBot import *
newDrawing() # required by drawbot module

#--------------------------------------------------
# tracking test

newPage(200, 100)
fs = FormattedString(
    'TESTING',
    fontSize=24,
    tracking=5)

textBox(fs, (10, 10, 200, 50))

#--------------------------------------------------
# saving the file

import os

currentDir = os.path.dirname(os.path.abspath(__file__))

saveImage(f"{currentDir}/tracking-test.png")

Result

▶ python3 ./tracking-test.py
Traceback (most recent call last):
  File "/Users/sn/code/drawbot-tracking/tracking-test.py", line 12, in <module>
    tracking=pointSize*trackingUnits/1000)
  File "/Users/sn/code/drawbot-tracking/venv/lib/python3.7/site-packages/drawBot/drawBotDrawingTools.py", line 1893, in FormattedString
    return self._formattedStringClass(*args, **kwargs)
  File "/Users/sn/code/drawbot-tracking/venv/lib/python3.7/site-packages/drawBot/context/baseContext.py", line 1095, in __init__
    self.append(txt, **attributes)
  File "/Users/sn/code/drawbot-tracking/venv/lib/python3.7/site-packages/drawBot/context/baseContext.py", line 1324, in append
    attributes[CoreText.kCTTrackingAttributeName] = self._tracking
  File "/Users/sn/code/drawbot-tracking/venv/lib/python3.7/site-packages/objc/_lazyimport.py", line 181, in __getattr__
    raise AttributeError(name)
AttributeError: kCTTrackingAttributeName

Result in DrawBot app

It works fine:

image

Context

justvanrossum commented 2 years ago

Is your pyobjc up to date?

arrowtype commented 2 years ago

Ah, simple! That was my issue.

pip install -U pyobjc solved the problem.

arrowtype commented 2 years ago

Thank you, @justvanrossum!