Version 7 of Gnocl JukeBox

Updated 2011-03-18 12:34:06 by RLE

WJG (17/03/11) I don't like bloatware. I like things simple, like me. The media players that ship with our Distros are just too complicated and well, annoying. I wanted to listen to my favourite audio tracks whilst working this morning and was so fed up of fiddling with apps that I thought: "Gnocl has built-in sound playback, let's build a custom jukebox!" So, here it is.

#---------------
# playOGG.tcl
#---------------
#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

set box [gnocl::box -orientation vertical]

set i 0
foreach track [lsort [glob *.ogg]] {
        set b($i) [gnocl::button \
                -icon %#Cdrom \
                -text $track \
                -onClicked "gnocl::sound \"$track\""]
        $box add $b($i)
        incr i
}

gnocl::window -child $box
gnocl::mainLoop

WJG (18/03/11) The problem with little nibbles like the one above is that they make me greedy, I want more. After a little while bloating might occur! However, all that extra power comes from the Gnocl bindings to the Gtk+ libraries so even the a growing Tcl based app remains slim.

Yesterday I listened to my favourite Italian madrigals all day long and wanted a bit of a change. So, modified the code somewhat to allow directory changes and used a gnocl::list widget rather than buttons. Much nicer. I think that I'll listen to my favourite Vivaldi guitar concertos today. Here's my screenshot:

https://lh3.googleusercontent.com/_yaFgKvuZ36o/TYNP8_Y8tsI/AAAAAAAAA2c/OOJo0qyMqm4/s800/Screenshot-JukeBox%20%281.0%29.png

And the script:

#---------------
# jukeBox.tcl
#---------------
#!/bin/sh
#\
exec tclsh "$0" "$@"

package require Gnocl

#---------------
# create playlist
#---------------
proc playList { dir {type ogg} } {
        global lst

        cd  $dir

        # clear the existing playlist
        $lst erase 0 end

        set tracks ""
        catch { set tracks [glob *.ogg] }

        if {$tracks == ""} {
                makeUI [gnocl::fileChooserDialog \
                        -title "JukeBox: No tracks found. Select Collection Folder.." \
                        -action openFolder \
                        -currentFolder $dir ]
        }

        foreach track [lsort $tracks] {
                $lst add [list [list $track]]
                }
}

#---------------
# make ui
#---------------
proc makeUI {dir} {
        global lst

        cd $dir

        set cb [gnocl::folderChooserButton \
                -title "JukeBox: Select Collection Folder" \
                -onFileSet {playList %f}]

        set lst [gnocl::list \
                -titles {"Track"} \
                -types {string } \
                -onSelectionChanged {
                        gnocl::sound [%w get %p 0 ]
                        }]

        playList $dir

        set box [gnocl::box -orientation vertical]
        $box add $cb
        $box add $lst -expand 1 -fill {1 1}

        gnocl::window \
                -title "JukeBox (1.0)" \
                -child $box \
                -onDelete exit
}

#---------------
# use specified directory or pick a new one
#---------------
 if { $::argc > 0 } {
         makeUI $::argv
  } else {
        # select a directory
        makeUI [gnocl::fileChooserDialog \
                -title "JukeBox: Select Collection Folder" \
                -action openFolder \
                -currentFolder $::env(HOME)/Music ]
  }