jython

How to use Java 8 lambdas in Jython

柔情痞子 提交于 2019-12-11 06:02:13
问题 I am trying to experiment with java 8 streams and collections in jython to see if they are any efficient then when implemented in pure jython. It occurs to me it could (any comments on this also appreciated) I started with some examples, the counting from java.util.function import Function from java.util import ArrayList from java.util.stream import Collectors letters = ArrayList(['a','b','a','c']); cnt=letters.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())

Jython Swing: Passing more than self and event on a button press

余生颓废 提交于 2019-12-11 05:29:20
问题 I'm creating a couple of swing JButtons buttons in a loop in Jython. On press, each button should call the same function, but with one different parameter. I'm having trouble passing any parameters outside of self, and event. This works: for x in range(0,3): name = JButton(str(x)) name.actionPerformed = self.foo def foo(self, event): print "I work." Somehow event magically is passed to the method. This doesn't: for x in range(0,3): name = JButton(str(x)) name.actionPerformed = self.foo(x) def

jython to python version mapping

怎甘沉沦 提交于 2019-12-11 04:35:16
问题 Jython is an implementaion of python. Is there any way to find the version of python that is being supported by a particular jython jar. eg: Few posts in the web say that Jython 2.5 supports python 2.5 Similarly I want to know the jython version that supports python 2.7.14 or more. It would be helpful if the version mapping can be referred to in any user-guides or pages. 来源: https://stackoverflow.com/questions/50965533/jython-to-python-version-mapping

Translating Java annotations

北城余情 提交于 2019-12-11 04:33:13
问题 Note this is similar to Jython @property SyntaxError: mismatched input '' expecting CLASS but I am using Jython 2.7.0 and that answer references a specfic bug in 2.5.2 I have some Java code that has annotations that I am trying to rewrite in Jython: @ProcessInput public void process(SomeEvent event) { ... } I tried to convert this method into Python leaving the annotation alone: @ProcessInput def process(event): But that fails with the error from the other post, SyntaxError: mismatched input

Is there any way of quickening monkeyrunner script execution?

淺唱寂寞╮ 提交于 2019-12-11 04:32:27
问题 I've got a particular monkeyrunner script (in Jython), which I use for taking screenshots or touching particular coordinates. My main program is written in Perl - it just executes monkeyrunner scripts when their functionality is need. The problem is in slowness of such method: every time in monkeyrunner script I should get a MonkeyDevice object and work with it: device = MonkeyRunner.waitForConnection() And the whole operation seems to take from 5 to 9 seconds, which is very slow for my

How to convert PyObject to java boolean type

你离开我真会死。 提交于 2019-12-11 04:26:51
问题 I would like to cast org.python.core.PyObject to java.lang.Boolean. Something similar to: boolean i = ((Boolean) PyObject).booleanValue(); 回答1: Just try the following: PyObject obj = interpreter.eval("True"); boolean i = ((PyInteger) obj).asInt() != 0; 回答2: You should use the Python standard object interface nonzero method: PyObject obj = interpreter.eval("True"); boolean i = obj.__nonzero__(); (it's called "nonzero" because it existed before Python had a boolean type and Guido's ways are

Saving changes to newPic when copying an image in jython

Deadly 提交于 2019-12-11 04:23:56
问题 There are similar questions on Stack Overflow, but I cannot find what I am doing wrong in my code. def copyPic(): file=pickAFile() oldPic=makePicture(file) newPic=makeEmptyPicture(getWidth(oldPic),getHeight(oldPic)) for y in range(0,getHeight(oldPic)): for x in range(0,getWidth(oldPic)): oldPixel=getPixel(oldPic,x,y) colour=getColor(oldPixel) newPixel=getPixel(newPic,x,y) setColor(newPixel,colour) explore(newPic) When I use explore(newPic) or show(newPic) outside of the function, gives a

jython standalone jar with reduced package list?

假装没事ソ 提交于 2019-12-11 02:24:00
问题 The new version of Jython 2.7.0 standalone weighs in at 36155 KB; the previous released version 2.5.3 is 14005 KB. Is there any way to safely remove functionality from the .jar file, if certain Python packages are not needed? I want to use the updated Jython release but the file size is an issue now, much more so than 2.5.3. 回答1: From the Jython developer mailing list: Yes, sorry about that. We are focused on correctness first, then we will go and trim down in subsequent 2.7.x releases, where

Calling right overload of the java method from jython

点点圈 提交于 2019-12-11 02:22:45
问题 I am using java library, that has overloaded methods in the class that I use. JAVA: void f(float[]); void f(Object[]); Now I call this class from jython, and I want to call the Object[] overload. The problem is that python sees my array as array of floats, and therefore calls the wrong overload methods. JYTHON: f([[1, 1.0]) How to force the Object[] method to be executed? 回答1: It took me considerable amount of time to find out, so I decided to post a question together with the answer. Forcing

Use Button as renderer for list

旧街凉风 提交于 2019-12-11 00:48:12
问题 I would like to use a more complex renderer consisting of several components for a list (more precisely something like this (a textfieldinput with some buttons arranged in a panel). However when I try to use a button in a list it seems to ignore clicks. Minimal example from javax.swing import DefaultListCellRenderer from javax.swing import DefaultListSelectionModel from javax.swing import JButton from javax.swing import JLabel from javax.swing import JPanel from javax.swing import JList from