Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 18 Jun 2013, 17:57
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Xdialog input tags and items (SOLVED)
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 1 of 2 Posts_count   Goto page: 1, 2 Next
Author Message
seaside

Joined: 11 Apr 2007
Posts: 841

PostPosted: Mon 17 Oct 2011, 22:43    Post_subject:  Xdialog input tags and items (SOLVED)  

Xdialog has a number of widgets that take variable input in the form of "tag1 item1 status1".

However, if some of these inputs have multiple words such as the following-

Code:
# echo $i
tag "this is one item"
# Xdialog --menubox something 0 0 0 $i

fails

Also, "$i", '"$i"' $(<i) ...etc. doesn't work.


Am I missing something or perhaps Xdialog doesn't accept variable input with quoted groups of words?

Cheers,
s

Edited_time_total
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 3845

PostPosted: Tue 18 Oct 2011, 03:39    Post_subject: Re: Xdialog input tags and items  

seaside wrote:
Xdialog has a number of widgets that take variable input in the form of "tag1 item1 status1".

However, if some of these inputs have multiple words such as the following-

Code:
# echo $i
tag "this is one item"
# Xdialog --menubox something 0 0 0 $i

fails

Also, "$i", '"$i"' $(<i) ...etc. doesn't work.


Am I missing something or perhaps Xdialog doesn't accept variable input with quoted groups of words?

Cheers,
s
how about
`echo "${i}"`
note that you will have to backslash quotes first

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
8-bit


Joined: 03 Apr 2007
Posts: 3033
Location: Oregon

PostPosted: Tue 18 Oct 2011, 06:00    Post_subject:
Sub_title: example found on internet
 

I found this example on the internet.
Hope it helps.

Code:

#!/bin/sh
#DIALOG=${DIALOG=dialog}
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
trap "rm -f $tempfile" 0 1 2 5 15

Xdialog --clear --title "My  favorite HINDI singer" \
        --menu "Hi, Choose  your favorite HINDI singer:" 0 0 0 \
        "Rafi"  "Mohammed Rafi" \
        "Mukesh" "Mukesh" \
        "Kishore" "Kishore Kumar" \
        "Saigal" "K L Saigal" \
        "Lata"  "Lata Mangeshkar" \
        "Yesudas"  "K J Yesudas" 2> $tempfile

retval=$?

choice=`cat $tempfile`

case $retval in
  0)
    echo "'$choice' is your favorite hindi singer";;
  1)
    echo "Cancel pressed.";;
  255)
    echo "ESC pressed.";;
esac
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 841

PostPosted: Tue 18 Oct 2011, 09:43    Post_subject:  

technosaurus,

`echo \"${i}\"`
No, it breaks the line.

8-bit,

Thanks for the example. Unfortunately, the example isn't a variable input being used.

Regards,
s
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 3845

PostPosted: Tue 18 Oct 2011, 11:12    Post_subject:  

seaside wrote:
technosaurus,

`echo \"${i}\"`
No, it breaks the line.

8-bit,

Thanks for the example. Unfortunately, the example isn't a variable input being used.

Regards,
s
I meant any quotes inside the variable itself

i='word word word \"set of words\" word word'
... `echo "${i}"`

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 841

PostPosted: Tue 18 Oct 2011, 11:26    Post_subject:  

technosaurus wrote:
I meant any quotes inside the variable itself

i='word word word \"set of words\" word word'
... `echo "${i}"`


technosaurus,

No, that breaks it also. Darn.

Thanks for the ideas, though.

Regards,
s
EDIT: The following works, but is very difficult to construct.

tag1=431
item="this is one item"
Xdialog --menubox something 0 0 0 $tag1 "$item" $tag1 "$item"
Back to top
View user's profile Send_private_message 
Karl Godt


Joined: 20 Jun 2010
Posts: 2730
Location: Kiel,Germany

PostPosted: Tue 18 Oct 2011, 13:06    Post_subject:  

Xdialog is like xmessage : a '\'backslash gets printed literally into the gui .
The documentation inside the source does not reveal much about escaping ; just for color variables .

playing around i found this :

echo "tag1 this is the item1" >/tmp/test

Xdialog -menubox "TEST" 0 0 6 "`cat /tmp/test | cut -f 1 -d ' '`" "`cat /tmp/test | cut -f 2-99 -d ' '`"

which would only work for one item .
would need some kind of loop with probably sed -n "$lineNumber p" ....
Back to top
View user's profile Send_private_message Visit_website 
seaside

Joined: 11 Apr 2007
Posts: 841

PostPosted: Tue 18 Oct 2011, 15:20    Post_subject:  

Karl Godt wrote:
Xdialog is like xmessage : a '\'backslash gets printed literally into the gui .
The documentation inside the source does not reveal much about escaping ; just for color variables .

playing around i found this :

echo "tag1 this is the item1" >/tmp/test

Xdialog -menubox "TEST" 0 0 6 "`cat /tmp/test | cut -f 1 -d ' '`" "`cat /tmp/test | cut -f 2-99 -d ' '`"

which would only work for one item .
would need some kind of loop with probably sed -n "$lineNumber p" ....


Karl,

Wow - a double cat. I had to stare at that one for a while. Smile

It seems to be doing the same as-
Code:
Xdialog --menubox something 0 0 0 $tag1 "$item" $tag1 "$item"
which I mentioned before.

Thanks for checking out the Xdialog source details

Regards,
s
(It seems there should be a simple and less complex solution to this problem - but sometimes not Smile )
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 3845

