Clarisse 4.0 SP4b SDK  4.0.0.0.4.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Using Qt through Python in Clarisse

Table of Contents

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 http://www.riverbankcomputing.com/software/pyqt/intro for more information on how to install PyQt, and PySide webiste https://wiki.qt.io/PySide 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 pyqt_clarisse.py can be found in the python directory inside the Clarisse binary folder.

Note
For legacy reason it's named pyqt_clarisse.py 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.

1 # import your version of Qt **BEFORE** importing the Clarisse's helper.
2 from PyQt4 import Qt
3 
4 # note: if you want to use PySide, just use the following instead of
5 # the previous import statement:
6 #
7 # import PySide import QtGui
8 #
9 # and replace Qt module by QtGui in the rest of the example.
10 # Be careful not to import both PyQt4 and PySide (in this case,
11 # importing pyqt_clarisse should throw an exception)
12 
13 # import the Clarisse's helper
14 import pyqt_clarisse
15 
16 # now you can create your Qt application as usual
17 app = Qt.QApplication(["Clarisse"])
18 hello = Qt.QLabel("Hello, World")
19 hello.resize(320, 240)
20 hello.show()
21 
22 # instead of calling app.exec_() like you would do normally in PyQt,
23 # you call pyqt_clarisse.exec_(app).

Note on Command History

Warning
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:

1 ix.disable_command_history()

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

1 ix.enable_command_history()