Jython Build has no Output - netbeans

Hey, I've been playing around with Jython a bit and I wrote the following test program:
from javax.swing import *
from java.awt import *
from java.awt.event import ActionListener
class JythonTest(JFrame):
_windowTitle = ""
def __init__(self):
self.initVars()
self.initLookAndFeel()
self.initComponents()
self.initGui()
def initVars(self):
self._windowTitle = "Jython Test"
JFrame.__init__(self, self._windowTitle)
def initLookAndFeel(self):
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName())
def initComponents(self):
label = JLabel("Hello World!", JLabel.CENTER)
label.setFont(Font("Arial", Font.BOLD, 30))
tabs = JTabbedPane()
tabs.addTab("Test", label)
tabs.addTab("Calculator", self.CalculatorPane())
self.add(tabs)
def initGui(self):
self.setSize(400,200)
self.setDefaultCloseOperation(self.EXIT_ON_CLOSE)
self.setVisible(1)
class CalculatorPane(JPanel, ActionListener):
_txt1 = 0
_txt2 = 0
_box = 0
def __init__(self):
self.initVars()
self.initComponents()
def initVars(self):
pass
def initComponents(self):
self._txt1 = JTextField(5)
self._box = JComboBox(["+", "-", "*", "/"])
self._txt2 = JTextField(5)
btn = JButton("Go")
btn.addActionListener(self)
self.add(self._txt1)
self.add(self._box)
self.add(self._txt2)
self.add(btn)
def actionPerformed(self, ev):
val1 = self._txt1.getText()
val2 = self._txt2.getText()
operation = self._box.getSelectedItem()
val1 = int(val1)
val2 = int(val2)
if operation == "+":
answer = val1+val2
elif operation == "-":
answer = val1-val2
elif operation == "*":
answer = val1*val2
elif operation == "/":
answer = val1/val2
JOptionPane.showMessageDialog(self, "The answer is: " + str(answer))
if __name__ == "__main__":
win = JythonTest()
Here's my system info:
Operating System: Ubuntun 10.10
Netbeans Version: 6.9
My problem is that I can't compile the above code. It runs just fine when I click the run button, however, when I hit build or clean & build then I don't get any results. The build process runs in the bottom right corner for about half a second and then finishes. The output box opens up but it's entirely empty, even after the process ends. When I look at my project folder, nothing changes. Only two folders exist, nbproject and src. There probably should be a dist folder with a jar inside of it. Here's what's in the file structure:
user#computer: ~/NetBeansProjects/pythontest$ ls
nbproject src
user#computer: ~/NetBeansProjects/pythontest$ ls nbproject
private project.properties project.xml
user#computer: ~/NetBeansProjects/pythontest$ ls nbproject/private
private.xml
user#computer: ~/NetBeansProjects/pythontest$ ls src
pythontest.py setup.py
All I did to set up was install netbeans from the debian package (quite a while ago) and set up python/jython through the NetBeans python plugin. Any idea what's wrong?

The short answer is that it doesn't really work like that; I'm not aware of any IDE or tool support for packaging jython programs.
Usually what I do is just make a shell script that says:
java -cp "the/classpath/;" org.python.util.jython myscript.py
I've found that is the most foolproof way to run a jython program, and has saved me many headaches from not-working .jar files during development.
That said, there are methods of packaging jython programs in standalone .jar files, if that's what you want.
The best resource that I've found is the Distributing Jython Scripts page in the Jython FAQ, which describes a few different techniques for distributing jython scripts.
I usually only use the methods described there when "publishing" a program.

Related

Yocto - git revision in the image name

