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
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#801 Post by smokey01 »

Does anyone know how to automatically shrink a gtkdialog window?

By unhiding frames the window will automatically expand to show the new frames but unfortunately it won't shrink back when the frames are hidden again.

User avatar
Nathan F
Posts: 1764
Joined: Wed 08 Jun 2005, 14:45
Location: Wadsworth, OH (occasionally home)
Contact:

#802 Post by Nathan F »

From my experiments if you set 'resizable="false"' then it will resize back.
Bring on the locusts ...

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#803 Post by don570 »

Here's a tip for the entry widget...

To make a button so that it will execute when the <ENTER>
key is pressed...


To get the default button to work properly with an
entry widget I found that I needed to put
activates_default="true" with the entry tag

Code: Select all

<entry max_length="2"  activates_default="true">
and then make the button the default

Code: Select all

<button can-default="true" has-default="true">
Taken from Bulldog Finder application
Image
_______________________________________
Last edited by don570 on Sat 24 Aug 2013, 18:23, edited 1 time in total.

User avatar
smokey01
Posts: 2813
Joined: Sat 30 Dec 2006, 23:15
Location: South Australia :-(
Contact:

#804 Post by smokey01 »

Nathan F wrote:From my experiments if you set 'resizable="false"' then it will resize back.
Thanks Nathan, works great.

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

#805 Post by disciple »

thunor wrote:Here's another top tip:

A text widget that has space-expand and space-fill set to true can be used as a spacer to push neighbouring widgets in certain directions.

Here the spacer text is "[]" so you can see it -- drag the window out and watch the button.

Code: Select all

#!/bin/sh

GTKDIALOG=gtkdialog

Spacer="[]"

MAIN_DIALOG='
<window title="Spacer Test" window-position="1">
	<vbox>
		<hbox>
			<button space-expand="false" space-fill="false">
				<label>This button will stay put</label>
				<input file stock="gtk-about"></input>
			</button>
			<text space-expand="true" space-fill="true">
				<label>"'$Spacer'"</label>
			</text>
		</hbox>
   </vbox>
</window>
'
export MAIN_DIALOG

case $1 in
   -d | --dump) echo "$MAIN_DIALOG" ;;
   *) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
Regards,
Thunor
Question: is the space-fill tag actually supposed to do anything? Changing it doesn't seem to have any effect here (0.8.3)...
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#806 Post by don570 »

to Disciple:

Just guessing... but maybe it's related to 'resizable="false/true"' option
in the window tag

____________________________

User avatar
koulaxizis
Posts: 452
Joined: Sun 17 Jul 2011, 18:43
Location: Greece
Contact:

#807 Post by koulaxizis »

Still playing with gtkdialog! :)

If you have some spare time, try this one and suggest me ways to improve it, so i can further understand the possibilities of gtkdialog.

Thank you friends!!

Code: Select all

#!/bin/sh

GTKDIALOG=gtkdialog

export MAIN_DIALOG='
<window title="Find Subtitles" window_position="1">
<vbox>
<frame Choose preferred interface>
<hbox>
<combobox>
<variable>COMBOBOX1</variable>
<item>el</item>
<item>en</item>
<item>es/sp</item>
</combobox>
</hbox>
</frame>
<frame Choose preferred language>
<hbox>
<combobox>
<variable>COMBOBOX2</variable>
<item>ell</item>
<item>eng</item>
<item>spa</item>
</combobox>
</hbox>
</frame>
<frame Paste the exact movie name>
<hbox>
<entry>
<variable>ent2</variable>
</entry>
</hbox>
</frame>
<hbox>
<button>
<label>Find subs!</label>
<action>defaultbrowser http://www.opensubtitles.org/"$COMBOBOX1"/search/sublanguageid-"$COMBOBOX2"/moviename-"$ent2" &</action>
<action>exit:EXIT</action>
</button> 
<button cancel></button>
</hbox>
</vbox>
</window>
'

$GTKDIALOG --program=MAIN_DIALOG
Question: Is there a way to automatically read the movie's name with "right-click" on the movie file and clicking the script instead of copy-paste it in the entry?
[b]Christos Koulaxizis[/b]
[i]Woof woof from Greece![/i]

