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
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#401 Post by technosaurus »

This scripts worked after deleting the ayttm desktop entry that contains / as separators - needs a workaround - my version of gtkdialog doesn't find pixmaps in the standard directories and sh: locate: command not found is emitted from running in rxvt - is there a way to make icons work without hacking the full icon paths

Edit: it wasn't the / in the Name= field... it was " (double quotes) in the Comment= field that caused the problem - .desktop files shouldn't contain quotes anyways AFAIK - I just fixed ayttm.desktop and all is well

the icons should be found if you have puppy 44a or stardust with updatedb and locate commands

This is not by any means a finished product - just a starting point that should be easily tweakable to your liking using other tips from this thread. I have it set up for right-handed touchscreen mode (everything on the right side) but it could still use a lot of formatting for appearance and speed. (ex. for faster start after first run you could write DLG to a file and use it if available)

Code: Select all

#!/bin/ash
# can't use entries with " (double quote) in the comment section maybe others - Ayttm is one example
for x in `ls /usr/share/applications/*.desktop`; do
	EXE="`grep "^Exec=" $x |cut -d = -f 2`"
	CAT="`grep "^Categories=" $x |cut -d = -f 2`"
	NAM="`grep "^Name=" $x |cut -d = -f 2`"
	ICO="`grep "^Icon=" $x |cut -d = -f 2`"
	##needs full path to icon - will rework later
	COM="`grep "^Comment=" $x |cut -d = -f 2`"
	NEW="<hbox tooltip-text=\"$COM\"><button><label>$NAM</label><input file>$ICO</input><action>$EXE &</action></button></hbox>"
	case $CAT in
		*alculat*|*inance|*heet|ProjectManagement)	BUS=$BUS$NEW;;
		*eskto*|*creensave*|*ccessib*)	DSK=$DSK$NEW;;
		*ocumen*|*ordProcessor|*ebDevelo*)	DOC=$DOC$NEW;;
		*ile*)	FIL=$FIL$NEW;;
		*Game|*olePla*|*imulation|*musement)	FUN=$FUN$NEW;;
		*raphics|*hotography|*resent*|*art)	GFX=$GFX$NEW;;
		*udio*|*ideo*|*layer|*ecorder|*usic|*idi|*ixer|*equencer|*uner|TV|*iskBurning)	MED=$MED$NEW;;
		Dialup|Network|HamRadio|RemoteAccess)	NET=$NET$NEW;;
		X-PersonalUtility|X-Personal|Calendar|ContactManagement)	PER=$PER$NEW;;
		*etup*|PackageManager)	SET=$SET$NEW;;
		*onitor|*ecurity|*ardware*|*ore|*ystem)	SYS=$SYS$NEW;;
		Utility|Viewer|Development|Building|Debugger|IDE|Profiling|Translation|GUIDesigner|Archiving|TerminalEmulator|Shell)	UTL=$UTL$NEW;;
		*nternet|*rowser|*mail|*ews|*essaging|*elephony|*lient|*ransfer|P2P)	WEB=$WEB$NEW;;
		*) MSC=$MSC$NEW;;
	esac
	
done
DLG="<notebook page=\"0\" tab-pos=\"1\" enable-popup=\"true\" labels=\"Business|Desktop|Document|File|Fun|Graphics|Media|Network|Personal|Setup|System|Utility|Web|Miscellaneous\">
<frame Business>$BUS</frame>
<frame Desktop>$DSK</frame>
<frame Document>$DOC</frame>
<frame File>$FIL</frame>
<frame Fun>$FUN</frame>
<frame Graphics>$GFX</frame>
<frame Media>$MED</frame>
<frame Network>$NET</frame>
<frame Personal>$PER</frame>
<frame Setup>$SET</frame>
<frame System>$SYS</frame>
<frame Utility>$UTL</frame>
<frame Web>$WEB</frame>
<frame Misc>$MSC</frame>
</notebook>"

export DLG
gtkdialog3 --program=DLG
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].

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

#402 Post by technosaurus »

this is a line of code that will set up your locatedb if needed so that your icons will be found

Code: Select all

[ -f /var/locatedb ] && echo file database detected, skipping updatedb for finding of icons || updatedb --localpaths=/usr
I also reworked the menu script for this (and ability to use a menu file if it exists) if you want an example it is also attached
Attachments
pgtkmenu.gz
(1.2 KiB) Downloaded 555 times
findutils-4.2.33-i486.pet
gtkdialog needs findutils - otherwise you may need to specify the full path for icons
(59.84 KiB) Downloaded 480 times
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].

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#403 Post by jpeps »

I haven't found much regarding use of variables. For example, how do I:

1. Create or change a new or existing variable from an <action> command?
example: <action>export MyVariable="new value"</action> (doesn't work)

2. Use existing variables, like changing default entry from say a checkbox or button action command.
example: <action>ENTRY1="$NewVal"</action> (doesn't work)

edit: One other thing: I can't get bash functions to work from an action command. (think I tried an example somewhere that didn't work)
function MyFunction() {
rxvt -e echo "Hello World"
}

example <action>MyFunction</action> (doesn't work)


Thanks

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#404 Post by seaside »

jpeps wrote:I haven't found much regarding use of variables.
jpeps,

You can't make dynamic variables as in Items 1 and 2.
When you invoke a subshell (<action>something<action>), variables created here are not visible to the parent.

The work-around is to make "tmp" files to store variable info.

As far as the function not working - did you "export -f MyFunction"?

Cheers,
s

jpeps
Posts: 3179
Joined: Sat 31 May 2008, 19:00

#405 Post by jpeps »

seaside wrote:
The work-around is to make "tmp" files to store variable info.
That's what I've been doing; thought I might have missed something.
..be nice if a "set" command was included.
As far as the function not working - did you "export -f MyFunction"?
,
Ah....that works. Thanks!

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#406 Post 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

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#407 Post 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

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#408 Post 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?

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

#409 Post 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 &&)
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].

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#410 Post 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... :?

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

#411 Post 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.
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].

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#412 Post 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

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

#413 Post 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
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].

User avatar
neurino
Posts: 362
Joined: Thu 15 Oct 2009, 13:08

#414 Post 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...

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#415 Post 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"
Attachments
gtk-theme-switch-i386.pet
(11.57 KiB) Downloaded 1287 times
forum.png
(22.58 KiB) Downloaded 1908 times

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#416 Post 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

Attachments
forum.png
(43.09 KiB) Downloaded 1879 times

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

#417 Post 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
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].

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#418 Post 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

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#419 Post 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

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#420 Post by 01micko »

Haha!

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

Cheers
Attachments
xfce-view.png
(26.59 KiB) Downloaded 1822 times
Puppy Linux Blog - contact me for access

Post Reply