Here are some tips I use when building a gui.
1) Every time you write an opening directive, copy and edit it into closing one. Then go back and continue
Code: Select all
<window>
Code: Select all
<window>
</window>
Code: Select all
<window title="GUI">
<vbox>
</window>
Code: Select all
<window title="GUI">
<vbox>
</vbox>
</window>
2) Use indentation for clarity and self checking. This is your code formated with indentation.
Code: Select all
#!/bin/sh
export SETTINGS="
<window title=\". DM Settings\">
<hbox>
<vbox>
<frame Max. Drive List Height >
<vbox>
<text>
<label>Set Maximum Number of</label>
</text>
<text>
<label>Drives to Show in Drive List.</label>
</text>
<hbox>
<button>
<label>Increase</label>
<action>$1/driveman lstHEIGHT up</action>
<action type=\"clear\">HEIGHT</action>
<action type=\"refresh\">HEIGHT</action>
</button>
<button>
<label>Decrease</label>
<action>$1/driveman lstHEIGHT dn</action>
<action type=\"clear\">HEIGHT</action>
<action type=\"refresh\">HEIGHT</action>
</button>
<entry>
<variable>HEIGHT</variable>
<input>cat $1/lstHEIGHT.set</input>
<width>40</width>
<height>25</height>
</entry>
</hbox>
</vbox>
</frame>
<frame Bootup Control>
<vbox>
<checkbox>
<label>Run DriveMan at Bootup.</label>
<variable>DMBOOT</variable>
<action>$1/driveman dmBOOT</action>
</checkbox>
<checkbox>
<label>Run Auto-Drive at Bootup.</label>
<variable>AUTOBOOT</variable>
<action>$1/driveman autoBOOT</action>
</checkbox>
</vbox>
</frame>
</vbox>
<vbox>
<frame Auto-Drive Control >
<vbox>
<checkbox>
<label>Start or Stop Auto-Drive.</label>
<variable>AUTODRV</variable>
<action>$1/driveman autoDRV</action>
</checkbox>
<checkbox>
<label>Auto-Drive Pops up ROX.</label>
<variable>AUTOROX</variable>
<action>$1/driveman autoROX</action>
</checkbox>
</vbox>
</frame>
<button>
<label>Exit</label>
<action>exit</action>
</button>
</vbox>
</hbox>
</window>
"
gtkdialog3 -d -p SETTINGS
3) Use the construct GUI=$(cat <<EOV|sed 's/#.*//'...EOV) This allows you to comment your gui and can greatly speed up those tweaks
Code: Select all
GUI=$(cat <<EOV|sed 's/#.*//'
<window title="gui">
<vbox>
<text label="Use This></text>
#<text label="Do Not Use This"></text>
</vbox>
</window>
EOV)
4)KISS I try to divorce the gui from the actions of the gui. By this I mean when you have an action rather than writing the code into your gui, perform a subroutine instead e.g
Code: Select all
<action>display ENTRY</action>
Code: Select all
display(){ echo "${!1}"; }
Code: Select all
<action>echo \$ENTRY</action>
- Testing: you can get the gui working without having to worry about your bash code working
Reuse: You can use a function anywhere, inside another script or even on the command line
Looks: Funnily enough using functions and variables indirectly as parameters ( ${!1} in a function means use the literal of the first parameter as a variable) fits right in in with the look and feel of the xml(ish) gui
Code: Select all
gtkdialog3 -d -p GUI
Potong