For participants only. Not for public distribution.

Note #32
Programming with the Photon GUI

John Nagle
Last revised November 4, 2003.

Graphical user interface programming for QNX

Photon

QNX comes with a graphical user interface system called Photon. It's an event-driven C-based system, generally similar to those on most other platforms.

Using the Photon Application Builder (PhAB)

Photon applications are built using the Photon Application Builder, which does layout, generates code, and in a limited way, manages the project. There are five tutorials on the Photon Application Builder available in the QNX help system. Working through them takes about a day, and is reasonably worthwhile. Tutorials 1-4 are good. Tutorial 5 is poorly designed and has some bad coding practices, but is worth doing as a bad example.

The generated code consists of big files containing GUI data, and tiny stub files for any "callbacks" the programmer asks PhAB to generate. The stub source files generated by PhAB contain no data that PhAB needs to change. Once created, PhAB will not overwrite them. You can safely go back and change your graphical elements, then "regenerate" in PhAB.So editing a stub file doesn't commit you to layout decisions made via PhAB.

C++ support

Photon is a C GUI, but it is possible to use it with C++. All the C code it generates appears to compile and run with C++.

To work in C++, use the Application->Build+Run menu and click on Advanced Options..., which brings up the Build Preferences dialog. By default, this just says "make". Change it to "make -e CC=QCC LD=QCC", which will cause PhAB to generate makefiles which call the QCC compiler (for C++) for compiling and linking.

After doing this, C++ code in Photon-generated stubs will work

Adding your own files to a PhAB project

PhAB generates three files which tell PhAB's makefiles what files belong to the project: These just set variables for the makefiles. Here's an example of adding a C++ source file to the project.

indHfiles

MYHDR = ../cameraread.h

indOfiles

MYOBJ = ../cameraread.o

indSfiles

MYSRC = ../cameraread.cpp

"cameraread" has now been added to the project, and will be compiled and linked.

Photon and CVS

(from the Photon manual)

Here are the files you need to save if you're using version-control software (PhAB can generate some of them, but it's a good idea to save them all):

File Type
Binary/Text
OK to edit
Notes
abapp.dfn
binary
No
Callbacks and other information
wgt/*
binary
No
Widget resources -- these might look like text, but they're binary.
src/*.{c,cc,cpp,C,h}
text
Yes
Source files and headers.
src/*files
text
Yes
Files that list non-PhAB source files. Be sure to save the non-PhAB source, too.
src/Makefile
src/*/Makefile
text
Maybe
All the make files.
application_name.ldb
text
No
Your application's language database. Save any translation files as well.
abapp.wsp
binary
No
Not mentioned in QNX docs, but seems to be needed.

The files listed as "OK to edit" are created initially by PhAB, but can then be manually edited. PhAB. PhAB creates them if they do not exist, but does not change their contents if they do exist.

There's one known exception to this. If you change the type of a widget, source files may be regenerated.

The generated makefiles can be edited if absolutely necessary, but it's better to change "Command to make application" and the "ind*" files to modify the build process.

Summary

Overall, PhAB is easier to use than the corresponding tools for Windows and Macintosh platforms. The widgets aren't as pretty, but they work. PhAB is an object-oriented system written in C, which is always a bit painful, but it's not overdone and works reasonably.


More to come.

To be addressed:

  • Integration with Eclipse IDE
  • Conventions on naming