gtkdialog getting started
Re: gtkdialog getting started
double post removed
Last edited by bigbass on 28 Nov 2012, 16:44, edited 2 times in total.
Re: gtkdialog getting started
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
*I have a binary I wrote to convert spaces to tabs and justify text
called 2tabs written in BaCon I used to allow for code indentation in this post
IMAGE

I wrote this for gtkdialog so we have some easy examples
This example shows how to control back end services that may or not be running
*Will port this to BaCon too
Sometimes I forget to turn on my modem and when booting slackware 14 it times out
and as a result I don't have internet using LAN so this is a quick way my kids and I can check if the modem is working
A GUI is nice to have to make things easy
Joe
Re: gtkdialog getting started
gtkdialog-0.8.3 compiled on 32bit slackware 14.0
http://bigbass-porteus.googlecode.com/f ... lack14.tgz
Joe
http://bigbass-porteus.googlecode.com/f ... lack14.tgz
Joe
- freestyler
- Contributor
- Posts: 382
- Joined: 17 Oct 2013, 14:21
- Distribution: Porteus KDE4
- Location: Traveller
- Contact:
Re: gtkdialog getting started
I'm trying to make a gtkdialog script that lets you select and open a file from a set directory with a set file type. I did in with kdialog a while ago like this:
Is there any equivalent way to do this with gtkdialog?
Ive searched the internet all day and the closest I got was by using zenity.
Code: Select all
kdialog --getopenfilename /etc/openvpn/. "*.ovpn"
Ive searched the internet all day and the closest I got was by using zenity.
https://www.porteus-apps.org
- brokenman
- Site Admin
- Posts: 6104
- Joined: 27 Dec 2010, 03:50
- Distribution: Porteus v4 all desktops
- Location: Brazil
- Contact:
Re: gtkdialog getting started
gtkdialog is a little more complex than zenity, kdialog and xdialog. It doesn't provide you with prebuilt dialogs, but allows you create them. If all you need is a simple one off dialog to choose a file then zenity or xdialog may be what you need. In any case here is a script that will open a gtkdialog requesting the user to chose a file.
Run it like this: ./myscript /etc/openvpn ovpn
You can also place it in a function in your existing script and just call the function. Something like:
The result will be spat out to stdout or you can send it to a file.
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
You can also place it in a function in your existing script and just call the function. Something like:
Code: Select all
choose_file(){
place_above_code_in_here
}
choose_file /etc/openvpn ovpn
How do i become super user?
Wear your underpants on the outside and put on a cape.
Wear your underpants on the outside and put on a cape.
- freestyler
- Contributor
- Posts: 382
- Joined: 17 Oct 2013, 14:21
- Distribution: Porteus KDE4
- Location: Traveller
- Contact:
Re: gtkdialog getting started
Thanks for the help brokenman, that works great.
I'm now having problems calling a function. It says:
the function is
I am trying to call it with a button like this
Any idea's what i'm doing wrong?
I'm now having problems calling a function. It says:
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>
https://www.porteus-apps.org
- freestyler
- Contributor
- Posts: 382
- Joined: 17 Oct 2013, 14:21
- Distribution: Porteus KDE4
- Location: Traveller
- Contact:
Re: gtkdialog getting started
Got the function working had to use
Code: Select all
export -f term
https://www.porteus-apps.org
-
- Full of knowledge
- Posts: 304
- Joined: 02 Jan 2011, 18:41
- Distribution: Porteus 5.0-RC1
- Location: In a hayfield
Re: gtkdialog getting started
Getting this when I run gtkdialog.
It's on 32bit Porteus-Kde v3.0
guest@porteus:~$ gtkdialog
** (gtkdialog:3266): ERROR **: Gtkdialog: Could not find the dialog description in the environment variable 'MAIN_DIALOG'.
Trace/breakpoint trap
Does gtkdialog need to be called with a file option?
Yes, I'm new to Gtkdialog...finding lots of examples online, but very little about the program itself.
It's on 32bit Porteus-Kde v3.0
guest@porteus:~$ gtkdialog
** (gtkdialog:3266): ERROR **: Gtkdialog: Could not find the dialog description in the environment variable 'MAIN_DIALOG'.
Trace/breakpoint trap
Does gtkdialog need to be called with a file option?
Yes, I'm new to Gtkdialog...finding lots of examples online, but very little about the program itself.
- brokenman
- Site Admin
- Posts: 6104
- Joined: 27 Dec 2010, 03:50
- Distribution: Porteus v4 all desktops
- Location: Brazil
- Contact:
Re: gtkdialog getting started
gtkdialog is not the same as xdialog or kdialog in that it comes with ready made widgets. This is the expected output if you simply type gtkdialog into a terminal. It needs to be run together with a file option or a variable.
http://murga-linux.com/puppy/viewtopic.php?t=38608
http://murga-linux.com/puppy/viewtopic.php?t=38608
How do i become super user?
Wear your underpants on the outside and put on a cape.
Wear your underpants on the outside and put on a cape.