Clarisse 5.0 SP10 SDK
No Matches
Using Qt through Python in Clarisse

This topic covers how to integrate PyQt or PySide widgets with Clarisse. Remember, Clarisse does not distribute a custom Python version. It uses the Python environment installed on your system. In order to use PyQt or PySide, you must install it on your system. Please refer to PyQt website for more information on how to install PyQt, and PySide webiste for PySide installation.

QApplication and Clarisse Event Loop.

If you already tried to run a QApplication inside Clarisse, you may have noticed Clarisse application gets frozen. It's simple, when running the PyQt script blocks Clarisse's event loop. We provide a special helper to let you run your scripts in non-blocking mode. This file can be found in the python directory inside the Clarisse binary folder.

For legacy reason it's named but it also handles PySide

Running a non-blocking QApplication in Clarisse

Instead of using the method QApplication::exec_, Clarisse provides a method helper pyqt_clarisse.exec_ that must be used to run your script in a non-blocking fashion.

# import your version of Qt **BEFORE** importing the Clarisse's helper.
from PyQt4 import Qt
# note: if you want to use PySide, just use the following instead of
# the previous import statement:
# import PySide import QtGui
# and replace Qt module by QtGui in the rest of the example.
# Be careful not to import both PyQt4 and PySide (in this case,
# importing pyqt_clarisse should throw an exception)
# import the Clarisse's helper
import pyqt_clarisse
# now you can create your Qt application as usual
app = Qt.QApplication(["Clarisse"])
hello = Qt.QLabel("Hello, World")
hello.resize(320, 240)
# instead of calling app.exec_() like you would do normally in PyQt,
# you call pyqt_clarisse.exec_(app).
def exec_(application)
Runs the specified QApplication without blocking Clarisse main-loop.

Note on Command History

Running a non-blocking script should be strictly reserved to experienced users as it may cause instabilities with the internal command history system.

By default, command history is disabled when Clarisse is running a script. However, if the application isn't blocked by the execution of a script, it is best to reactivate command history. Failing to do so would disable Clarisse's undo system.

This is why pyqt_clarisse.exec_ forces the application to enable command history. That way, when an user modifies or creates items in Clarisse, proper commands are pushed to the application command stack even if the script is still running.

This also means that each time the running script modifies item attributes a command will be pushed. To avoid filling the command history, it's recommended to create a batch command. For more information please refer to Command History section.

If you are very careful, you can also disable command history prior modifying an item. To disable the application history you can call:


After your modifications, you can re-enable the command history by calling: