Resource Management

| | Comments (0) | TrackBacks (0)

How to manage resources (icons, basically) in a ETK application? Currently we have many implementations but no defined standards. Even worst, we do not use Qt 4 features regarding resource management.

The Problem:

The resource management in an application consist in two phases: Making resources available and accessing them. The source for these resources are plain image files stored in the source-tree. The resource management must be able to make these resources available where they are needed, usually, in GUI elements.

The Requirements:

Multiple sources

The user can declare multiple sources of resources inside a project. In other words, the resources are not grouped by "project".

Embed

The resources must be embed in python code, not image files or binary resources files in the final distribution

Easy

It must be easy to make resources available and using them. All error-prone tasks must be automatized.

The Solution:

Qt 4 provides a simple and elegant way for handling resources (The Qt Resource System). We will take advantage of their implementation and add some automatisms to it.

codegen_res

The tool codegen_res searches for directories in the format res_* and generates a python source from it, containing all the resources (images files) embed using PyQt4 pyrcc4 tool. The user must import the generated module to make the resources available.

Once loaded, it's possible to use these resource by passing theirs registered name as the filename for any resource class:

icon = QIcon( ":sci20/camera/preset_x.png" )

Categories

Leave a comment