Gtkdialog Development

Under development: PCMCIA, wireless, etc.
Message
Author
User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#661 Post by zigbert »

Thunor
r480 Works!!!

But if function_is_true(argument) should be if command_is_true(argument) - at least in my case.


Sigmund

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#662 Post by thunor »

zigbert wrote:... But if function_is_true(argument) should be if command_is_true(argument) - at least in my case. ...
Yeah, I'm working on the wiki at the moment which I haven't committed yet, but you've got a choice of these:

Code: Select all

+------------------------------+-------------------------------+---------------+
|             Type             |          Description          |    Argument   |
+------------------------------+-------------------------------+---------------+
| active_is_true(argument)     | Active state of toggle widget | Variable name |
| active_is_false(argument)    | Active state of toggle widget | Variable name |
| command_is_true(argument)    | Output of shell command       | Shell command |
| command_is_false(argument)   | Output of shell command       | Shell command |
| file_is_true(argument)       | Contents of a file            | Filename      |
| file_is_false(argument)      | Contents of a file            | Filename      |
| sensitive_is_true(argument)  | Sensitive state of widget     | Variable name |
| sensitive_is_false(argument) | Sensitive state of widget     | Variable name |
| visible_is_true(argument)    | Visible state of widget       | Variable name |
| visible_is_false(argument)   | Visible state of widget       | Variable name |
+------------------------------+-------------------------------+---------------+
With command_is_true/false() the widget variables are placed into the shell which is not necessary for the other functions. Other than file_is_true/false(), the rest are simple widget property reads.

Regards,
Thunor

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#663 Post by thunor »

The action directive's documented type="function" attribute I've renamed function="type" so that we now have:

Code: Select all

<action signal="type" function="type" condition="type">parameter</action>
The docs and examples have been updated and of course type="function" is still supported (it was really type="type" but I think it's pretty obvious why it wasn't documented as such).

I'm not sure if anyone is aware of the fact that it is possible to use all of the action's attributes together as shown above which isn't obvious from the wiki/docs or examples therefore you'd never need to use the shortcut function:parameter because you can always move the function into its own function="type" attribute.

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

#664 Post by zigbert »

Yes, I am boring you - I know.....
I have tried so many times to get the reorderable attribute to work properly. - Not in an example, but in real code. With that I mean to update the <input> after each move. - Else the inputfile are not the same as the outputfile. So my simple test code looks like this, but it does not work. There MUST be a way .... ???

Code: Select all

#!/bin/sh

echo "gtk-ok|row1
|row2
|row3

" > /tmp/inputfile

echo '
<window>
   <vbox>
      <tree reorderable="true">
         <label>A|B</label>
         <variable>tree</variable>
         <height>150</height>
         <input file stock-column="0">/tmp/inputfile</input>
         <output file>/tmp/outputfile</output>
         <action signal="button-release-event">save:tree</action>
         <action signal="button-release-event">cut -d"|" -f2- /tmp/outputfile > /tmp/inputfile</action>
         <action signal="button-release-event">refresh:tree</action>
      </tree>
   </vbox>
</window>
' | gtkdialog -s
Thanks for any help
Sigmund

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

#665 Post by zigbert »

Thunor

I think there is a minor bug in r483.
condition="command_is_true()" does not work, but using if as earlier versions, it works. command_is_false works.

This is how I set it to work

Code: Select all

       <action signal="button-release-event" condition="command_is_false([ $COPY_FORMAT != flac ] && echo false)">enable:VBOX_CONVERT1</action>
       <action signal="button-release-event" condition="if command_is_true([ $COPY_FORMAT = flac ] && echo true)">disable:VBOX_CONVERT1</action>

Sigmund

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#666 Post by thunor »

zigbert wrote:...

Code: Select all

<action signal="button-release-event" condition="if command_is_true([ $COPY_FORMAT = flac ] && echo true)">disable:VBOX_CONVERT1</action>
...
Check the terminal: if a condition is not recognised then it is ignored and you'll see "Unkown expression...", therefore it won't stop the execution of the action because it's not valid.

"if command_is_true(...)" will result in "Unkown expression..." and it'll be ignored.

Try playing with examples/miscellaneous/conditional_actions in r484 and see if you can break it because it's working for me.

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

#667 Post by thunor »

I really should turn my laptop off as it's approaching 4am, but just place <action signal="button-release-event">echo COPY_FORMAT=$COPY_FORMAT</action> above your problematic line and then you'll know what the outcome should be.

Goodnight and god morgen :)

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

#668 Post by zigbert »

What an idiot I met in the mirror this morning.....
It is all clear now (command_is_true). The major bug is between the keyboard and the chair. For pMusic testing I have made a gtkdialog5 symlink to gtkdialog-0.8.2 which is preferred by pMusic if exist. There was no chance for the new code to work.


