1

I'm trying to use Gephi Toolkit in Jython, but having problems with it. The code is below:

import sys
sys.path.append('gephi-toolkit.jar')
from org.openide.util import Lookup
import org.gephi.project.api.ProjectController as ProjectController

pc = Lookup.getDefault().lookup(ProjectController)
workspace = pc.newProject()

print "done."

It never reaches the last line. Instead gives the following error:

Traceback (most recent call last):
  File "standalone.py", line 9, in <module>
    workspace = pc.newProject()
AttributeError: 'NoneType' object has no attribute 'newProject'

Apparently, "Lookup.getDefault().lookup(ProjectController)" is returning None. Can anyone tell me why? I found that the following workaround works (which bypasses Lookup):

...
import org.gephi.project.impl.ProjectControllerImpl as ProjectControllerImpl
pc = ProjectControllerImpl()
workspace = pc.newProject()

I'd like to know more about this issue. Thanks.

Ruggiero Spearman
  • 6,735
  • 5
  • 26
  • 37

1 Answers1

1

i think it's because the lookup needs a reference to the java class, not the jython wrapper

try this and see if it works for you,for me at least it returns an instance of org.gephi.project.impl.ProjectControllerImpl

import sys

from org.openide.util import Lookup

import java.lang.Class

import org.gephi.project.api.ProjectController as ProjectController

pc = Lookup.getDefault().lookup(java.lang.Class.forName("org.gephi.project.api.ProjectController"))

print(pc)


invoke using (change to wherever your gephi is installed)

set CLASSPATH=%CLASSPATH%;C:\java\gephi-toolkit-0.7.2014-all\gephi-toolkit.jar

jython.bat gephi_test.jy

you should see something like

C:\jython2.5.2>jython.bat gephi_test.jy

org.gephi.project.impl.ProjectControllerImpl@8ddb93

rlawson
  • 160
  • 6
  • Thanks! That definitely makes sense, but I couldn't make it work. My code is: import org.gephi.project.api.ProjectController ref = java.lang.Class.forName("org.gephi.project.api.ProjectController") And I get: java.lang.ClassNotFoundException: java.lang.ClassNotFoundException: org.gephi.project.api.ProjectController Could you post your full code which returns ProjectControllerImpl and your JythonPath? – Ruggiero Spearman May 11 '11 at 14:15
  • also one thing to look out for, in your code post the call to newProject() returns void should be pc.newProject() followed by workspace = pc.getCurrentWorkspace() – rlawson May 11 '11 at 14:43
  • Well, the problem was not the class reference but the missing CLASSPATH. Adding the jar file to sys.path is not enough and one should also set the CLASS PATH like you say. My original code works in this case. Thanks again. – Ruggiero Spearman May 11 '11 at 14:46