Gtkdialog question

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

Gtkdialog question

#1 Post by rhadon »

Hi,

with this problem I'm struggling for a long time and I don't see a easy solution.

I have a file with one item per line and want another one with several selected items from the first.

I can add selected items to the new file and I can clear (delete) it. Where I'm struggling is, if I want to remove an item from the new list and saving it.

For better understanding I wrote a small example:

Code: Select all

#!/bin/sh
 [ ! -s /tmp/items ] && echo -e -n 'item1\n22222\n33333\nitem4\n55555\n66666\n77777\n' > /tmp/items

GTKDIALOG=gtkdialog4

export MAIN_DIALOG='
<hbox>
  <tree>
    <label>available Items:</label>
    <variable>TREE1</variable>
    <width>150</width><height>250</height>
    <input file> /tmp/items</input>
  </tree>
      <vbox homogeneous="true">
		<button>
			<label>"Add"</label> 
			<action>"echo $TREE1 >>/tmp/selected"  </action> 
 			<action>refresh:TREE2</action> 			
		</button> 		
			<button> 
				<label>"Remove"</label> 
				<action>removeselected:TREE2</action> 
				<action>"echo $TREE2_ALL > /tmp/selected2"</action> 
			</button> 	
			<button> 	
				<label>"Clear"</label> 
				<action>clear:TREE2</action> 
				<action>" rm /tmp/selected"</action>
			</button> 	
			<button ok> </button> 						
	</vbox>
  <tree>
    <label>Selected items:</label>
    <variable>TREE2</variable>
    <width>150</width><height>250</height>
    <input file> /tmp/selected</input>
 	<action>removeselected:TREE2</action> 
 	<action>"echo $TREE2_ALL > /tmp/selected2"</action> 
  </tree>
</hbox>
'

case $1 in
	-d | --dump) echo "$MAIN_DIALOG" ;;
	*) $GTKDIALOG --program=MAIN_DIALOG ;;
esac
It seems to me, the information I want is in TREE2_ALL, but moving its content to the new file, I get e.g.:

Code: Select all

"'22222' '77777' '33333'"
but I want a file with

Code: Select all

22222
77777
33333
Do I really need a command for truncating quotes and replacing spaces by line feeds or something similar, or is there a easier way to do it? Maybe something like

Code: Select all

<action>save:TREE2</action>
( it doesn't work, unsupported)

I've found a lot of examples about tree widgets but nothing about saving back to a file.

Can anybody help please?
Thanks in advance,

Rolf
Attachments
gtkdialog-example.png
(20.29 KiB) Downloaded 326 times
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Re: Gtkdialog question

#2 Post by L18L »

rhadon wrote:,,,
but I want a file with

Code: Select all

22222
77777
33333
Do I really need a command for truncating quotes and replacing spaces by line feeds or something similar, or is there a easier way to do it?...
The easier way is:

Code: Select all

cat /tmp/selected
:wink:

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#3 Post by amigo »

Something like this:

Code: Select all

for ITEM in $(echo $TREE2_ALL) ; do
  echo $ITEM >> /tmp/selected2
done
should do it.

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#4 Post by seaside »

rhadon,

In addition - Xdialog has a similar widget

Code: Select all

Xdialog --buildlist
Cheers,
s

User avatar
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

#5 Post by L18L »

amigo wrote:Something like this:

Code: Select all

for ITEM in $(echo $TREE2_ALL) ; do
  echo $ITEM >> /tmp/selected2
done
should do it.

And then:

Code: Select all

cat /tmp/selected2 | tr -d '"' | tr -d "'" | tr ' ' '\n'
This time tested :lol:

User avatar
rhadon
Posts: 1292
Joined: Thu 27 Mar 2008, 11:05
Location: Germany

#6 Post by rhadon »

Thanks for all replies.
L18L wrote:cat /tmp/selected
I get the same result with

Code: Select all

echo $TREE2_ALL > /tmp/selected
Not really helpful.
amigo wrote:for ITEM in $(echo $TREE2_ALL) ; do
TREE2_ALL isn't working, olthough I defined export TREE2_ALL at the beginning (maybe it works if I create a function for that). But I can use at least the input from a file like

Code: Select all

for ITEM in `cat /tmp/selected2` ...
Adding
L18L wrote:cat /tmp/selected2 | tr -d '"' | tr -d "'" | tr ' ' '\n'
works as I want :D .

Also Thank You to seaside for pointing me to Xdialog.

At last, my problem is solved, but I still have a problem of understanding:

There is a very fine tree widget.
I can list the content of a file

Code: Select all

<input file> /tmp/selected</input>
I can add items and I can remove items

Code: Select all

<action>removeselected:TREE2</action>
but I'm not able to save the result of my changes in the same comfortable way. That's not logical for me :oops: .

After all, gtkdialog is really great :D .

Rolf
Ich verwende "frugal", und das ist gut so. :wink:
Raspberry Pi without Puppy? No, thanks.

Post Reply