Difference between revisions of "Scripting - Chapter 2: Basic Functions"
RoninDusette (talk | contribs) |
(Consistent dash-bang line with playonlinux-bash tip) (Tag: visualeditor) |
||
(12 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | + | {{Info|All of the commands we're about to see must be inserted between the '''POL_SetupWindow_Init''' and the '''POL_SetupWindow_Close''' commands. }} | |
− | |||
− | |||
== Displaying a message == | == Displaying a message == | ||
− | Here comes the command POL_SetupWindow_message: | + | Here comes the command '''POL_SetupWindow_message''': |
'''Syntax:''' | '''Syntax:''' | ||
Line 13: | Line 11: | ||
'''Example:''' | '''Example:''' | ||
− | <pre class= | + | <pre class="code playonlinux"> |
− | #!/bin/bash | + | #!/usr/bin/env playonlinux-bash |
[ "$PLAYONLINUX" = "" ] && exit 0 | [ "$PLAYONLINUX" = "" ] && exit 0 | ||
source "$PLAYONLINUX/lib/sources" | source "$PLAYONLINUX/lib/sources" | ||
Line 34: | Line 32: | ||
== A text zone == | == A text zone == | ||
− | Do you want to ask the user a question? The POL_SetupWindow_textbox function was created for that purpose. Add the following code to your script: | + | Do you want to ask the user a question? The '''POL_SetupWindow_textbox''' function was created for that purpose. Add the following code to your script: |
'''Syntax:''' | '''Syntax:''' | ||
Line 52: | Line 50: | ||
== A question? == | == A question? == | ||
− | Do you want the user to be able to answer by yes or no? Then use this function POL_SetupWindow_question | + | Do you want the user to be able to answer by yes or no? Then use this function '''POL_SetupWindow_question''' |
'''Syntax:''' | '''Syntax:''' | ||
Line 77: | Line 75: | ||
</pre> | </pre> | ||
− | + | {{Info|The different entries must be separated by a single character separator, specified in the call; it should be provided as the last positional argument. The characters most often used for that are dash (-), pipe (¦), and tilda (~).}} | |
'''Example:''' | '''Example:''' | ||
Line 90: | Line 88: | ||
== Select a file == | == Select a file == | ||
− | You can ask the user to select a file from | + | You can ask the user to select a file from their computer in the following manner: |
'''Syntax:''' | '''Syntax:''' | ||
Line 133: | Line 131: | ||
'''Previous:''' [[Scripting - Chapter 1: Getting to know Bash|Chapter 1: Getting to know Bash]] | '''Previous:''' [[Scripting - Chapter 1: Getting to know Bash|Chapter 1: Getting to know Bash]] | ||
+ | |||
'''Next:''' [[Scripting - Chapter 3: Variables|Chapter 3: Variables]] | '''Next:''' [[Scripting - Chapter 3: Variables|Chapter 3: Variables]] | ||
[[Category:Scripting]] | [[Category:Scripting]] |
Latest revision as of 16:50, 22 March 2015
Contents
Displaying a message
Here comes the command POL_SetupWindow_message:
Syntax:
POL_SetupWindow_message "Message" "Window title"
Example:
#!/usr/bin/env playonlinux-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
Hello World!
You can now display a message. Congratulations.
A text zone
Do you want to ask the user a question? The POL_SetupWindow_textbox function was created for that purpose. Add the following code to your script:
Syntax:
POL_SetupWindow_textbox "Message" "Window title"
Example:
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.
A question?
Do you want the user to be able to answer by yes or no? Then use this function POL_SetupWindow_question
Syntax:
POL_SetupWindow_question "Question" "Window title"
Example:
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.
Syntax:
POL_SetupWindow_menu "Message" "Window title" "Available choices separated with the separator" "The separator"
Example:
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 their computer in the following manner:
Syntax:
POL_SetupWindow_browse "Message" "Window title"
Example:
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 they install it.
Syntax:
POL_SetupWindow_presentation "Name of the program" "Editor of the program" "Editor's site" "your pseudo" "Program's prefix (cf chapter 5)"
Example:
POL_SetupWindow_presentation "Mozilla Firefox" "Mozilla" "http://www.mozilla.com" "Script author" "MozillaFirefox"
Comment your code
The "#" symbol (also known as hashtag, hash, pound sign, etc.) 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.
Previous: Chapter 1: Getting to know Bash
Next: Chapter 3: Variables