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
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1426 Post by MochiMoppel »

I made small changes to your example. Every time the button is pressed, the file /tmp/myfile is updated.
The timer widget monitors this file and, when the file changed, emits a "file-changed" signal. I have no idea why the signal is emitted twice.

IMO using the timer widget in this way makes little sense.
Interesting detail: The widget allows more than one input file. Add an <input file> tag for each file and the timer widget will emit a signal when any of these files change.

Code: Select all

#!/bin/bash
touch /tmp/myfile
echo ' 
 <button> 
    <variable>BUT</variable> 
    <label>press me</label> 
    <action>date > /tmp/myfile</action> 
 </button> 
     
 <timer visible="true" milliseconds="true" file-monitor="true"> 
    <input file>/tmp/myfile</input> 
    <action signal="file-changed">echo "working signal"</action> 
 </timer> 
 '| gtkdialog -s

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#1427 Post by fabrice_035 »

Again thank you MochiMoppel.

And I propose this to answer the question of Argolance.
what do you think about it?

Code: Select all

#!/bin/bash
# 

touch /tmp/enable_button
touch /tmp/disable_button

# rem 

myscript () {

echo "script execute until end and disable button, user must wait"

echo 0 > /tmp/disable_button
#...
sleep 5
#...
echo 0 > /tmp/enable_button
echo "enable now!"

} ; export -f myscript 

echo '
 <button>
    <variable>BUT</variable>
	<label> START </label>
    <action>myscript&</action>
 </button>
     
 <timer visible="true" milliseconds="true" file-monitor="true" >
   <input file>/tmp/disable_button</input>
   <action signal="file-changed">disable:BUT</action>
 </timer>
 
  <timer visible="true" milliseconds="true" file-monitor="true" >
   <input file>/tmp/enable_button</input>
   <action signal="file-changed">enable:BUT</action>
 </timer>

 '| gtkdialog -s

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1428 Post by MochiMoppel »

Methinks that it will not work.
And since Argolances's question was asked in a different thread you should link to his question or better post in his thread.

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#1429 Post by fabrice_035 »

Perhaps. But i think it's the only way to activate and/or desactivate button while waiting for the end of a script. But i am not expert! Regard.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#1430 Post by Argolance »

Bonsoir,
Is it possible to execute a command when a combobox widget is clicked to select an item in the list (for example to echo some message to any temporary file)? If yes, how?

Code: Select all

<combobox>
 <variable>COMBOBOX</variable>
 <item>First item</item>
 <item>Second item</item>
 <item>Third item</item>
 <action>echo yes > /tmp/tmpfile</action>
</combobox>
Thank you.

Cordialement.

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#1431 Post by fabrice_035 »

@Argolance,

I search too, i think it's not possible.

I tried that with comboboxtext

https://github.com/oshazard/gtkdialog/b ... us/signals

key event work, not mouse activity.

Of course changed event work

Code: Select all

<action signal="changed">echo changed item!</action>
while waiting for an expert :oops:

Bonne soirée.
Bionicpup64-8.0 _ Kernel 5.4.27-64oz _ Asus Rog GL752

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

#1432 Post by don570 »

Looking at docs
http://01micko.com/reference/combobox.html

Various action signals are mentioned.
__________________________________________

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#1433 Post by fabrice_035 »

don570 wrote:Looking at docs
http://01micko.com/reference/combobox.html

Various action signals are mentioned.
__________________________________________
http://01micko.com/reference/combobox.html

Code: Select all

The following signals are connected-up for all widgets:
button-press-event, button-release-event, configure-event, enter-notify-event, leave-notify-event, focus-in-event, focus-out-event, hide, show, realize, key-press-event, key-release-event, map-event, unmap-event
I think is wrong, u can try.

I hope I'm wrong.

:shock:
Bionicpup64-8.0 _ Kernel 5.4.27-64oz _ Asus Rog GL752

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#1434 Post by Argolance »

don570 wrote:Looking at docs
http://01micko.com/reference/combobox.html

Various action signals are mentioned.
__________________________________________
I had a look to this page which is in my favorites... but I make the same observation as fabrice_035 (que je salue au passage! :wink:): I didn't get any results!
On the other hand, this works as expected for me with the comboboxtext:

Code: Select all

<action signal="changed">echo changed item!</action>
... that I discover and is much better in my case, because this kind of combobox prevents user to alter or type some wrong item in the entry. The option value-in-list seems to be instable and to make the script freezing in some cases.
Thanks!
Last edited by Argolance on Sun 11 Nov 2018, 09:24, edited 1 time in total.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#1435 Post by MochiMoppel »

