Script to Standalone app
-
Is there a way to execute the Run command using shell or applescript?
-
If drawBot is installed as a module you can access it anywhere!
If
Variable(..)
is a key thing in your script, use a drawBot package, where you can set a main script that gets executed when the file is opened in DrawBot.app.
-
@frederik thanks!!! I just got curious about it. I'm having a problem with the package, it doesn't open the script when I open it in DrawBot, this is the tree I have
myPackage.drawbot ├── info.plist └── lib ├── squareAdjustments.py ├── logoAdjustments.py ├── fontAdjustments.py ├── userText.py ├── main.py ├── resources │ └── fonts │ ├── VF.ttf │ └── Logo.otf └── save.py
When I open main by itself it runs
-
this should work!
You can open the debugger in drawBot by hitten
alt
with the help menu open.
-
Debugger shows the problem now:
Traceback (most recent call last): File "main.py", line 45, in <module> File "drawBot/drawBotDrawingTools.pyc", line 2548, in Variable drawBot.misc.DrawBotError: There is no document open
It works if I run
main.py
does it need to open a window first and then run Variable?
-
@eduairet I tried this and now opens the script and it's not giving me errors but it still doesn't run entirely:
openWindows = Quartz.CGWindowListCopyWindowInfo( Quartz.kCGWindowListOptionOnScreenOnly | Quartz.kCGWindowListExcludeDesktopElements, Quartz.kCGNullWindowID ) openWindows = [window.get('kCGWindowName', u'Unknown').encode('ascii','ignore') for window in openWindows if window['kCGWindowOwnerName'] == 'DrawBot'] if b'main.py' not in openWindows: os.system(f'open -a DrawBot {__file__}')
-
that is way to complex
Variable
works fine with the UI of drawBot... dont use it outside a drawBot documentYou will have more control when you build it with vanilla and use this in a drawBot packages.
import vanilla class MyController: def __init__(self): self.w = vanilla.Window((150, 40), "My Tool Name") self.w.slider = vanilla.Slider((10, 10, -10, 22), callback=self.sliderCallback) self.w.open() def sliderCallback(self, sender): x = sender.get() newDrawing() fill(random(), random(), random()) oval(x, 0, 1000, 1000) saveImage('/Users/frederik/Desktop/issueDrawBotPackage/test.pdf') endDrawing() MyController()
-
Thanks Frederik you've helped me a lot!!!
-
Hi @eduairet I stumpled upon your thread as I am currently working on something similar. I need to share some code for someone else to work with and the package seems to be a perfect fit.
I just have a problem that my font is not loaded from the resource directory. Everytime I set text it uses standard fallback font.
Looking at your tree file I see that you use a varFont as well located within resource. Is there a trick to get it working?Would be a bummer if the user needs to input a path to the font file.
-
If you use a path in
font(filePath)
then the path is relative to the current directory (which is not always the the directory of the python file)DrawBot the app set the current directory to the .py file directory. When used as module this does not happen.
So either set the a correct current directory or get a absolute path from the .py file:
os.path.join(os.path.basename(__file__), "font.otf")
-
The hint with
__file__
was just what I needed and got me on the right track.
Usingos.path.join(os.path.dirname(__file__), 'resource', 'font.otf')
within themain.py
now gives me the ability to pull content from the resource directory. Perfect!Thank you so much @frederik, as always