CP5_addDrawable_python mode

edited March 2016 in Python Mode

Hello everybody, I have a question about controlP5 in Python mode. I need to add a .jpg image to a group, and from this discussion (http://forum.processing.org/two/discussion/1841/controlp5-canvas-and-group/p1) I know I need the addDrawable() method. I can't figure out how to translate this short piece of Java code into Python:

import controlP5.*;
ControlP5 cp5;
PImage pic;
void setup() {
  size(400, 400);
  cp5 = new ControlP5(this);
  pic = loadImage("bucky.jpg");
  Group t = cp5.addGroup("group-test").setPosition(100, 100).setWidth(200);
  cp5.addSlider("slider").setPosition(0, 10).moveTo(t);
  t.addDrawable(new CDrawable() {
    public void draw(PApplet p) {

void draw() {

I tried this, but I get a NullPointerException.

pic = loadImage("bucky.jpg")

def setup():
    cp5 = ControlP5(this) 
    g = cp5.addGroup('blah') \
           .setPosition(50,50) \

def draw():

Does anybody have a clue? Thank you all.



  • edited June 2014 Answer ✓

    Dunno Python yet but I'd daresay that cp5 is a local variable scoped to setup()! :-?
    Moreover we shouldn't be messing w/ field g, since that's where the canvas' reference is stored! :-S

    P.S.: Dunno whether Python Mode has this limitation but in Java Mode (and even in others)
    sketchPath, width & height aren't initialized until setup() is called!

  • @GoToLoop thanks for your answer, I'll have some new attempts while waiting for some python expert to join the conversation ;)

Sign In or Register to comment.