Register
It is currently Mon Dec 22, 2014 7:54 pm

Dynamic list from var or file using Zenity framework


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Sat May 29, 2010 5:12 am   

Joined: Sat May 29, 2010 5:04 am
Posts: 2
Hello every,

I've just starting my own personal project, but got stuck on step when I need to create dynamically Zenity "Radio List".

My actual code:
Code:
for f in `find -type f -iname \*.lang` ; do
   text=`basename $f .lang`
   echo -n 'FALSE "'$text'" ' >> languages
done

IFS=$'\n'
for l in `cat languages`
do
   export langList="${l}"
done

lang=$(zenity --list --title="Language selection" --text="Select language:" --radiolist  --column "Pick" --column "Language" echo "$langList")

There is a problem with echo, because Zenity do not understood it well - instead of list of languages available I've got only one position with whole string. I'm just a beginner and this task at the moment for me is unfortunately unsolvable : (

I was searching for some advanced examples of Zenity based scripts, but I found nothing.

Hoped you give me some advices or show me solution of this problem.


Top
 Profile  
 PostPosted: Sat May 29, 2010 7:09 am   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
Code:
languages=( *.lang )
langList=( ${languages[@]%.lang} )
zenity --list --title="Language selection" --text="Select language:" --radiolist  --column "Pick" --column "Language" TRUE ${langList[@]::1} $(printf 'FALSE %s\n' ${langList[@]:1})


Top
 Profile  
 PostPosted: Sat May 29, 2010 4:37 pm   

Joined: Sat May 29, 2010 5:04 am
Posts: 2
Works great! Thank you!

Could you in free time wrote short explanation of this code, be cause I'm not getting everything here ; >


Top
 Profile  
 PostPosted: Sat May 29, 2010 5:09 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 579
languages and langList are arrays.
languages lists all files that end with '.lang' in the current directory.
in langList, I delete for each item in ${languages[@]} the '.lang' part of the filename (this could also have been done using ${languages[@]%.*}). I let the changing of name though it's not necessary.
${langList[@]::1} is langList first item,
${langList[@]:1} is all items except the first.

:) see man bash /Parameter Expansion


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP