Difference between revisions of "Scripting - Chapter 2: Basic Functions"
(Page créée avec « == Let's see some basic commands for writing PlayOnLinux scripts. == Note: all the commands we're about to see must be inserted between the POL_SetupWindow_Init and the P... »)
m (RoninDusette a déplacé la page Creating Scripting - Chapter 2: Basic Functions vers Scripting - Chapter 2: Basic Functions)
Revision as of 01:09, 27 February 2015
Let's see some basic commands for writing PlayOnLinux scripts.
Note: all the commands we're about to see must be inserted between the POL_SetupWindow_Init and the POL_SetupWindow_Close commands.
Displaying a message
Here comes the command POL_SetupWindow_message:
POL_SetupWindow_message "Message" "Window title"
#!/bin/bash [ "$PLAYONLINUX" = "" ] && exit 0 source "$PLAYONLINUX/lib/sources" POL_SetupWindow_Init POL_SetupWindow_message "Hello World!" "My first message" POL_SetupWindow_Close exit
This is what you will get:
PlayOnLinux Wizard My first message
You can now display a message. Congratulations.
A text zone
You want to ask something to the user? The function POL_SetupWindow_textbox was created for that purpose. Add the following code to your script:
POL_SetupWindow_textbox "Message" "Window title"
POL_SetupWindow_textbox "What is your name?" "Text zone"
We'll see in the next chapter how to retrieve the text that the user entered.
You want the user the answer by yes or no? Then use this function POL_SetupWindow_question
POL_SetupWindow_question "Question" "Window title"
POL_SetupWindow_question "Do you like PlayOnLinux?" "My first question"
In the next chapter we will see how to retrieve the answer to the question.
Just like for the two previous functions, you can create a menu for PlayOnLinux.
POL_SetupWindow_menu "Message" "Window title" "Available choices separated with the separator" "The separator" </pre< '' '''NOTE: The different entries must be separated a single character separator, that is provided as the next argument, the characters most often used for that are dash (-), and tilda (~).''' '' '''Example:''' <pre class='code playonlinux'> POL_SetupWindow_menu "What would you like to eat tonight?" "Tonight's menu" "Carrots|Potatoes|French-Fries" "|"
In the next chapter we will see how to retrieve the selected entry.
Select a file
You can ask the user to select a file from his/her computer.
POL_SetupWindow_browse "Message" "Window title"
POL_SetupWindow_browse "Select installation program" "File selection"
In the next chapter we will see how to retrieve the selected file.
Introducing your application
This command is very important. It allows you to introduce the application to the user before he installs it.
POL_SetupWindow_presentation "Name of the program" "Editor of the program" "Editor's site" "your pseudo" "Program's prefix (cf chapter 5)"
POL_SetupWindow_presentation "Mozilla Firefox" "Mozilla" "http://www.mozilla.com" "Script author" "MozillaFirefox"
Comment your code
The symbol "#" tells Bash to ignore the text until the end of the line. Here's an example:
POL_SetupWindow_message "Hello" "Test" # A nice comment POL_SetupWindow_message "Goodbye" "Test"
You should comment your scripts as much as possible to improve their readability and help scripters in their validation task.