Search in Jython (and Gephi)

I am trying to use the Gephi Toolkit in Jython, but have problems with it. Code 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." 

He never reaches the last line. Instead, the following error appears:

 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)” returns None. Can someone 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 would like to know more about this issue. Thanks.

+1
source share
1 answer

I think, because to search you need a reference to the java class, not to the jython shell

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 anywhere in your gephi)

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

+1
source

Source: https://habr.com/ru/post/1447595/


All Articles