Lookup in Jython (and Gephi)

感情迁移 提交于 2019-12-11 08:29:58

问题


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.


回答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



来源:https://stackoverflow.com/questions/5954852/lookup-in-jython-and-gephi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!