Group Details Private

administrators

  • RE: Script to Standalone app

    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")

    posted in Code snippets
  • RE: Rounded Rectangle

    cool way to make a rounded rect!

    there are already a roundedRect example in the repository: see https://github.com/typemytype/drawbot/blob/master/examples/roundedRect.py

    I would encourage you to make a python package out of your helper tools that you import when you needed it...

    # a separate file with the name "roundedRect.py"
    def roundedRect(...):
        # draw your stuff here
    
    # an other file in the same directory
    
    #  name of the file/module  name of the function 
    from roundedRect import roundedRect
    
    # call it
    roundedRect(...)
    

    hope this makes sense!

    posted in Code snippets
  • RE: Script to Standalone app

    that is way to complex 🙂

    Variable works fine with the UI of drawBot... dont use it outside a drawBot document 😉

    You 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()
    

    this script wrapped in a .drawBot package

    posted in Code snippets
  • RE: Script to Standalone app

    this should work!

    8dec76fd-0762-4dc0-b37c-eb95a37420d2-image.png

    You can open the debugger in drawBot by hitten alt with the help menu open.

    posted in Code snippets
  • RE: Script to Standalone app

    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.

    posted in Code snippets
  • RE: Change the value of a bool with (arrow) keys

    yes, thanks @jo

    possible with cmd + arrows keys or cmd + click when ever True or False is selected

    posted in Feature Requests
  • RE: Script to Standalone app

    Some parts of drawBots api don't work automatically outside the application, mainly parts where an UI is involved.

    But first why building an app?

    I would recommend UI parts to build separately. Build a window with vanilla, add some sliders and callback whenever that slider will change.

    DrawBot has a drawBot package, so drawBot code can be shared without looking a complex script folder structure: https://www.drawbot.com/content/drawBotApp/drawBotPackage.html

    posted in Code snippets
  • RE: QR code with type

    expanding Gustavo's example:

    import colorsys
    
    path = bytes('http://www.drawbot.com/', 'utf-8')
    
    w, h = 31, 31
    s = 10
    
    size(w*s, h*s)
    
    img = ImageObject()
    img.QRCodeGenerator((w, h), path, 'Q')
    
    iw, ih = img.size()
    
    t = ""
    
    for y in reversed(range(int(ih))):
        for x in range(int(iw)):
            r, g, b, a = imagePixelColor(img, (x, y))
            _, l, _ = colorsys.rgb_to_hls(r, g, b)
            if l < 0.51:
                fill(0)            
                rect(x*s, y*s, s, s)
                t += "W"
            else:
                t += " "
        
        t += "\n"
    
    newPage()
    font("Menlo", 16)
    lineHeight(10)
    textBox(t, (0, 0, width(), height()))
    print(t)
    

    and the corners are always the same 🙂

    posted in General Discussion
  • RE: Forced justified

    DrawBot is using CoreText to layout text. This is the same engine as TextEdit.app, and it seems this is also not possible there...

    posted in General Discussion
  • RE: FontTools, probably a simple question

    this works...

    from fontTools.misc.bezierTools import calcCubicArcLength
    
    
    pt1 = 100, 100
    pt2 = 200, 100
    pt3 = 400, 150
    pt4 = 400, 400
    
    l = calcCubicArcLength(pt1, pt2, pt3, pt4)
    
    path = BezierPath()
    path.moveTo(pt1)
    path.curveTo(pt2, pt3, pt4)
    
    text(str(l), pt3)
    
    fill(None)
    stroke(0)
    drawPath(path)
    
    posted in General Discussion