gtkdialog getting started

For discussions about programming and projects not necessarily associated with Porteus.
User avatar
bigbass
Contributor
Contributor
Posts: 151
Joined: 13 Jan 2012, 14:35
Distribution: slackware 14

Re: gtkdialog getting started

Post#16 by bigbass » 28 Nov 2012, 16:14

double post removed
Last edited by bigbass on 28 Nov 2012, 16:44, edited 2 times in total.

User avatar
bigbass
Contributor
Contributor
Posts: 151
Joined: 13 Jan 2012, 14:35
Distribution: slackware 14

Re: gtkdialog getting started

Post#17 by bigbass » 28 Nov 2012, 16:18

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
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

User avatar
bigbass
Contributor
Contributor
Posts: 151
Joined: 13 Jan 2012, 14:35
Distribution: slackware 14

Re: gtkdialog getting started

Post#18 by bigbass » 15 Feb 2013, 16:28

gtkdialog-0.8.3 compiled on 32bit slackware 14.0
http://bigbass-porteus.googlecode.com/f ... lack14.tgz



Joe

User avatar
freestyler
Contributor
Contributor
Posts: 384
Joined: 17 Oct 2013, 14:21
Distribution: Porteus XFCE

Re: gtkdialog getting started

Post#19 by freestyler » 05 Mar 2014, 04:27

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:

Code: Select all

kdialog --getopenfilename /etc/openvpn/. "*.ovpn"
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.
https://www.porteus-apps.org

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: gtkdialog getting started

Post#20 by brokenman » 06 Mar 2014, 01:26

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.

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
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:

Code: Select all

choose_file(){
place_above_code_in_here
}

choose_file /etc/openvpn ovpn
The result will be spat out to stdout or you can send it to a file.
How do i become super user?
Wear your underpants on the outside and put on a cape.

User avatar
freestyler
Contributor
Contributor
Posts: 384
Joined: 17 Oct 2013, 14:21
Distribution: Porteus XFCE

Re: gtkdialog getting started

Post#21 by freestyler » 06 Mar 2014, 23:22

Thanks for the help brokenman, that works great.
I'm now having problems calling a function. It says:

Code: Select all

sh: term: command not found
the function is

Code: Select all

function term(){
exec xterm -e "openvpn --config $entselFile"
}
I am trying to call it with a button like this

Code: Select all

    <button>
      <label>Start</label>
      <action>term</action></button>
    <button>
Any idea's what i'm doing wrong?
https://www.porteus-apps.org

User avatar
freestyler
Contributor
Contributor
Posts: 384
Joined: 17 Oct 2013, 14:21
Distribution: Porteus XFCE

Re: gtkdialog getting started

Post#22 by freestyler » 07 Mar 2014, 01:22

Got the function working had to use

Code: Select all

export -f term
https://www.porteus-apps.org

roadie
Full of knowledge
Full of knowledge
Posts: 400
Joined: 02 Jan 2011, 18:41
Distribution: Porteus 5.0-RC1
Location: In a hayfield

Re: gtkdialog getting started

Post#23 by roadie » 22 Mar 2014, 20:48

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.

User avatar
brokenman
Site Admin
Site Admin
Posts: 6105
Joined: 27 Dec 2010, 03:50
Distribution: Porteus v4 all desktops
Location: Brazil

Re: gtkdialog getting started

Post#24 by brokenman » 23 Mar 2014, 23:59

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
How do i become super user?
Wear your underpants on the outside and put on a cape.

bour59
Samurai
Samurai
Posts: 181
Joined: 29 Dec 2010, 08:10
Distribution: porteus v5.0-xfce K5.19.7
Location: France

gtkdialog getting started

Post#25 by bour59 » 28 Sep 2022, 09:49

Can't display a file in Porteus5.0-xfce but ok in APorteus
Here is my script

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>

User avatar
ncmprhnsbl
DEV Team
DEV Team
Posts: 3924
Joined: 20 Mar 2012, 03:42
Distribution: v5.0-64bit
Location: australia
Contact:

gtkdialog getting started

Post#26 by ncmprhnsbl » 28 Sep 2022, 12:54

bour59 wrote:
28 Sep 2022, 09:49
Can't display a file in Porteus5.0-xfce but ok in APorteus
this is because Porteus5.0 gtkdialog is built with/for gtk+3 (and APorteus is still using gtk+2 version)
"table" was deprecated in gkt+2 and then removed in gtk+3
but
you can use "tree" in the same way:

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"
see here: https://github.com/puppylinux-woof-CE/gtkdialog/wiki for relatively up to date documentation..
Forum Rules : https://forum.porteus.org/viewtopic.php?f=35&t=44

bour59
Samurai
Samurai
Posts: 181
Joined: 29 Dec 2010, 08:10
Distribution: porteus v5.0-xfce K5.19.7
Location: France

gtkdialog getting started

Post#27 by bour59 » 28 Sep 2022, 15:31

thx, @ncmprhnsbl it's fine now.
will look at the relatively up to date documentation.

Post Reply