Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Thu 27 Nov 2014, 21:41
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
GtkDialog - tips
Post new topic   Reply to topic View previous topic :: View next topic
Page 28 of 64 [956 Posts]   Goto page: Previous 1, 2, 3, ..., 26, 27, 28, 29, 30, ..., 62, 63, 64 Next
Author Message
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: 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
View user's profile Send private message 
zigbert


Joined: 29 Mar 2006
Posts: 5789
Location: Valåmoen, Norway

PostPosted: 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
View user's profile Send private message Visit poster's website 
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: 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
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4380

PostPosted: 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 &&)

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
neurino


Joined: 15 Oct 2009
Posts: 360

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

Code:
my_func && EXIT:OK


sadly won't work... Confused
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4380

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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
seaside

Joined: 11 Apr 2007
Posts: 887

PostPosted: 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. Very Happy

Cheers,
s
Back to top
View user's profile Send private message 
technosaurus


Joined: 18 May 2008
Posts: 4380

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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
neurino


Joined: 15 Oct 2009
Posts: 360

PostPosted: 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
View user's profile Send private message 
zigbert


Joined: 29 Mar 2006
Posts: 5789
Location: Valåmoen, Norway

PostPosted: Fri 27 Aug 2010, 16:58    Post subject:  

Here is an example that allows preview of images..... and you thought it wasn't possible Laughing

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"
gtk-theme-switch-i386.pet
Description 
pet

 Download 
Filename  gtk-theme-switch-i386.pet 
Filesize  11.57 KB 
Downloaded  791 Time(s) 
forum.png
 Description   
 Filesize   22.58 KB
 Viewed   1622 Time(s)

forum.png


_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
zigbert


Joined: 29 Mar 2006
Posts: 5789
Location: Valåmoen, Norway

PostPosted: Fri 27 Aug 2010, 17:56    Post subject:  

Ok, this is might more useful... Very Happy

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

forum.png
 Description   
 Filesize   43.09 KB
 Viewed   1608 Time(s)

forum.png


_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4380

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

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
big_bass

Joined: 13 Aug 2007
Posts: 1747

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

_________________
debian wheezy ,linux mint, slackware I use them all and they all have good points
Mint would be best for general users though
Back to top
View user's profile Send private message 
zigbert


Joined: 29 Mar 2006
Posts: 5789
Location: Valåmoen, Norway

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


Sigmund

_________________
Stardust resources
Back to top
View user's profile Send private message Visit poster's website 
01micko


Joined: 11 Oct 2008
Posts: 7841
Location: qld

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

Cheers
xfce-view.png
 Description   
 Filesize   26.59 KB
 Viewed   1561 Time(s)

xfce-view.png


_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 28 of 64 [956 Posts]   Goto page: Previous 1, 2, 3, ..., 26, 27, 28, 29, 30, ..., 62, 63, 64 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1238s ][ Queries: 13 (0.0228s) ][ GZIP on ]