Surface doesn't work in Python mode

edited May 2018 in Python Mode

The surface thing works in java, but when I do the same thing in python, it says "global name surface is not defined." If anyone know the solution for this, please help me out!

void setup() { size(400, 400); // size always goes first! surface.setResizable(true); }

Untitled

Answers

  • edited May 2016 Answer ✓
    # forum.Processing.org/two/discussion/16721/surface-doesn-t-work-in-python-mode
    # GoToLoop (2016-May-20)
    
    def setup():
        size(400, 400)
        frameRate(1)
    
        frame.setResizable(True) # use frame instead.
        this.surface.setSize(600, 400) # or prefix surface w/ this.
    
    
    def draw():
        background(int(random(0x1000000)))
        this.getSurface().setTitle(`frameCount`) # or prefix getSurface() w/ this.
    
  • edited May 2016 Answer ✓

    You can also shoot your luck and beg for both surface & getSurface() to be directly accessed w/o this. here: https://GitHub.com/jdf/Processing.py-Bugs/issues

    Ah, while you're at it, request the same for getGraphics(), sketchFile(), dataFile(), dataPath(), and args[] too. :P

  • Amazing! Thank you!!!!

  • But what are these: getGraphics(), sketchFile(), dataFile(), dataPath() and args[] ? :(

  • edited May 2016 Answer ✓
    • While getSurface() returns sketch canvas' PSurface, getGraphics() returns its PGraphics.
    • sketchFile() is similar to sketchPath(), but returns a File instead of a String.
    • Same rule for dataFile() is related to dataPath(). Which is sketchPath + "/data".
    • args[] is a String[] array which keeps the arguments passed to the sketch when calling it from terminal or from another program.
  • Got it! You are such a nice guy. Thanks a lot!

  • Thanks for the info GoToLoop! I was wondering if this works when using the PDF renderer? I'm outputting large PDF files from processing and would like to dynamically set the PDF size after I've done some calculations on the input files. I'm getting the following error when I try to include the frame.setResizable(True). I'm using Processing 3.3.6 btw.

    AttributeError: 'NoneType' object has no attribute 'surface'

    Thanks in advance for any info you might have!

  • edited May 2018

    @pxlmnkeee, any PApplet public member not yet available in globals():

    for k, v in enumerate(globals().items()): print k, v
    exit()
    

    Can be accessed by prefixing them w/ this.. :-B

    You can see in my 1st reply example, I can access the non-globals() member getSurface() either w/ this.getSurface() or this.surface. :ar!

    Also, you can import any Processing classes not yet available in globals() via from package.name import class.

    For example, we can import the non-globals() class IntList like this: :bz
    https://Processing.org/reference/IntList.html

    from processing.data import IntList
    print dir(IntList)
    exit()
    

    Or even something more "obscure" like the PGL class: >-)
    https://GitHub.com/processing/processing/blob/master/core/src/processing/opengl/PGL.java

    from processing.opengl import PGL
    print dir(PGL)
    exit()
    
  • edited June 2018

    Finally got a chance to try this, thanks again for the knowledge GoToLoop! Well, I added this to the surface call, but the PDF output is still at the initial size set in the size command.

    size(100,100, PDF, 'pdfOutput.pdf')
    this.surface.setResizable(True)
    this.surface.setSize(5760, 5760)
    

    Sorry if this is obvious, still a Processing newbie.

    THANKS again for any additional info! :D

  • @pxlmnkeee, as explained at the 1st comment of class PSurfaceNone:
    https://GitHub.com/processing/processing/blob/master/core/src/processing/core/PSurfaceNone.java#L27-L28

    Surface that's not really visible. Used for PDF and friends, or as a base class for other drawing surfaces. It includes the standard rendering loop.

    As we can attest inside class PGraphicsPDF at its method createSurface():
    https://GitHub.com/processing/processing/blob/master/java/libraries/pdf/src/processing/pdf/PGraphicsPDF.java#L109

    public PSurface createSurface() {
      return surface = new PSurfaceNone(this);
    }
    

    It doesn't seem the renderer PDF can be resizable at all. :(

  • OK, it didn't seem like I could get the PDF to resize so I'm glad you came to the same result GoToLoop.

    Thanks again for your time and helpful info!

Sign In or Register to comment.