Restrain COMBOBOX list

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
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

Restrain COMBOBOX list

#1 Post by don570 »

I've written a short script to demonstrate the restraining of
a COMBOBOX list

Image

The script simply plays a sound file or it can be an m3u playlist
(for hours of music with just the click of a button).

It's easy to set the
the sound file in the beginning of the script if you wish.

The basic idea is this...

From a list of possible Audio players a search is done to
find the Audio players that are actually installed in your computer.


The COMBOBOX shows the list of installed players, so the
user can choose among these to play a sound file.

I wanted to show that it was easy to edit the list and
I think I succeeded. :lol:
It's a very simple script. I'll show it in the next post.

Notice the quoting of

Code: Select all

'"$(COMBOBOX)"'
This is the function that makes the list.


_______________________________________________
Last edited by don570 on Sat 04 Aug 2012, 19:47, edited 3 times in total.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

script to restrain combobox using ls

#2 Post by don570 »

Code: Select all

#!/bin/sh
#aug2 2012
#Combobox example by don570 

# find version of gtkdialog
for P in gtkdialog4 gtkdialog3 gtkdialog; do
           GTKDIALOG=$(which $P) && break
done

         mkdir -p /tmp/COMBOBOX_LIST
         rm -f /tmp/COMBOBOX_LIST/* # clear out temp folder of files

export SOUND=/root/puppy-reference/audio/2barks.wav
export i=0  # initialize loop counter
  
#  loop through the list of apps that you make
for P in pmusic audacious deadbeef gnome-mplayer aqualung xine; do 

          APP_FOUND=`echo $(which $P)` 
          if [  -n  "$APP_FOUND"  ] ; then    
          APP[$i]="${APP_FOUND##*/}"   # shorten to the app name  
          let  i=$i+1   #  number of apps found
          fi
done
  
#  fill folder with files representing the APP names
        cd  /tmp/COMBOBOX_LIST
        for ((a=0; a <= i ; a++))
        do
        touch  ${APP[$a]}
        done
 
function COMBOBOX()
{
       ls -A | while read line; do
       echo "<item>${line}</item>"
       done
}

export BUILD_LIST='

<vbox>
   
            <text>
                      <label>Audio Player</label>
            </text>
            
            <combobox case-sensitive="false" value-in-list="true">
                    <variable>PLAYER</variable>
                     '"$(COMBOBOX)"'
            </combobox>      
  
 <hbox>
             <button cancel></button>
             <button>
                    <label>Play Sound</label>            
                    <action>$PLAYER  "$SOUND" &</action>
            </button>          
            
 </hbox>    

</vbox>
'
$GTKDIALOG --program=BUILD_LIST 

Here's the script to download. Remove gz extension :lol:

________________________
Attachments
build_list.sh.gz
remove gz extension to obtain script
(1.55 KiB) Downloaded 451 times

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#3 Post by don570 »

Here's an alternate way to restrain the combobox that is even
simpler. It uses the 'cat' command rather that the 'ls' command.
This script avoids the use of an array and the use of a temporary
folder. It uses a temporary file to hold the app names.

Code: Select all

#!/bin/sh
#aug2 2012
#Combobox example by don570 

# find version of gtkdialog
for P in gtkdialog4 gtkdialog3 gtkdialog; do
           GTKDIALOG=$(which $P) && break
done

         rm -f /tmp/COMBO_LIST

export SOUND="$HOME/puppy-reference/audio/2barks.wav"
  
#  loop through the list of apps that you make
for P in pmusic audacious deadbeef gnome-mplayer aqualung xine; do 

          APP_FOUND=`echo $(which $P)`               
          APP="${APP_FOUND##*/}"   # shorten to the app name
          if [ -n "$APP" ] ; then  # avoid blank lines          
         echo $APP >> /tmp/COMBO_LIST
          fi