[color=darkred][url=https://sourceforge.net/projects/puppystuff/][ Puppy Stuff Repository ][/url][/color]

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#808 Post by Karl Godt »

There are two options for a wrapper :

MOVIENAME="$MOVIENAME" /root/my-applications/bin/myz-gui

or

/root/my-applications/bin/myz-gui "$@"

.
The second is the common one .


Then myz-gui would look like

ent2="$MOVIENAME" for the first case

or

ent2="$@" for the second case

and

export ent2
ORIGINAL_CODE
here ..

IfIUnderstoodCorrectly

User avatar
koulaxizis
Posts: 452
Joined: Sun 17 Jul 2011, 18:43
Location: Greece
Contact:

#809 Post by koulaxizis »

Karl Godt wrote:There are two options for a wrapper :

MOVIENAME="$MOVIENAME" /root/my-applications/bin/myz-gui

or

/root/my-applications/bin/myz-gui "$@"

.
The second is the common one .


Then myz-gui would look like

ent2="$MOVIENAME" for the first case

or

ent2="$@" for the second case

and

export ent2
ORIGINAL_CODE
here ..

IfIUnderstoodCorrectly
I'm not sure if i understood... :(

Can you please place it in the code to figure out how it works?
[b]Christos Koulaxizis[/b]
[i]Woof woof from Greece![/i]

[color=darkred][url=https://sourceforge.net/projects/puppystuff/][ Puppy Stuff Repository ][/url][/color]

User avatar
Nathan F
Posts: 1764
Joined: Wed 08 Jun 2005, 14:45
Location: Wadsworth, OH (occasionally home)
Contact:

#810 Post by Nathan F »

Mainly stylistic changes, use what you like and discard the rest.

Code: Select all

#!/bin/sh 

: ${GTKDIALOG:=gtkdialog}

export MAIN_DIALOG=" 
<window title=\"Find Subtitles\" window_position=\"2\"> 
<vbox>
<hbox>
<text space-expand=\"false\" space-fill=\"false\">
 <label>$(gettext 'Preferred interface')</label>
</text>
<hbox space-expand=\"true\" space-fill=\"true\"><text><label>\"\"</label></text></hbox>
<comboboxtext space-expand=\"false\" space-fill=\"false\" tooltip-text=\"$(gettext 'The language used to display search results and information')\"> 
<variable>COMBOBOX1</variable>
<item>el</item> 
<item>en</item> 
<item>es/sp</item> 
</comboboxtext> 
</hbox>
<hbox>
<text space-expand=\"false\" space-fill=\"false\">
 <label>$(gettext 'Preferred language')</label>
</text>
<hbox space-expand=\"true\" space-fill=\"true\"><text><label>\"\"</label></text></hbox>
<comboboxtext space-expand=\"false\" space-fill=\"false\" tooltip-text=\"$(gettext 'The language the subtitles should be in')\"> 
<variable>COMBOBOX2</variable> 
<item>ell</item> 
<item>eng</item> 
<item>spa</item> 
</comboboxtext> 
</hbox>
<hbox>
<entry tooltip-text=\"$(gettext 'Paste the exact movie title in this box')\" activates-default=\"true\"> 
<variable>ent2</variable> 
</entry> 
</hbox>
<hbox> 
<button tooltip-text=\"$(gettext 'Get subtitles with an internet browser')\" can-default=\"true\" has-default=\"true\">
<input file icon=\"gtk-ok\"></input>
<label>$(gettext 'Go')</label>
<action>defaultbrowser \"http://www.opensubtitles.org/\$COMBOBOX1/search/sublanguageid-\$COMBOBOX2/moviename-\$ent2\" &</action> 
<action>exit:EXIT</action> 
</button> 
<button tooltip-text=\"$(gettext 'Exit program')\">
<label>$(gettext 'Cancel')</label>
<input file stock=\"gtk-cancel\"></input>
<action>exit:ABORT</action>
</button> 
</hbox> 
</vbox> 
</window> 
" 

$GTKDIALOG -p MAIN_DIALOG
The construct at the top only assigns the variable GTKDIALOG if it isn't already set. Useful for portability.

My feelings are that sometimes a more concise gui is desirable. I don't really care for the use of frames to display information or to label content, although I've done it before to mock something up quick. Here there is a concise label and a more meaningful tooltip. The entry should be obvious so it's unlabeled, but if unsure the tooltip should clue the user in.

The code to activate the "Go" button is very useful in a case like this and makes it quicker since the user can just press Enter and be taken to the site. Less mouse interaction is desired by a lot of users, especially power users.

I thought it appropriate that an app designed to get subtitles should be localized, so all text strings are displayed via gettext. You would need a line saying 'export TEXTDOMAIN=" near the top, and then it would be localization ready.

It seems more concise to me to quote the entire url.

I wrapped the entire dialog description in double quotes rather than single. This means all double quotes have to be ascaped, but it allows command substitution within the dialog description. Also escaped are the variables set by the comboboxes, so that if you follow my advice below about a state file they will use the current value rather than the saved one.

I also switched it from centered display to display near mouse. Centered display is somehow arrogant to me (look at my app now user!) and not as useful anyway. Place it near the pointer and it's quicker for the user to access. IMO dialogs should only be centered if they are displaying important system information and need to grab the user's attention.

One further suggestion would be to save the output to a state file inside ~/.config, which can then be sourced to set defaults for the two comboboxes on future runs of the program. Users appreciate little touches like that.

Cheers!
Bring on the locusts ...

User avatar
Karl Godt
Posts: 4199
Joined: Sun 20 Jun 2010, 13:52
Location: Kiel,Germany

#811 Post by Karl Godt »

First you would need a wrapper script that calls the main script.
This wrapper script needs to be linked into the rox open with directory to be able to right-click it.
( /root/.config/rox.sourceforge.net/OpenWith/ )

Wrapper :

Code: Select all

#!/bin/sh

exec myz-gui "$@"

Code: Select all

#!/bin/sh
GTKDIALOG=gtkdialog

ent2=`basename "$@"`
[ "$ent2" ] && export ent2

export MAIN_DIALOG="
<window title=\"Find Subtitles\" window_position=\"1\">
<vbox>
<frame Choose preferred interface>
<hbox>
<combobox>
<variable>COMBOBOX1</variable>
<item>el</item>
<item>en</item>
<item>es/sp</item>
</combobox>
</hbox>
</frame>
<frame Choose preferred language>
<hbox>
<combobox>
<variable>COMBOBOX2</variable>
<item>ell</item>
<item>eng</item>
<item>spa</item>
</combobox>
</hbox>
</frame>
<frame Paste the exact movie name>
<hbox>
<entry>
<default>\"$ent2\"</default>
<variable>ent2</variable>
</entry>
</hbox>
</frame>
<hbox>
<button>
<label>Find subs!</label>
<action>defaultbrowser http://www.opensubtitles.org/\"$COMBOBOX1\"/search/sublanguageid-\"$COMBOBOX2\"/moviename-\"$ent2\" &</action>
<action>exit:EXIT</action>
</button>
<button cancel></button>
</hbox>
</vbox>
</window>
"

$GTKDIALOG --program=MAIN_DIALOG

User avatar
Nathan F
Posts: 1764
Joined: Wed 08 Jun 2005, 14:45
Location: Wadsworth, OH (occasionally home)
Contact:

#812 Post by Nathan F »

Question: Is there a way to automatically read the movie's name with "right-click" on the movie file and clicking the script instead of copy-paste it in the entry?
Assuming the title of the movie file is the exact title of the movie plus some extension then yes. Say for an avi:

Code: Select all

TITLE="$(basename "$@" .avi)"
To handle multiple extensions it gets a little more involved.

Code: Select all

TITLE="$(basename "$@" | \
sed -e 's/.avi//' | \
-e 's/.mpeg//' | \
-e 's/.wmv//' | \
-e 's/.m4v//')"
Bring on the locusts ...

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

mukstart

#813 Post by recobayu »

Hi All,
I just make a simple menu like start metro wdz8. I learn by looking another script, especially in programming thread and akita. But it just simple and so far to good. I have a problem in search and press enter. The screenshot is here:
http://dl.dropboxusercontent.com/s/g38l ... kstart.png
I originally wanted if search button pressed, the button (not tree) show. Another things are can gtkdesklet show blur transparent? So it will like unity effect. But it seems, that are not easy for me. Can anyone help me? Or developing this script? I really happy.
Thank you.
:D
Attachments
mukstart.gz
remove .gz, then chmod +x mukstart
(5.76 KiB) Downloaded 474 times

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#814 Post by don570 »

To recobayu:


If your problem is how to transfer data using the clipboard I suggest that you
read this script by forum member Seaside.

He uses an utility app (xclip) that is built into every puppy.

The app was written to compare md5sums to make sure that the
download was correct.
Attachments
Clipboard_MD5sum-1.2.pet
(2.81 KiB) Downloaded 452 times

User avatar
recobayu
Posts: 387
Joined: Wed 15 Sep 2010, 22:48
Location: indonesia

#815 Post by recobayu »

thanks don570, but I still don't understand with that. I had extract that pet and find any script I can study, but still not too much understand that. Ok, I make the simple problem. Now I have this script, there are an entrybox and a tree. When I change the entrybox, I want the tree selected on the top of tree, and when I press enter, it can execute the selection (top of tree). How to do that? Can anyone help me? Thank You.

Code: Select all

#!/bin/sh
ls /usr/share/applications > aplikasiku
luru(){
	cat aplikasiku | grep $Entriku > ketemu
}
export -f luru
export auto='
<window height-request="400" width-request="200">
	<vbox>
		<entry>
			<variable>Entriku</variable>
			<label>search application here</label>
			<action>luru</action>
			<action>refresh:Wit</action>
		</entry>
		<tree rules-hint="true" headers-visible="false">
			<variable>Wit</variable>
			<input file>ketemu</input>
		</tree>
	</vbox>
</window>'
gtkdialog --program=auto --center

User avatar
Nathan F
Posts: 1764
Joined: Wed 08 Jun 2005, 14:45
Location: Wadsworth, OH (occasionally home)
Contact:

#816 Post by Nathan F »

If I'm understanding what you want to do correctly, you need to change the signal for the entrybox so that it performs the action you want when you press Enter.

Code: Select all

<action signal="activate">actions...</action>
I'm having a hard time following exactly what you want to do. It seems to be a language barrier problem. Sorry if that's not helpful.
Bring on the locusts ...

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#817 Post by don570 »

The old fashioned way of getting something to the top of a list
was to have a default tag <default>....</default> then relaunch.

...But that wasn't very slick so there are better ways of doing it
as Nathan F points out.


If you install the gtkdialog examples by Thunor
http://murga-linux.com/puppy/viewtopic.php?t=82059
Look at comboboxtext and comboboxentry examples. They are difficult to
understand but maybe they will explain how signal activation works.
__________________________________________________
Last edited by don570 on Sat 24 Aug 2013, 18:12, edited 1 time in total.

User avatar
Nathan F
Posts: 1764
Joined: Wed 08 Jun 2005, 14:45
Location: Wadsworth, OH (occasionally home)
Contact:

#818 Post by Nathan F »

+1 but to make them easier to follow run them with the --dump option, which will spit out the actual dialog passed to gtkdialog instead of all the functions he used to build the dialog. Even better save the dump to a file so you can look it over while you actually run the example.
Bring on the locusts ...

User avatar
Nathan F
Posts: 1764
Joined: Wed 08 Jun 2005, 14:45
Location: Wadsworth, OH (occasionally home)
Contact:

#819 Post by Nathan F »

The key here if I understand correctly what is wanted, is that the default signal passed by the entry widget is "changed", and it's emitted every time you type any character into the box. What is needed is to perform the action on the press of the "Enter" key, which is why you have to change the signal to "activate".
Bring on the locusts ...

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#820 Post by don570 »

To NathanF

Thanks for tip. The only way I could make any sense of
the combobox entry examples was to cut out as many buttons and
tags as possible to simplify the examples.

_________________________________________

The options in the entry tag are important to set
See my example
http://murga-linux.com/puppy/viewtopic. ... 397#720397


Here is the official list of options available
https://code.google.com/p/gtkdialog/wiki/entry

_________________________

Post Reply