From: Ted B. <te...@et...> - 2001-09-26 20:35:09
|
On Wednesday 26 September 2001 13:01, you wrote: > [Ted Berg] > > > > have you an __init__.py or __init__$py.class there? > > > > No, I don't. Do I need to do anything special in the __init__.py file, > > or does it just need to be there? > > Just need to be there. If then it still don't work it's a bug ;) > or you have other secrets. > > regards. :) no secrets, but not much of a clue either. Here's the relevant code, if it helps. Essentially every time someone imports or creates a new node in a tree control in the application, a new BaseNodehandler subclass is created based on info provided in the XML that describes the node. if, for example, the XML element says it's for a textctrl_handler, the java class net.etherstorm.jOpenRPG.nodehandlers.textctrl_handler is created. If the XML element says it's for a alias_handler, the loadJavaNodehandler call returns null, and the code tries to load the script/pyhandlers/alias_handler.py script included in the jar or, failing that, the <user's home directory>/nodehandlers/alias_handler.py script. I've put an __init__.py file in both the pyhandlers and nodehandlers directories, but i still get the 'ImportError: no module named ...' errors. ( note that they are suppressed in this code ). ---- <code> /** * Method declaration * * * @param name * @param e * * @return * * */ BaseNodehandler loadJavaNodehandler( String name, Element e ) { try { String classname = "net.etherstorm.jOpenRPG.nodehandlers." + name; Class c = getClass().getClassLoader().loadClass( classname ); Class[] arg_types = { Element.class }; java.lang.reflect.Constructor ctor = c.getConstructor( arg_types ); Object[] args = { e }; BaseNodehandler bnh = ( BaseNodehandler )ctor.newInstance( args ); return bnh; } catch ( Exception ex ) { /* ExceptionHandler.handleException( ex ); */ return null; } } /** * Method declaration * * * @param name * @param e * * @return * * */ BaseNodehandler loadInternalPyNodehandler( String name, Element e ) { try { this.referenceManager.getPythonInterpreter().exec( "import java\nimport sys\njava.lang.System.out.println( sys.path )" ); System.out.println( "using internal python nodehandler" ); /* this.referenceManager.getPythonInterpreter().exec( "import scripts" ); */ /* this.referencemanager.getpythoninterpreter().exec( "import scripts.pyhandlers" ); */ this.referenceManager.getPythonInterpreter().exec( "import pyhandlers" ); this.referenceManager.getPythonInterpreter().set( "__element", e ); this.referenceManager.getPythonInterpreter().exec( "__foo = pyhandlers." + name + "( __element )" ); BaseNodehandler bnh = ( BaseNodehandler )this.referenceManager.getPythonInterpreter().get( "__foo", BaseNodehandler.class ); System.out.println( bnh ); System.out.println( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" ); return bnh; } catch ( Exception ex ) { /* ExceptionHandler.handleException( ex ); */ return null; } } /** * Method declaration * * * @param name * @param e * * @return * * */ BaseNodehandler loadExternalPyNodehandler( String name, Element e ) { try { File f = new File( System.getProperty( "user.home" ) + File.separator + "jopenrpg" + File.separator + "nodehandlers" + File.separator + name + ".py" ); if ( f.exists() ) { this.referenceManager.getPythonInterpreter().exec( "import nodehandlers" ); this.referenceManager.getPythonInterpreter().set( "__element", e ); this.referenceManager.getPythonInterpreter().exec( "__foo = nodehandlers." + name + "( __element )" ); BaseNodehandler bnh = ( BaseNodehandler )this.referenceManager.getPythonInterpreter().get( "__foo", BaseNodehandler.class ); return bnh; } else { return null; } } catch ( Exception ex ) { /* ExceptionHandler.handleException( ex ); */ return null; } } /** * * * @param name * @param e * @return */ BaseNodehandler loadHandler( String name, Element e ) { BaseNodehandler bnh = loadJavaNodehandler( name, e ); if ( bnh == null ) { bnh = loadInternalPyNodehandler( name, e ); if ( bnh == null ) { bnh = loadExternalPyNodehandler( name, e ); if ( bnh == null ) { bnh = new UnknownNodehandler( e ); } } } return bnh; } </code> ---- |