7. Advanced Syntax - make your code readable
Comments in your code
Gtkdialog doesn't support comments in its xml code. But if we convert all comments before execution, it works. The reason why I use double hash (##) for my comments, is because colors in a <span> tag might be defined as red or #FF0000. The latter would be removed by using a single hash.
XML=' <vbox> ##this is how to comment your xml code. <text height-request="50"> ##force the text to take more space. <label>Hello</label> </text> <hbox> ##hbox to align button to the right. <button ok></button> ##button ok is fetched from the gtk stock. </hbox> </vbox>' export GUI="`echo "$XML" | sed -e 's/##.*//'`" gtkdialog -p GUI
Include code if...
It is possible to build the gtkdialog out of many small pieces. Every piece is a variable and are put together when exporting the gtkdialog code. It is easy to think that a button should have different label depending on "this or that". Or like in the following example, - include a button if file/app/... exists. Instead of defining all these pieces before the actual gtkdialog code, it is much more human readable if you define all 'inside' the gtkdialog code.
script=' <vbox> <hbox> <text> <label>Yes button added if file /root/testfile exists</label> </text>' [ -f /root/testfile ;then script=${script}'<button yes></button>' script=${script}' <button no> </button> </hbox> </vbox>' export SCRIPT="$script" gtkdialog --program=SCRIPT