Xdialog: checklist box option

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
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

Xdialog: checklist box option

#1 Post by nic007 »

I want to use Xdialog, checklist box option in a script but need some help with the construction thereof. Simple example of what I want:

tag1=1 item1=john status=off
tag2=2 item2=peter status=off
If I select john from the list, the command cp /a.txt /root must be executed.
If I select peter, cp /b.txt /root must be executed.
If I select both from the list, the command for each item must be executed seperately (in other words john and its command, followed by peter and its command).

Thanks

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

#2 Post by MochiMoppel »

Try

Code: Select all

ANSWER=$(Xdialog --stdout --checklist "Select one or more" 0 0 6 "1" "John" "off" "2" "Peter" "off")
case /$ANSWER/ in
*/1/*) echo cp a.txt /root ;;&
*/2/*) echo cp b.txt /root ;;
esac

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#3 Post by nic007 »

Thanks, I'll give it a try.

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#4 Post by nic007 »

Script does not work for me with the & added. Works without the & but only one item's command is executed (even if you select more than one item from the list).

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

#5 Post by MochiMoppel »

nic007 wrote:Script does not work for me with the & added
Requires bash 4 or newer.
You didn't specify a particular shell so I assumed that you use bash.

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#6 Post by nic007 »

Oh, okay. I was using Racy. Works with the newer Puppys. Thanks.

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#7 Post by Moose On The Loose »

nic007 wrote:Oh, okay. I was using Racy. Works with the newer Puppys. Thanks.
BTW:
I find that if you make the "6" number one more than the number of items, the script looks much better.
If there are So many that the dialog box will be over about 400 pixels tall make the number at least two less than the actual number and also small enough that it comes in under 400. Some people, like me when traveling, are using a machine with a very limited screen.

User avatar
nic007
Posts: 3408
Joined: Sun 13 Nov 2011, 12:31
Location: Cradle of Humankind

#8 Post by nic007 »

Moose On The Loose wrote:
nic007 wrote:Oh, okay. I was using Racy. Works with the newer Puppys. Thanks.
BTW:
I find that if you make the "6" number one more than the number of items, the script looks much better.
If there are So many that the dialog box will be over about 400 pixels tall make the number at least two less than the actual number and also small enough that it comes in under 400. Some people, like me when traveling, are using a machine with a very limited screen.
Yes that number is for the space allocated for items in the list. On the average laptop screen about 20 items will fill the screen from top to bottom. But - there should be a scrollbar if you have more items.

User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#9 Post by Moose On The Loose »

nic007 wrote:
Moose On The Loose wrote:
nic007 wrote:Oh, okay. I was using Racy. Works with the newer Puppys. Thanks.
BTW:
I find that if you make the "6" number one more than the number of items, the
Yes that number is for the space allocated for items in the list. On the average laptop screen about 20 items will fill the screen from top to bottom. But - there should be a scrollbar if you have more items.
Yes, I knew that. My advice was based on that and the fact that the "average screen" is very like the "average person". There is none that is actually the average. The 400 Pixels size was based on the idea that it is the size of a small screen that may be used. We want our programs to be accessible to all so we should be designing around the most limited case that is reasonable.

The "two less" bit in my advice is because a scrolling window that is just slightly smaller than the list makes a scroll bar that looks a bit wrong. With a bar nearly the full height of the scroll range, if fakes some people out and they seem not to see that it is a scroll bar. I had this happen with something I created for a "non-linux user". I made a bootable CD that did the thing they needed but that one point messed them up.

Post Reply