From: Geoff B. <geo...@gm...> - 2010-10-22 15:44:58
|
Hi Stefan, Jeff, I have tried that and it works. Of course it isn't really that useful, because I can't just go on defining all my objects in Java or there would be no point in using Jython :) One interesting thing is that the "isinstance" call in Jython now returns False, so Jython and Java clearly have different ideas of what constitutes org.hamcrest.Matcher. I tried to make PySystemState work, but got into a horrible CLASSPATH mess with Eclipse and jython.jar that I haven't yet got my head round. In any case, the point of using JSR-223 was to get a generic interface for any dynamic language, and importing Jython things directly kind of defeats the object there. Also, it surely shouldn't be necessary? I tried replacing the SWTWorkbenchBot with a class that just did this: import org.hamcrest.Matcher; public class Method { public void doSomething(Matcher matcher) throws Exception { System.out.println(matcher.matches(matcher)); } } and then it worked just fine. Basically, it seems rather like a bug. But I'm still a bit unsure on how to investigate it further. Regards, Geoff On Fri, Oct 22, 2010 at 12:58 PM, Stefan Sonnenberg-Carstens <ste...@py...> wrote: > Or, have you tried this: > > SWTWorkbenchBot bot = new SWTWorkbenchBot(); > ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("py"); > org.hamcrest.Matcher matcher = new org.hamcrest.core.IsAnything(); > engine.put("bot", bot); > engine.put("matcher", matcher); > engine.eval("allWidgets = bot.widgets(matcher)"); > > And perhaps, you need to create a PySystemState: > http://wiki.python.org/jython/UserGuide#using-jsr-223 > > The classloader lives in sys, so perhaps this solves your issue. > > Am Fr, 22.10.2010, 10:21 schrieb Geoff Bache: >> Hi Jeff, >> >>> My guess is that there is a classloader mismatch. Perhaps IsAnything >>> and >>> its superclasses/interfaces are loaded by one classloader, but those >>> accessed >>> through the `bot` instance are from another. >> >> I imagine you may be right. Can you give me some hints as to what to >> do about it? >> Googling "Jython classloader mismatch" didn't find much and I'm pretty new >> to >> Jython and indeed to Java also. >> >> I'm using JSR-223, so the "bot" object is created in Java code like this. >> >> SWTWorkbenchBot bot = new SWTWorkbenchBot(); >> ScriptEngine engine = new >> ScriptEngineManager().getEngineByExtension("py"); >> engine.put("bot", bot); >> engine.eval(reader); >> >> where "reader" is reading the Python code I sent before. This is a >> workaround for >> another issue, that the "SWTWorkbenchBot" cannot be constructed in Jython >> for >> some reason. >> >> I translated your example code to also do something like this and it >> worked fine >> though. >> >> Regards, >> Geoff >> >> ------------------------------------------------------------------------------ >> Nokia and AT&T present the 2010 Calling All Innovators-North America >> contest >> Create new apps & games for the Nokia N8 for consumers in U.S. and Canada >> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in >> marketing >> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store >> http://p.sf.net/sfu/nokia-dev2dev >> _______________________________________________ >> Jython-users mailing list >> Jyt...@li... >> https://lists.sourceforge.net/lists/listinfo/jython-users >> >> > > > -- > MfG, > > Stefan Sonnenberg-Carstens > > IT Architect > - Project management > - System analysis, design and build > - Security and business continuity > - IT risk management > |