Author |
Message |
neurino

Joined: 15 Oct 2009 Posts: 360
|
Posted: Mon 23 Aug 2010, 06:35 Post subject:
|
|
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: | <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
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6541 Location: Valåmoen, Norway
|
Posted: Mon 23 Aug 2010, 10:12 Post subject:
|
|
<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
_________________ Stardust resources
|
Back to top
|
|
 |
neurino

Joined: 15 Oct 2009 Posts: 360
|
Posted: Mon 23 Aug 2010, 10:14 Post subject:
|
|
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?
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Mon 23 Aug 2010, 10:38 Post subject:
|
|
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 &&)
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
neurino

Joined: 15 Oct 2009 Posts: 360
|
Posted: Mon 23 Aug 2010, 12:19 Post subject:
|
|
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:
sadly won't work...
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Mon 23 Aug 2010, 13:56 Post subject:
|
|
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.
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
seaside
Joined: 11 Apr 2007 Posts: 917
|
Posted: Mon 23 Aug 2010, 15:10 Post subject:
|
|
neurino,
Perhaps put the Exit inside my_func , as the last command.
Just a possible guess, since I haven't tried Libglade.
Cheers,
s
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Mon 23 Aug 2010, 15:29 Post subject:
|
|
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
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
neurino

Joined: 15 Oct 2009 Posts: 360
|
Posted: Tue 24 Aug 2010, 04:13 Post subject:
|
|
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...
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6541 Location: Valåmoen, Norway
|
Posted: Fri 27 Aug 2010, 16:58 Post subject:
|
|
Here is an example that allows preview of images..... and you thought it wasn't possible
It requires another gtk-theme switcher that allows changing theme from commandline
Code: |
#!/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"
|
 |
Description |
|

Download |
Filename |
gtk-theme-switch-i386.pet |
Filesize |
11.57 KB |
Downloaded |
994 Time(s) |
Description |
|
Filesize |
22.58 KB |
Viewed |
1802 Time(s) |

|
_________________ Stardust resources
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6541 Location: Valåmoen, Norway
|
Posted: Fri 27 Aug 2010, 17:56 Post subject:
|
|
Ok, this is might more useful...
A right click menu is sometimes nice.....
Code: | #!/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
|
 |
Description |
|
Filesize |
43.09 KB |
Viewed |
1769 Time(s) |

|
_________________ Stardust resources
|
Back to top
|
|
 |
technosaurus

Joined: 18 May 2008 Posts: 4786 Location: Kingwood, TX
|
Posted: Fri 27 Aug 2010, 20:34 Post subject:
|
|
Excellent work Zigbert.
One step closer to eliminating that cursed curses dialog at startup.
Making a first run script:
Code: | #!/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
_________________ Check out my github repositories. I may eventually get around to updating my blogspot.
|
Back to top
|
|
 |
big_bass
Joined: 13 Aug 2007 Posts: 1742
|
Posted: Fri 27 Aug 2010, 23:07 Post subject:
|
|
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
Quote: |
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
|
Back to top
|
|
 |
zigbert

Joined: 29 Mar 2006 Posts: 6541 Location: Valåmoen, Norway
|
Posted: Sun 29 Aug 2010, 03:20 Post subject:
|
|
big_bass
Quote: | 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
_________________ Stardust resources
|
Back to top
|
|
 |
01micko

Joined: 11 Oct 2008 Posts: 8670 Location: qld
|
Posted: Sun 29 Aug 2010, 06:41 Post subject:
|
|
Haha!
Cool stuff Sigmund... actually works in Xfce4 too, which I am experimenting with at the moment
Cheers
Description |
|
Filesize |
26.59 KB |
Viewed |
1714 Time(s) |

|
_________________ Puppy Linux Blog - contact me for access
|
Back to top
|
|
 |
|