PostPosted: Tue 18 Oct 2011, 16:58    Post_subject:  

oops I meant eval, not echo
Code:
i='Xdialog --infobox "this is an infobox" 0 0'
`eval "${i}"`

Does anyone else mix up words that start with the same letter?

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 841

PostPosted: Tue 18 Oct 2011, 17:44    Post_subject:  

technosaurus wrote:
oops I meant eval, not echo
Code:
i='Xdialog --infobox "this is an infobox" 0 0'
`eval "${i}"`

Does anyone else mix up words that start with the same letter?


technosaurus,

Thanks for another try but no go. Also infobox doesn't have extra tag item. Needs a solution to -
#echo $i
tag "this is one item"
# Xdialog --menubox something 0 0 0 $????here

Regards,
s
Back to top
View user's profile Send_private_message 
8-bit


Joined: 03 Apr 2007
Posts: 3033
Location: Oregon

PostPosted: Tue 18 Oct 2011, 21:03    Post_subject:  

I think Xdialog's processing is what is giving you problems.

The syntax of "Xdialog --menubox tag item tag item " is interpreting the string as (this)tag , (is)item, one(tag), (item)item.

I can get it all to display on one line by replacing the space with a period in the string, but it is still splitting the string into a tag-item display.

As in the example I posted, the first name is the tag that gets returned and the second full name is the item that does not.

So the way it is interpreting your string, it returns "this" as the tag and ignores the "is" item.
And it is using the space as a delimiter for the values so the last part of the string is seen by it as another tag-item.

I still do not have an answer for you as to how you would get it to interpret and pass back the entire string when selected.
Back to top
View user's profile Send_private_message 
8-bit


Joined: 03 Apr 2007
Posts: 3033
Location: Oregon

PostPosted: Tue 18 Oct 2011, 21:26    Post_subject:  

seaside, I am back after following the logic I tried to explain with an example for you to run. The example you can run follows. There is a space between the backslash and the line it follows. Also, the string "this is one item" is actually a tag and the string "and this is another" is actually an item.

Code:

#! /bin/bash
i=$tag
#echo $i
Xdialog --menubox something 10 40 0 $i \
           "this is one item" "and this is another" \
           "tag2 is here" "item 2 is here" \
`eval "${i}"`
Back to top
View user's profile Send_private_message 
seaside

Joined: 11 Apr 2007
Posts: 841

PostPosted: Tue 18 Oct 2011, 23:06    Post_subject:  

8-bit wrote:
seaside, I am back after following the logic I tried to explain with an example for you to run. The example you can run follows. There is a space between the backslash and the line it follows. Also, the string "this is one item" is actually a tag and the string "and this is another" is actually an item.

Code:

#! /bin/bash
i=$tag
#echo $i
Xdialog --menubox something 10 40 0 $i \
           "this is one item" "and this is another" \
           "tag2 is here" "item 2 is here" \
`eval "${i}"`


8-bit,

Thanks for looking at this. The input for Xdialog --menubox is this format.

tag1 item1 tag2 item2 tag3 item3 ......etc

In your example the line pairs are not variables but quoted constants ("tag2 is here" "item 2 is here") . So it can only be used that way for strings that are unchanging.

Whew...this problem seems to resist a reasonable answer. Smile .

Regards,
s
Back to top
View user's profile Send_private_message 
technosaurus


Joined: 18 May 2008
Posts: 3845

PostPosted: Tue 18 Oct 2011, 23:08    Post_subject:  

seaside wrote:
technosaurus wrote:
oops I meant eval, not echo
Code:
i='Xdialog --infobox "this is an infobox" 0 0'
`eval "${i}"`

Does anyone else mix up words that start with the same letter?


technosaurus,

Thanks for another try but no go. Also infobox doesn't have extra tag item. Needs a solution to -
#echo $i
tag "this is one item"
# Xdialog --menubox something 0 0 0 $????here

Regards,
s
you can just keep adding to your variable as necessary
i=${i}' '${PARAM}' 0 0' #add this to what is already in variable "i"....
i=${i}' '${NEWPARAM}' 0 0' #add another one
#.... above could be a loop that tacks on parameters each time
#then run it with:
eval "${i}"

ex.
i='Xdialog --menubox "This is a menubox example" 0 0 3 1 "option 1" 2 "option 2"'
i=$i' 3 "option 3"'
eval $i

_________________
Puppy Web Desktop Now with pet packages - Pet Packaging 100 & 101
Back to top
View user's profile Send_private_message 
8-bit


Joined: 03 Apr 2007
Posts: 3033
Location: Oregon

PostPosted: Wed 19 Oct 2011, 00:51    Post_subject:  

seaside,
How about another example using variables to hold tag and item strings.
I just modified my fixed string example so anything you put in the variables would display. You do need separate variables for tag and item with it though. When I tried to combine them, the display and output would mess up.
EDIT: If you change the second line to t1="$1" you can even send the t1 variable from the command line by doing Program.sh "Some text".
I have not figured out yet how one gets the item variable passed back as the selection. Currently, the tag variable only gets returned.
So other than the display, the item variable just as well be a dummy.

Code:

#! /bin/bash
t1="this is one item"
m1="and this is another"
t2="tag 2 is here"
m2="item 2 is here"


Xdialog --menubox something 10 40 0 $i \
           "$t1" "$m1" \
           "$t2" "$m2" \
`eval "${i}"`
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 1 of 2 Posts_count   Goto page: 1, 2 Next
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Off-Topic Area » Programming
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0953s ][ Queries: 12 (0.0157s) ][ GZIP on ]