By default Yocto adds build timestamp to the output image file name, but I would like to replace it by the revision of my integration Git repository (which references all my layers and configuration files). To achieve this, I put the following code to my image recipe:
def get_image_version(d):
import subprocess
import os.path
try:
parentRepo = os.path.dirname(d.getVar("COREBASE", True))
return subprocess.check_output(["git", "describe", "--tags", "--long", "--dirty"], cwd = parentRepo, stderr = subprocess.DEVNULL).strip().decode('UTF-8')
except:
return d.getVar("MACHINE", True) + "-" + d.getVar("DATETIME", True)
IMAGE_VERSION = "${#get_image_version(d)}"
IMAGE_NAME = "${IMAGE_BASENAME}-${IMAGE_VERSION}"
IMAGE_NAME[vardepsexclude] = "IMAGE_VERSION"
This code works properly until I change Git revision (e.g. by adding a new commit). Then I receive the following error:
ERROR: When reparsing /home/ubuntu/yocto/poky/../mylayer/recipes-custom/images/core-image-minimal.bb.do_image_tar, the basehash value changed from 63e1e69797d2813a4c36297517478a28 to 9788d4bf2950a23d0f758e4508b0a894. The metadata is not deterministic and this needs to be fixed.
I understand this happens because the image recipe has already been parsed with older Git revision, but why constant changes of the build timestamp do not cause the same error? How can I fix my code to overcome this problem?
The timestamp does not have this effect since its added to vardepsexclude:
https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-metadata.html#variable-flags
[vardepsexclude]: Specifies a space-separated list of variables that should be excluded from a variable’s dependencies for the purposes of calculating its signature.
You may need to add this in a couple of places, e.g.:
https://git.yoctoproject.org/poky/tree/meta/classes/image-artifact-names.bbclass#n7
IMAGE_VERSION_SUFFIX ?= "-${DATETIME}"
IMAGE_VERSION_SUFFIX[vardepsexclude] += "DATETIME SOURCE_DATE_EPOCH"
IMAGE_NAME ?= "${IMAGE_BASENAME}-${MACHINE}${IMAGE_VERSION_SUFFIX}"
After some research it turned out the problem was in this line
IMAGE_VERSION = "${#get_image_version(d)}"
because the function get_image_version() was called during parsing. I took inspiration from the source file in aehs29's post and moved the code to the anonymous Python function which is called after parsing.
I also had to add vardepsexclude attribute to the IMAGE_NAME variable. I tried to add vardepvalue flag to IMAGE_VERSION variable as well and in this particular case it did the same job as vardepsexclude. Mentioned Bitbake class uses both flags, but I think in my case using only one of them is enough.
The final code is below:
IMAGE_VERSION ?= "${MACHINE}-${DATETIME}"
IMAGE_NAME = "${IMAGE_BASENAME}-${IMAGE_VERSION}"
IMAGE_NAME[vardepsexclude] += "IMAGE_VERSION"
python () {
import subprocess
import os.path
try:
parentRepo = os.path.dirname(d.getVar("COREBASE", True))
version = subprocess.check_output(["git", "describe", "--tags", "--long", "--dirty"], cwd = parentRepo, stderr = subprocess.DEVNULL).strip().decode('UTF-8')
d.setVar("IMAGE_VERSION", version)
except:
bb.warning("Could not get Git revision, image will have default name.")
}
EDIT:
After some research I realized it's better to define a global variable in layer.conf file of the layer containing the recipes referencing the variable. The variable is set by a python script and is immediately expanded to prevent deterministic build warning:
layer.conf:
require conf/image-version.py.inc
IMAGE_VERSION := "${#get_image_version(d)}"
image-version.py.inc:
def get_image_version(d):
import subprocess
import os.path
try:
parentRepo = os.path.dirname(d.getVar("COREBASE", True))
return subprocess.check_output(["git", "describe", "--tags", "--long", "--dirty"], cwd = parentRepo, stderr = subprocess.DEVNULL).strip().decode('UTF-8')
except:
bb.warn("Could not determine image version. Default naming schema will be used.")
return d.getVar("MACHINE", True) + "-" + d.getVar("DATETIME", True)
I think this is cleaner approach which fits BitBake build system better.

Shell like application using sbt console

I would like to deploy some scala code, to be used very similar to sbt console
(command line interface, history, etc)
and would like to
customize it
and made it simple to deploy.
Can sbt console be used with these changes:
Removed startup info messages
Removed scala welcome message
Customized command prompt instead of "scala>" to be "myApp>"
No access to local nor global ivy/maven repositories (all jars
available, including sbt jars and dependencies)
Anybody passed this path ?
I have tried
Using sbt to build command line application
but with no much progress so far
(I guessed it was intented to very similar situation)
Are there ready made plugin available ?
Any other tool related or unrelated to sbt ?
Thank you
Actully, no need for sbt. To have it tweaked, scala code should be changed.
For the sbt "Customized command prompt" part, you have a good example with "sbt: Customize the Shell prompt in sbt" from Patrick Bailey (patmandenver).
create the ~/.sbt/0.13/global.sbt file:
vi ~/.sbt/0.13/global.sbt
And place the following in it.
shellPrompt := { state =>
def textColor(color: Int) = { s"\033[38;5;${color}m" }
def backgroundColor(color:Int) = { s"\033[48;5;${color}m" }
def reset = { s"\033[0m" }
def formatText(str: String)(txtColor: Int, backColor: Int) = {
s"${textColor(txtColor)}${backgroundColor(backColor)}${str}${reset}"
}
val red = 1
val green = 2
val yellow = 11
val white = 15
val black = 16
val orange = 166
formatText(s"[${name.value}]")(white, orange) +
"\n " +
formatText("\u276f")(green, black) +
formatText("\u276f")(yellow, black) +
formatText("\u276f ")(red, black)
}
Run reload in sbt and….
That can be amended/enhanced/completed to add other information you would need in your case.

