My first gadget: Hello world
We are going to write a simple gadget to get used to the Gadget Maker for Tux Droid. This gadget is a typical 'hello world' example.
Important: This tutorial is for the Tux Gadget Maker included in the tuxsetup1.2beta. If you want to use the Gadget Maker please upgrade your software to this version.
Also important: Both the Gadget Manager and Gadget Maker use the gadget framework which cannot run multiple instances at the same time. Meaning, when using the Gadget Maker make sure the Gadget Manager is NOT running and vice versa.
1.1 Creating a new gadget
- Start the Tux Gadget Maker from the desktop menu in Applications > Programming > Tux Gadget Maker.
- Once the program is launched, select "New TGF file" from the "Files" menu.
- Enter the new gadget name: "hello_world.tgf" and save it. After saving the tgf file, it is automatically opened in the Gadget Maker.
1.2 Adding gadget information
We are going to define the system name and add additional gadget information about our new gadget.
In the "About" tab you enter the following in the text fields:
Next, save the changes in the tgf file by selecting Files > Save as TGF file in the menu.
1.3 Defining the localized gadget name
The localized gadget name is the name that will displayed in the Gadget Manager and the gadget window. The gadget framework has multi-language support, meaning for every language another gadget name can be specified.
We will do this for the English language.
- Click the "Strings" tab. Here you can specify the localized name for your gadget.
- Select "<en_us> English United States" in the "language" list.
- In the "Strings" list, select "name_to_read", on the right of the list the "Name" and "Value" will be displayed for "name_to_read"
- In the "Value" text field, replace "Template" with "Hello world"
- Click the "Modify" button to update the changes.
From this point the localized name for US English has been defined. Execute the gadget by selecting Files > Execute in the menu.
Both the gadget window and settings window will be displayed with the updated name.
1.4 Making Tux Droid talk
Here we will add a function to our gadget making Tux say something.
- First select in the menu Files > Stop to make the gadget stop.
- Next, select the "Codes" tab.
- Select the entry "/Scripts/Python/main.pyp" in the "Commons" list. The source code main.pyp is responsible for the "voiceget" side of the gadget. Meaning it represents the Text-To-Speech service.
- Click the "edit" button to view the selected code with gedit.
- Add the following line to the code:
tux.tts.speak('Hello world! How are you?') - Save the edited code and execute the gadget.
- When pushing the "ok" button on the remote control Tux will say the gadget's localized name. Next you will hear and interface sound as used in the Gadget Manager. And after that Tux will say the Text-To-Speech message we just added to the code.
1.5 Testing the gadget in the Gadget Manager
Now lets try the hello world gadget for real:
- Stop the gadget (in the menu: File > Stop) and save our changes (in the menu Files > Save as TGF file).
- Close the Gadget Maker and start the Gadget Manager
- Locate your new Hello_world.tgf file and drag and drop it into the Gadget Manager.
- The gadget should be added below in the gadget list. From here you can select it with the remote control and start it. Or use the right-click menu and select "Run".
- Also when, selecting the "About" in the right click menu of our gadget you see the information we added at the start of this tutorial.
1.6 Adding multi-language support
This part explains how to add support for a second language (French in our example) to the hello world gadget. First we will translate the localized gadget name and next translate the Text-To-Speech message.
1.6.1 Localized gadget name
- Close the Gadget Manager and start the Gadget Maker again.
- Select "Files > Open a TGF file" to load the hello world gadget.
- Go to the the "Strings" tab and select "<FR_ALL> French" in the "Language" list.
- Look for the "name_to_read" entry in the "Strings" list and select it.
- Replace "Template" in the "Value" field on the right with "Salut monde"
- To finish, click on the "Modify" button and the translation is done.
1.6.2 TTS message "Hello world! How are you!"
- Select "<en_US> English United States
- In the text fields on the right side, enter "voiceget_text1" in the "Name" field and "Hello world! How are you?" in the "Value" field.
- Next, click the "Add" button.
- Now, for the French version: Select "<fr_ALL> French" in the language list.
- For voiceget_text1, change the "Value" text field with the French translation: "Salut tout le monde! Comment allez vous?"
- Finish the translation by clicking the "Modify" button.
- Go to the "Codes" tab
- Select main.pyp and click the "Edit" button.
- In the text editor, replace:
tux.tts.speak('Hello world! How are you?")
with:tux.tts.speak(_me.string('voiceget_text1'))
- Save the edited code and close gedit. Also store the changes of our gadget by selecting "Save as TGF file" from the menu.
Our gadget now supports French and US English. Be careful though, you cannot not test the multi-language support from the Gadget Maker. The reason: there is no interface to switch to a different language. So the only way to test the gadget is to re-install it in the Gadget Manager.
Another note: If the Gadget Manager is configured in a language that is not supported by your gadget, US English will be used by default.
For reference you can download the hello world gadget here.