Main Thread error

Hello,

I am trying to import DrawBot (forum.drawbot.com/topic/26/usin … -drawbot/7)…this results in an error:

The script and the error are provided below.

Any suggestions of what I am doing wrong or what I can try?

I also ran the same code using Terminal with both the latest version of Python3 and in a virtual environment with Python3.5.1, and both run the script successfully so I assume this is something related to running the script in TD directly that is causing error.

Any help is appreciated. Thank you.

CODE:

[code]import vanilla
import drawBot
from drawBot.ui.drawView import DrawView

class PreviewController(object):

def __init__(self):
    self.w = vanilla.Window((400, 400))
    self.w.view = DrawView((0, 0, 0, 0))
    
    self.drawSomeThing()
    
    self.w.open()

def drawSomeThing(self):
    # draw something
    drawBot.newDrawing()
    drawBot.newPage(300, 300)
    drawBot.fill(1, 0, 0)
    drawBot.rect(20, 20, 200, 200)
    # get the pdf document
    pdfDocument = drawBot.pdfImage()
    drawBot.endDrawing()        
    # set the pdf document in the view
    self.w.view.setPDFDocument(pdfDocument)

from vanilla.test.testTools import executeVanillaTest
executeVanillaTest(PreviewController)


ERROR:
[code]Traceback (most recent call last):
  File "</project1/text6:op('/project1/text6').run()>", line 1
td.Error: File "/project1/text6", line 40
  File "/Users/gorjious/Desktop/virtualenv_test/py35_env/lib/python3.5/site-packages/vanilla-0.1-py3.5.egg/vanilla/test/testTools.py", line 43, in executeVanillaTest
    cls(**kwargs)
  File "/project1/text6", line 19, in __init__
  File "/Users/gorjious/Desktop/virtualenv_test/py35_env/lib/python3.5/site-packages/vanilla-0.1-py3.5.egg/vanilla/vanillaWindows.py", line 132, in __init__
    frame, mask, NSBackingStoreBuffered, False, screen)
objc.error: NSInternalInconsistencyException - NSWindow drag regions should only be invalidated on the Main Thread!
Results of run operation resulted in exception. Value:type:textDAT path:/project1/text6 Type:<class 'td.textDAT'>.[/code]

Hey,
All of the UI work in TD on macOS is done in a different thread than where all our ndoes and Python execute. So a Python library that needs to execute on the UI thread on macOS isn’t going to work. sorry

Hi Malcolm,

Thanks for the reply. I have some follow-up questions.

Is it possible to somehow specify the thread which TD is on?

Maybe if I explain what I am trying to achieve you may be able to suggest a better solution.

I am using the DrawBot module because of its advanced access to OpenType features. I can run scripts using DrawBot in TD which are able to save images, however, I am not able to see those changes in real-time. What I would like to do is to be able to render the changes and see the results in real time through some sort of preview window. The original idea was to use Vanilla to create that window but that is running into the the main thread error…is there a preview window option native in TD that I can use to pass the info from the script into? Or any other way that you can imagine it is possible to render text?