Vanilla object and drawing in TinyDrawbot

RoboFont Forums Help / General Vanilla object and drawing in TinyDrawbot

Tagged: 

This topic contains 4 replies, has 2 voices, and was last updated by  Roberto Arista 4 years, 11 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #6203

    Roberto Arista
    Participant

    Hi Frederik,
    I’d like to control the TinyDrawbot Canvas through a small interface built with Vanilla.

    I am trying to achieve something similar to these example:
    http://drawbot.readthedocs.org/en/latest/content/variables.html
    http://doc.robofont.com/api/mojo/mojo-canvas/ (at the bottom of the page)

    My plugin has a draw() method where I’ve put all the drawbot drawing commands, but nothing happens in the canvas.
    Here a short example of the code structure:

    from vanilla import *
    
    def drawRect(side):
        rect(0,0,side,side)
    
    class SliderDemo(object):
    
         def __init__(self):
             self.w = Window((200, 43))
             self.w.slider = Slider((10, 10, -10, 23),
                                tickMarkCount=10,
                                callback=self.sliderCallback)
             self.w.open()
    
         def sliderCallback(self, sender):
             drawRect(float(sender.get())*100)
    
    SliderDemo()
    

    Any suggestion about how to deal correctly with this?

    Thanks

    #6204

    frederik
    Keymaster

    Hi Roberto

    In your example you don’t have a canvas object that is able to show drawing callbacks.

    Please see the example http://doc.robofont.com/api/mojo/mojo-canvas/

    The slider just tells the canvas object to redraw itself. While getting a draw callback some drawBot methods are called to draw something into the canvas

    hope this helps

    good luck!

    #6206

    Roberto Arista
    Participant

    Hi Frederik,
    I’ve probably not explained correctly.
    I’d like to act on the TinyDrawbot canvas, not the mojo one (it is what I am doing now for testing).

    So, maybe I can rephrase the question in this way: is it possible to point to the TinyDrawbot/Drawbot canvas –like to the mojo one– from a vanilla object?

    I need this kind of behavior:
    http://drawbot.readthedocs.org/en/latest/content/variables.html
    but I can’t use the Variable class because I need more freedom concerning UI.

    hope this is more clear
    thanks

    #6207

    frederik
    Keymaster

    oh, here is an example, it is required to install the drawBot extension, get it here: https://github.com/typemytype/drawBotRoboFontExtension

    import drawBot
    from drawBot.ui.drawView import DrawView
    
    from vanilla import *
    
    class Test(object):
        
        def __init__(self):
            
            self.w = Window((400, 400), minSize=(200, 200))
            
            self.w.s = Slider((10, 10, -10, 22), minValue=10, maxValue=100, value=50, callback=self.sliderCallback)
            self.w.c = DrawView((10, 40, -10, -10))
            
            self.w.open()
    
        def sliderCallback(self, sender):
            value = sender.get()
            # start a new drawing
            drawBot.newDrawing()
            # add a page
            drawBot.newPage(100, 100)
            # draw something
            drawBot.rect(10, 10, value, value)
            # get the pdf data
            pdf = drawBot.pdfImage()
            # set the pdf data in the canvas
            self.w.c.setPDFDocument(pdf)
    
    Test()
    

    good luck!

    #6209

    Roberto Arista
    Participant

    Thanks, I’ll try!

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.