Sorry for bothering you.
Sigmund

Code: Select all

Goodnight and god morgen
Det er faktisk en vidunderlig morgen!
Kan vi fortsette å skrive på norsk. Det går veldig mye fortere for meg.... :wink:

User avatar
EDDIE_THE_HEAD
Posts: 15
Joined: Mon 03 Dec 2012, 02:24
Location: Córdoba, Argentina

HELP!!!

#669 Post by EDDIE_THE_HEAD »

Hi there! I am new to the forum, and I come seeking for help :oops:

A couple of days ago I came across gtkdialog and I found it quite interesting. While tampering with it I encountered some trouble regarding variables and functions.

Take this code, for example:

Code: Select all

#!/bin/bash

now () {
   date > /tmp/date
}
export -f now

export script='
<vbox>
  <entry>
    <variable>ENTRY_DATE</variable>
    <input>cat /tmp/date</input>
  </entry>
  <button>
    <label>Refresh</label>
    <action>now</action>
    <action>refresh:ENTRY_DATE</action>
  </button>
</vbox>'

gtkdialog -p script
(It belongs to one of the examples in zigbert's tips).
When I run it and click the 'Refresh' button, it seems that the dialog doesn't recognize the function 'now', for I get the following error:

Code: Select all

sh: 1: now: not found
As you see, the function was exported to the environment so this shouldn't be happening. Any ideas?

As far as variables are concerned, I haven't been able to figure out how to assign new values to pre-declared variables inside the action tags, for example:

Code: Select all

#!/bin/bash

MY_VAR="DEFAULT VALUE"

export script='
<vbox>
  <entry>
    <variable>ENTRY</variable>
    <input>echo '"$MY_VAR"'</input>
  </entry>
  <button>
    <label>Change</label>
    <action>MY_VAR="NEW VALUE"</action>
    <action>refresh:ENTRY</action>
  </button>
</vbox>'

gtkdialog -p script
My intention here is to change the value of the entry field by clicking a button, though I click it and nothing happens. I have tried exporting MY_VAR, but still nothing.


I appreciate any help you can provide!! :D

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

Re: HELP!!!

#670 Post by thunor »

EDDIE_THE_HEAD wrote:...

Code: Select all

#!/bin/bash
...
    <action>now</action>
...
...

Code: Select all

...
    <action>MY_VAR="NEW VALUE"</action>
...
...
Welcome EDDIE_THE_HEAD

Exporting functions is a bashism and since you do indeed have /bin/bash at the top of your script, everything would appear to be fine but the contents of the action will be executed as /bin/sh -c now because gtkdialog was written with C and the C library uses /bin/sh, so I'll hazard a guess that you are using Ubuntu and your /bin/sh is a symlink to dash which doesn't support exported functions.

The easy way to deal with this is to use <action>/bin/bash -c now</action> which gtkdialog will ultimately execute as /bin/sh -c /bin/bash -c now.

You could not use bashisms and instead write portable script:

Code: Select all

#!/bin/sh

## Create the function as a file somewhere (/tmp will do for this).
echo "funcNow() {
	date > /tmp/date
}" > /tmp/funcNow

## The action below will first include the function (known as sourcing)
## and then execute it.
script='
<vbox>
	<entry>
		<variable>ENTRY_DATE</variable>
		<input>cat /tmp/date</input>
	</entry>
	<button>
		<label>Refresh</label>
		<action>. /tmp/funcNow; funcNow</action>
		<action>refresh:ENTRY_DATE</action>
	</button>
</vbox>'
export script

gtkdialog -p script
export script= is a bashism too which is why I modified it.

Widget variables (the ones that you have created and named yourself) will be placed into the shell when an action executes so that you can read the contents of widgets, but you can't change the contents of widgets by modifying their variables -- you'll likely want something like this:

Code: Select all

<entry>
	<variable>ENTRY</variable>
	<input file>/tmp/inputfile</input>
</entry>
<button>
	<label>Change</label>
	<action>echo "NEW VALUE" > /tmp/inputfile</action>
	<action>refresh:ENTRY</action>
</button>
Regards,
Thunor

User avatar
EDDIE_THE_HEAD
Posts: 15
Joined: Mon 03 Dec 2012, 02:24
Location: Córdoba, Argentina

Re: HELP!!!

#671 Post by EDDIE_THE_HEAD »

thunor wrote: Regards,
Thunor
Thanks a lot Thunor!! You were right, I am using Ubuntu and that was exactly the problem.

