Showing posts with label jython. Show all posts
Showing posts with label jython. Show all posts

Sunday, December 8, 2013

Jython swing UI similar to zenity

For simple UI to request user information. Such as input dialogs with lists, input boxes, file/dir chooser, tree list.

http://sourceforge.net/projects/jythonsimpledialog/

Wednesday, December 4, 2013

Eclipse + PyDev + PortablePython or Jython + Local install

Portable and client installable packages are so much easier with Jython since it is a small jar and better yet very portable and has the ability to call java jars into its fold.
I also like pure-python implementations for the same reason as there is no concern with portability.

So, I am recording steps for a local install and how to use a package.
In this example I will use xlrd and xlwt.

Prerequisites:
  • MingW or MSYS tools so I can run shell scripts. This is obviously far more usable than just for this one reason. You can get it from http://www.mingw.org/wiki/MSYS . You can also install MobaXterm a one-stop-shop that has cygwin stuffed into it.
  • A way to launch python or jython. 
    • Python: This is reasonably simple: python portable has to be added to $PATH then you can run 'python' from command line.
    • Jython: This is slightly more work but simple:
    • #!/bin/bash 
      #export JAVA_HOME=/usr/java/latest
      
      export JYTHON_HOME=`msys2winpath "/PortableApps/Jython2.7b1"`
      #export JYTHON_HOME=`msys2winpath "/PortableApps/jython2.5.3"`
      export JVMOPTS="$JAVA_OPTIONS $JVMOPTS"
      
      export JYTHONCACHEDIR="./jythoncache"
      echo $JYTHONPATH
      export PATH=$JYTHON_HOME/bin:$PATH
      export CLASSPATH="$CLASSPATH;$JYTHON_HOME/jython.jar"
      export JVMOPTS="$JVMOPTS -Dpython.home=$JYTHON_HOME -Dpython.cachedir=$JYTHONCACHEDIR" 
      
      export PYTHONPATH=$JYTHONPATH
      
      #echo $JVMOPTS
      echo $CLASSPATH
      set -x
      $JAVA_HOME/bin/java.exe -cp "$CLASSPATH" $JVMOPTS org.python.util.jython $*
      
       
      And, msys2winpath is a simple script:
       
      #!/bin/bash --login
      if [ $# -eq 0 ]
      then
       pwd -W
      else
       cd "$1"
       pwd -W
      fi
Now, create a shell script, I called it 'dopylocalinstall.sh', to make it easier to setup the local site-packages.

#!/bin/bash

CPWD=`pwd -W | sed 's/\//\\\\/g'`
if [ ! -d 'dist/Lib/site-packages' ]
then
 mkdir -p dist/Lib/site-packages
fi
export PYTHONPATH="$CPWD\\dist\\Lib\\site-packages"
export JYTHONPATH="$PYTHONPATH"
pycmd="runjython.sh"
#pycmd="python"
$pycmd setup.py build
$pycmd setup.py install --prefix="$CPWD\\dist"

Now, change to the xlrd unzipped folder and run the dopylocalinstall.sh
This should have now created a dist folder with Lib and site-packages within.

The contenets of the site-packages/xlrd can now be copied into a folder in Eclipse and you should be able to use the package in your projects.