GtkDialog - tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#706 Post by zigbert »

sklimkin
I have read your post some times to get the grip of the problem....
Is it this line that won't work?

Code: Select all

<action>cat [ echo $COMMANDSTRING ] | scrot </action>
If you find gtkdialog sensitive to your bash code, remember, you can always place bash code in an external function. Like:

Code: Select all

call() {
 cat "$COMMANDSTRING" | scrot
}

[...]

<action>call </action>

Sigmund

sklimkin
Posts: 157
Joined: Wed 11 Jul 2012, 21:21
Location: Russia Moscow

#707 Post by sklimkin »

zigbert wrote:sklimkin
... ...
If you find gtkdialog sensitive to your bash code, remember, you can always place bash code in an external function. Like:

Code: Select all

call() {
 cat "$COMMANDSTRING" | scrot
}
[...]
<action>call </action>
Sigmund
Thanks for attention, Sigmund.
I read some hours about bash-scripting successively.
After that has corrected the program text:

Code: Select all

#!/bin/bash
GTKDIALOG=gtkdialog

funccommand () {
if [ "$COMBOBOX1" == "All" ]; then
COMMAND1= 
else COMMAND1="-s"
echo "COMMAND1= $COMMAND1"
COMMAND2="$COMBOBOX2"
echo "COMMAND2= $COMMAND2"
COMMANDSTRING="-d $COMMAND2 $COMMAND1 -e 'mv $f ~'"
echo "COMMANDSTRING= $COMMANDSTRING"
echo "End of export variables."
fi
}

export MAIN_DIALOG='
... ... ...

	<button>
		<label>ACCEPT</label>
		<variable>GOMMANDSRING</variable>
		<action>echo "Start of scrot:"</action>
		<action>funccommand $COMBOBOX1 $COMBOBOX2</action>
		<action>echo "COMMANDSTRING= $COMMANDSTRING"</action>
		<action>cat [ echo $COMMANDSTRING ] | scrot </action>
				</button>
In bash-script it works:

Code: Select all

sklimkin@sklimkin-desktop:~$ funccommand () {
> if [ "$COMBOBOX1" == "All" ]; then
> COMMAND1= 
> else COMMAND1="-s"
> echo "COMMAND1= $COMMAND1"
> COMMAND2="$COMBOBOX2"
> echo "COMMAND2= $COMMAND2"
> COMMANDSTRING="-d $COMMAND2 $COMMAND1 -e 'mv $f ~'"
> echo "COMMANDSTRING= $COMMANDSTRING"
> echo "End of export variables."
> fi
> }
sklimkin@sklimkin-desktop:~$ COMBOBOX2="5"
sklimkin@sklimkin-desktop:~$ COMBOBOX1="Window"
sklimkin@sklimkin-desktop:~$ GOMMANDSRING=""
sklimkin@sklimkin-desktop:~$ funccommand $COMBOBOX1 $COMBOBOX2
COMMAND1= -s
COMMAND2= 5
COMMANDSTRING= -d 5 -s -e 'mv  ~'
End of export variables.
sklimkin@sklimkin-desktop:~$
And in gtkdialog isn't works:

Code: Select all

Start of scrot:
sh: funccommand: command not found
COMMANDSTRING= 
sh: scrot: command not found
cat: [: file or dir missing
cat: echo: file or dir missing
cat: ]: file or dir missing
COMBOBOX1="Window"
COMBOBOX2="5"
FILE="/home/sklimkin/projects/gtkdialog/scrotdlg-bash2/dialog"
GOMMANDSRING=""
EXIT="Cancel"
sklimkin@sklimkin-desktop:~/projects/gtkdialog/scrotdlg-bash2$ 
gtkdialog doesn't find my new function funccommand ()

Code: Select all

sh: funccommand: command not found

Problem in this string:

Code: Select all

<action>funccommand $COMBOBOX1 $COMBOBOX2</action>
I want to understand how correctly to cause external functions from gtkdialog.
Probably such calls are inaccessible in prior versions gtkdialog
At me now:

Code: Select all

