开发者

Lookup in Jython (and Gephi)

开发者 https://www.devze.com 2023-03-05 09:28 出处:网络
I\'m trying to use Gephi Toolkit in Jython, but having problems with it. The code is below: import sys

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 Looku开发者_运维技巧p):

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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号