Skip to content

Commit

Permalink
updated and translated tutorial 2
Browse files Browse the repository at this point in the history
  • Loading branch information
EstherMi committed Jul 20, 2017
1 parent 3780534 commit 57ecc95
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 85 deletions.
4 changes: 2 additions & 2 deletions docs/de/programming/python/tutorial-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ Nach der Installation ist die Anwendung sichtbar!

![tut1_img7.png](../../../en/programming/python/tut1_img7.png)

So sieht die Ausgabe des Programms auf dem TXT aus:
So sieht die Ausgabe der Anwendung auf dem TXT aus:

![tut1_img10.png](../../../en/programming/python/tut1_img10.png)

Sie ist jetzt auch im Webinterface zu sehen:
Die Anwendung ist jetzt auch im Webinterface zu sehen:

![tut1_img8.png](../../../en/programming/python/tut1_img8.png)

Expand Down
95 changes: 28 additions & 67 deletions docs/de/programming/python/tutorial-2.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,78 @@
---
nav-title: Development
nav-title: Entwicklung
nav-pos: 2
---
# Programming in Python: Development
# Programmieren in Python: Entwicklung

Warning: This tutorial is outdated and needs to be updated!
[Programmieren in Python: Die erste Anwendung](tutorial-1.md) erklärte die Entwicklung einer einfachen App. Der komplette Entwicklungszyklus lädt eine App über das Web-Interface auf den TXT. Leider ist dieser Weg etwas umständlich, weshalb in diesem Tutorial einige Abkürzungen zur Erleichterung der Entwicklung erklärt werden.

[Programming Python: The First App](tutorial-1.md) introduced a basic first app. The whole development cycle used the standard way to upload the app to the TXT via the Web interface. Unfortunately this way of developing an app is not very convenient. This tutorial will present some useful shortcuts to speed development up.
# Update einer App über SSH

# App update via SSH
Während der Entwicklung werden normalerweise nur einzelne Dateien geändert. Daher ist es nicht nötig, in dieser Phase die ganze App immer wieder zu löschen und neu zu installieren. Es ist einfacher, geänderte Dateien über SSH auf den TXT hochzuladen.

During development usually only single files are being changed and it's not necessary to remove and re-install the entire app on the TXT during the develoment phase. Instead single files can be uploaded to the TXT via SSH.

With a command line SSH client the `test.py` from tutorial 1 can be updated like this if the IP address of your TXT is 192.168.0.12 (use the TXTs netinfo app to find the ip address of your TXT):
Mit SCP (Secure Copy Protocol) kannst du die Datei `test.py` aus dem ersten Tutorial auf dem TXT aktualisieren. In diesem Beispiel ist die IP-Adresse des TXT 192.168.0.12. Die aktuelle IP-Adresse deines TXT findest du mit der Netinfo-App auf dem TXT heraus.

```
scp test.py root@192.168.0.12:/opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281/
scp test.py ftc@192.168.0.12:/opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281/
```

This will copy the new `test.py` file into the correct directory on the TXT. The directory target name on the TXT is the uuid from the manifest in the ZIP file you initially uploaded. E.g. if your apps manifest contained the line ```uuid: 191fe5a6-313b-4083-af65-d1ad7fd6d281``` then the target directory is `/opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281`

You can now start your updated app on the TXT using the launcher.
Den Verbindungsaufbau musst du auf dem TXT erlauben. Mit diesem Befehl kopierst du die neue Version der `test.py`-Datei in das richtige Verzeichnis auf dem TXT. Der Name des Verzeichnisses kommt von der UUID aus der Manifest-Datei, die du in der ZIP-Datei am Anfang hochgeladen hast. Das heißt, wenn das Manifest deiner App die Zeile ```uuid: 191fe5a6-313b-4083-af65-d1ad7fd6d281```enthielt, dann ist das Ziel-Verzeicnis `/opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281`.