fabrice_035 wrote:I think is wrong, u can try.
I hope I'm wrong.
I'm afraid you are right.
May depend on what "connected-up" is supposed to mean. Things can be connected but not working (my laptop battery :cry: ). There is hardly any widget for which all signals in the list work, but combobox, comboboxtext and comboboxentry are an extreme. Only key-press-event and key-release-event seem to work.

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#1436 Post by Argolance »

Duplicate
Last edited by Argolance on Mon 12 Nov 2018, 10:20, edited 1 time in total.

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#1437 Post by fabrice_035 »

Hi,

The source code can teach us a few things

Example about combobox, open widget_combobox.c, and go to line 223

Code: Select all

		/* Connect signals */
It's empty!

Compare with widget_comboboxtext.c (line 487)

Code: Select all

/* Connect signals */
		g_signal_connect(G_OBJECT(var->Widget), "changed", 
			G_CALLBACK(on_any_widget_changed_event),
			(gpointer)var->Attributes);
(...)
I wanted to copy the behavior of wigget_button.c to -> widget_comboboxtext.c but

Code: Select all

(gtkdialog:30539): GLib-GObject-WARNING **: /build/buildd/glib2.0-2.40.2/./gobject/gsignal.c:2462: signal 'toggled' is invalid for instance '0x916d918' of type 'GtkComboBox'
Which is curious https://github.com/oshazard/gtkdialog/b ... /ChangeLog read changelog:

Code: Select all

* Thu Nov 1 2012 Thunor <thunorsif@hotmail.com>
- Connected-up the button-press/release-event signals to the
comboboxentry widget's child entry widget.
It's important -> *widget's child entry widget* <-

Comboboxtext and comboboxentry *are the same* widget (there is no source code for comboboxentry https://github.com/oshazard/gtkdialog/tree/master/src

widget_comboboxtext.c :

Code: Select all

g_signal_connect(G_OBJECT(gtk_bin_get_child(
				GTK_BIN(var->Widget))), "button-press-event",
				G_CALLBACK(on_any_widget_button_pressed),
				(gpointer)var->Attributes);
			g_signal_connect(G_OBJECT(gtk_bin_get_child(
				GTK_BIN(var->Widget))), "button-release-event",
				G_CALLBACK(on_any_widget_button_released),
				(gpointer)var->Attributes);
I think the window decoration is not tested but just the inside text.

Bon dimanche, nice sunday
Bionicpup64-8.0 _ Kernel 5.4.27-64oz _ Asus Rog GL752

User avatar
fabrice_035
Posts: 765
Joined: Mon 28 Apr 2014, 17:54
Location: Bretagne / France

#1438 Post by fabrice_035 »

@Argolance

Code: Select all

Bonsoir,
Is it possible to execute a command when a combobox widget is clicked to select an item in the list (for example to echo some message to any temporary file)? If yes, how? 
Hey, finaly it's possible ! :lol:

Code: Select all

#!/bin/sh
#
# find more here http://blogs.czapski.id.au/category/demo-building/gtkdialog
# fxc


export ytdlgui='
<window title="event box demonstration">
<hbox>
<eventbox above-child="false" visible-window="true" has-tooltip="true" tooltip-markup="This is tooltip for eventbox" height-request="30" sensitive="true" visible="true" width-request="140">


<hbox>
<frame All Events here>
<comboboxtext>

 <variable>COMBOBOXTEXT</variable>
 <item>First item</item>
 <item>Second item</item>
 <item>Third item</item>
 
	<action signal="changed">echo Combobox: changed</action>
</comboboxtext> 
</frame>
</hbox>
				<variable>vEventBoxOuter</variable>
			
				<action signal="button-press-event">echo Event: button-press-event</action>
				<action signal="button-release-event">echo Event: button-release-event</action>
				<action signal="configure-event">echo Event: configure-event</action>
				<action signal="enter-notify-event">echo Event: enter-notify-event</action>
				<action signal="leave-notify-event">echo Event: leave-notify-event</action>
				<action signal="focus-in-event">echo Event: focus-in-event</action>
				<action signal="focus-out-event">echo Event: focus-out-event</action>
				<action signal="key-press-event">echo Event: key-press-event</action>
				<action signal="key-release-event">echo Event: key-release-event</action>
				<action signal="hide">echo Event: hide</action>
				<action signal="show">echo Event: show</action>
				<action signal="realize">echo Event: realize</action>
				<action signal="map-event">echo Event: map-event</action>
				<action signal="unmap-event">echo Event: unmap-event</action>
				
				
</eventbox>

<frame dedicate >
<comboboxtext>

 <variable>COMBOBOXTEXT2</variable>
 <item>First item</item>
 <item>Second item</item>
 <item>Third item</item>
    
	<action signal="changed">echo Combobox: changed</action>
</comboboxtext> 
</frame>

</hbox>
</window>'

gtkdialog --program=ytdlgui 
8) OK it's not perfect :roll:
Bionicpup64-8.0 _ Kernel 5.4.27-64oz _ Asus Rog GL752

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#1439 Post by Argolance »

