GithubHelp home page GithubHelp logo

processing.py-bugs's Introduction

processing.py-bugs's People

Contributors

saloni-garg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

processing.py-bugs's Issues

Python mode "build number message" is not updated in Mode Manager.

In the Processing Mode Manager window, the Build number message appears to be stuck at 337, even though the build has advanced beyond this. Currently the message says the following when I select "Add Mode...":

"Write Processing sketches in Python (build 0337)."
Since things are changing quickly, it would be helpful if this number kept pace.

As an aside, it might be helpful to introduce a printable system constant, e.g.:

println (PROCESSING_VERSION);
println (PYTHON_MODE_VERSION);

Best
Golan

Better messages for certain syntax errors.

Reported by Jim Roberts:

When bogus syntax is encountered like a // instead of # for a comment delimiter, the error is:
"mismatched input '//' expecting EOF

novices do not have any idea what EOF or EOLN means.
Can this be displayed for the novice in a manner similar to this:
I found this: // and I do not understand what you mean

Auto import modules.

This is Processing.py, and as autoglobal is there, autoimport would be useful, too.

Set window title to the name of the sketch

When a sketch is launched (in the current release version), it appears to set the frame title to the absolute path to the PDE file (or maybe it's sketch folder?) It should just be the sketch name.

Seeing this on OS X with a version installed today.

How to define rectangle bound for text?

The following code gives an array out of bounds error in Python mode:

text("Hello", 6, 6, 100, 100)

This is the output in Java mode for the same line:

screen shot 2014-05-21 at 11 52 49 am

In the Processing reference there are two ways to call text() with five arguments:

text(chars, start, stop, x, y)

and

text(str, x1, y1, x2, y2)

But since there is no separate char type in Python, this implicit distinction doesn't seem possible. So there is currently no way (as far as I know) to define a rectangle bound using text().

Objects can't access global variables from main tab

This Python code gives the error: "global name 'i' is not defined".

Main tab:

from cat import Cat

i = 10

def setup():
    cat = Cat()

def draw():
    pass

cat.py:

class Cat(object):
    def __init__(self):
        println(i)

This Java code prints "10" as expected.

Main tab:

int i = 10;

void setup() {
  Cat cat = new Cat();
}

void draw() {}

cat.pde

class Cat {
 Cat() {
  println(i);
 } 
}

loadStrings and loadBytes fail with coercion errors

On my machine, attempting to run:

data = loadStrings("data.txt")

fails with:

processing.app.SketchException: TypeError: loadStrings(): 1st arg can't be coerced to java.io.InputStream, java.io.File, String, java.io.BufferedReader
    at jycessing.mode.run.SketchRunner.convertPythonSketchError(Unknown Source)
    at jycessing.mode.run.SketchRunner.access$300(Unknown Source)
    at jycessing.mode.run.SketchRunner$2.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

The same thing happens with loadBytes. However, all the other load* functions work.
This is very strange, seeing as Jython strs are supposed to be Java Strings.

Highlight self.

The word self isn't highlighted. (I know, self is just a name, but it is commonly called 'self'.)

Add new library?

Not sure how (where) to add a new library so that it can be imported by a script.

Sketch window appears under other windows or not at all

(Processing 2.2.1, Processing.py build 337, Mac OSX Mavericks)

These possibly are two separate issues, but I think they are related.

Issue 1: Whenever a sketch is run, the graphics window appears under other windows. In particular, it appears at a lower stacking level than the PDE window that started the sketch. If there is room in the desktop so that the window fits to the left of the PDE window, this is not a serious issue, but if the graphics windows is somewhat large, the lower stacking order will make the PDE window actually cover the graphics window, so that the only way to see it is to move the PDE window out of the way. Moreover, the graphics window does not receive the mouse focus by default. Even worse, it is not recognized by the Finder / OS either as a separate application (e.g. as a Java application in the case of Java Processing) or as part of the Processing application. This means that we cannot put the sketch application in foreground using the usual means for Mac OS, such as cycling amongst the Processing windows using Cmd-` or cycling through applications using Cmd-TAB. To reproduce this behavior, just run an empty sketch with the PDE window placed close to the left edge of the desktop.

Issue 2: The graphics window may never appear at all. I've had this problem on several occasions. One sure way to trigger this behavior is as follows: (a) Start the PDE and create an empty sketch in Python mode. Run it and the graphics window appears after a while. (b) Create a new sketch in Java mode, but do not close the Python sketch. Run the empty Java sketch and the little 100x100 graphics window appears as expected. (c) Now go back to the Python sketch and run it. Although the "Play" button stays highlighted, no graphics window appears. Because of issue 1, it may have been mapped to some invalid desktop position and we will never know, since there is no way to put it in foreground.

doc strings on classes break the editor

so I added a doc string to a Python class and things ... went wrong.

here's a py-processing project in question: https://gist.github.com/jordanorelli/4a32d0b58efda1439e9d

in walker.py, there's a doc string on line 4 for the Walker class. This actually runs fine, but editing it and saving the file causes a litany of errors in the editor. On first shot I thought having one long line was the problem, but even short lines create all sorts of crazy behaviors. If you save the sketch, everything goes wrong. If you then load it again, and then run it, it runs just fine; it seems that the problem is localized to the editor, not the runtime.

e.g., a lot of code fails to paint, and there are repeated index errors on a long comment string:
screen shot 2014-06-08 at 12 14 36 pm

or this is a good one: with a short doc string, save the sketch. Editor barfs. Close the sketch and reopen it. Put your editor cursor in the doc string. Hit space. The editor now loops on the following error:

java.lang.ArrayIndexOutOfBoundsException
Error repainting line range {3,3}:

like so:

image

'textureWrap' and 'beginPGL' not defined

def setup():
    size(50,50,P3D)
    textureWrap(REPEAT)

This code gives a "NameError: global name 'textureWrap' is not defined", while its Java equivalent runs fine.

'link()' not defined in Python mode

Running the following line in Python mode gives a NameError, while it runs as expected in Java mode (opens default browser to link):

 link("http://www.google.com")

EDIT: I'm running Processing 2.2.1 on on Mac OSX 10.9.

Runtime error does not seem to cause editor to jump to source line

For example

processing.app.SketchException: Traceback (most recent call last):
File "/usr/local/google/home/feinberg/sketchbook/Yellowtail/Yellowtail.pyde", line 50, in mousePressed
gesture.addPoint(mouseX, mouseY)
File "/usr/local/google/home/feinberg/sketchbook/Yellowtail/gesture.py", line 35, in addPoint
if self.nPoints >= self.capacity:
AttributeError: 'Gesture' object has no attribute 'capacity'

keyPressed callback does not receive CODED keystrokes

There seems to be a problem in how variable key is set in keyPressed callbacks. Relevant code:

def draw(): pass

def keyPressed () :
  if key == CODED:
    print "Coded",
    if keyCode == UP : 
      print "UP"
    else :
      print "OTHER"
  else:
    print "key "+str(key)

When the sketch is run and one presses the UP key, the output is:

key 65535

rather than

Coded UP

Java Processing code for comparison:

void draw() {}

void keyPressed () {
  if (key == CODED) {
    print ("Coded ");
    if (keyCode == UP)  
      println ("UP");
    else 
      println ("OTHER");
  }
  else
    println ("key "+key);
}

Catch and explain UnboundLocalError

banana = 12

def draw():
    # forgot to say
    # global banana
    banana += 1

processing.app.SketchException: UnboundLocalError: local variable 'banana' referenced before assignment
at jycessing.mode.run.SketchRunner.convertPythonSketchError(SketchRunner.java:167)
at jycessing.mode.run.SketchRunner.access$3(SketchRunner.java:144)
at jycessing.mode.run.SketchRunner$1.run(SketchRunner.java:50)
at java.lang.Thread.run(Thread.java:745)

Discrepancy between color() and pixels/get()

This code outputs False in Python mode, and true in Java mode.

background(0)
println(get(50,50) == color(0,0,0))

It seems like Python mode color() does not handle pixel data the way that get() and the pixels array do:

background(0)
loadPixels()
println(get(50, 50))
println(pixels[50 * 100 + 50])
println(color(0,0,0))

Python mode output:

4278190080
4278190080
-16777216

Java mode output:

-16777216
-16777216
-16777216

Can't nest functions inside a class?

Following example will work if you comment out the run() function inside the Ball class and just call Ball.drawBall() and Ball.update() separately. However, if you combine them into one Ball.run() function that then calls drawBall() and update()...you get "NameError: global name 'drawBall' is not defined" and "NameError: global name 'update' is not defined".

def setup():
    global b
    size(640, 480, P3D)
    b = Ball()
    background(0)


def draw():
    global b
    blendMode(NORMAL)
    noStroke()
    fill(0, 5)
    rect(0, 0, width, height)
    blendMode(ADD)
    #b.update()
    #b.drawBall()
    b.run()

# ~~~~~~~~~~~~~~~~

class Ball:
    def __init__(self):
        global p, counter, counterMax
        p = [random(width), random(height)]
        counter = 0
        counterMax = 100

    def drawBall(self):
        global p, counter, counterMax
        stroke(0, 100, 255)
        strokeWeight(5)
        noFill()
        ellipseMode(CENTER)
        ellipse(p[0], p[1], 30, 30)

    def update(self):
        global p, counter, counterMax
        p[0] = random(width)
        counter += 1
        if(counter > counterMax):
            counter = 0
            p[1] = random(height)

    def run(self):
        drawBall()
        update()

Brightness example runs at 1/100 speed in Python mode

Hi Jonathan,

For some reason the brightness example is egregiously slow in Python mode. Golan and I went through the code to see if there was a particular line or function that was causing the slowdown, but we couldn't find a single culprit.

In Python mode the outer for loop takes about 700ms to run vs. 6ms in Java mode.

Python code:

"""
Brightness
by Daniel Shiffman. 

This program adjusts the brightness of a part of the image by
calculating the distance of each pixel to the mouse.
"""

img = None
runningavg = 0;
total = 0;

def setup():
    size(640, 360)
    frameRate(30)
    img = loadImage("moon-wide.jpg")
    img.loadPixels()
    # Only need to load the pixels[] array once, because we're only
    # manipulating pixels[] inside draw(), not drawing shapes.
    loadPixels()


def draw():
    now = millis()
    for x in range(img.width):
        for y in range(img.height):
            # Calculate the 1D location from a 2D grid
            loc = x + y * img.width
            # Get the R,G,B values from image
            r = 0 
            g = 0 
            b = 0
            r = red(img.pixels[loc])
            #g = green (img.pixels[loc])
            #b = blue (img.pixels[loc])
            # Calculate an amount to change brightness based on proximity to
            # the mouse
            maxdist = 50  # dist(0,0,width,height)
            d = dist(x, y, mouseX, mouseY)
            adjustbrightness = 255 * (maxdist - d) / maxdist
            r += adjustbrightness
            #g += adjustbrightness
            #b += adjustbrightness
            # Constrain RGB to make sure they are within 0-255 color range
            r = constrain(r, 0, 255)
            #g = constrain(g, 0, 255)
            #b = constrain(b, 0, 255)
            # Make a color and set pixel in the window
            # color c = color(r, g, b)
            c = color(r)
            pixels[y * width + x] = c
    then = millis()
    total += then - now
    runningavg += 1
    println(total/runningavg)
    updatePixels()

Java code:

/**
 * Brightness
 * by Daniel Shiffman. 
 * 
 * This program adjusts the brightness of a part of the image by
 * calculating the distance of each pixel to the mouse.
 */

// The next line is needed if running in JavaScript Mode with Processing.js
/* @pjs preload="moon-wide.jpg"; */ 

PImage img;
int runningavg = 0;
int total = 0;

void setup() {
  size(640, 360);
  frameRate(30);
  img = loadImage("moon-wide.jpg");
  img.loadPixels();
  // Only need to load the pixels[] array once, because we're only
  // manipulating pixels[] inside draw(), not drawing shapes.
  loadPixels();
}

void draw() {
  float now = millis();
  for (int x = 0; x < img.width; x++) {
    for (int y = 0; y < img.height; y++ ) {
      // Calculate the 1D location from a 2D grid
      int loc = x + y*img.width;
      // Get the R,G,B values from image
      float r,g,b;
      r = red (img.pixels[loc]);
      //g = green (img.pixels[loc]);
      //b = blue (img.pixels[loc]);
      // Calculate an amount to change brightness based on proximity to the mouse
      float maxdist = 50;//dist(0,0,width,height);
      float d = dist(x, y, mouseX, mouseY);
      float adjustbrightness = 255*(maxdist-d)/maxdist;
      r += adjustbrightness;
      //g += adjustbrightness;
      //b += adjustbrightness;
      // Constrain RGB to make sure they are within 0-255 color range
      r = constrain(r, 0, 255);
      //g = constrain(g, 0, 255);
      //b = constrain(b, 0, 255);
      // Make a new color and set pixel in the window
      //color c = color(r, g, b);
      color c = color(r);
      pixels[y*width + x] = c;
    }
  }
  float then = millis();
  total += then - now;
  runningavg += 1;
  println(total/runningavg);
  updatePixels();
}

Global variables leak

Global sketch variables retain memory when the sketch closes. I noticed this while writing a sketch that loaded lots of images, but even something like:

data = "data" * 10000000

will grab heap space and hang around after the sketch is terminated.

For example, run this sketch a few times:

import java.lang.Runtime as Runtime

print "Allocating memory..."
data = "data"*10000000

runtime = Runtime.getRuntime()
print "Memory statistics:"
print "Max memory: {} mb".format(runtime.maxMemory()/1048576)
print "Total memory: {} mb".format(runtime.totalMemory()/1048576)
print "Free memory: {} mb".format(runtime.freeMemory()/1048576)
print "Used memory: {} mb".format((runtime.totalMemory()-runtime.freeMemory)/1048576

The numbers fluctuate - stuff appears to get gc'd eventually - so it's possible this won't cause problems. Still, it smells fishy.

mousePressed

If the user defines a mousePressed() function, then the mousePressed variable is clobbered.

Make it hard to quit the sketch runner

Right now, if you hit cmd-Q while the sketch is focused, it "works", in that the sketch stops running and control is returned to the PDE. But it would be better to intercept the command and simply close the sketch, leaving the sketch runner running.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.