Chapter 4. Reference

Table of Contents

4.1. Application XML
4.2. Dialog XML
4.3. Wizard XML
4.4. Dialog/Wizard classes
4.5. Base widget class
4.6. Button widget class
4.7. Check widget class
4.8. Combo widget class
4.9. Date widget class
4.10. Dummy widget class
4.11. File widget class
4.12. Grid widget class
4.13. Group widget class
4.14. Label widget class
4.15. Line widget class
4.16. List widget class
4.17. Pixmap widget class
4.18. Progress widget class
4.19. Radio widget class
4.20. Rule widget class
4.21. Scroll widget class
4.22. Slider widget class
4.23. Spin widget class
4.24. Split widget class
4.25. Stack widget class
4.26. Table widget class
4.27. Tabs widget class
4.28. Text widget class
4.29. Time widget class
4.30. Tree widget class
4.31. Custom widgets integration
4.32. Using Qt Designer
4.33. Client code execution
4.34. XML-RPC functions
4.35. DAO objects
4.36. Server's configuration file
4.37. PyDADL's scripts
4.38. Apache integration via mod_python
4.39. Internationalization
4.40. Deployment

4.1. Application XML

A PyDADL application is described with a single XML file located in the ui_xml directory. This file can hold :

  • The application's title and icon.
  • The parameters for database connexion.
  • The users allowed to connect to the application.
  • The application's menus, toolbars and dock widgets.
  • The global application's style sheet.
  • An initialization code that can be executed when starting the application.
  • A cleanup code that can be executed when the application closes.

The root element of an application XML file is the application tag. This tag can hold the following attributes :

name
The application's name. This attribute is mandatory.
title
The application's title.
icon
The path to the application's icon file. The format can be BMP, GIF, JPEG, PNG or XPM.
values_call
An XML-RPC function that will be executed when retrieving the application's definition. The purpose of this attribute is to avoid multiple XML-RPC calls at application start. The syntax is function_name or function_name(arg1, arg2, ..., argN). The return value is accessible via the global variable AppValues.

The sub tag data_server contains the parameters for creating a handler to the database used for storing the application's data. There is only one data handler per application. This tag must have the following attributes :

type
Database driver. For the moment, the only valid driver is mysql.
host
Database server address.
port
Database server port.
user
Username used to connect to the database server.
passwd
Password used to connect to the database server.
db
Name of the database.

The sub tag user is used to declare a user account. You can specify multiple users accounts, each one can have different privileges and parameters. This tag holds two attributes : login and passwd. Inside this tag you can declare restrictions and variables, those elements form the user's flags. The syntax of the declarations are :

  • allow menu|toolbar|item|dock|dialog ALL|<name>
  • deny menu|toolbar|item|dock|dialog ALL|<name>
  • define <attribute> [<value>]

Here is an example of a user declaration that only has access to a dialog named d1 :

<user login='foo' passwd='foo'>
    deny dialog ALL
    allow dialog d1
</user>

The sub tag menu is used to create an application's menu. You can specify multiple menus, you can also create sub menus by cascading menu declaration. This tag can hold the following attributes :

name
Name of the menu. This name can be used to programmatically refer to the menu, for example in the user privileges declaration or used in the menu manipulation functions.
label
Label of the menu.
icon
Menu's icon file.
window_menu
If this attribute is set to 1, the menu will be the window menu of the application, it will hold a list of opened dialogs and can be used to navigate between them.

The sub tag toolbar is used to create an application's toolbar, you can specify multiple toolbars. This tag can hold the following attributes :

name
Name of the toolbar. This name can be used to programmatically refer to the toolbar, for example in the user privileges declaration or used in the toolbar manipulation functions.
label
Label of the toolbar.
area
The area on which the toolbar will reside. Possible values are : left, right, top and bottom.
allowed_areas
The areas on which the toolbar can be moved. Possible values are : all, left, right, top and bottom. You can specify more than one value separated by spaces.

The sub tag dock is used to display a dialog as a dock widget, the dialog's name is specified as a tag value. This tag can hold the following attributes :