Bonsoir,
Bon, là, on joue plus dans la même cour! :oops:
Effectivement ça marche mais j'avoue être perso "somewhat" largué, eh eh, sur la façon de parvenir à un tel résultat, ah ah...
Well done and thanks :).

Cheers!

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#1440 Post by Argolance »

Bonjour,

Code: Select all

#!/bin/sh

echo "My_tailor_is_rich
My tailor is NOT rich" > /tmp/checkbox_test

FILE="`cat /tmp/checkbox_test`"

for LINE in $FILE; do
LIST="${LIST}
	<checkbox>
		<variable>$LINE</variable>
		<default>true</default>
		<label>$LINE</label>
		<action>if false disable:$LINE</action>
		<action>sed -i 's/$LINE//' /tmp/checkbox_test</action>
		<action>refresh:TEXT</action>
	</checkbox>
"
done

export MAIN="
<window window_position=\"1\">
	<vbox>
		<hbox border-width=\"5\">
			<frame Text (/tmp/checkbox_test)>
				<edit>
				<input file>/tmp/checkbox_test</input>
				<variable>TEXT</variable>
				</edit>
			</frame>
			<frame Checkboxes>
				${LIST}
			</frame>
		</hbox>
		<hbox>
		<button><input file stock=\"gtk-undo\"></input>
			<label>$(gettext 'Reset')</label>
			<action>EXIT:restart</action>
		</button>		
			<button cancel></button>
		</hbox>
	</vbox>
</window>
"
I=$IFS; IFS=""
for STATEMENTS in  $(gtkdialog --program=MAIN); do
   eval $STATEMENTS
done
IFS=$I

[ "$EXIT" = "restart" ] && $0
In this script, I can't find the solution so that the sentence containing spaces is not segmented.
I tried a lot of things by manipulating single and double quotes, escaping spaces, etc... but without success!
Any idea?

Cordialement

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

#1441 Post by don570 »

echo command can have options . I would try echo -n

or maybe echo -e and then use \n for a new line.

http://linuxcommand.org/lc3_man_pages/echoh.html
_____________________________________________

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#1442 Post by Argolance »

Thanks.
In the script above, the temporary text file is built at startup using the echo command only as example, but in reality, this text file is a list of files (built with the find command) which can have spaces in their path and in their name (example: /root/.moonchild productions/pale moon/xxx). It is these files that are problematic and are processed in segments instead of in one piece.
What could be done to avoid this?

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#1443 Post by SFR »

Argolance wrote:What could be done to avoid this?
This, for example:

Code: Select all

while read -r LINE; do
LIST="${LIST}
   <checkbox>
      <variable>$LINE</variable>
      <default>true</default>
      <label>$LINE</label>
      <action>if false disable:$LINE</action>
      <action>sed -i 's/$LINE//' /tmp/checkbox_test</action>
      <action>refresh:TEXT</action>
   </checkbox>
"
done < /tmp/checkbox_test
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#1444 Post by Argolance »

Oh yes, thank you SFR! :D

some1
Posts: 117
Joined: Thu 17 Jan 2013, 11:07

#1445 Post by some1 »

Argolance,SFR:Nice :)
----
Argolance:
this text file is a list of files (built with the find command) which can have spaces in their path and in their name (example: /root/.moonchild productions/pale moon/xxx).
With your demo - try som slashes in the DATA:

Code: Select all

echo "My_tailor_is_rich
My/tailor/is/NOT/rich" > /tmp/checkbox_test 
 
and consider this:

Code: Select all

 <action>sed -i 's/$LINE//' /tmp/checkbox_test</action>
In the sed command -you can use | or some other char - instead of the default- /-s -but...?

The i-switch in sed may be convenient - but sed is in reality rewriting the whole file using a tempfile - which is moved to be the updated input-file.
Alternatively-we can emulate that -using awk,grep -v or a read-loop to update the input-file via a tempfile every time we choose a $LINE to be excluded.


----
Anyway -Nice demo.

Post Reply