jython

From Qt 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

Thiago Macieira
Qt
KDE
Qt Jambi
Contributors
QtCreator
QtMobility
Posted by Thiago Macieira
 in Qt, KDE, Qt Jambi, Contributors, QtCreator, QtMobility
 on Tuesday, October 27, 2009 @ 10:05

For those of you who don’t read the new Qt blog website, where Qt Marketing and Product Management talk about “corporatey” stuff (affectionately called the “PHB blog” by our developers), we’ve just announced that our brand, new bugtracker is public: see http://bugreports.qt.nokia.com.
So, I won’t repeat everything that is in the other blog (it is, after […]

» 22 comments «
Eskil Abrahamsen Blomfeldt
Qt Jambi
Bindings Generator
 in Qt Jambi, Bindings Generator
 on Friday, October 02, 2009 @ 18:01

Ever since Nokia announced that the official support for Qt Jambi would end after the 4.5 series, I’ve had a few people ask me how they can help adapt the Qt 4.6 changes to Qt Jambi. I thought this blog would be a good place to offer my experiences on the subject, so here’s a […]

» 1 comment «
Eskil Abrahamsen Blomfeldt
Qt
Qt Jambi
News
Contributors
Git
 in Qt, Qt Jambi, News, Contributors, Git
 on Monday, May 11, 2009 @ 12:06

It’s taken a little longer than expected, but the nice and polished Qt Jambi 4.5.0_01 packages are finally ready for download on Qt Software’s server. As usual, there are both source and binary packages available, but to match the new licensing of Qt, the GPL packages have been replaced by LGPL packages this time around. […]

» 10 comments «
Tor Arne Vestbø
Qt
KDE
Qt Jambi
Labs
News
QtCreator
 in Qt, KDE, Qt Jambi, Labs, News, QtCreator
 on Monday, May 11, 2009 @ 12:00

With the announcement back in January of Qt going LGPL there was a small piece of information that slipped though the cracks of the wider news reporting, namely the fact that we were planing on opening up our repositories and development model. The first major phase of this work is now complete, and we are […]

» 22 comments «
Eskil Abrahamsen Blomfeldt
Qt Jambi
 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 «


© 2008 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners.