community firmware

Programming in Python: The First App

This tutorial will give a basic introduction on how to write an application for the Community Firmware of the Fischertechnik TXT controller.

An app consists of at least three files:

The application program

The application program can be any script or binary the TXT is able to execute. Since apps are usually started from the TXTs launcher the user will expect some output on the screen. Thus the program should include a minimalistic GUI.

Currently all apps use the Qt4-Toolkit for their user interface. We’ll thus also use Qt. A minimal python application opening a TXT styled window looks like this:

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import sys
from TouchStyle import *

class FtcGuiApplication(TouchApplication):
    def __init__(self, args):
        TouchApplication.__init__(self, args)

        # Creates an empty MainWindow
        w = TouchWindow("Test")
        w.show()
        self.exec_()        

if __name__ == "__main__":
    FtcGuiApplication(sys.argv)

Please save this file under the name test.py

This app subclasses the TouchApplication class which was imported from TouchStyle. It creates a window labeled “Test”, shows that window and hands over execution to the window so it can interact with the user until it’s closed.

The manifest

The manifest file is a simple text file containing various fields describing the app.

[app]
name: Test
category: Tests
author: Joe Developer
icon: icon.png
desc: TXT app tutorial #1
url: http://cfw.ftcommunity.de/ftcommunity-TXT/en/programming/python/tutorial-1.html
exec: test.py
managed: yes
uuid: 191fe5a6-313b-4083-af65-d1ad7fd6d281
version: 1.0
firmware: 0.9

The mandatory fields are name, icon, desc, exec, uuid and managed.

Some optional fields are also used:

The set and model entries are currently unused but may be used in the future to allow the user to find apps relating to a specific model he e.g. just built.

Please save this file under the name manifest

The icon

The icon can be any file in JPG or PNG format. It should be 64x64 pixels in size.

icon.png

An example file can be found at here

This icon has been created using the Inkscape but most other paint programs will also do. The inkscape SVG file for this icon is also available here

Package it up

Now we have the three mandatory files

To get these installed on the TXT they’ll need to be put into a ZIP archive. Any program like WinZIP should work. All three files should be in the toplevel of the ZIP and not e.g. in some subfolder.

A prepared archive of our little demo app is also available.

Upload it to the TXT

Now use your PC’s web browser to connect to the TXT. The main web page will show all installed apps:

tut1_img1.jpg

Use the file dialog to select our test.zip archive and hit upload:

tut1_img2.jpg

The app is now being intalled on the TXT and becomes visible in the TXTs launcher:

tut1_img7.png

The app can be launched like any other app by clicking it:

tut1_img10.png

It’s now also visible in the web interface:

tut1_img8.png

Selecting it shows some of the details from the manifest file:

tut1_img9.png

In the web interface, you can also delete the app.

Continue reading Programming Python: Development