sklimkin@sklimkin-desktop:~$ gtkdialog -v
gtkdialog version 0.8.0 (C) 2003-2007 Laszlo Pere, 2011 Thunor
Also isn't works:

Code: Select all

#!/bin/bash
GTKDIALOG=gtkdialog

call() {
funccommand $COMBOBOX1 $COMBOBOX2
echo "call_COMMANDSTRING= $COMMANDSTRING"
cat "$COMMANDSTRING" | scrot
}

funccommand () {
if [ "$COMBOBOX1" == "All" ]; then
COMMAND1= 
else COMMAND1="-s"
echo "COMMAND1= $COMMAND1"
COMMAND2="$COMBOBOX2"
echo "COMMAND2= $COMMAND2"
COMMANDSTRING="-d $COMMAND2 $COMMAND1 -e 'mv $f ~'"
echo "COMMANDSTRING= $COMMANDSTRING"
echo "End of export variables."
fi
}

export MAIN_DIALOG='

	<button>
		<label>ACCEPT</label>
		<variable>GOMMANDSRING</variable>
		<action>echo "Start of scrot:"</action>
		<action>call </action>
	</button>
Thankful in advance for the correct helps.

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#708 Post by technosaurus »

export -f func_name
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

sklimkin
Posts: 157
Joined: Wed 11 Jul 2012, 21:21
Location: Russia Moscow

#709 Post by sklimkin »

technosaurus wrote:export -f func_name
export -f
This that magic word of which didn't suffice for the question decision.
Thanks for the help, mr technosaurus!

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#710 Post by oldyeller »

Hello Everyone

Has anyone used the fontbutton widget yet?

I have tried to use it to increase the font in the reader that I am making with the edit widget.

Don't know if you can use it in the edit widget or not.

This is my code so far
#!/bin/bash

GTKDIALOG=gtkdialog

WORKDIR="/usr/local/Manna"
NOTES_DIR="$WORKDIR/notestxt"

funcbtnCreate() {
echo '<button image-position="'$2'">
<label>"'"$3"'"</label>
<input file stock="'$4'"></input>
<action>echo "'"$5"' '$1'"</action>
<action type="'"$3"'">'$1'</action>
</button>'
}
export TMPDIR=/tmp/notes
mkdir -p "$TMPDIR"

echo "$TMPDIR"/reading

export MAIN_DIALOG='
<window title="Notes" icon-name="Com">

<frame>
<vbox spacing="0">
<menubar>
<menu use-underline="true">
<menuitem stock-id="gtk-quit" accel-key="0x51" accel-mods="4">
<action>exit:Quit</action>
</menuitem>
<label>"_File"</label>
</menu>
<menu label="_Edit" use-underline="true">
<menuitem stock-id="gtk-home" label="Send to Abiword">
<action>abiword '"$TMPDIR"'/reading &</action>
</menuitem>
</menu>
</menubar>
</vbox>
<hbox>
<vbox width-request="120">
<table>
<label>Notes</label>
<variable>ITEM</variable>
<input>ls '"$NOTES_DIR"'</input>
<action>ln -sf "/usr/local/Manna/notestxt/$ITEM" '"$TMPDIR"'/reading</action>
<action>refresh:EDITOR</action>
</table>
</vbox>
<edit editable="true" accepts-tab="true" indent="" justification="0" left-margin="12" right-margin="15" wrap-mode="1">
<variable>EDITOR</variable>
<height>600</height>
<width>350</width>
<input file>'"$TMPDIR"'/reading</input>
<output file>'"$TMPDIR"'/reading</output>
</edit>

</hbox>

<hbox homogeneous="true" spacing="28" width-request="350">
'"$(funcbtnCreate EDITOR 0 Refresh gtk-refresh Refreshing)"'
'"$(funcbtnCreate EDITOR 0 Save gtk-save Saving)"'

<fontbutton font-name="Sans 14" use-font="true" use-size="true">
<variable>$EDITOR</variable>
<input file>'"$TMPDIR"'/reading</input>
<output file>'"$TMPDIR"'/reading</output>

<action>refresh:EDITOR</action>
</fontbutton>
</hbox>
</frame>
</window>
'

