jython

From Trolltech Labs

Jump to: navigation, search
Qt Jambi Jython bindings
Project logo: QtJambiLogo200.png
Platforms: Linux, Windows, Mac OS X
Qt version: Requires Qt Jambi
License: Trolltech GPL
Depends on: Jython
   Jambi Qt Jambi Jython bindings blogs
Subversion:
svn://labs.trolltech.com/svn/qtjambi/jython


[edit] Qt Jambi Jython Bindings

As Håvard pointed out in his blog some time ago, Qt Jambi is really a door opener into a number of other languages. Jython for instance, the python implementation done in Java. By just putting the qtjambi.jar files into classpath one can write this code in Jython:

from com.trolltech.qt.gui import *

QApplication.initialize([])

hello = QPushButton("Hello Jython!")
hello.show()

QApplication.exec()

This is pretty neat by itself, but it usually comes to a problem with signals and slots, as we implement these based on reflection of method names. Very few of these scripting solutions produce reflectable methods that we can use, so we need to bridge this gap. This project provides a few classes that solves this problem for jython. Enjoy!

[edit] Building

Run ant, it should automatically pick up the build.xml build description and build a qtjambi-jython.jar file in the current directory. Please note that both Qt Jambi libraries and jython libraries must be in the local path when compiling. It should look something like this:

C:\qtjambi\jython>ant

Buildfile: build.xml

qtjambi-jython.jar:
   [mkdir] Created dir: C:\qtjambi\jython\out
   [javac] Compiling 13 source files to C:\qtjambi\jython\out
   [javac] Note: Some input files use unchecked or unsafe operations.
   [javac] Note: Recompile with -Xlint:unchecked for details.
     [jar] Building jar: C:\qtjambi\jython\qtjambi-jython.jar
  [delete] Deleting directory C:\qtjambi\jython\out

BUILD SUCCESSFUL

Total time: 2 seconds

C:\qtjambi\jython>

[edit] Running the examples

Be sure that Qt Jambi and jython is set up in the environment and run the minimalist demo:

> jython mybutton.py

or

> jython paint.py

[edit] Known Issue: Accidental private constructor...

Qt Jambi classes, like QWidget have a special constructor that takes a QPrivateConstructor. This constructor is protected and not callable in Java unless the user does something nasty and should he do, it will result in an exception. The problem is that jython won't have the option of selecting between

 QWidget(QWidget parent)

and

 QWidget(QPrivateConstructor ctor)

The result of this is that the code:

class Fail(QWidget):
   def __init__(self, parent):
       QWidget.__init__(self, parent)

f1 = Fail(aParent)
f2 = Fail(None)

Will fail in the case f2 because parent is None. I don't have a good solution for this just yet, but I'll see if something comes to mind...


[edit] Latest 5 Qt Jambi Blogs

eskil
Qt Jambi
Posted by eskil
 in Qt Jambi
 on Wednesday, July 23, 2008 @ 14:11

A while back we announced the research project Qt Jambi AWT Bridge which allows you to mix AWT/Swing components and Qt widgets in the same window on Windows and Linux.
There were a few issues with the original version. The main problems were the fact that your window would be deactivated by the window manager […]

» No comments «
gunnar
Uncategorized
Qt
Qt Jambi
WebKit
Qt Concurrent
Graphics View
Patternist
Posted by gunnar
 in Uncategorized, Qt, Qt Jambi, WebKit, Qt Concurrent, Graphics View, Patternist
 on Tuesday, June 10, 2008 @ 09:13

So the time is finally here. Qt 4.4.0 was released a few weeks ago and as promised Qt Jambi is right behind. A lot of effort has gone into this one, in addition to supporting all the new Qt features, like Phonon, Webkit, Widgets in Graphics View, XQuery and Qt Concurrent, we also have a […]

» 2 comments «
eskil
Qt
Qt Jambi
Posted by eskil
 in Qt, Qt Jambi
 on Wednesday, March 12, 2008 @ 13:03

The Qt 4.4 beta was released on February 26th, and, true to form, the corresponding Qt Jambi release comes a couple of weeks later.
In honor of the 4.4 release, we’d like to go through some of the new features you should look out for.
WebKit integration
WebKit is an open source web browser engine which is […]

» 3 comments «
eskil
Qt Jambi
Posted by eskil
 in Qt Jambi
 on Tuesday, March 04, 2008 @ 09:12

The Qt Jambi team has, as have all devs in Trolltech, been busy preparing two separate releases the past few weeks slash months (Qt Jambi 4.3.4_01 and Qt Jambi 4.4.0_01.)
In the midst of this, someone reminded me that I promised I’d post a blog when we added prebuilt Windows binaries to the repository for […]

» 1 comment «
gunnar
Qt
Qt Jambi
Posted by gunnar
 in Qt, Qt Jambi
 on Tuesday, February 05, 2008 @ 08:39

I planned on writing a blog about some of the work we’ve done on deployment for Qt Jambi 4.4, but I realized when writing that the memory of “Why the !”#!%!§ doesn’t it work on that linux box!” was still to fresh in memory and I was simply to upset to write anything about it. […]

» 5 comments «