#!/usr/bin/python """ pymemos - play voice memos recorded by memorec Copyright (c) 2002 by Dave W Capella All Rights Reserved This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --------------------------------------------------------------------------- Developed on a Compaq iPaq 3835: Linux pda 2.4.17-rmk5 #15 Mon Mar 11 18:43:52 EST 2002 armv4l unknown Feedback welcome: dave.capella@cornell.edu """ import os #import sys import gtk import string def delsound(fnam): filename = "/mnt/ramfs/"+fnam try: os.remove(filename) except: print "unable to delete file" def playit(fnam): filename = "/mnt/ramfs/"+fnam try: fin=open(filename,"r") except: print "unable to open file %s" % filename return try: fout=open("/dev/dsp","w") except: print "unable to open sound device, /dev/dsp." return # print "playing %s" % filename fout.write(fin.read()) fin.close() fout.close() class HButtonBox(gtk.GtkHButtonBox): def __init__(self, buttons): gtk.GtkHButtonBox.__init__(self) self.set_spacing(0) self.set_child_ipadding_default(0, 0) self.set_child_size_default(0,0) for button in buttons: self.add(button) class Button(gtk.GtkButton): def __init__(self, title, onclicked, name=None): gtk.GtkButton.__init__(self,title) self.connect("clicked", onclicked) if name: self.set_name(name) class memos(gtk.GtkWindow): def __init__(self): gtk.GtkWindow.__init__(self,gtk.WINDOW_TOPLEVEL) self.set_name("pyMemos") self.set_title("pyMemos") self.connect('destroy',gtk.mainquit) self.playbtn = Button("Play",self.OnPlay) self.delbtn = Button("Delete",self.OnDel) self.refbtn = Button("Refresh",self.OnRefresh) self.quitbtn = Button("Quit",self.OnDestroy) self.buttons = HButtonBox([self.playbtn,self.delbtn,self.refbtn,self.quitbtn]) self.clist = gtk.GtkCList() self.makelist(self.clist) self.sw = gtk.GtkScrolledWindow() self.sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.sw.add_with_viewport(self.clist) self.clist.connect("select_row",self.OnSel) self.vbox = gtk.GtkVBox() self.add(self.vbox) self.vbox.pack_start(self.buttons) self.vbox.pack_end(self.sw) self.show_all() self.selected = -1 def makelist(self,clist): self.clist.clear() for filename in os.listdir("/mnt/ramfs"): if string.find(filename,'voice') == 0: self.clist.append([filename]) self.selected = -1 def OnSel(self,clist,r,c,ev): self.selected = r f = self.clist.get_text(self.selected,0) def OnPlay(self,widget): if self.selected >= 0: f = self.clist.get_text(self.selected,0) playit(f) self.makelist(self.clist) def OnDel(self,widget): if self.selected >= 0: f = self.clist.get_text(self.selected,0) delsound(f) self.makelist(self.clist) def OnRefresh(self,clist): self.makelist(self.clist) def OnDestroy(self,widget): gtk.mainquit() def main(): mw = memos() gtk.mainloop() if __name__ == "__main__": main()