2011/10/9 Jose Vicente Nunez Zuleta <josevnz@yahoo.com>
Hello to all,

Playin with JavaFX + Jython and tried to convert the code that appears on the following location: http://download.oracle.com/javafx/2.0/charts/pie-chart.htm#CIHFDADD

So far the original Java code works well but the following Jython script:

#!/usr/bin/env jython
import sys
from javafx.application import Application
from javafx.collections import FXCollections
from javafx.collections import ObservableList
from javafx.scene import Scene
from javafx.stage import Stage
from javafx.scene.chart import PieChart
from javafx.scene import Group

class PieChartSample(Application):

    def __init__(self):
        pass

    def start(self, stage):
        scene = Scene(Group())
        stage.setTitle("Imported Fruits")
        stage.setWidth(500)
        stage.setHeight(500)

        pieChartData = FXCollections.observableArrayList(
                PieChart.Data("Grapefruit", 13),
                PieChart.Data("Oranges", 25),
                PieChart.Data("Plums", 10),
                PieChart.Data("Pears", 22),
                PieChart.Data("Apples", 30))
        chart = PieChart(pieChartData)
        chart.setTitle("Imported Fruits")

        scene.getRoot().getChildren().add(chart)
        stage.setScene(scene)
        stage.show()

if __name__ == "__main__":
        PieChartSample().launch(sys.argv[1:])

Gives me the following exception:

 ./piechart.py *sys-package-mgr*: can't create package cache dir, '/Users/Shared/jython2.5.2/cachedir/packages'
Traceback (most recent call last):
  File "./piechart.py", line 36, in <module>
    PieChartSample().launch(sys.argv[1:])
    at javafx.application.Application.launch(Application.java:186)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)

java.lang.RuntimeException: java.lang.RuntimeException: Error: class sun.reflect.NativeMethodAccessorImpl is not a subclass of javafx.application.Application

Does anybody had a similar issue while trying to create JavaFX applications using Jython? Somehow Jython doesn't think I overrode the start method on my class.

--José



Hello José,

I think "stage" parameter in the "start" method is a simple object. We can verify this assumption by using Java reflexion. If it is the case I believe you'll have to create a Java class to wrap PieChartSample. I don't know how to specify the type of a method parameter in Jython. I don't know if it is possible.
 
Pierre Thibault

Python Developer/Développeur Python
Montréal, QC
pierre.thibault1@gmail.com