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

_________________________

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

#821 Post by recobayu »

:D
Thank you don570 and nathan. signal="activate" works great.
I do a little trick here. I make a function mlaku that run the application that writed in the first item of tree (by read a < ketemu). Ya, although the clicked effect doesn't appear in the tree. :) Please correct me.

Code: Select all

#!/bin/sh
ls /usr/share/applications > aplikasiku

luru(){
	cat aplikasiku | grep -i $Entriku > ketemu
	cat ketemu | sed 's/.desktop//' > ditampilkan
}
export -f luru
mlaku(){
	read a < ketemu
	$(cat /usr/share/applications/$a | grep Exec | cut -d "=" -f2)&
}
export -f mlaku
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>
			<action signal="activate">mlaku</action>
		</entry>
		<tree rules-hint="true" headers-visible="false" activates-default="true" hover-selection="true">
			<variable>Wit</variable>
			<input file>ditampilkan</input>
			<action>exec $Wit</action>
		</tree>
	</vbox>
</window>'
gtkdialog --program=auto --center
Ok, now I want to hide the tree if the entrybox is empty and show that again if I write something in the entrybox. How to do that?

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

#822 Post by Nathan F »

Ok, now I want to hide the tree if the entrybox is empty and show that again if I write something in the entrybox. How to do that?
Try something like this

Code: Select all

<tree visible="false">
  <variable>TREE</variable>
</tree>
<entry>
 <action function="show">TREE</action>
</entry>
I do a little trick here. I make a function mlaku that run the application that writed in the first item of tree (by read a < ketemu). Ya, although the clicked effect doesn't appear in the tree. Please correct me.
Not sure what the question is again, sorry.
Bring on the locusts ...

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

#823 Post by recobayu »

Nathan F wrote: Try something like this

Code: Select all

<tree visible="false">
  <variable>TREE</variable>
</tree>
<entry>
 <action function="show">TREE</action>
</entry>
:) yes, it happen just one time. But when i clear the text in entry, the tree still show, it doesn't hide anymore.
I try this code, but fail.

Code: Select all

#!/bin/sh
a="false"
muncul(){
	if [[ $Entryku == "" ]]; then
		echo '<action function="hide">Wit</action>';
	else
		echo '<action function="show">Wit</action>';
	fi
	echo $Entryku
}
export -f muncul

export ketok='
<window>
	<vbox>
		<entry>
			<variable>Entryku</variable>
			<action>eval $Entryku</action>
			'"`muncul`"'
			<action>refresh:Entryku</action>
		</entry>
			<tree visible="'$a'">
				<variable>Wit</variable>
				<item>first line</item>
				<item>second</item>
				<item>third</item>
			</tree>
			<button>
				<label>ada</label>
				<action function="show">Wit</action>
			</button>
			<button>
				<label>sembunyi</label>
				<action function="hide">Wit</action>
			</button>
	</vbox>
</window>'

gtkdialog --program=ketok

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

#824 Post by Nathan F »

That's probably because your function is only being run the first time the dialog is created. In order to get it to run whenever the widget refreshes you have to put it inside a pair of input tags.

Code: Select all

      <entry> 
         <variable>Entryku</variable> 
         <action>eval $Entryku</action> 
         <input>muncul</input
         <action>refresh:Entryku</action> 
      </entry>
EDIT: I'm still fuzzy on whether it will do what you want it to. I think you need to use a conditional on the action itself (as a tag attribute), which I've only tried once.
Bring on the locusts ...

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

#825 Post by recobayu »

Thanks All, this is the new mukstart from me. I also use gtk2desklet by akash_rawal. here: http://murga-linux.com/puppy/viewtopic.php?t=74204
how about this? :)
Attachments
mukstart1.0.tar.gz
now, i think it's better than before..
(2.89 KiB) Downloaded 435 times

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

notebook trick

#826 Post by recobayu »

I learn something very usefull with notebook from here:
/usr/share/doc/gtkdialog/examples/notebook/notebook_advanced
I uncomment the dump line and I know some trick, there is in the inputfile:
0 --> tab0
1 --> tab1
...
here is my code:

Code: Select all

#!/bin/bash
cek(){
	if [[ $E = "" ]]; then
		#echo kosong
		echo 0 > inputfile
	else
		#echo ada
		echo 1 > inputfile
	fi
}
export -f cek
Width=`xwininfo -root | grep Width | awk '{ print $2 }'`
Height=`xwininfo -root | grep Height | awk '{ print $2 }'`
export aku='
<window title="nbkNotebook" width-request="'$Width'" height-request="'$Height'">
  <vbox>
		<entry>
			<variable>E</variable>
			<action>cek</action>
			<action>refresh:nbk0</action>
		</entry>
		<notebook show-tabs="false" show-border="false">
			<vbox border-width="20">
				<text label="this is the main start metro"></text>
			</vbox>
			<vbox border-width="20">
				<text label="and this is the search window"></text>
			</vbox>
			<variable>nbk0</variable>
			<input file>inputfile</input>
		</notebook>
  </vbox>
</window>'
gtkdialog --program=aku
if we type in the entry box, we can see the window get different face, and when we clear the entrybox, the window back to the our first face.
Nice gtkdialog :D
I Like it

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

#827 Post by don570 »

Here's a simple example to show how the refresh button works.

Just enter text in Entry box and click 'REFRESH'.

The entry goes to the
head of a text file that in displayed in comboboxtext widget

The refresh button code looks like this. Add another action tag line and
the refresh button could do some useful function.

Code: Select all

    <button>
               <label>refresh</label>
               <action>list_refresh</action>
               <action>refresh:LIST_ENTRY</action>
          </button>

Image
Attachments
Script-refresh.gz
remove fake gz extension
(1.37 KiB) Downloaded 437 times

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

example of refreshing

#828 Post by don570 »

More examples of practical refreshing...

This example(suggested by Nathan F) shows the contents of a dot file in /root.
The user then selects a file on the list and then
a function can be run by clicking button.

To make the comboboxtext items a command was used

Code: Select all

find $HOME -maxdepth 1 -mindepth 1 -type d -name ".*"
Image
Attachments
Script-tree.gz
remove fake gz extension
(1.51 KiB) Downloaded 407 times

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

#829 Post by don570 »

Here is another refresh example using comboboxtext.
The letters of alphabet are the items. Choosing a letter will
refresh the righthand side list of applications found installed.
Note the first letter of application.

Then a selection of the list can be further used by a function.
(Click on button 'refresh' to see what is possible with selection)

Image

____________________________________________________
Attachments
Script-app.gz
Remove fake extension
(2.09 KiB) Downloaded 404 times
Last edited by don570 on Wed 04 Sep 2013, 00:25, edited 1 time in total.

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

#830 Post by don570 »

Here is the same example as before but instead of a comboboxtext widget
a list widget is used. It then refreshes a tree .
A selection of the tree can then be further processed by
clicking on the button.



Image
Attachments
Script-list.gz
remove fake gz extension
(1.64 KiB) Downloaded 408 times

Post Reply