case $1 in
-d | --dump) echo "$MAIN_DIALOG" ;;
*) $GTKDIALOG --center --program=MAIN_DIALOG ;;
esac


sklimkin
Posts: 157
Joined: Wed 11 Jul 2012, 21:21
Location: Russia Moscow

GtkDialog + scrot = Graphic-interface

#711 Post by sklimkin »

sklimkin wrote:
technosaurus wrote:export -f func_name
export -f
This that magic word of which didn't suffice for the question decision.
Thanks for the help, mr technosaurus!
There was a task to make the graphic interface with the program scrot.
It is for this purpose convenient and pleasant to use gtkdialog and bash.
The variant with a call of additional function works.

Here that has turned out:

Code: Select all

#!/bin/bash 
## or /bin/sh 

funccommand () {
if [ "$COMBOBOX1" == "All" ]; then
COMMAND1="-m"
else COMMAND1="-s"
fi
## !!! Attention: This works in scrot ver. >= 0.8 only !!!
if [ "$COMBOBOX1" == "Window" ]; then
COMMAND1="-u"
fi
COMMAND2="$COMBOBOX2"
COMMANDSTRING="$COMMAND1-b-d $COMMAND2"
cd "$FILE"
scrot "$COMMANDSTRING"
}

export MAIN_DIALOG="
<window>
	<vbox>
		<text>
			<label>SCReenshOT  screen-grabber</label>
		</text>
		<frame Command button EXIT>
			<hbox>
				<button cancel></button>
			</hbox>
		</frame>
		<frame User-settings>
			<hbox>
				<vbox>
					<text>
						<label>Select grab-mode</label>
					</text>
					<combobox>
						<variable>COMBOBOX1</variable>
						<item>All</item>
						<item>Window</item>
						<item>Area</item>
						<action>save:COMBOBOX1</action>
					</combobox>
				</vbox>
				<vbox>
					<text>
						<label>Time-delay-sec</label>
					</text>
					<combobox>
						<variable>COMBOBOX2</variable>
						<item>0</item>
						<item>1</item>
						<item>2</item>
						<item>3</item>
						<item>5</item>
						<item>10</item>
						<item>20</item>
						<action>save:COMBOBOX2</action>
					</combobox>
				</vbox>
				<button>
					<label>ACCEPT</label>
					<action>$0 func</action>
				</button>
			</hbox>
		</frame>
		<frame Select DIR for save screenshot>
			<chooser>
				<height>200</height>
				<width>200</width>
				<variable>FILE</variable>
				<default>/home/</default>
				<action>save:FILE</action>
				<action>$2= $FILE</action>
			</chooser>
		</frame>
	</vbox>
</window>
"

case $1 in
	func) funccommand $2 ;;
	*) gtkdialog --program=MAIN_DIALOG ;;
esac
And it is variant of usage gtkdialog for C-lang:
http://www.mediafire.com/download.php?el5ruubgov613qg

ScreenShot of "SreenShoter":[/img][/code]

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#712 Post by recobayu »

hi everyone,
i want to make a startmenu in puppy linux like "unity" in ubuntu or something like "metro start menu" in windows8. below, i make a button and scroll in vbox and gtkdialog desklet. but i want more..
i want to a textbox (an entry), that can search every program by change (key-pressed). can anyone help me, please?
thanks in advance
myblog: [url]http://muktyas.blogspot.com[/url]

User avatar
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#713 Post by smokey01 »


sklimkin
Posts: 157
Joined: Wed 11 Jul 2012, 21:21
Location: Russia Moscow

tag for closewindow

#714 Post by sklimkin »

I read old authoring gtkdialog help:
6.2 Widget manipulation
6.2.1 'Closewindow:NAME'
The command closes the named window opened by the 'Launch:' command. The program remain active if there are more windows active.
6.2.2 'Launch:NAME'
The command opens a new window using the environment variable 'Widget'.
For some reasons I can't use tags:

Code: Select all

<action type="launch">DIALOG1</action>
<action type="closewindow">DIALOG1</action>
I use and It works:

Code: Select all

<action>Launch:DIALOG1</action>
And it isn't works:

Code: Select all

<action>Closewindow:DIALOG1</action>
Why?
Who can help?

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

