7 Steps to New Widgets in pyFLTK


Here's a little guide on adding new widgets to pyFLTK. It shows the basic steps and conventions we've been using.

  1. Preferrably, place the widget - its header, source and Readme file - in the contrib/ directory. This will allow for a simple inclusion in the build of pyFltk. For a larger distribution, you can keep it intact and adjust the include paths as well (see below).

  2. Add support to setup.py for the new widget. If you placed your sources in the directory contrib/, then you can add the source files to the list UserDefinedSources, at the very top of setup.py, in the form ./contrib/UserWidget1.cpp. If you placed the widget somewhere else, then you will also have to extend the include path by adding the new path to the list UserIncludeDirs.

  3. Create the SWIG interface file(s). I've been creating a swig/xxxx.i file for each header file for the widget. Import the files into the swig build by adding lines to the file swig/UserDefinedWidgets.i, of the form %include UserWidget1.i.

  4. Address the ownership of your new widget! If your widget is derived from Fl_Widget, then you can add the following lines to your interface file:
    %include macros.i
    CHANGE_OWNERSHIP(UserWidget1)

  5. By default, all widgets are wrapped using the director feature of swig. If this is not desirable for your widget, you can disable it by placing the line %feature (nodirector) UserWidget1; somewhere before your code.

  6. You can now build your distribution by first executing python MakeSwig.py in the directory python/, followd by python setup.py build in the root directory. Check for compilation errors! For MinGW on Windows, you should use python setup.py build -cmingw32 install instead.

  7. Now create a test program in test/ and test the widget.