Table of Contents
A PyDADL application is described with a single XML file located in the ui_xml directory. This file can hold :
The root element of an application XML file is the application tag. This tag can hold the following attributes :
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 :
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 :
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 :
The sub tag toolbar is used to create an application's toolbar, you can specify multiple toolbars. This tag can hold the following attributes :
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 :
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 :
The item tag value can be one of the following :
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 | |
---|---|
Since Python uses indentation for delimiting blocks, you must start all you code blocks from the beginning of the line. |