One last question (for now :oops: ): I understand that you can't change the content of a widget by assigning new values to their variables, but say you wanna change the content of a variable (not related to a widget) by clicking a button or with any other signal, how can you do it? For example:

Code: Select all

#!/bin/bash

MY_VAR="DEFAULT VALUE"

export script='
<vbox>
  <button>
    <label>Change</label>
    # What should I put here to assign another value to MY_VAR?? 
    <action></action>    
</button>
</vbox>'

gtkdialog -p script

echo MY_VAR
 
I've tried many things but no matter what the last line keeps printing "DEFAULT VALUE". Perhaps storing the variable in another file??

User avatar
thunor
Posts: 350
Joined: Thu 14 Oct 2010, 15:24
Location: Minas Tirith, in the Pelennor Fields fighting the Easterlings
Contact:

Re: HELP!!!

#672 Post by thunor »

EDDIE_THE_HEAD wrote:... I've tried many things but no matter what the last line keeps printing "DEFAULT VALUE". Perhaps storing the variable in another file??
That's exactly what you have to do. You need to maintain variables as files. Anything other than a very simple program will require quite a few variables so I personally create a temporary folder in /tmp and store them in there, then delete the folder on program exit.

For the record, if you want shell variables to be visible to subshells then you have to export them, but any changes that you might make to exported variables will be lost when the subshell exits.

See this page.

I don't know if you have the examples that are included with the source package but you should have a look at them.

Cheers and have fun :)

Thunor

User avatar
EDDIE_THE_HEAD
Posts: 15
Joined: Mon 03 Dec 2012, 02:24
Location: Córdoba, Argentina

Re: HELP!!!

#673 Post by EDDIE_THE_HEAD »

thunor wrote: Cheers and have fun :)
Thanks again!! Yes, I've had a look at some of the examples but I must confess I rather felt at a loss while trying to analyze them. Now with your explanations everything is starting to add up. I will be playing with gtkdialog for the next few days, working on some project for university. Wish me luck!!

Greetings from Argentina! :wink:

User avatar
EDDIE_THE_HEAD
Posts: 15
Joined: Mon 03 Dec 2012, 02:24
Location: Córdoba, Argentina

#674 Post by EDDIE_THE_HEAD »

Thunor, me again :roll:

So far the only widgets that have given me trouble are the menu, menubar and menuitems. My gtkdialog seems to be ignoring them completely. No matter how I define them, they won't appear in my dialogs.

I've attached a screen capture for you to see. The code belongs to one of your examples.

I am inclined to think that it has something to do with Ubuntu. Or maybe something went wrong during the installation of the package, which would be weird 'cause neither configure nor make install complained...

Any hints??

EDDIE_THE_HEAD a.k.a the BALL BUSTER :|
Attachments
screen.jpg
(60.74 KiB) Downloaded 572 times

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

#675 Post by technosaurus »

in ubuntu /bin/sh is dash, so $() does not work, try changing it to backticks or the first line to #!/bin/bash

It looks like Thunor has fixed some bashisms in latest source
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
EDDIE_THE_HEAD
Posts: 15
Joined: Mon 03 Dec 2012, 02:24
Location: Córdoba, Argentina

#676 Post by EDDIE_THE_HEAD »

technosaurus wrote:in ubuntu /bin/sh is dash, so $() does not work, try changing it to backticks or the first line to #!/bin/bash

It looks like Thunor has fixed some bashisms in latest source
Yes, I get you, but that doesn't seem to be the problem. See this code:

Code: Select all

#!/bin/bash

DIALOG='
<menubar>
  <menu>
    <menuitem>
      <label>open</label>
    </menuitem>
    <menuitem>
      <label>save</label>
    </menuitem>
    <menuitem>
      <label>quit</label>
      <action>EXIT:quit</action>
    </menuitem>
    <label>File</label>
  </menu>
</menubar>'

export DIALOG

gtkdialog -p DIALOG
There's no bashisms, no code that could cause any trouble. I could change the first line to #!/bin/sh but it wouldn't matter. I still get an empty dialog. :?

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

#677 Post by zigbert »

Any terminal output?
The problem does not seem to be related to gtkdialog.... works here (Puppy 5.3.3)
Image

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

#678 Post by smokey01 »

Works fine in Fatdog too.

User avatar
EDDIE_THE_HEAD
Posts: 15
Joined: Mon 03 Dec 2012, 02:24
Location: Córdoba, Argentina

#679 Post by EDDIE_THE_HEAD »

zigbert wrote:Any terminal output?
Nope!

My guess would be that something's wrong with either my GTK+ library or Ubuntu.

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

#680 Post by technosaurus »

Maybe, what does ldd `which gtkdialog` output?

you could also try using a puppy built gtkdialog in ubuntu
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].

Post Reply