Page 21 of 76

Posted: Mon 23 Aug 2010, 10:35
by neurino
This is a libglade-related question but maybe gtkdialod works the same with the syntax explained here...

I want my dialog to commit an action then close itself after a certain button is pressed so I put two actions (signals for libglade) in sequence:

Code: Select all

<signal name="clicked" handler="my_function"/>
<signal name="clicked" handler="EXIT:OK"/>
but the dialog exits before my_function gets executed, I know it because if I remove the EXIT:OK part the function executes flawlessly.

Does this happen with <action>s too?
Is there a turnaround or something for this?


Thanks

Posted: Mon 23 Aug 2010, 14:12
by zigbert
<actions> is executed in the order you put them into your code, so it would execute my_function and then exit. It seems that signals have an internal order.....


Sigmund

Posted: Mon 23 Aug 2010, 14:14
by neurino
sob, unluckily this is not in glade code, I put my_func tag before EXIT but it's not enough

Any ideas or link to refer?

Posted: Mon 23 Aug 2010, 14:38
by technosaurus
I don't know if it will work but if you just need them in order maybe something like?
my_function1 && my_function2 && ...
or possibly
`my_function1 && my_function2 && ...`
or
'`my_function1 && my_function2 && ...`'
or
"`my_function1 && my_function2 && ...`"
(depending on how you write the code quotes may need a "\" before them as well)

hopefully one of those works
(if they don't need to be completed in order, just started in order use a single & instead of the double &&)

Posted: Mon 23 Aug 2010, 16:19
by neurino
technosaurus wrote:I don't know if it will work but if you just need them in order maybe something like?
my_function1 && my_function2 && ...
Ok but I don't need 2 functions but a function THEN EXIT:

Code: Select all

my_func && EXIT:OK
sadly won't work... :?

Posted: Mon 23 Aug 2010, 17:56
by technosaurus
hmmm that would be bad since just having a function that would
killall <program_name>
would prevent being able to use any variables that gtkdialog would return

I wonder if it is possible to export the variables first by:
my_function && export var1 var2 ... && killall <my_program>

there is a way to give your program a name so that it doesn't kill other gtkdialog programs but I don't remember off hand ... could just make a symlink for it so that the name is different.

Posted: Mon 23 Aug 2010, 19:10
by seaside
neurino,

Perhaps put the Exit inside my_func , as the last command.

Just a possible guess, since I haven't tried Libglade. :D

Cheers,
s

Posted: Mon 23 Aug 2010, 19:29
by technosaurus
using exit in the function would exit the whole script... but you got me thinking... what if you use?
return EXIT:OK
and put the call to the function as discussed before

Posted: Tue 24 Aug 2010, 08:13
by neurino
technosaurus, thanks but it doesn't work (simply does not close dialog)

If you are sure using <action>s instead of <signal>s will act as expected I'll translate all XML code...

Posted: Fri 27 Aug 2010, 20:58
by zigbert
Here is an example that allows preview of images..... and you thought it wasn't possible :lol:

It requires another gtk-theme switcher that allows changing theme from commandline

Code: Select all

#!/bin/sh
set -a
mkdir -p /tmp/gtk-theme/gtk-2.0
cp -f "$HOME/.gtkrc-2.0" "$HOME/.gtkrcbak"

#define working gtk-theme
TMP=`grep -F '/usr/' $HOME/.gtkrc-2.0 | awk -F'"' '{print $2}' | sed -e 's%//%/%g'` #'
TARGET_DIR=`dirname $TMP`
cp $TARGET_DIR/* /tmp/gtk-theme/gtk-2.0

#add our own special gtk-theme-extension with wallpaper definition
echo 'style "icon-style" {
stock["gtk-wallpaper"] = { 
{ "stock_wall.png", *, *, *}}}
class "GtkWidget" style "icon-style"' >> /tmp/gtk-theme/gtk-2.0/gtkrc

#build list for <tree> widget
ls -1 /usr/share/backgrounds > /tmp/wallpapers
while read I; do
	ITEMS="$ITEMS<item>$I</item>"
done < /tmp/wallpapers

#switch image preview
preview() {
	cp -f /usr/share/backgrounds/"$WALLPAPER" /tmp/gtk-theme/gtk-2.0/stock_wall.png
	gtk-theme-switch2 /tmp/gtk-theme
}

#define default preview
WALLPAPER='default.jpg'
preview

#gui
export MAIN_DIALOG='<vbox height-request="250">
  <pixmap icon_size="6"><input file stock="gtk-wallpaper"></input></pixmap>
  <tree>
    <label>Wallpapers</label>
    <variable>WALLPAPER</variable>
    '$ITEMS'
    <action signal="button-release-event">preview</action>
  </tree>
  <hbox><button ok></button></hbox>
</vbox>'
gtkdialog3 -p MAIN_DIALOG

#clean up
rm -rf /tmp/gtk-theme
cp -f "$HOME/.gtkrcbak" "$HOME/.gtkrc-2.0"

Posted: Fri 27 Aug 2010, 21:56
by zigbert
Ok, this is might more useful... :D

A right click menu is sometimes nice.....

Code: Select all

#!/bin/sh
set -a

external_menu(){
	[ ! $BUTTON = 3 ] && exit
	#Try to fetch COLOR from gtk-theme
	TMP="/`grep '/usr/share/themes/' $HOME/.gtkrc-2.0 | cut -d/ -f2- | tr -d '"' | sed 's%//%/%g'`" #'
	COLOR="#`grep -A40 'default' "$TMP" | grep -F 'base[SELECTED]' | cut -d'#' -f2 | cut -d'"' -f1`" #'
	[ "$COLOR" = "#" ] && COLOR='#777777'
	
	#set gtk-theme
	echo 'style "menu" {
	  font_name				= "DejaVu Sans 12"
	  bg[NORMAL]			= "#cccccc"
	  base[NORMAL]			= "#cccccc"	
	  base[SELECTED]		= "'$COLOR'"
	  text[NORMAL]			= "#222222"
	  text[SELECTED]		= "#ffffff"
	  engine "pixmap" {
	    image {
	    function			= FOCUS
	    file				= "<none>"}}}
	class "*" style "menu"' > /tmp/gtkrc
	export GTK2_RC_FILES=/tmp/gtkrc 
	
	#show menu
	export menu='
	<window title="menu" decorated="false" skip_taskbar_hint="true" window_position="2">
	 <vbox>
	  <tree hover-selection="true" headers-visible="false">
	   <label>a</label>
	   <variable>MENU</variable>
	   <height>100</height><width>250</width>
	   <item stock="gtk-apply">Set theme</item>
	   <item stock="gtk-jump-to">Show JWM_switcher</item>
	   <item stock="gtk-quit">Quit</item>
	   <action signal="button-release-event">EXIT:exit</action>
	  </tree>
	 </vbox>
	 <action signal="leave-notify-event">EXIT:exit</action>
	</window>'
	gtkdialog3 -p menu > /tmp/OUTPUT 2> /dev/null
	
	#actions
	OUTPUT="`grep 'MENU=' /tmp/OUTPUT | cut -d '"' -f 2`" #'
	case $OUTPUT in
		'Set theme')
			cp -f /root/.jwm/themes/${JWM_THEME}-jwmrc /root/.jwm/jwmrc-theme
			cp -f /root/.jwm/themes/${JWM_THEME}-colors /root/.jwm/jwm_colors
			jwm -restart
			;;
		'Show JWM_switcher')
			/usr/local/jwmconfig2/theme_switcher
			;;
		'Quit')
			for I in `ps | grep -w "MAIN_DIALOG" | awk '{print $1}'`; do kill -9 $I; done
			exit 0
			;;
	esac
}

#this builds the list for the <tree> widget
for THEME in `ls -1 /root/.jwm/themes/ | grep 'jwmrc' | sed -e 's/-jwmrc//' | tr '\n' ' '`; do
	THEME="`basename $THEME`"
	ITEMS="$ITEMS<item>$THEME</item>"
done

MAIN_DIALOG='<vbox height-request="250">
  <text><label>Example of an right-click-menu with gtkdialog</label></text>
  <tree hover-selection="true">
    <label>JWM themes</label>
    <variable>JWM_THEME</variable>
    '$ITEMS'
    <action signal="button-press-event">external_menu</action>
  </tree>
  <hbox><button ok></button></hbox>
</vbox>'
export GTK2_RC_FILES=/root/.gtkrc-2.0
gtkdialog3 -p MAIN_DIALOG


Posted: Sat 28 Aug 2010, 00:34
by technosaurus
Excellent work Zigbert.

One step closer to eliminating that cursed curses dialog at startup.

Making a first run script:

Code: Select all

#!/bin/sh
#bunch of scripting goes here
[ "`basename $0`" = "Script-firstrun" ] && rm -f $0
now just make a symlink called "Script-firstrun" in /root/Startup and it will run the next time X is started then delete only the symlink

there is an alternative to the delayed run script and I can get Xvesa + jwm to start in less than a second this way
Xvesa -br -screen `Xvesa -listmodes 2>&1 |grep 0x[123][246] |sort |cut -d " " -f 2|tr "\n" " "|cut -d " " -f 1` -shadow -mouse /dev/mouse -nolisten tcp -tst -I & jwm -display :0 && killall Xvesa
or simply
Xvesa & jwm -display :0 && killall Xvesa

jwm has a startup command function builtin - example:
<StartupCommand>rox -p /root/Choices/ROX-Filer/PuppyPin</StartupCommand>
or
<StartupCommand>delayedrun</StartupCommand>
etc...

but you don't even need to start a window manager at all - gtkdialog has a builtin method of attaching itself to a display just as a window manager does

Xvesa & gtkdialog3 -f <file> --display=:0 -c && killall Xvesa
#this can also be -p VARIABLE and can be part of a script

Posted: Sat 28 Aug 2010, 03:07
by big_bass
excellent stuff Zigbert


couldn't get the viewer up but the rest of the code worked
I am missing this bash: gtk-theme-switch2: command not found
It requires another gtk-theme switcher that allows changing theme from commandline


can someone post that script please or a diff
so I test the image viewer

thanks keep the good stuff coming


Joe

Posted: Sun 29 Aug 2010, 07:20
by zigbert
big_bass
couldn't get the viewer up but the rest of the code worked
I am missing this bash: gtk-theme-switch2: command not found
Download gtk-theme-switch2 from 3 posts above. You missed a attachment :)


Sigmund

Posted: Sun 29 Aug 2010, 10:41
by 01micko
Haha!

Cool stuff Sigmund... actually works in Xfce4 too, which I am experimenting with at the moment :wink:

Cheers

Posted: Sun 29 Aug 2010, 19:26
by big_bass
Download gtk-theme-switch2 from 3 posts above. You missed a attachment Smile


Sigmund

Thanks Sigmund

now its working :D



*about two years ago I was working on an image viewer using imagelib and urxvt
yours is much better and lighter you may get some more formats to view with this
lib http://www.afterstep.org/afterimage/

I made an image viewer using the using the terminal
http://www.murga-linux.com/puppy/viewtopic.php?t=31254

I was looking for a light way to do this
thanks for posting your code

Joe

Re: GtkDialog - tips

Posted: Fri 24 Sep 2010, 02:02
by ken geometrics
zigbert wrote:GtkDialog
Patriot has released his Patriot-edition of the latest gtkdialog. - See chapter 'Gtkdialog - Patriot edition'.
What should I see if I say:
gtkdialog3 --version

I currently see
gtkdialog version 0.7.20 (C) 2004, 2005, 2006, 2007 by Laszlo Pere


I have found a handful of very serious bugs in it and want to be sure that I am using the latest version.

In the copy I have, the list_actions example does not work.

Posted: Fri 24 Sep 2010, 16:53
by Aitch
Ken

From the gtkdialog website,

http://linux.pte.hu/~pipas/gtkdialog/

the version you have IS the latest, though it was posted in April 2007, and development seems to have stopped, though the dev's email is on the site
As I understand it Patriot has made some changes for Puppy users adding *buntu patches

http://www.murga-linux.com/puppy/viewto ... 081#355081

Aitch :)

Posted: Sat 25 Sep 2010, 14:50
by ken geometrics
Aitch wrote:Ken

From the gtkdialog website,

http://linux.pte.hu/~pipas/gtkdialog/

the version you have IS the latest, though it was posted in April 2007, and development seems to have stopped, though the dev's email is on the site
As I understand it Patriot has made some changes for Puppy users adding *buntu patches

http://www.murga-linux.com/puppy/viewto ... 081#355081

Aitch :)
I think I must be running the Patriot version because I downloaded the pet for it and installed it.

Is there any interest in a less buggy version? I am trying to work up enough motivation to attack the problem.

The main bug I have found is that some valid descriptions involving the "<list>" construct do not display. They don't report an error but no dialog box comes up. The program hangs at that point until you ^C tp break out of it.

There are a few improvements that I am thinking of adding too.
One is to all things like this to work:

Code: Select all

<text>
<variable>TEXT</variable>
<input>SomeScript</input>
</text>
....somewhere else..
<action>refresh:TEXT</action>


If the <text> was an entry instead, the TEXT variable would get changed so the script could know what it generated last time.
As it is <text> seems to allow a <variable> but not ever update
its contents.

I figure this would be a matter to looking at how an entry did it and making the text one do the same.

One other change is to make the xalign="0" construct work for all widgets.

The other would be to make the parser generate a warning on unrecognized attributes. This would help to catch typos.

Posted: Tue 28 Sep 2010, 12:45
by 8-bit
I too would like to see the list option work right and have the same problem with it as you described.
But I am not enough of a programmer to troubleshoot it.
I do know that it fails even using the example in the gtkdialog3 examples.
So any help in improvements of gtkdialog3 would be most welcome.
The main thing is that a lot of scripts have been written for Puppy using it and any changes should be made so as to not break existing scripts.