name
Name of the dock. This name can be used to programmatically refer to the dock, for example in the user privileges declaration or used in the dock manipulation functions.
label
Label of the dock.
area
The area on which the dock will reside. Possible values are : left, right, top and bottom.
allowed_areas
The areas on which the dock can be moved. Possible values are : all, left, right, top and bottom. You can specify more than one value separated by spaces.
features
Available features of the dock. Possible values are : close to permit closing the dock, move to permit moving the dock, float to permit detaching the dock from the application's main window, all to permit all features.

The sub tag item can only be declared inside a menu or toolbar tag. It is used to declare items inside those elements. The attributes of item tag are :

name
Name of the item. This name can be used to programmatically refer to the item, for example in the user privileges declaration or used in the item manipulation functions.
label
Label of the item. If the label starts with "+" or "-" character, the item will be a checkbox.
icon
Item's icon file.
shortcut
Shortcut for the item. Ex: Ctrl+F
group
The group in which the item belongs. When you group items, you ensure that only one of them can be checked at a time.

The item tag value can be one of the following :

  • dialog:<name> : when you click on the item, the dialog <name> is opened.
  • callback:<name> : when you click on the item, the callback <name> is executed.
  • Empty value : nothing happend, this can be usefull when you declare checkbox items.

The sub tag callback is used to write Python code that will be executed when the corresponding item is clicked. The callback tag has one attribute : name, it is this name that is used in the item declaration. In the Python code, there are two global variables available : name which is the item name and checked which is the checked state of the item.

The sub tag style can be used to declare a global style sheet for the application. Example :

<style>
QPushButton { color: red; background-color: white }
QComboBox::down-arrow:pressed {
    margin-right: 20px;
    position: relative;
    top: 1px; left: 1px;
}
QCheckBox:hover:checked { color: white }
</style>

See Qt documentation for more details about style sheet syntaxes.

The sub tag init can be used to write Python code that will be executed at application start. See Section 4.33, “Client code execution” for more details on client side code.

The sub tag post_show is similar to init tag, the difference is that the code writing here will be executed after showing the application main window.

The sub tag cleanup can be used to write Python code that will be executed when closing the application.

The sub tag code can be used to declare Python functions or objects, those objects will be available as global objects in other code tags in the application and dialogs namespaces.

The sub tag thread can be used to write Python code that will be executed in a parallel thread. This tag has one attribute: name which is the thread's name. There is a global Thread object with the same name declared in the name attribute. To start the thread, call the Thread object with optional arguments passed in *args and/or **kwargs. The Thread object inherits QThread Qt class, so you can use functions like isFinished() or isRunning().

When calling the Thread object, thread begins execution and the call returns immediately. You can wait until the thread has finished or let the thread run in the background. When the thread finishes, the return value is available via the attribute ret of the Thread object.

The sub tag event can be used to write Python code that will be added to an event queue for later execution (when the Qt's main event loop runs). The main purpose of this tag is to perform GUI-related operations from threads other than the main thread. In Qt, the main thread is also called the GUI thread because it's the only thread that is allowed to perform GUI-related operations. An event is called in the same way as a thread (with the name specified in name attribute and with optional *args and/or **kwargs).

Here is an example of thread/event usage :

<event name='my_event_1'>
d.widget_1.resize(100, 100)
...
</event>

<thread name='my_thread_1'>
print Args # Args is the arguments list -> ('orange', 'apple')
print Kwargs # Kwargs is a dict that holds the keyword arguments -> {'family':'fruits'}
print family # keyword arguments are also available via global variables -> 'fruits'
...THREAD CODE...
my_event_1('red', 'blue') # post an event
...THREAD CODE...
</thread>

<connection widget='button_1' signal='clicked()'>
my_thread_1('orange', 'apple', family='fruits')
while my_thread_1.isRunning(): ProcessEvents()
print 'Thread finished, return value is :', my_thread_1.ret
</connection>

Threads and events declared in the application XML file are available for dialogs too.

[Note]Note
Since Python uses indentation for delimiting blocks, you must start all you code blocks from the beginning of the line.