Currently the root password of the TXT is `root`. Later the root login will probably be disabled by default. We'll then provide information how to activate it.
Jetzt kannst du die aktualisierte App auf dem TXT mit dem Launcher starten.

# Starting apps via SSH
# Apps über SSH starten

When apps are being started using the launcher no debug output and no error message are visible. This may be a problem during development. You can launch apps when being logged in into the TXT via SSH (preferrably as user "ftc"). In order to start the test app log into the TXT via SSH first. Then type:
Wenn Apps über den Launcher (Startbildschirm) gestartet werden, werden keine Fehlermeldungen angezeigt. Dies kann während der Entwicklung ein Nachteil sein. Du kannst die Apps auch starten, wenn du über SSH (als User "ftc", kein Passwort) auf dem TXT eingeloggt bist. Verbinde dich zuest über SSH mit dem TXT (`ssh ftc@192.168.0.12`). Du musst auf dem TXT die Verbindung erlauben. In der Remote Shell gibst du ein:

```
$ export PYTHONPATH=/opt/ftc
$ /opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281/test.py
```

Again the path is derived from the UUID in the manifest file of your app.

You'll then see the error messages and debug output on the remote shell.
Der Pfad ergibt sich wieder aus der UUID, wie sie in der Manifest-Datei deiner App steht.

# Start/stop apps via telnet/netcat
Jetzt kannst du Fehlermeldungen und Debug-Ausgaben in deiner Remote-Shell sehen.

SSH is not the only way to start apps remotely. The TXTs launcher implements a little command server to start and stop apps. This has been added to be used via the web interface but can also be used with tools like telnet or netcat.

Connect to the TXT via telnet on port 9000 using the command `telnet 192.168.0.12 9000`. Once connected you can enter `launch test/test.py` to launch the test app. The command `stop-app` will stop the currently running app. The command `quit` will close the telnet connection to the TXT.
# TXT-Apps auf dem PC ausführen

