Xdialog make a ratiolist from a Directory listing?

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
HoerMirAuf
Posts: 255
Joined: Tue 22 Jan 2008, 12:11
Location: Würzburg

Xdialog make a ratiolist from a Directory listing?

#1 Post by HoerMirAuf »

Hi Volks.

I am a novice in scripting bash scripts and/or Xdialog or gtkdialog

I want to make a ratiolist, where i can choose on of all folders in a directory. I am interested in to do this in Xdialog also in gtkdialog

i know a little bit about "ls -d */" and about to build the ratiolist. But how can i make now a ratiolist from the result from "ls -d */" ??

Maybe anyone can explaine me or give me a hint or an example?

User avatar
RSH
Posts: 2397
Joined: Mon 05 Sep 2011, 14:21
Location: Germany

#2 Post by RSH »

Here is an example from don570's bulldog finder (I think).

It gives a small gtkdialog gui of all mounted drives.

Maybe a good starting point ?

Remove the fake '.gz' and make executable.
Attachments
drive-list.sh.gz
(1.88 KiB) Downloaded 195 times
[b][url=http://lazy-puppy.weebly.com]LazY Puppy[/url][/b]
[b][url=http://rshs-dna.weebly.com]RSH's DNA[/url][/b]
[url=http://murga-linux.com/puppy/viewtopic.php?t=91422][b]SARA B.[/b][/url]

PANZERKOPF
Posts: 282
Joined: Wed 16 Dec 2009, 21:38
Location: Earth

Re: Xdialog make a ratiolist from a Directory listing?

#3 Post by PANZERKOPF »

Code: Select all

#!/bin/sh

for ONEFILE in /path/*; do
    [ -d ${ONEFILE} ] || continue
    DIALOGLIST="${DIALOGLIST} ${ONEFILE} - off"
done
Xdialog --checklist "Directories" 0 0 5 ${DIALOGLIST}
SUUM CUIQUE.

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

#4 Post by MochiMoppel »

Here a slight variation of PANZERKOPF's code:

Code: Select all

#!/bin/sh

DIRECTORY="/root"
for ONEFILE in "$DIRECTORY"/*; do 
     [ -d $ONEFILE ] || continue 
     DIALOGLIST="${DIALOGLIST} ${ONEFILE} ${ONEFILE##*/} off"
 done 
ANSWER=`Xdialog --no-tags  --stdout --radiolist "Subdirectories in $DIRECTORY" 30 30 5 ${DIALOGLIST}`
Xdialog --msgbox  "$ANSWER"  5 30
Haven't figured out yet how to accomodate code for directory names containing spaces.

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

#5 Post by technosaurus »

Why not just use:

Code: Select all

Xdialog --dselect $PARENTDIR 0 0
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
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#6 Post by MochiMoppel »

technosaurus wrote:Why not just use...
Spec violation! No radiobuttons... :lol:

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

#7 Post by technosaurus »

The result is the same, radio buttons only allow one selection... the same as dselect... except that the intention is more clear with dselect

A radiolist can be done:

Code: Select all

A='Xdialog --no-tags --radiolist "select something" 0 0 9 '
for x in *;do
   [ -d "$x" ] && A="$A \"$x\" \"$x\" 0 "
done
RESULT=`eval $A`
...but I don't find it as appealing as a simple -dselect
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].

PANZERKOPF
Posts: 282
Joined: Wed 16 Dec 2009, 21:38
Location: Earth

#8 Post by PANZERKOPF »

technosaurus wrote:Why not just use:

Code: Select all

Xdialog --dselect $PARENTDIR 0 0
I presumed HoerMirAuf wants to choose not only one but number of directories at same time, therefore I recommended a checklist instead of radiolist.
SUUM CUIQUE.

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

#9 Post by technosaurus »

PANZERKOPF wrote:I presumed HoerMirAuf wants to choose not only one but number of directories at same time, therefore I recommended a checklist instead of radiolist.
... I have no idea what a "ratiolist" is either or "on" of all folders ... but I assumed "radiolist" and "one".... honestly Zigbert's pprocess2 is a better looking example for gtkdialog selections than the Xdialog --radiolist
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
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: Xdialog make a ratiolist from a Directory listing?

#10 Post by MochiMoppel »

And now the ultimate challenge :lol: :
HoerMirAuf wrote: But how can i make now a ratiolist from the result from "ls -d */" ??
Usefulness apart, at least it could serve as a blueprint for reading any external list into a radiolist :

Code: Select all

ls -d */ > /tmp/list
A='Xdialog --no-tags --stdout --radiolist "select something" 0 0 9 ' 
while read x; do
	A="$A "$x" "$x" 0 " 
done < /tmp/list 
RESULT=`eval $A`

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

Re: Xdialog make a ratiolist from a Directory listing?

#11 Post by technosaurus »

MochiMoppel wrote:And now the ultimate challenge :lol: :
HoerMirAuf wrote: But how can i make now a ratiolist from the result from "ls -d */" ??
Usefulness apart, at least it could serve as a blueprint for reading any external list into a radiolist :

Code: Select all

ls -d */ > /tmp/list
A='Xdialog --no-tags --stdout --radiolist "select something" 0 0 9 ' 
while read x; do
	A="$A "$x" "$x" 0 " 
done < /tmp/list 
RESULT=`eval $A`
That does the same thing as my example except that it requires an extra external binary, and superfluous file write and read

ls -d */ is roughly the same as echo */ but echo is a shell builtin (much faster)
rather than writing to a file as command >file (slow) you can do VAR=`command` and then you can echo $VAR | through a pipe or use <<< $VAR redirection

BTW, my example needed --stdout (Xdialog has some stupid defaults) ... and the [ -d ... ] bit could be replace with a */

Code: Select all

A='Xdialog --stdout --no-tags --radiolist "select something" 0 0 9 '
for x in */;do A="$A "$x" "$x" 0 ";done
RESULT=`eval $A`
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
L18L
Posts: 3479
Joined: Sat 19 Jun 2010, 18:56
Location: www.eussenheim.de/

Off-Topic of the topic

#12 Post by L18L »

technosaurus wrote:... I have no idea what a "ratiolist" is
The assumption radiolist is right.

In Franconian dialect (HoerMirAuf's Location Würzburg is the capital of Lower Franconia) the pronounciation of d and t are swapped, same for b and p when Franconians want to speak "Hochdeutsch". This phenomen has been stuff for some sketches. e.g.:
http://www.youtube.com/watch?v=VdkwkASm6OM

Watch and listen Willy Astor - Wortspiele Franken - Frankenlied - Live! +Text 4:09 -4:12

Have fun

PANZERKOPF
Posts: 282
Joined: Wed 16 Dec 2009, 21:38
Location: Earth

Re: Off-Topic of the topic

#13 Post by PANZERKOPF »

L18L wrote: The assumption radiolist is right.
Thanks for correction.
If he wants to choose only one directory, an example shown by technosaurus (--dselect) is simpler and better for this purpose.
SUUM CUIQUE.

User avatar
HoerMirAuf
Posts: 255
Joined: Tue 22 Jan 2008, 12:11
Location: Würzburg

#14 Post by HoerMirAuf »

Damn guys!

Thank you so much for your many replies. I have to check them all out.

Maybe a little mor explain to my request:

I want only choose one Directory from a lot.
It is not neccesary to solve this with "ls -d */" ... this was the only idea, i have had.

But i cant take a "Xdialog -deselct" box, because there are subfolders in the Directory i want to choose ... and with deselect this subfolders are also selectable ... ore not?

Ok ... now i will try out your suggestions :)

Thanks a lot ! :D

PANZERKOPF
Posts: 282
Joined: Wed 16 Dec 2009, 21:38
Location: Earth

#15 Post by PANZERKOPF »

HoerMirAuf wrote: But i cant take a "Xdialog -deselct" box, because there are subfolders in the Directory i want to choose ... and with deselect this subfolders are also selectable ... ore not?
Yes, it works like filemanager, You can browse directory tree and enter in
any subdirectory.
SUUM CUIQUE.

User avatar
HoerMirAuf
Posts: 255
Joined: Tue 22 Jan 2008, 12:11
Location: Würzburg

#16 Post by HoerMirAuf »

hmmmm

Code: Select all

A='Xdialog --no-tags --radiolist "select something" 0 0 5 '
for x in *;do
   [ -d "$x" ] && A="$A \"$x\" \"$x\" 0 "
done
RESULT=`eval $A`
this is just a very nice solution... Thank you all a lot!

But eval will give back the result only in a terminal output. Why eval dont write it to the variable "RESULT" ??

PANZERKOPF
Posts: 282
Joined: Wed 16 Dec 2009, 21:38
Location: Earth

#17 Post by PANZERKOPF »

HoerMirAuf wrote:hmmmm
But eval will give back the result only in a terminal output. Why eval dont write it to the variable "RESULT" ??
IMHO Xdialog prints a result to stderr by default. It needs additional option "--stdout"
for printing to stdout.

Change first line of code:

Code: Select all

A='Xdialog --stdout --no-tags --radiolist "select something" 0 0 5 '
SUUM CUIQUE.

User avatar
HoerMirAuf
Posts: 255
Joined: Tue 22 Jan 2008, 12:11
Location: Würzburg

#18 Post by HoerMirAuf »

Hi Panzerkopf.

Thanks a lot!! ... It works ... why i havent seen that by myself? :)

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

#19 Post by Moose On The Loose »

PANZERKOPF wrote:
HoerMirAuf wrote:hmmmm
But eval will give back the result only in a terminal output. Why eval dont write it to the variable "RESULT" ??
IMHO Xdialog prints a result to stderr by default. It needs additional option "--stdout"
for printing to stdout.

Change first line of code:

Code: Select all

A='Xdialog --stdout --no-tags --radiolist "select something" 0 0 5 '
You can also use the 2>&1 construct to re-rout the stderr to stdout

A while back, on puppy 4.3.1, I wrote a thing that needed to ask a lot of questions via Xdialog. I discovered to my horror that after so many calls to Xdialog in a script, it would start to fail. As a result, I ended up recoding it to use just "dialog" and pop up a terminal. Hopefully this problem won't plague people today.

Post Reply