For beginners in programming here is a tutorial in gtkdialog script writing.
Install the gtkdialog debian package first

.
Some useful tips for using the terminal...
memorize
ctrl-a will place cursor at beginning of line
ctrl-e will place cursor at end of line
ctrl-l will clear screen
Up and down arrow keys will enter previous commands.
To study how gtkdialog behaves with a text line fed to it, we will take advantage
of a special option of gtkdialog, -s.
In a terminal a program line is fed into gtkdialog with the echo command.
So type each line in a terminal and press
<ENTER> to execute the line
or copy the lines into the terminal with a drag and click of the mouse.
Strong or weak quoting is possible. Here is an example with weak quoting.
Code: Select all
echo "<window><text><label>Hello World</label></text></window>" | gtkdialog -s
A window is formed with text inside. There are two widgets used, a window widget to form a window,
and a text widget to write the text inside the window.
Note that the display text is actually inside label tags. Here is the alternative
method with strong quoting.
Code: Select all
echo '<window><text><label>Hello World</label></text></window>' | gtkdialog -s
So either strong quoting or weak quoting can be used.
However they aren't quite equivalent.
The special characters are treated differently.
As an example type the following as one line and observe that a substitution has occurred.
$World is substituted with the contents of the variable
World
Code: Select all
World=MESSAGE; echo "<window><text><label>Hello $World</label></text></window>" | gtkdialog -s
Strong quoting would have resulted in a literal translation i.e. there is no substitution. You should test this by
changing the line (weak quoting to strong quoting) and running it in a terminal.
Code: Select all
World=MESSAGE; echo '<window><text><label>Hello $World</label></text></window>' | gtkdialog -s
Notice that there is no substitution!!
Warning ! After running this command in your terminal window you must
now close your terminal and launch another terminal window,
since you have assigned the variable
World to a value. If you don't
the results are not consistent.
__________________________________________________________________________
The backslash will provide protection of special characters so that a literal translation is made.
In this example
Hello \$World will be shown in the window even though weak quoting is being used.
Code: Select all
echo "<window><text><label>Hello \$World</label></text></window>" | gtkdialog -s
_____________________________________________________________________________
Note that if the variable isn't assigned then
$World is blank . To see this
be sure to launch a new terminal and type....
Code: Select all
echo "<window><text><label>Hello $World</label></text></window>" | gtkdialog -s
_______________________________________________________________________
In situations where a variable needs substitution , weak quoting is preferred by some programmers.
However, there is a potential problem. Widgets can have attributes and these attributes must use
weak quoting. They will need protection. Here's an example...
Code: Select all
echo "<window title=\"Window Title\"><text><label>"Hello World"</label></text></window>" | gtkdialog -s
Note the that the text in the label tag can have weak quotes as well. You mustn't protect those
quotes, unless you want those quotes to show in window.
Another benefit of using weak quoting when feeding gtkdialog is the automatic protection of the apostophe
in the display text of the text widget.
Code: Select all
echo "<window><text><label>Tom's book</label></text></window>" | gtkdialog -s
However protection of the apostrophe is needed in the following example
because the display text is between weak quotes.
Code: Select all
echo "<window><text><label>"Tom\'s book"</label></text></window>" | gtkdialog -s
Here is another example to show how strong quotes in the text widget label
can have unexpected consequences...
Code: Select all
echo "<window><text><label>'Toms book'</label></text></window>" | gtkdialog -s
________________________________________________________________________________
By putting the text to be fed to gtkdialog in strong quotes avoids the need for protection
of the attributes.
Note that no protection of the attribute is needed in this example...
Code: Select all
echo '<window title="Window Title"><text><label>Hello World</label></text></window>' | gtkdialog -s
In the following the display text will be
Hello $World since no substitution occurs
i.e. there is a literal translation.
Code: Select all
echo '<window><text><label>Hello $World</label></text></window>' | gtkdialog -s
If you
DO want substitution to occur then it is possible with the right quoting...
Code: Select all
World=MESSAGE;echo '<window><text><label>'"Hello $World"'</label></text></window>' | gtkdialog -s
_______________________________________________________________________
There are 5 predefined buttons possible, cancel , ok , help , yes and no
The cancel button is demonstrated ...
Code: Select all
echo "<window><button cancel></button></window>" | gtkdialog -s
Code: Select all
echo '<window><button cancel></button></window>' | gtkdialog -s
You can make your own button. The most common method is putting a label
on the button...
Code: Select all
echo '<window><button><label>Click Here</label></button></window>' | gtkdialog -s
__________________________________________________________________________
Warning !! When feeding with strong quotes, the hyphen causes problems
as shown by this example...
Code: Select all
echo '<window><text><label>"Tom's book"</label></text></window>' | gtkdialog -s
but there are solutions possible. Here are two possible solutions...
Code: Select all
echo '<window><text><label>'"Tom's book"'</label></text></window>' | gtkdialog -s
Code: Select all
echo '<window><text><label>"'"Tom's book"'"</label></text></window>' | gtkdialog -s
_____________________________________________________________________________________________
By using the
-e option with the echo command, the new line command (\n) is possible.
Code: Select all
echo -e '<window title="Window Title"><text><label>"Hello\n World"</label></text></window>' | gtkdialog -s
Note that the
Hello World text needs to be in quotes.
_____________________________________________________________________
The text widget can have width or height requests. Try this example...
Code: Select all
echo '<window title="Window Title"><text width-request="200"><label>"Hello World"</label></text></window>' | gtkdialog -s
________________________________________________________________
Note that label tags can be replaced with a label attribute if you wish...
Code: Select all
echo '<window title="Window Title"><text width-request="200" label="Hello World"></text></window>' | gtkdialog -s
_______________________________________________________________________________________
Widgets naturally flow from the top of the window to the bottom of the window.
However in the hbox widget the flow is from the right side of the window
to the left side. Here's an example ...
Code: Select all
echo '<window><hbox><button help></button><button cancel></button></hbox></window>' | gtkdialog -s
Note that the cancel button is on the right side of the window and the help button is to the left.
Tip: Give the hbox widget a
width-request="300" to see this effect better.
____________________________________________________________
You now have enough background information to write your first script.
You can now convert the terminal line into a gtkdialog script.
The bash shell should be used to ensure consistent results.
Create a blank text file. Copy the final script into the file and save.
Make sure the script is executable and run
it in the terminal.
Here's how to convert...
Let us convert a terminal line...
Code: Select all
echo '<window><button><label>Click Here</label></button></window>' | gtkdialog -s
The final result...
Code: Select all
#! /bin/bash
export APP='
<window>
<button>
<label>Click Here</label>
</button>
</window>
'
gtkdialog --program=APP
Congratulations ! You are now a gtkdialog programmer.
______________________________________________________________