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:

#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 1289 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

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

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

ken geometrics
Posts: 76
Joined: Fri 23 Jan 2009, 14:59
Location: California

Re: GtkDialog - tips

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

User avatar
Aitch
Posts: 6518
Joined: Wed 04 Apr 2007, 15:57
Location: Chatham, Kent, UK

#423 Post 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 :)

ken geometrics
Posts: 76
Joined: Fri 23 Jan 2009, 14:59
Location: California

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

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

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

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

#426 Post by technosaurus »

It is a new feature, not a bug... If I recall the previous method couldn't use items with spaces unless you used quotes and then it caused other problems.

VAR1="<combobox><variable>COMBO1</variable>"
for x in `ls ./*.pet`; do VAR1=$VAR1"<item>"$x"</item>"; done
VAR1=$VAR1"</combobox>"

this one will list all pets in the current directory

A similar method also works for checkbox and radiobox, except that you need to have a variable for each entry ... there is an example of this in bbgui (I posted it earlier in the thread)... it uses eval to set up a series of variable names from 1 to N and has templates for most input types.
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
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#427 Post by zigbert »

ken geometrics
Improvements of gtkdialog is very welcomed. :)
You find Patriots gtkdialog-source in the main post.


Sigmund

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#428 Post by disciple »

ken geometrics wrote:Is there any interest in a less buggy version? I am trying to work up enough motivation to attack the problem.
Yes, any improvements to gtkdialog would be fantastic, as Puppy uses it so much :)
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

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

#429 Post by zigbert »

This example especially shows 3 features of gtkdialog
- progressbars with fixed size
- right click menu
- change an icon in <tree> widget without re-render gui.

Updating icons in tree requires gtk-theme-switch (attached). This could replace gtk-chtheme with this
Image
Attachments
example.tar.gz
(3.39 KiB) Downloaded 595 times
gtk-theme-switch-i386.pet
(11.57 KiB) Downloaded 570 times

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

#430 Post by technosaurus »

Very Nice!
- I think a parted frontend has been on the back burner of many puppy devs for a while (myself include), just waiting for a starting point.
- great work, I can't wait to test it out.
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
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#431 Post by zigbert »

technosaurus wrote:Very Nice!
- I think a parted frontend has been on the back burner of many puppy devs for a while (myself include), just waiting for a starting point.
- great work, I can't wait to test it out.
Be aware!
This is not a frontend for parted. - Just a silly try to see if gtkdialog is capable to show a proper gui for a gparted-clone.


Sigmund

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

#432 Post by technosaurus »

It looks like you have succeeded in that - If you write the stubs for the functions your GUI needs, I'd be happy to help with writing them

Code: Select all

some_function() { #what you want it to do 
}
it could stay as inline documentation... but ...umm that would be backwards from almost every other open source project - writing the documentation first (or at all) - setting up an api and writing the code to achieve its goals - unheard of ... I must have momentarily stepped into an alternate dimension
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
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#433 Post by abushcrafter »

technosaurus wrote:it could stay as inline documentation... but ...umm that would be backwards from almost every other open source project - writing the documentation first (or at all) - setting up an api and writing the code to achieve its goals - unheard of ... I must have momentarily stepped into an alternate dimension
Sounds interesting...
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

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

#434 Post by zigbert »

technosaurus wrote:It looks like you have succeeded in that - If you write the stubs for the functions your GUI needs, I'd be happy to help with writing them

Code: Select all

some_function() { #what you want it to do 
}
it could stay as inline documentation... but ...umm that would be backwards from almost every other open source project - writing the documentation first (or at all) - setting up an api and writing the code to achieve its goals - unheard of ... I must have momentarily stepped into an alternate dimension
Thanks for the invite........here is the status
- Barry suggested that bacon might be a better alternative for such a gui. I f he or anyone intend to build it, I think that is a wonderful idea. His words just inspired me to check out how gtkdialog could handle such a task (with our knowledge today).
- I am in a hectic period at the moment..... things will slow down after Christmas. I hardly write command-lines these days.
- I don't know anything about parted nor partitions, so help would be required if we say 'go'.
- If you or anyone want to build further on the gui, it's yours.


Sigmund

Post Reply