The same can be achived with netcat. E.g. `echo "stop-app" | nc 192.168.0.12 9000` will stop the currently running app.
Trotz dieser Tricks ist die Entwicklung auf dem TXT noch nicht besonders bequem. Glücklicherweise können TXT-Apps auch auf dem PC ausgeführt werden. Aktuell basieren alle TXT-Apps auf der Programmiersprache [Python](https://www.python.org/) und dem [Qt Framework](http://www.qt.io/). Die Kombination aus beidem heißt [PyQt](https://riverbankcomputing.com/software/pyqt/intro). In der TXT-Community-Firmware ist PyQt bereits vorinstalliert. Auf einem PC muss man PyQt erst installieren, um TXT-Apps ausführen zu können.

# Running TXT apps on the PC
Ein anderer Ansatz, um Python und Qt zu integrieren, ist `PySide`. PySide wird auf dem TXT nicht verwendet. Da PyQt und PySide recht ähnlich sind, kann es möglich sein, TXT-Apps mit minimalen Anpassungen unter PySide auszuführen. Dieser Ansatz wurde von uns jedoch nicht getestet.

Using the TXT for development still isn't very convenient. Fortunately TXT apps can be run an a PC. Currently all TXT apps are based on the [Python](https://www.python.org/) language and the [Qt Framework](http://www.qt.io/). The combination of both is named [PyQt](https://riverbankcomputing.com/software/pyqt/intro). PyQt comes pre-installed with the TXT community firmware. When running TXT apps on a PC PyQt has to be installed in the PC.

Another approach to integrate Python with Qt is named `PySide`. We are not using PySide on the TXT. But PyQt and PySide are quite similar and it may possible to run TXT apps under PySide with minimal modifications. But this has not been tested.
## Unter Linux

## Using a Linux PC
PyQt ist für alle großen Linux-Distributionen verfügbar. Suche mit deinem bevorzugten Paket-Manager nach einem Paket namens `pyqt`, `python-qt` oder ähnlich und installiere es.

PyQt is available for all major linux distributions. Use your favorite package managager and search for a package named `pyqt` or `python-qt` or similar. Install this on your PC.
Die TXT-Apps brauchen ein spezielles Qt-TXT-Thema. Um die TXT-Apps auf dem PC ausführen zu können, müssen die Dateien für dieses Thema auch auf dem PC installiert werden.

The TXT apps come with a special Qt TXT theming. In order to run TXT apps on the PC the files implementing this theme have also to be installed on the PC.
Kopiere `TouchStyle.py` und das ganze `themes`-Verzeichnis in ein gemeinsames Verzeichnis auf deinem PC. Du findest diese Dateien im [Repository](https://github.com/ftCommunity/ftcommunity-TXT/tree/master/board/fischertechnik/TXT/rootfs/opt/ftc).

Please copy the file `TxtStyle.py` and the entire `themes` subdirectory to the same place on your PC. You can get these files from the [Repository](https://github.com/ftCommunity/ftcommunity-TXT/tree/master/board/fischertechnik/TXT/rootfs/opt/ftc).

If you placed the files into the directory of you app then you don't have to do anything else. If you placed them somewhere else you need to make notify python of this directory. E.g. if `TxtStyle.py` and the `themes` directory have been placed under `/tmp/mytxtenv` then you need to enter:
Wenn du die Dateien in dem Verzeichnis abgelegt hast, in dem auch deine App abgelegt hast, brauchst du nichts weiter zu tun. Wenn sie an einem anderen Ort liegen, musst du Python mit diesem Ort bekannt machen. Wenn `TxtStyle.py` und das `themes`-Verzeichnis unter `/tmp/mytxtenv` liegen, dann musst du folgendes eingeben:

```
export PYTHONPATH=/tmp/mytxtenv
```
to tell python about it.
um Python über den Pfad zu den anderen Dateien zu informieren.

Please make sure you have made your python program executable like this:
Außerdem musst du sicherstellen, dass dein Python-Programm ausführbar ist:

```
$ chmod +x test.py
```

You can now run your app locally on your PC by typing:
Mit diesem Befehl startest du deine App auf deinem PC:

```
$ ./test.py
```

The file `TxtStyle.py` detects that you are running the app on a PC and creates a Window of 240x320 pixels for it.

You might notice that the Apps don't look 100% the same. One reason is a different font handling on the TXT and on the desktop PC. Furthermore the Qt and Python versions are not necessarily the same on the TXT and on the PC. Furthermore the app runs under the X11 window system on a PC while the TXT uses the QWS window manager for embedded systems. But the differences are small enough to allow for convenient app development on a PC.

![Running on a TXT](tut2_img1.png) ![Running on a PC](tut2_img2.png)

Small font rendering differences on TXT (left) and PC (right)

## Using a Windows PC (by LK)

On all Versions which python supports is it possible to develop and test applications for the
TXT.

At first you need a python version, which is ok with the PyQt Version: For this you need to check first which Python version you need. Look at: https://www.riverbankcomputing.com/software/pyqt/download, there is a part which
is called „Binary Packages“ go there and downloads one version (64bit/32bit) for every download look for the Python version.

**Example:**
If your download name is: `PyQt4-4.11.4-gpl-Py3.4-Qt4.8.7-x64.exe`:
Do you get PyQt version 4-4.11.4 or Qt version 4.8.7
You need Python version 3.4 (Note: every other Python version can go, but maybe not
correct)

Your version is a 64bit version.
Now download (https://www.python.org/download/releases/3.4.3/) and install the Python
version which you found before.
Now you can go through the installer.
Now you should be able to start PyQt Programs!
Die Datei `TouchStyle.py` stellt fest, dass die App auf einem PC läuft und baut ein Fenster mit 240x320 Pixel.

Before you can start developing you Programs you must first download one file and one
directory. Go for it at https://github.com/ftCommunity/ftcommunity-TXT/tree/master/board/fischertechnik/TXT/rootfs/opt/ftc and download the themes folder and next to the `TxtStyle.py` file. Copy it into your Path in which your Python program is.
Du wirst merken, dass die Apps auf dem TXT und dem PC nicht 100 % gleich aussehen. Ein Grund ist die unterschiedliche Darstellung der Schrift auf dem TXT und dem PC. Außerdem sind die Qt- und Python-Versionen nicht auf beiden Systemen gleich. Schließlich läuft die App auf dem PC unter einem X11-Window-System, während der TXT den QWS-Window-Manager für Embedded Systeme verwendet. Die Änderungen sind aber so klein, dass eine bequeme App-Entwicklung auf dem PC möglich ist.

Like on Linux the Window don’t looks like at the TXT. Why can you read in the end of the
Linux contribution. But to show you how it looks on Windows here is it:
![Ausführung auf dem TXT oder PC](../../../en/programming/python/tut2_img1b.png)

![Running on a Windows PC](tut2_img3.png)
Kleine Abweichungen in der Schriftdarstellung zwischen TXT (links) und PC (rechts)

(Tipp: It’s normal that the TxtStyle modul says: “('Unable to connect to launcher:’ ConnectionRefusedError (10061, 'Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte', None, 10061, None))”, and think on it your PC is normaly really faster than the TXT!)
Binary file added docs/en/programming/python/tut2_img1b.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 12 additions & 16 deletions docs/en/programming/python/tutorial-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,25 @@ nav-pos: 2
---
# Programming in Python: Development

Warning: This tutorial is outdated and needs to be updated!

[Programming Python: The First App](tutorial-1.md) introduced a basic first app. The whole development cycle used the standard way to upload the app to the TXT via the Web interface. Unfortunately this way of developing an app is not very convenient. This tutorial will present some useful shortcuts to speed development up.
[Programming Python: The First App](tutorial-1.md) introduced a basic first app. The whole development cycle uses the standard way to upload the app to the TXT via the Web interface. Unfortunately this way of developing an app is not very convenient. This tutorial will present some useful shortcuts to speed up development.

# App update via SSH

During development usually only single files are being changed and it's not necessary to remove and re-install the entire app on the TXT during the develoment phase. Instead single files can be uploaded to the TXT via SSH.
During development usually only single files are changed and it's not necessary to remove and re-install the entire app on the TXT during the develoment phase. Instead single files can be uploaded to the TXT via SCP and SSH.

With a command line SSH client the `test.py` from tutorial 1 can be updated like this if the IP address of your TXT is 192.168.0.12 (use the TXTs netinfo app to find the ip address of your TXT):

```
scp test.py root@192.168.0.12:/opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281/
scp test.py ftc@192.168.0.12:/opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281/
```

This will copy the new `test.py` file into the correct directory on the TXT. The directory target name on the TXT is the uuid from the manifest in the ZIP file you initially uploaded. E.g. if your apps manifest contained the line ```uuid: 191fe5a6-313b-4083-af65-d1ad7fd6d281``` then the target directory is `/opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281`
This will copy the new `test.py` file into the correct directory on the TXT. The directory target name on the TXT is the uuid from the manifest in the ZIP file you initially uploaded. E.g. if your apps manifest contained the line ```uuid: 191fe5a6-313b-4083-af65-d1ad7fd6d281``` then the target directory is `/opt/ftc/apps/user/191fe5a6-313b-4083-af65-d1ad7fd6d281`. Please note that community-firmware-versions built after September 21, 2016 show a confirmation dialog on the screen of the TXT when the user 'ftc' logs on via SSH.

You can now start your updated app on the TXT using the launcher.

Currently the root password of the TXT is `root`. Later the root login will probably be disabled by default. We'll then provide information how to activate it.

# Starting apps via SSH

When apps are being started using the launcher no debug output and no error message are visible. This may be a problem during development. You can launch apps when being logged in into the TXT via SSH (preferrably as user "ftc"). In order to start the test app log into the TXT via SSH first. Then type:
When apps are being started using the launcher no debug output and no error messages are visible. This may be a problem during development. You can launch apps when being logged in into the TXT via SSH (as user "ftc", no password). In order to start the test app log into the TXT via SSH first. Then type:

```
$ export PYTHONPATH=/opt/ftc
Expand All @@ -37,7 +33,7 @@ Again the path is derived from the UUID in the manifest file of your app.

You'll then see the error messages and debug output on the remote shell.

# Start/stop apps via telnet/netcat
# Start/stop apps via telnet/netcat (needs update)

SSH is not the only way to start apps remotely. The TXTs launcher implements a little command server to start and stop apps. This has been added to be used via the web interface but can also be used with tools like telnet or netcat.

Expand All @@ -57,9 +53,9 @@ PyQt is available for all major linux distributions. Use your favorite package m

The TXT apps come with a special Qt TXT theming. In order to run TXT apps on the PC the files implementing this theme have also to be installed on the PC.

Please copy the file `TxtStyle.py` and the entire `themes` subdirectory to the same place on your PC. You can get these files from the [Repository](https://github.com/ftCommunity/ftcommunity-TXT/tree/master/board/fischertechnik/TXT/rootfs/opt/ftc).
Please copy the file `TouchStyle.py` and the entire `themes` subdirectory to the same place on your PC. You can get these files from the [Repository](https://github.com/ftCommunity/ftcommunity-TXT/tree/master/board/fischertechnik/TXT/rootfs/opt/ftc).

If you placed the files into the directory of you app then you don't have to do anything else. If you placed them somewhere else you need to make notify python of this directory. E.g. if `TxtStyle.py` and the `themes` directory have been placed under `/tmp/mytxtenv` then you need to enter:
If you placed the files into the directory of your app then you don't have to do anything else. If you placed them somewhere else you need to notify python of this directory. E.g. if `TouchStyle.py` and the `themes` directory have been placed under `/tmp/mytxtenv` then you need to enter:

```
export PYTHONPATH=/tmp/mytxtenv
Expand All @@ -78,15 +74,15 @@ You can now run your app locally on your PC by typing:
$ ./test.py
```

The file `TxtStyle.py` detects that you are running the app on a PC and creates a Window of 240x320 pixels for it.
The file `TouchStyle.py` detects that you are running the app on a PC and creates a window of 240x320 pixels for it.

You might notice that the Apps don't look 100% the same. One reason is a different font handling on the TXT and on the desktop PC. Furthermore the Qt and Python versions are not necessarily the same on the TXT and on the PC. Furthermore the app runs under the X11 window system on a PC while the TXT uses the QWS window manager for embedded systems. But the differences are small enough to allow for convenient app development on a PC.
You might notice that the apps don't look 100% the same. One reason is a different font handling on the TXT and on the desktop PC. Furthermore the Qt and Python versions are not necessarily the same on the TXT and on the PC. Furthermore the app runs under the X11 window system on a PC while the TXT uses the QWS window manager for embedded systems. But the differences are small enough to allow for convenient app development on a PC.

![Running on a TXT](tut2_img1.png) ![Running on a PC](tut2_img2.png)
![Running on a TXT or a PC](tut2_img1b.png)

Small font rendering differences on TXT (left) and PC (right)

## Using a Windows PC (by LK)
## Using a Windows PC (by LK, needs update)

On all Versions which python supports is it possible to develop and test applications for the
TXT.
Expand Down

1 comment on commit 57ecc95

@EstherMi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated tutorial 2. Now matches cfw 0.9.3.
Two paragraphs still need updates, because I did not test them:

  • Using a Windows PC (no Windows available)
  • Telnet (current instruction did not work)

Both paragraphs are currently not included in the German version.

Please sign in to comment.