From c994406bba73dedd7d060e2b1a14ee453c7d608a Mon Sep 17 00:00:00 2001 From: Paulo Roma Cavalcanti Date: Jan 15 2010 20:00:00 +0000 Subject: updated to 2.0.1 --- diff --git a/.cvsignore b/.cvsignore index 8f30c5f..47a8dac 100644 --- a/.cvsignore +++ b/.cvsignore @@ -1,2 +1,2 @@ fmcontrol.tar.gz -fmtools-1.0.2.tar.gz +fmtools-2.0.1.tar.gz diff --git a/fmlircrc b/fmlircrc new file mode 100644 index 0000000..8d7a6d4 --- /dev/null +++ b/fmlircrc @@ -0,0 +1,126 @@ +# File: .fmlircrc +# Remote Control: Pixelview PlayTV MPEG2 PV-M4900 FM.RC +# Author: Paulo Roma on 28/12/2009 +# Configuration file for fmtools-tkradio. +# +begin + prog = tkradio + button = power + config = quit +end + +begin + prog = tkradio + button = ch+ + config = next +end + +begin + prog = tkradio + button = ch- + config = previous +end + +begin + prog = tkradio + button = mute + config = off +end + +begin + prog = tkradio + button = rec + config = rec +end + +begin + prog = tkradio + button = stop + config = stop +end + +begin + prog = tkradio + button = play + config = on +end + +begin + prog = tkradio + button = loop + config = loop +end + +begin + prog = tkradio + button = vol+ + config = volup +end + +begin + prog = tkradio + button = vol- + config = voldown +end + +begin + prog = tkradio + button = 1 + config = 1 +end + +begin + prog = tkradio + button = 2 + config = 2 +end + +begin + prog = tkradio + button = 3 + config = 3 +end + +begin + prog = tkradio + button = 4 + config = 4 +end + +begin + prog = tkradio + button = 5 + config = 5 +end + +begin + prog = tkradio + button = 6 + config = 6 +end + +begin + prog = tkradio + button = 7 + config = 7 +end + +begin + prog = tkradio + button = 8 + config = 8 +end + +begin + prog = tkradio + button = 9 + config = 9 +end + +begin + prog = tkradio + button = 0 + config = 0 +end + + diff --git a/fmtools.desktop b/fmtools.desktop new file mode 100644 index 0000000..2697ef1 --- /dev/null +++ b/fmtools.desktop @@ -0,0 +1,11 @@ +[Desktop Entry] +Name=tkradio +Comment=Python/Tk wrapper for fmtools +Exec=tkradio.py +Icon=radio +Terminal=0 +Type=Application +StartupNotify=false +StartupWMClass=tkradio +Encoding=UTF-8 +Categories=Application;AudioVideo; diff --git a/fmtools.spec b/fmtools.spec index d1b0767..240fbdb 100644 --- a/fmtools.spec +++ b/fmtools.spec @@ -1,71 +1,137 @@ -Summary: Simple Video for Linux radio card programs -Name: fmtools -Version: 1.0.2 -Release: 6%{?dist} -License: GPLv2+ -Group: Applications/Multimedia -URL: http://www.stanford.edu/~blp/fmtools/ -Source0: http://www.stanford.edu/~blp/%{name}/%{name}-%{version}.tar.gz -Source1: fmcontrol.tar.gz -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +Summary: Simple Video for Linux radio card programs +Name: fmtools +Version: 2.0.1 +Release: 1%{?dist} +License: GPLv2+ +Group: Applications/Multimedia +URL: http://www.stanford.edu/~blp/fmtools/ +Source0: http://benpfaff.org/fmtools/%{name}-%{version}.tar.gz +Source1: fmcontrol.tar.gz +Source2: http://www.stanford.edu/~blp/fmtools/tkradio +Source3: http://www.stanford.edu/~blp/fmtools/tkradio-mute +Source4: fmtools.desktop +Source5: radio.png +Source8: radio.gif +Source6: tkradio.py +Source7: fmlircrc +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) %description This is a pair of hopefully useful control programs for Video for Linux -(v4l) radio card drivers. The focus is on control, so you may find these +(v4l2) radio card drivers. The focus is on control, so you may find these programs a bit unfriendly. Users are encouraged to investigate the source and create wrappers or new programs based on this design. - fm - a simple tuner - fmscan - a simple band scanner - -The script fmcontrol is something Adrian Lester put together one evening to -save from himself having to remember frequencies and volumes when using the fm -program from fmtools by Russell Kroll. - -The script does not support any of fm's command line options with the -exception of volume. - -All that it does is to tune in to a station specified by name at the -frequency and volume specified in $HOME/.fmrc and $HOME/.radiostations +fm - a simple tuner +fmscan - a simple band scanner + +%package tkradio +Summary: Python/Tk wrapper for fmtools +Group: Applications/Multimedia +BuildRequires: desktop-file-utils +Requires: %{name} = %{version} +Requires: python, python-lirc, notify-python +Requires: vorbis-tools, tkinter, alsa-utils +BuildArch: noarch + +%description tkradio +This package provides a GUI for %{name}, with lirc support. +The stations are read from the same files used by fmcontrol, +and the lirc configuration file is in $HOME/.fmlircrc + +The script fmcontrol.py saves one from remembering frequencies +and volumes when using the "fm" program from %{name}. +All that it does is to tune into a station specified by name, at the +frequency and volume specified in $HOME/.fmrc or $HOME/.radiostations, or the volume given on the command line. %prep -%setup0 -q -# include fmcontrol script -tar xzvf %{SOURCE1} -install -pm 0644 fmcontrol/README README.fmcontrol - -# Fix Makefile -sed -i -e 's|/usr/local/bin|%{_bindir}|' Makefile -sed -i -e 's|/usr/local/man|%{_mandir}|' Makefile -sed -i -e 's|-Wall -O2|$(RPM_OPT_FLAGS)|' Makefile - -# Remove header -rm videodev.h -sed -i.header -e 's|"videodev.h"||'g fm.c fmscan.c - -# Add shebang to fmcontrol -sed -i '1i#!/bin/sh' fmcontrol/fmcontrol +%setup -q -a1 %build -make %{?_smp_mflags} +%configure +make %{_smp_mflags} %install -rm -rf $RPM_BUILD_ROOT -make install DESTDIR=$RPM_BUILD_ROOT INSTALL="install -p" -install -pm 0755 fmcontrol/fmcontrol $RPM_BUILD_ROOT%{_bindir} +rm -rf %{buildroot} +make DESTDIR=%{buildroot} install +install -pm 0755 %{SOURCE2} %{buildroot}%{_bindir}/tkradio.tcl +install -pm 0755 %{SOURCE3} %{buildroot}%{_bindir}/tkradio-mute.tcl +install -pm 0755 %{SOURCE6} %{buildroot}%{_bindir}/tkradio.py +install -pm 0755 fmcontrol/fmcontrol %{buildroot}%{_bindir}/fmcontrol.py +install -pm 0644 fmcontrol/README README.fmcontrol + +# menu entry +desktop-file-install \ + --vendor "" \ + --dir %{buildroot}%{_datadir}/applications \ + %{SOURCE4} + +install -Dpm 0644 %{SOURCE5} %{buildroot}%{_datadir}/pixmaps/radio.png +install -Dpm 0644 %{SOURCE7} %{buildroot}%{_datadir}/%{name}/fmlircrc +install -Dpm 0644 %{SOURCE8} %{buildroot}%{_datadir}/%{name}/radio.gif %clean -rm -rf $RPM_BUILD_ROOT +rm -rf %{buildroot} -%files +%files %defattr(-,root,root,-) -%doc CHANGES COPYING README README.fmcontrol fmcontrol/dot.* -%{_bindir}/* -%{_mandir}/man1/* +%doc README COPYING +%{_bindir}/fm +%{_bindir}/fmscan +%{_mandir}/man1/fm*.gz +%files tkradio +%defattr(-,root,root,-) +%doc README.fmcontrol fmcontrol/dot.* +%{_bindir}/tkradio* +%{_bindir}/fmcontrol.py +%{_datadir}/applications/fmtools.desktop +%{_datadir}/pixmaps/radio.png +%{_datadir}/%{name}/fmlircrc +%{_datadir}/%{name}/radio.gif %changelog + +* Sat Jan 09 2010 Paulo Roma 2.0.1-1 +- Updated to 2.0.1 +- Removed fmtools.patch +- Added man pages. + +* Thu Jan 07 2010 Paulo Roma 2.0-10 +- Fixed grep expression in tkradio.py + +* Sat Jan 02 2010 Paulo Roma 2.0-9 +- Added libnotify support. +- Addded compression using oggenc. +- Added window icon. + +* Sun Dec 30 2009 Paulo Roma 2.0-8 +- Added recording support. + +* Sun Dec 27 2009 Paulo Roma 2.0-7 +- Replaced fmcontrol for fmcontrol.py +- Moved fmcontrol to tkradio package. +- Added lirc support. + +* Sun Dec 23 2009 Paulo Roma 2.0-5 +- Replaced BR tk for tkinter. + +* Sun Dec 23 2009 Paulo Roma 2.0-4 +- Include tkradio.py +- Fixed fmtools.desktop + +* Sun Dec 20 2009 Paulo Roma 2.0-3 +- Packaging tkradio separately. + +* Sun Dec 20 2009 Paulo Roma 2.0-2 +- Patched to make it work. +- Added desktop entry. + +* Sun Dec 13 2009 Paulo Roma 2.0-1 +- Initial v4l2 support provided by version 2.0 +- Included tkradio and fmcontrol. + * Fri Jul 24 2009 Fedora Release Engineering - 1.0.2-6 - Rebuilt for https://fedoraproject.org/wiki/Fedora_12_Mass_Rebuild @@ -75,7 +141,7 @@ rm -rf $RPM_BUILD_ROOT * Fri Oct 17 2008 kwizart < kwizart at gmail.com > - 1.0.2-4 - Rebuild for F-10 -* Sat Feb 9 2008 kwizart < kwizart at gmail.com > - 1.0.2-3 +* Sat Feb 09 2008 kwizart < kwizart at gmail.com > - 1.0.2-3 - Rebuild for gcc43 * Fri Sep 21 2007 kwizart - 1.0.2-2 @@ -87,6 +153,5 @@ rm -rf $RPM_BUILD_ROOT * Sun Aug 26 2007 kwizart - 1.0.2-1 - Update to 1.0.2 -* Mon Sep 4 2006 TC Wan +* Mon Sep 04 2006 TC Wan - Built Version 1.0 for FC 5 - diff --git a/import.log b/import.log new file mode 100644 index 0000000..f65661e --- /dev/null +++ b/import.log @@ -0,0 +1 @@ +fmtools-2_0_1-1_fc12:HEAD:fmtools-2.0.1-1.fc12.src.rpm:1263585439 diff --git a/radio.gif b/radio.gif new file mode 100644 index 0000000..d247728 Binary files /dev/null and b/radio.gif differ diff --git a/radio.png b/radio.png new file mode 100644 index 0000000..d1d89db Binary files /dev/null and b/radio.png differ diff --git a/sources b/sources index f326498..240ca82 100644 --- a/sources +++ b/sources @@ -1,2 +1,2 @@ -fe40296a7515f506c6b46a0ec7f056eb fmcontrol.tar.gz -4bae0e5feeb8cbf4cfcb950301e9509d fmtools-1.0.2.tar.gz +8accad958c3f0cd0fb582aad922857aa fmcontrol.tar.gz +5b48f552180f18d46fe92124b2fcfca0 fmtools-2.0.1.tar.gz diff --git a/tkradio b/tkradio new file mode 100644 index 0000000..99255ca --- /dev/null +++ b/tkradio @@ -0,0 +1,66 @@ +#!/usr/bin/wish +# Matt Willis - simple tk interface to fmtools +# The radio keeps on after leaving. +# -*- tcl -*- + +# These are stations in the Rio de Janeiro area. Customize for your own locale. +set stations \ + " + MPB 90.3 + CBN 92.5 + BandNews 94.9 + PARADISO 95.7 + Nativa 96.5 + 98FM 98.0 + MEC 98.9 + JBFM 99.7 + O_Dia 100.5 + Transamerica 101.3 + JovenPan 102.1 + Oi 102.9 + Antena1 103.7 + " + +# intial volume +set volume 100 +set n [expr [llength $stations]/2] +# default radio station +set radbut 3 + +# make tuner buttons +frame .labels +for {set i 0} {$i<$n} {incr i 1} { + radiobutton .r$i -value $i -variable radbut \ + -text [lindex $stations [expr $i *2]] -command setstation + pack .r$i -anchor w -in .labels +} + +# turns the radio on +eval exec fm on + +frame .rhs +scale .vol -orient horizontal -from 0 -to 100 -showvalue 0 \ + -variable volume -label Volume: +entry .stn -bg black -fg yellow -font "-*-helvetica-*-r-*-*-60-*-*-*-*-*-*-*" \ + -width 6 -justify right -state disabled +button .exit -command exit -text exit +pack .vol .stn .exit -in .rhs + +pack .labels .rhs -side left +.vol configure -command setvolume + +proc setstation {} { + global stations radbut volume +# roma 20091221 +# eval exec fm [lindex $stations [expr $radbut*2+1]] $volume + eval exec fm [lindex $stations [expr $radbut*2+1]] + eval exec amixer -q -c 0 set PCM $volume% + .stn configure -state normal + .stn delete 0 end + .stn insert 0 [lindex $stations [expr $radbut*2+1]] + .stn configure -state disabled +} + +proc setvolume {sliderval} { + setstation +} diff --git a/tkradio-mute b/tkradio-mute new file mode 100644 index 0000000..93c6d83 --- /dev/null +++ b/tkradio-mute @@ -0,0 +1,98 @@ +#!/usr/bin/wish +# Matt Willis - simple tk interface to fmtools +# mute button added by James Smith +# The radio is turned off after leaving. +# -*- tcl -*- + +# These are stations in the Rio de Janeiro area. Customize for your own locale. +set stations \ + " + MPB 90.3 + CBN 92.5 + BandNews 94.9 + PARADISO 95.7 + Nativa 96.5 + 98FM 98.0 + MEC 98.9 + JBFM 99.7 + O_Dia 100.5 + Transamerica 101.3 + JovenPan 102.1 + Oi 102.9 + Antena1 103.7 + " + +# initial volume [0,100] +set volume 100 +set n [expr [llength $stations]/2] +# default radio station +set radbut 3 +set rvol 100 +set state 0 + +# make tuner buttons +frame .labels +for {set i 0} {$i<$n} {incr i 1} { + radiobutton .r$i -value $i -variable radbut \ + -text [lindex $stations [expr $i *2]] -command setstation + pack .r$i -anchor w -in .labels +} + +# turns the radio on +eval exec fm on + +frame .rhs +scale .vol -orient horizontal -from 0 -to 100 -showvalue 0 \ + -variable volume -label Volume: +entry .stn -bg black -fg green -font "-*-helvetica-*-r-*-*-20-*-*-*-*-*-*-*" \ + -width 6 -justify right -state disabled +button .exit -command out -text exit +button .mute -command mute -text mute + +pack .vol .stn .exit .mute -in .rhs + + +pack .labels .rhs -side left +.vol configure -command setvolume + +proc setstation {} { + global stations radbut volume +# roma 20091221 +# eval exec fm [lindex $stations [expr $radbut*2+1]] $volume + eval exec fm [lindex $stations [expr $radbut*2+1]] + eval exec amixer -q -c 0 set PCM $volume% + .stn configure -state normal + .stn delete 0 end + .stn insert 0 [lindex $stations [expr $radbut*2+1]] + .stn configure -state disabled +} + +proc setvolume {sliderval} { + setstation +} + +proc out {} { + global stations radbut volume +# roma 20070217 +# eval exec fm [lindex $stations [expr $radbut*2+1]] 0 + eval exec fm off + exit +} + +proc mute {} { + global stations radbut volume rvol state + if {$state==0} { + set rvol $volume +# roma 20070217 +# eval exec fm [lindex $stations [expr $radbut*2+1]] 0 + eval exec fm off + set state 1 + .mute config -text unmute + + } else { +# eval exec fm [lindex $stations [expr $radbut*2+1]] $volume + eval exec fm on + set state 0 + .mute config -text mute + } +} diff --git a/tkradio.py b/tkradio.py new file mode 100644 index 0000000..1acb4e0 --- /dev/null +++ b/tkradio.py @@ -0,0 +1,503 @@ +#!/usr/bin/env python +# Paulo Roma - simple tkinter interface for fmtools, +# with lirc and recording support. +# Date: 23/12/2009 +# The radio is turned off on exit. + +from Tkinter import * +import Tkinter +import os, sys, string +import datetime, time +from threading import Thread +from subprocess import Popen, PIPE + +try: + import pylirc +except: + sys.exit ( "pylirc not found: http://pylirc.mccabe.nu/" ) + +try: + import pynotify + if pynotify.init("tkradio"): + use_notify = True + else: + use_notify = False + print "pynotify module initialization failed" +except: + use_notify = False + print "notify-python not found: http://www.galago-project.org/downloads.php" + +# These are stations in the Rio de Janeiro area. +# Customize for your own locale. They can be set +# in file ~/.fmrc or ~/.radiostations: +# station name, frequency and volume. + +stations = [["MPB", "90.3 100"], + ["CBN", "92.5 100"], + ["Band News", "94.9 100"], + ["Paradiso", "95.7 100"], + ["Tupy", "96.5 100"], + ["Beat98 FM", "98.0 100"], + ["MEC", "98.9 100"], + ["JB FM", "99.7 100"], + ["O Dia", "100.5 100"], + ["Transamerica", "101.3 100"], + ["Mix", "102.1 100"], + ["Oi", "102.9 100"], + ["Nativa", "103.7 100"]] + +radbut = stations[3][1] # default radio frequency +volume = 100 # initial volume [0,100] +state = False # keep track of mutting/unmutting +blocking = 0 # lirc blocking control +tid = 0 # recorder thread id +lid = 0 # loopback process id +fmrec = None # recorder thread variable +irrec = None # lirc thread variable + +class IRRec(Thread): + """Class for interacting with lirc.""" + + def __init__ (self, lirc_handle): + """Constructor.""" + + Thread.__init__ (self) + self.lirc_handle = lirc_handle + self.__on = True + + def stop ( self ): + """Kills this thread.""" + + self.__on = False + + def run(self): + """Run the thread code.""" + + code = {"config" : ""} + + while ( self.__on ): + # Delay... + time.sleep(1) + + s = pylirc.nextcode(1) + while ( s ): + for code in s: + if ( code["config"] == "next" ): + next() + elif ( code["config"] == "previous" ): + previous() + elif ( code["config"] == "off" ): + mute() + elif ( code["config"] == "on" ): + radio ("on") + elif ( code["config"] == "volup" ): + volup () + elif ( code["config"] == "voldown" ): + voldown() + elif ( code["config"] in "0123456789" ): + time.sleep(1) + b=pylirc.nextcode() + if ( b and b[0] in "0123456789" ): + code["config"] += b[0] + setStation ( int (code["config"]) ) + elif ( code["config"] == "rec" ): + rec_on() + elif ( code["config"] == "stop" ): + rec_off() + elif ( code["config"] == "loop" ): + loopon() + elif ( code["config"] == "quit" ): + quit() + else: + # Print all the configs... + print "Command: %s, Repeat: %d" % (code["config"], code["repeat"]) + if (not blocking): + s = pylirc.nextcode(1) + else: + s = [] + + # if we get here, the thread is over, so clean up lirc + pylirc.exit() + +class FMRec(Thread): + """Class for controlling the recording process.""" + + def __init__ (self): + """Constructor.""" + + Thread.__init__ (self) + self.__pid = 0 # arecord process id + self.__on = True # for implementing a thread stop, + # which python does not have + def __del__ (self): + """Destructor. Stops the recording, before quitting.""" + + self.stop() + + def stop ( self ): + + """Stops the recording, by killing the recorder process.""" + + global tid + + tid = 0 + + if ( self.__pid ): + os.kill ( self.__pid, 9 ) + self.__pid = 0 + self.__on = False + + def run(self): + """Start the thread.""" + + while (self.__on): + if ( not self.__pid ): + data = str(datetime.date.today()) + hora = list(time.localtime(time.time())) + hora = str(hora[3])+":"+str(hora[4])+":"+str(hora[5]) + rec_file = '/tmp/tkradio-'+fmstations[cur_station][0]+"-"+data+"-"+hora+'.ogg' + arec_param = ['/usr/bin/arecord', '-D', 'default', '-d', '0', '-f', 'cd', '-'] + ogge_param = ['/usr/bin/oggenc', '-', '-Q', '-o', rec_file] + if use_notify: + n = pynotify.Notification("tkradio recording on file:", rec_file, "/usr/share/pixmaps/radio.png") + n.show() + p1 = Popen(arec_param, stdout=PIPE) + p2 = Popen(ogge_param, stdin=p1.stdout) + self.__pid = p1.pid + + time.sleep(1.0) # Suspend execution for the given number of seconds + + # if we get here, the thread is finished + self.stop () + +def radio ( cmd ): + """Send the given command to the radio.""" + + os.system("fm "+cmd) + +def setCurStation ( frequency ): + """Update the current station.""" + + global cur_station + + ind = 0 + for st in fmstations: + if ( st[1] == frequency ): + cur_station = ind + break + ind += 1 + +def setstation(): + """Set the station chosen via Radio Button.""" + + freq = station.get() + changeStation ( freq ) + setCurStation ( freq ) + +def setStation(ind): + """Set the station to ind.""" + + if ( ind >= 0 and ind < ns ): + freq = fmstations[ind][1] + changeStation ( freq ) + setCurStation ( freq ) + +def changeStation ( st ): + """Set the station to the given station.""" + + radio ( st ) + freq.delete(0, END) + freq.insert(0,st.split()[0]) + station.set ( st ) + +def quit(): + """Quit the radio.""" + + radio ("off") + # kill all threads + if ( fmrec ): fmrec.stop() + if ( irrec ): irrec.stop() + if ( lid ): os.kill ( lid, 9 ) + + os._exit (0) + +def mute(): + """Mute/Unmute the radio.""" + + global state + + if ( not state ): + radio ("off") + state = True + btmute.set ( "On" ) + btm.config(state=ACTIVE) + else: + radio ("on") + state = False + btmute.set ( "Off" ) + btm.config(state=NORMAL) + +def on_move(value=0): + """Use slider position to set the volume.""" + + v = scale.get() + os.system("amixer -q -c 0 set PCM "+str(v)+"%") + +def volup (): + """Increases the volume.""" + + v = scale.get() + 5 + if ( v > 100 ): v = 100 + scale.set ( v ) + os.system("amixer -q -c 0 set PCM "+str(v)+"%") + +def voldown(): + """Decreases the volume.""" + + v = scale.get() - 5 + if ( v < 0 ): v = 0 + scale.set ( v ) + os.system("amixer -q -c 0 set PCM "+str(v)+"%") + +def enter (): + "Enter a new frequency.""" + + f = freq.get()+" "+ str(volume) + changeStation (f) + setCurStation (f) + +def readStations ( ): + """Read the preset station file.""" + + path = os.environ.get("HOME") + fname = path+"/.radiostations" + if ( not os.path.exists (fname) ): + fname = path+"/.fmrc" + + lst = [] + if ( os.path.exists (fname) ): + textf = open(fname, 'r') + + for line in textf: + l=line.split(None) + st = [l[0].replace("_"," "),l[1]+" "+l[2]] + lst.append ( st ) + textf.close() + return lst + +def next (): + "Go to the next station.""" + + global cur_station + cur_station = (cur_station + 1) % ns + changeStation ( fmstations[cur_station][1] ) + +def previous (): + "Go to the previous station.""" + + global cur_station + cur_station = (cur_station - 1) % ns + changeStation ( fmstations[cur_station][1] ) + +def trigger (): + """Creates a thread for recording.""" + + global tid, fmrec + + if ( not tid ): + fmrec = FMRec () + fmrec.start() + tid = 1 + +def loop(): + """Route the capture sources on the sound card back in as PCM audio.""" + + global lid + + if ( loopvar.get() == "ON" ): + if ( not lid ): + arec_param = ['/usr/bin/arecord', '-D', 'default', '-d', '0', '-f', 'cd'] + apla_param = ['/usr/bin/aplay', '-f', 'cd', '-D', 'default'] + p1 = Popen(arec_param, stdout=PIPE) + p2 = Popen(apla_param, stdin=p1.stdout) + lid = p1.pid + n = pynotify.Notification("tkradio", "Software Loop Back activated", + "/usr/share/pixmaps/radio.png") + n.set_timeout(2000) + n.show() + else: + if ( lid ): + os.kill ( lid, 9 ) + lid = 0 + +def loopon(): + """Toggles the loop variable.""" + + if ( loopvar.get() == "ON" ): + loopvar.set ("OFF") + else: + loopvar.set ("ON") + loop() + +def rec(): + """Record the current station.""" + + if ( recvar.get() == "ON" ): + rec_on() + else: + rec_off() + +def rec_on(): + """Turn the recorder on.""" + + recvar.set ("ON") + trigger() + +def rec_off(): + """Turn the recorder off.""" + + recvar.set ("OFF") + if ( fmrec ): fmrec.stop() + +def mouse_wheel(event): + """Respond to mouse wheel events.""" + + if event.num == 5 or event.delta == -120: + voldown () + if event.num == 4 or event.delta == 120: + volup () + +def str2num(datum): + """A conversion function that "guesses" the best conversion.""" + + try: + return int(datum) + except: + try: + return float(datum) + except: + return datum + +def main (argv=None): + """Main program.""" + + global scale # volume scale + global station # variable for the station radio buttons + global btmute # variable for the text in the mute button + global btm # mute button + global freq # variable for manually entering a frequency + global fmstations # preset fm stations + global cur_station # current station + global ns # number of preset fm stations + global recvar # variable for setting record on/off + global loopvar # variable for setting loopback on/off + global irrec # lirc thread variable + global lid # loopback process id + + if argv is None: + argv = sys.argv + + pyversion = string.split(sys.version)[0] + print "Python Version: ", pyversion + + # check whether tkradio is already running + stat = os.popen ("/bin/ps aux | /bin/grep -E \"python(" + pyversion[0:3] + ")? " + argv[0] + "\"").readline() + cid = os.getpid() + if ( stat ): + pid = stat.split()[1] + if ( cid != int(pid) ): + sys.exit ( "%s is already running: pid = %s" %(argv[0], pid) ) + + mw = Tk() + # do not resize the radio + mw.resizable(False,False) + + station = StringVar() + station.set ( radbut ) + + btmute = StringVar() + btmute.set ( "Off" ) + + top = Frame(); top.pack() + bbt = Frame(); bbt.pack() + bot = Frame(); bot.pack() + mw.title ("tkradio") + + fmstations = readStations ( ) + if ( not fmstations ): + fmstations = stations + ns = len ( fmstations ) + cur_station = -1 + + # make tuner buttons + for st in fmstations: + Radiobutton(bot,text=st[0],value=st[1],variable=station,command=setstation).pack(anchor=W) + + scale = Scale(top, from_=0, to=100, orient=HORIZONTAL, command=on_move, bd=0, + sliderlength=10, width=5, showvalue=0) + scale.pack(side='top') + scale.set(volume) + + # the current radio frequency + Button(bbt,text="<", command = previous).pack(side="left",anchor=E) + Button(bbt,text="Enter", command = enter).pack(side="left") + Button(bbt,text=">", command = next).pack(side="left",anchor=W) + freq=Entry(top,font="Arial 24",width=5,justify=CENTER) + freq.insert(0,station.get()) + freq.pack(side="bottom") + + recvar = StringVar() # creates a checkbutton for the alarm state + loopvar = StringVar() # creates a checkbutton for the loopback + recvar.set ( "OFF" ) + aid = os.popen ( '/sbin/pidof arecord' ).readline() + aid = aid.replace('\n','') + aid = str2num(aid) + if ( aid ): # is the loop back already on? + loopvar.set ( "ON" ) + lid = aid + else: + loopvar.set ( "OFF" ) + + # create quit and mute buttons + Button(top,text="Exit", command = quit).pack(side="right") + btm=Button(top,text="Off", command = mute, textvariable = btmute) + btm.pack(side="left") + Checkbutton (top, text="Rec", variable=recvar, onvalue="ON", offvalue="OFF", command=rec).pack(side="top",anchor=W) + Checkbutton (top, text="Loop", variable=loopvar, onvalue="ON", offvalue="OFF", command=loop).pack(side="right") + + # mouse whell control + mw.bind("", mouse_wheel) + mw.bind("", mouse_wheel) + + # turn the radio on + setstation() + radio ("on") + + # set an icon for the window + icon_img = PhotoImage(file="/usr/share/fmtools/radio.gif") + mw.tk.call('wm', 'iconphoto', mw._w, icon_img) + + lircid = os.popen ( '/sbin/pidof lircd' ).readline() + if ( lircid ): # is lirc running? + # handle lirc events + path = os.environ.get("HOME") + fname = path+"/.fmlircrc" + if ( not os.path.exists (fname) ): + fname = "/usr/share/fmtools/fmlircrc" + lirc_handle = pylirc.init("tkradio", fname, blocking) + if (lirc_handle): + if ( use_notify ): + n = pynotify.Notification("tkradio", "Successfully opened lirc. Handle is "+str(lirc_handle), + "/usr/share/pixmaps/radio.png") + n.set_timeout(2000) + n.show() + irrec = IRRec(lirc_handle) + irrec.start() + + top.mainloop() + +try: + if __name__=="__main__": + sys.exit(main()) +except KeyboardInterrupt,SystemExit: + quit()