yaf-splash tip

#715 Post by don570 »

Here's a tip....

Code: Select all

<action>yaf-splash -border false  -center -close box -bg orange -fontsize large -text "  John's  message
here   "  & </action>
The above code isn't allowed for the action of a button in a gtkdialog script,
because the text is on two lines.

A way around this problem is to define a variable at beginning of script
such as

Code: Select all

export MESSAGE=" John's message 
here "
Then the button's action becomes one line...

Code: Select all

<action>yaf-splash -border false  -center -close box -bg orange -fontsize large -text " $MESSAGE  "  & </action>

Image

_______________________________________________

I found that if Zigbert's localisation method is used then
MESSAGE=" John's message
here "

is all that is needed. In other words the exporting of the
variable isn't needed.

________________________________________


EDIT: I couldn't get this method of using yaf-splash in a button action
to work when there was a gettext text string :cry:

.
Last edited by don570 on Sat 16 Feb 2013, 19:33, edited 4 times in total.

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

newbe question

#716 Post by mavrothal »

Happy New Year "dialoguers" :D

I'm trying to make a simple GUI for pet installation (below), but I can not find the way to pass the fileselect choice to petget (apparently did not study enough :oops: )

I appreciate any suggestions

Code: Select all

export INSTALL_PET_GUI='<window title="Pet installer GUI">
 <vbox>
   <frame>
   <text use-markup="true"><label>"Sellect a pet to install"</label></text>
     
   <hbox>
    <text><label>Sellect pet</label></text>
    <entry fs-action="file" fs-folder="/root" 
	tooltip-text="Drag or type the pet path here or use the file select button">
     <default>pet</default>
     <variable>EXEC</variable>
    </entry>
	<button>
     <input file stock="gtk-directory"></input>
     <action>fileselect:EXEC</action>
    </button>
   </hbox> 
   <hbox homogeneous="true">
   <button>
     <label>"Install"</label>
     <action>/usr/local/petget/petget ??? </action>
     <action>exit:apply</action>
   </button>
   <button cancel></button>
  </hbox>  
  </frame>
 </vbox>
</window>'
gtkdialog -p INSTALL_PET_GUI
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#717 Post by Geoffrey »

Hi mavrothal,

This works

Code: Select all

<button>
     <label>"Install"</label>
     <action>/usr/local/petget/petget $EXEC</action>
     <action>exit:apply</action>
   </button>
or better yet, the full path isn't needed,

Code: Select all

<button>
     <label>"Install"</label>
     <action>petget $EXEC</action>
     <action>exit:apply</action>
   </button>
Cheers, ☃HaPpy NeWyEaR☘

Geoffrey
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

#718 Post by mavrothal »

Geoffrey wrote:This works

Code: Select all

<button>
     <label>"Install"</label>
     <action>/usr/local/petget/petget $EXEC</action>
     <action>exit:apply</action>
   </button>
Indeed it does.
Thanks and a Happy New Year to you
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#719 Post by thunor »

Here's a nice tip:

Activating a menuitem processes the actions within the menuitem immediately and then returns to the activater.

Activating a button returns to the activater and then processes the actions within the button later when the button has finished animating.

So, a hidden menuitem is a good place to store lots of code that can be called (activated) from multiple places -- it can be thought of as a subroutine of gtkdialog pseudo-XML.

Here's an example that demonstrates the speed difference and the processing order (watch stdout in terminal):

Code: Select all

#!/bin/sh

GTKDIALOG=gtkdialog

RandomGet="od -An -N2 -tu2 < /dev/urandom"

