All things Jythonic 18.1.2005

January 2005
MoTuWeThFrSaSu
      1 2
3 4 5 6 7 8 9
10111213141516
17181920212223
24252627282930
31      
Dec
2004
 Feb
2005

A blog tracking jython developments

XML-Image Syndication

XML-Image Comment Feed

Letterimage Contact me

2005-01-18

Daily Python-URL: Python port of SWT?

Scott Sanders (dotnot) asks: Is anyone working on a port of SWT to Python? Is anyone interested in such a thing?

Of course this is something that is possible today using Jython.  I have configured the RedRobin Jython Eclipse plugin to allow me to easily script SWT (and JFace from Jython ... works like a charm.)  Here is a quick Jython Hello World for SWT.

from org.eclipse.jface.window import *
from org.eclipse.swt import *
from org.eclipse.swt.widgets import *
import sys

class Hello(ApplicationWindow):
  def createContents(self, parent):
  b = Button(parent, SWT.PUSH, widgetSelected=self.helloWorld)
  b.text = "Hello World"
  return b    
  def helloWorld(self, evt):
     print "Hello There ..." 
     sys.exit(0)        
 
w = Hello(None)
w.blockOnOpen = 1
w.open()
Display.getCurrent().dispose()

In order to get this to work in eclipse using the Jython plugin, you need to either create a jython project in eclipse or add the Jython nature to an existing project, add the swt and jface jars into the class path in the project's jython properties and finally set the java.library.path to the location of the swt library also in the project's jython  properties.  This last step is so that swt can find its os native libraries. 

posted at 09:11:12    #
Creative Commons License
This work is licensed under a Creative Commons License.