Using Wuff (Gradle Plugin) to Build Eclipse Plugins

Thanks to this question, I stared looking at Wuff to help with a Gradle build (converting an Eclipse plugin).
This is probably such a newbie question, so I do apologize in advance, but I couldn't find the answer anywhere:
We're currently using Eclipse 4.3.1. So, I followed the wiki page and changed the version:
wuff{
selectedEclipseVersion = '4.3.1'
eclipseVersion('4.3.1') {
}
}
Which seems to work. However, the default mirror site does not contain that version anymore, so I'm a fileNotFoundException error (for eclipse-SDK-4.3.1-linux-gtk-x86_64.tar.gz).
Now, I'm guessing it should have automatically gone to the archive site, but for some reason it does not.
I tried fiddling around with the eclipseMirror extension (since changing extra properties is now disabled by Gradle):
wuff.ext.'eclipseMirror' = 'http://archive.eclipse.org'
but to no avail.
Any insight would be appreciated.
Using the same version name just overrides the exiting properties, it does not delete the rest, which was the problem (thanks to Andrey Hihlovskiy for pointing it out!). I wrote the following workaround:
selectedEclipseVersion = '4.3.1-mine'
...
eclipseVersion('4.3.1-mine'){
extendsFrom '4.2.2'
eclipseMavenGroup = 'eclipse-kepler-sr1'
eclipseMirror = 'http://mirror.netcologne.de'
eclipseArchiveMirror = 'http://archive.eclipse.org'
def suffix_os = [ 'linux': 'linux-gtk', 'macosx': 'macosx-cocoa', 'windows': 'win32' ]
def suffix_arch = [ 'x86_32': '', 'x86_64': '-x86_64' ]
def fileExt_os = [ 'linux': 'tar.gz', 'macosx': 'tar.gz', 'windows': 'zip' ]
def current_os = //your os
def current_arch = //your arch
sources {
source "$eclipseMirror/eclipse//technology/epp/downloads/release/kepler/SR1/eclipse-jee-kepler-SR1-${suffix_os[current_os]}${suffix_arch[current_arch]}.${fileExt_os[current_os]}"
source "$eclipseMirror/eclipse//technology/epp/downloads/release/kepler/SR1/eclipse-rcp-kepler-SR1-${suffix_os[current_os]}${suffix_arch[current_arch]}.${fileExt_os[current_os]}", sourcesOnly: true
languagePackTemplate '${eclipseMirror}/eclipse//technology/babel/babel_language_packs/R0.11.1/kepler/BabelLanguagePack-eclipse-${language}_4.3.0.v20131123020001.zip'
}

Wxpython drag and drop folder path, Popen not working with spaces on Windows

I have the below code which allows the user to drag and drop a folder to get the folder path. I then take this folder path and use it to pass through to a command line application in Windows using Popen. This all works fine except if there are spaces in the folder path, which then fails. I am currently getting round this by using win32api.GetShortPathName(folder_list) which shortens them to DOS 8.3 spec, but I would like to use the full absolute path. I know the command line application takes paths with spaces as I also use a batch file with drag and drop which works with spaces in paths. I have tried inserting escapes, etc, still no luck. How can I get this to work properly with full folder paths with spaces?
class SubmissionPane(wx.Panel):
def __init__(self, parent, queue_control):
wx.Panel.__init__(self, parent, -1)
self.parent = parent
self.queue_control = queue_control
self.selected_folder = None
self.txtTitle = wx.TextCtrl(self, pos=(125, 70), size=(215, 25), style= wx.SUNKEN_BORDER, value="Enter Series Title Here")
self.txtTitle.Show(False)
self.drop_target = MyFileDropTarget(self)
self.SetDropTarget(self.drop_target)
def SetSubmissionFolders(self, folder_list):
"""Called by the FileDropTarget when files are dropped"""
print "Setting submission folders", folder_list
self.tc_files.SetValue(','.join(folder_list))
self.selected_folders = folder_list
class MyFileDropTarget(wx.FileDropTarget):
""""""
def __init__(self, window):
wx.FileDropTarget.__init__(self)
print "Creating a drop file target..."
self.window = window
def OnDropFiles(self, x, y, filenames):
self.window.SetSubmissionFolders(filenames)
I then submit this to Popen like this:
command1 = commandLineApplication + folder_list
process = Popen(command1, shell=True, stdin=PIPE)
You probably just need to put quotes around each of the file paths. That usually works. The win32api.GetShortPathName is a neat trick though.
Here's one way to do it:
n = ['"%s"' % x for x in folderlist]
Then do the
','.join(folder_list)
You mentioned in your code.

Resource Not Found Exception in pyglet

I'm using Python 2.6.6 and pyglet 1.1.4. In my "Erosion" folder, I have "Erosion.py" and a folder named "Images." Inside images, there are .png images. One image is named "Guard.png."
In "Erosion.py" there is a segment that goes like so:
pyglet.resource.path = ['Images']
pyglet.resource.reindex()
self.image = pyglet.resource.image('%s%s' % (character, '.png'))
When I run this, I am given
File "C:\Python26\lib\site-packages\pyglet\resource.py", line 394, in file raise ResourceNotFoundException(name)
ResourceNotFoundException: Resource "Guard.png" was not found on the path. Ensure that the filename has the correct captialisation.
I have tried changing the path to ['./Images'] and ['../Images']. I've also tried removing the path and the reindex call and putting Erosion.py and Guard.png in the same folder.
This is what i do to be able to load resources:
pyglet.resource.path = ['C:\\Users\\myname\\Downloads\\temp']
pyglet.resource.reindex()
pic = pyglet.resource.image('1.jpg')
texture = pic.get_texture()
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_NEAREST)
texture.width = 960
texture.height = 720
texture.blit(0, 0, 0)
try this
pyglet.image.load('path/to/image.png')
If the relative path is not working you can try with the absolute path using the os module.
import pyglet
import os
working_dir = os.path.dirname(os.path.realpath(__file__))
pyglet.resource.path = [os.path.join(working_dir,'Images')]
pyglet.resource.reindex()
image = pyglet.resource.image('character.png'))
It's better to use the os.path.join method instead of writing it as a string for a better cross-platform support.
I get a problem like this using pyglet and pyscripter.(the text editor) In order for the file to be found I have to restart the editor before running the program.
This might be a problem with pyscripter however.
It is worth looking into: http://pyglet.readthedocs.io/en/pyglet-1.3-maintenance/programming_guide/resources.html
You should include all the directories into:
pyglet.resource.path = [...]
Then pass the ONLY the file name when you call:
pyglet.resource.image("ball_color.jpeg")
Try:
import os
import pyglet
working_dir = os.path.dirname(os.path.realpath(__file__))
image_dir = os.path.join(working_dir, 'images')
sound_dir = os.path.join(working_dir, 'sound')
print working_dir
print "Images are in: " + image_dir
print "Sounds are in: " + sound_dir
pyglet.resource.path = [working_dir, image_dir, sound_dir]
pyglet.resource.reindex()
try:
window = pyglet.window.Window()
image = pyglet.resource.image("ball_color.jpeg")
#window.event
def on_draw():
window.clear()
image.blit(0, 0)
pyglet.app.run()
finally:
window.close()
The use of try and finally are not necessary, but they are recommended. You might end up with a lot of open windows and pyglet back processes if you don't close the window when there are errors.
pyglet 1.4.4 format: HUD_img = pyglet.resource.image('ui\ui_gray_block_filled.png')
pyglet 1.4.8 format: HUD_img = pyglet.resource.image('ui/ui_gray_block_filled.png')
I was using pyglet 1.4.4 and was able to use this the first format.
After upgrading to pyglet 1.4.8 I had the error: pyglet.resource.ResourceNotFoundException: Resource "your_resource_path" was not found on the path.
Switching to the 2nd format with forward slashes solved this issue for me. Not sure why this change was made...I'm sure there was a good reason for it.