Xdialog input tags and items (SOLVED)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#16 Post by seaside »

technosaurus,

Thanks for all your help. Yes, it looks like the only way to keep the quoted multi-word variables from breaking is to build an input line.

# v1=tag1
# v2='item 1'
# v3=tag2
# v4='item 2'
# Xdialog --menubox "This is a menubox example" 0 0 3 "$v1" "$v2" "$v3" "$v4"

where tag/item pairs are split and go into separate consecutive sequential variables. (Now, how to parse and place those on the input line will be the next challenge)

8-bit,

It looks like you had as much fun as I did with this and thanks again. :)

Bottom line, as Carl mentioned, is that Xdialog does not see quotes as defining a group of words within a single variable stream.

I guess this was the reason that I couldn't find any examples of this use anywhere.

Regards,
s

User avatar
8-bit
Posts: 3406
Joined: Wed 04 Apr 2007, 03:37
Location: Oregon

#17 Post by 8-bit »

seaside,
DId you run the last example I posted. It uses user defined variables and not fixed strings. If you name each variable to $1,$2,$3,$4,etc.,
you can even send it the variables from the command line with

# Xdialog_prog "var1" "var2" "var3" "var4".
Each multiword variable will display and get returned just like it appears in the string.

Using the example I posted, this is what is displayed in the menubox:

this is one item.......... and this is another
tag 2 is here................ item 2 is here

The forum is eating my additional spaces so I used dots.
And after clicking on say the first entry, and then clicking OK, the script ends with echoing
this is one item

But.....
To use that returned string somewhere else, you cannot just use the $i string as it will be empty.

I played with using my first example posted as a guide to get the returned string into a variable I could then use.

But I thought I would pass this along to you.

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

#18 Post by seaside »

8-bit wrote:seaside,
DId you run the last example I posted. It uses user defined variables and not fixed strings...
8-bit,

Yes thanks, your examples are good. As for the tags , they are needed and can't be eliminated.

So, the challenge now is to be able to parse this example "menu" file-
apple "this is an apple"
orange "this is an orange"
pear "this is a pear"
and then translate this to incrementing variables-
v1="apple"
v2="this is an apple"
v3="orange"
v4="this is an orange"
v5="pear"
v6="this is a pear"
Then build this Xdialog command call line -
Xdialog --menubox "This is a menubox example" 0 0 3 "$v1" "$v2" "$v3" "$v4" ...."$vn"

I think my head is hurting now.. :)

Regards,
s

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

#19 Post by amigo »

It's really much simpler, in multiple-choice cases, to simply use a temporary file -write a 'header' with the first part of your Xdialog command, then process the options and echo them into the file, then add the 'footer', then execute the script.
As you can see, most Xdialog examples use this method -especially since the default behaviour of Xdialog sends output to stderr instead of stdout. Only when a single choice is expected do I use the '--stdout' option and capture the resut in a variable.
Maybe you've worked out a round-about way to achieve what you want, but you could have written dozens of dialogs in the same time using the 'standard' dialog/Xdialog methods. And your solution is complex enough that every time you want to do something similar you'll need to go back back and study your working example.
Onward through the fog...
http://www.oatwillies.com/about.htm

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

#20 Post by seaside »

amigo wrote: Maybe you've worked out a round-about way to achieve what you want, but you could have written dozens of dialogs in the same time using the 'standard' dialog/Xdialog methods. And your solution is complex enough that every time you want to do something similar you'll need to go back back and study your working example.
Onward through the fog...
http://www.oatwillies.com/about.htm
amigo,

Ironically, when I first encountered this issue I said to myself "oh, I'll simply put underscores between the words and make a single word-- problem solved" Then I stopped and said "no, I want it with proper spaces" and went into chasing an answer mode. :)

All good learning experiences in the long run.

Regards,
s

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

#21 Post by seaside »

As Amigo said "do it the easy puppy way".

Code: Select all

echo '#!/bin/sh ' >/dev/shm/fruits
echo 'Xdialog --menubox "This is a menubox example" 0 0 3 \' >>/dev/shm/fruits
echo '"apple" \
"this is an apple" \
"orange" \
"this is an orange" \
"pear" \
"this is a pear" \'>>/dev/shm/fruits
chmod +x /dev/shm/fruits
exec /dev/shm/fruits
The script header is created, followed by the Xdialog start, followed by the fruits being echo'd from a loop (fruit-loops they're called :) )

Make executable and run.

Thanks all,
s

Post Reply