MAIN_DIALOG='
<window title="Activate Test" window-position="1" resizable="false"
	border-width="0">
	<vbox spacing="0">
		<menubar>
			<menu use-underline="true" label="_File">
				<menuitem stock-id="gtk-quit" accel-key="0x51" accel-mods="4">
					<action>exit:Quit</action>
				</menuitem>
			</menu>
			<menu use-underline="true" label="_Code">
				<menuitem stock-id="gtk-refresh">
					<variable>muiMenuitemRoute</variable>
					<action>echo MenuitemRoute 2</action>
					<action>refresh:entMenuitemRoute</action>
					<action>echo MenuitemRoute 3</action>
				</menuitem>
			</menu>
		</menubar>
		<vbox border-width="50">
			<hbox>
				<button image-position="1">
					<label>Activate</label>
					<input file stock="gtk-go-forward"></input>
					<action>echo ButtonRoute 0</action>
					<action>activate:btnButtonRoute</action>
					<action>echo ButtonRoute 1</action>
				</button>
				<button image-position="1">
					<variable>btnButtonRoute</variable>
					<label>Refresh</label>
					<input file stock="gtk-go-forward"></input>
					<action>echo ButtonRoute 2</action>
					<action>refresh:entButtonRoute</action>
					<action>echo ButtonRoute 3</action>
				</button>
				<entry>
					<variable>entButtonRoute</variable>
					<input>"'$RandomGet'"</input>
				</entry>
			</hbox>
			<hbox>
				<button image-position="1">
					<label>Activate</label>
					<input file stock="gtk-go-forward"></input>
					<action>echo MenuitemRoute 0</action>
					<action>activate:muiMenuitemRoute</action>
					<action>echo MenuitemRoute 1</action>
				</button>
				<text label="Refresh"></text>
				<pixmap stock-icon-size="3">
					<input file stock="gtk-go-forward"></input>
				</pixmap>
				<entry>
					<variable>entMenuitemRoute</variable>
					<input>"'$RandomGet'"</input>
				</entry>
			</hbox>
		</vbox>
	</vbox>
</window>
'
export MAIN_DIALOG

case $1 in
	-d | --dump) echo "$MAIN_DIALOG" ;;
	*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
Regards,
Thunor
Last edited by thunor on Mon 07 Jan 2013, 17:53, edited 1 time in total.

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#720 Post by RSH »

Hi.

I wanted to test the above posted script but it gives me an gtkdialog error in gtkdialog3, gtidialog4 and gtkdialog5.

Which version is used for this script?

RSH
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#721 Post by thunor »

RSH wrote:Hi.

I wanted to test the above posted script but it gives me an gtkdialog error in gtkdialog3, gtidialog4 and gtkdialog5.

Which version is used for this script?

RSH
Hi RSH

Change all <variable export="false"> to <variable> and it'll work. I'll edit the script and remove them, they're not necessary.

Regards,
Thunor

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#722 Post by thunor »

Here's another top tip:

A text widget that has space-expand and space-fill set to true can be used as a spacer to push neighbouring widgets in certain directions.

Here the spacer text is "[]" so you can see it -- drag the window out and watch the button.

Code: Select all

#!/bin/sh

GTKDIALOG=gtkdialog

Spacer="[]"

MAIN_DIALOG='
<window title="Spacer Test" window-position="1">
	<vbox>
		<hbox>
			<button space-expand="false" space-fill="false">
				<label>This button will stay put</label>
				<input file stock="gtk-about"></input>
			</button>
			<text space-expand="true" space-fill="true">
				<label>"'$Spacer'"</label>
			</text>
		</hbox>
   </vbox>
</window>
'
export MAIN_DIALOG

case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
Regards,
Thunor

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#723 Post by oldyeller »

Hello Everyone,

I have a question, Has anyone done hyper-links in gtkdialog? If so how do you go about doing it.

What I would like to do is link from one program to another. Hit a word in one program to show the answer in another program.

Any help would be great thanks.


Cheers

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#724 Post by don570 »

Hit a word in one program to show the answer in another program
If you look at the code in puppy clock
you will see a button called 'World clock'

What it does is launch a second program.

You should check out how I wrote it.
When the button is first pressed, I check the version of
gtkdialog to make sure it is recent. Then I launch the second program.

_____________________________________________

User avatar
oldyeller
Posts: 889
Joined: Tue 15 Nov 2011, 14:26
Location: Alaska

#725 Post by oldyeller »

Hi don570,

Will take a look and see if that is what I am looking for.


Cheers

EDIT: Hi don570 took a look not what I was looking for thanks, but I did remember that what I need is just a button to go to one to another program.

Just need to look at my code.

Cheers

Post Reply