Re: gtkdialog getting started
Posted: 28 Nov 2012, 16:14
double post removed
Code: Select all
#!/bin/bash
# description of script:
# control Modem service on and off
# script name modem_control
# Nov 28,2012 Joe Arose "bigbass"
# this is an administrative script
# written to show what is happening with the service
# without obscuring the processes involved
# keeping everything transparent
rm /tmp/modem_status
# lets run this first to get the modem status before gtkdialog is run
ps -A| grep dhcpcd > /dev/null 2>&1 ;RETVAL=${PIPESTATUS[1]};[ $RETVAL -eq 0 ] && RESULT_="Modem running";[ $RETVAL -ne 0 ] && RESULT_="Modem not running"
echo $RESULT_ >/tmp/modem_status
export MODEM_DIALOG='
<window title="Modem Service Control">
<vbox>
<frame Start / stop modem>
<pixmap icon_size="6">
<input file stock= "gtk-connect"></input>
</pixmap>
</frame>
<frame Wait on status to change... >
<entry>
<input file>/tmp/modem_status</input>
<variable>ENTRY</variable>
</entry>
</frame>
<frame "Enable" starts modem "Disable" stops modem >
<hbox>
<button>
<label>Enable</label>
<action type="enable">ENTRY</action>
<action type="enable">CHECKBOX</action>
<action>/sbin/dhcpcd </action>
<action>ps -A| grep dhcpcd > /dev/null 2>&1 ;RETVAL=${PIPESTATUS[1]};[ $RETVAL -eq 0 ] && RESULT_="Modem running";[ $RETVAL -ne 0 ] && RESULT_="Modem not running" ;echo Modem running >/tmp/modem_status </action>
<action type="refresh">ENTRY</action>
</button>
<button>
<label>Disable</label>
<action type="enable">ENTRY</action>
<action type="enable">CHECKBOX</action>
<action>/sbin/dhcpcd -x</action>
<action>ps -A| grep dhcpcd > /dev/null 2>&1 ;RETVAL=${PIPESTATUS[1]};[ $RETVAL -eq 0 ] && RESULT_="Modem running";[ $RETVAL -ne 0 ] && RESULT_="Modem not running" ;echo Modem not running >/tmp/modem_status </action>
<action type="refresh">ENTRY</action>
</button>
</hbox>
</frame>
<hbox>
<button cancel></button>
</hbox>
</vbox>
</window>
'
gtkdialog --center --program MODEM_DIALOG
Code: Select all
kdialog --getopenfilename /etc/openvpn/. "*.ovpn"
Code: Select all
#!/bin/bash
echo '<window title="'$(gettext "Open a file")'" icon-name="gtk-open" width-request="350">
<vbox>
<text><label>Please select a file:</label></text>
<hbox>
<entry fs-action="file"
fs-title="Select a file"
fs-filters="*.'$2'"
fs-folder="'$1'"
editable="false">
<variable>entselFile</variable>
</entry>
<button space-expand="false" space-fill="false">
<label>Select</label>
<variable>butselFile</variable>
<action function="fileselect">entselFile</action>
</button>
</hbox>
</vbox>
</window>
'|gtkdialog -s -c
Code: Select all
choose_file(){
place_above_code_in_here
}
choose_file /etc/openvpn ovpn
Code: Select all
sh: term: command not found
Code: Select all
function term(){
exec xterm -e "openvpn --config $entselFile"
}
Code: Select all
<button>
<label>Start</label>
<action>term</action></button>
<button>
Code: Select all
export -f term
Code: Select all
Detect()
{ for item in Pomme Poire Abricot Prune Raisin
do echo $item ; done }
mainDialog()
{
TITLE="Choose a fruit "
FRUIT_FRAME="Select a fruit from available list"
FRUIT_NAME="Name of the fruit"
/bin/rm -f /tmp/fruits
Detect >> /tmp/fruits
local DIALOG='
<window title="'$TITLE'"> <vbox>
<frame '$FRUIT_FRAME'>
<table>
<width>60</width> <height>120</height>
<label>'$FRUIT_NAME'</label>
<input file>/tmp/fruits</input>
<variable>MY_FRUIT</variable>
</table>
</frame>
<hbox> <button ok></button> <button cancel></button> </hbox>
</vbox> </window> '
echo "$DIALOG" | sed '/^##/d'| gtkdialog -c -s 2> /dev/null
}
eval "`mainDialog`"
echo $MY_FRUIT" is selected"</code>
this is because Porteus5.0 gtkdialog is built with/for gtk+3 (and APorteus is still using gtk+2 version)
Code: Select all
Detect()
{ for item in Pomme Poire Abricot Prune Raisin
do echo $item ; done }
mainDialog()
{
TITLE="Choose a fruit "
FRUIT_FRAME="Select a fruit from available list"
FRUIT_NAME="Name of the fruit"
/bin/rm -f /tmp/fruits
Detect >> /tmp/fruits
local DIALOG='
<window title="'$TITLE'"> <vbox>
<frame '$FRUIT_FRAME'>
<tree>
<width>60</width> <height>120</height>
<label>'$FRUIT_NAME'</label>
<input file>/tmp/fruits</input>
<variable>MY_FRUIT</variable>
</tree>
</frame>
<hbox> <button ok></button> <button cancel></button> </hbox>
</vbox> </window> '
echo "$DIALOG" | sed '/^##/d'| gtkdialog -c -s 2> /dev/null
}
eval "`mainDialog`"
echo $MY_FRUIT" is selected"