done

 
function COMBOBOX()
{
       cat /tmp/COMBO_LIST | while read line; do
       echo "<item>${line}</item>"
       cat /tmp/COMBO_LIST |   sed '1d'  >  /tmp/COMBO_LIST_tmp
       mv -f /tmp/COMBO_LIST_tmp /tmp/COMBO_LIST
       done
       rm -f /tmp/COMBO_LIST
}

export BUILD_LIST='

<vbox>
   
            <text>
                      <label>Audio Player</label>
            </text>
            
            <combobox case-sensitive="false" value-in-list="true">
                    <variable>PLAYER</variable>
                     '"$(COMBOBOX)"'
            </combobox>      
  
 <hbox>
             <button cancel></button>
             <button>
                    <label>Play Sound</label>            
                    <action>$PLAYER  "$SOUND" &</action>
            </button>          
            
 </hbox>    

</vbox>
'
$GTKDIALOG --program=BUILD_LIST 

Attachments
build_list_alt.sh.gz
remove gz extension to obtain the script
(1.45 KiB) Downloaded 424 times

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

#4 Post by 8-bit »

I have Thunor's PMusic installed and when I select play sound, the sound file keeps repeating until I close PMusic.
But maybe that is a PMusic problem in that it may be setup to loop it's playlist.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#5 Post by don570 »

If you have gtkdialog 8 or better here is an interesting script
that lists all your mounted partitions including USB.
It is based on the previous script.

The button simply puts a message on your screen but
it might be useful to a developer.

Here's a look at it. Home refers to the partition where
your pupsave file is located. It should also work with a full install,
but I haven't tested that configuration.

Image
Attachments
drive-list.sh.gz
remove fake gz extension to obtain script
(1.88 KiB) Downloaded 315 times

R-S-H
Posts: 487
Joined: Mon 18 Feb 2013, 12:47

#6 Post by R-S-H »

Hi don570,

you are surely not only a "funny person" (remember?) you are surely a very kind person to show me a way how to get the unmounted drives in a seperate list?

Thanks

RSH
[b][url=http://lazy-puppy.weebly.com]LazY Puppy Home
The new LazY Puppy Information Centre[/url][/b]

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#7 Post by don570 »

'probepart' gives the full list. (Apparently related to 'partprobe command')

Then subtract my list from that list.
..but it's apparently buggy
http://bkhome.org/blog2/?viewDetailed=00094


I learned a lot about puppy when I put togeter 'report-system'


In my 'report-system' I looked for '/dev_save/'
to find which partition the pupsave file was stored.



Code: Select all

# PupSave file  -  LUCID or LAZY distro  uses rootfs  and unionfs
echo -e "\n========== $(gettext 'PupSave file') =========\n"  >> /tmp/report-video
df -h > /tmp/top.tmp
sed -n '/dev_save/p' /tmp/top.tmp > /tmp/top.tmp2
sed -n '/unionfs/p' /tmp/top.tmp > /tmp/top.tmp3
if  [ ! -s  /tmp/top.tmp2 ] ||  [ ! -s  /tmp/top.tmp3 ] ; then
echo -e "$(gettext 'PupSave file is not in use')\n"  >> /tmp/report-video
else
...
Here is the code that detects which SFS packages are installed

Code: Select all

# detect SFS files - code by James  Budiono
if [ -n "`which   losetup-FULL`"  ]; then
echo -e "\n=========== $(gettext 'SFS files loaded') ============\n"  >> /tmp/report-video
losetup-FULL -a | sed '/loop[0-3]:/ d;s_^.*/__;s/)$//' | sort  >> /tmp/report-video
fi


User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

version 1.4 of bulldog finder

#8 Post by don570 »

Version 1.4 of Bulldog finder uses this code to make a list of
mounted drives

http://murga-linux.com/puppy/viewtopic.php?t=78592


.

User avatar
don570
Posts: 5528
Joined: Wed 10 Mar 2010, 19:58
Location: Ontario

#9 Post by don570 »

I made small change to script to recognize the partitions
in a full install.
Attachments
drive-list2.sh.gz
remove gz extension to obtain script
(1.89 KiB) Downloaded 289 times

Post Reply