meta data for this page
  •  

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
maemo:shared_code [2011/08/18 19:38]
japskua [Template]
maemo:shared_code [2011/08/18 23:18]
grp4
Line 4: Line 4:
  
 So, add the codes underneath. You can copy the template underneath and just add to the line: So, add the codes underneath. You can copy the template underneath and just add to the line:
 +
 +===== Tutorial for PyGtk =====
 +http://www.pygtk.org/pygtk2tutorial/
 +
 +though not every function in pygtk library does work in maemo as developer were too lazy and didn't import them. like no scrollbar or slidebar exist in maemo.
 +
 +some examples
 +<code python examples.py>
 +        a= gtk.CheckButton("check button 1")
 +        hbox.pack_start(a, True, True, 0)
 +        
 +        b= gtk.ToggleButton("check button 1")
 +        hbox.pack_start(b, True, True, 0)
 +        
 +        c = gtk.RadioButton(None, "radio button1")
 +        hbox.pack_start(c, True, True, 0)
 +        
 +        adjus = gtk.Adjustment(value=60, lower=0, upper=100, step_incr=1, page_incr=0, page_size=0)
 +        d = gtk.SpinButton(adjustment= adjus, climb_rate=0.1, digits=5)
 +        hbox.pack_start(d, True, True, 0)
 +        
 +        combo = gtk.Combo()
 +        combo.entry.set_text("text")
 +        slist = [ "String 1", "String 2", "String 3", "String 4" ]
 +        combo.set_popdown_strings(slist)
 +        hbox.pack_start(combo, True, True, 0)
 +</code>
 +
 +===== Software playtrought =====
 +
 +  * Group: Esa-Petri and Hilmi
 +  * Description: program to play voice from mic
 + 
 +
 +<code python MeHear.py>
 +from optparse import OptionParser
 +from time import sleep
 +
 +import sys, os
 +import pygtk, gtk, gobject 
 +import dbus
 +import gst
 +import pygst
 +import sys
 +import time
 +import gtk 
 +import hildon
 +
 +
 +class Record():
 +    mic = None
 +    
 +    def __init__(self, sink):
 +        """
 +        @summary: The Constructor class, that searches for the microphone on initialization
 +        """
 +        bus = dbus.SystemBus()
 +        hal_manager = bus.get_object("org.freedesktop.Hal",
 +                                     "/org/freedesktop/Hal/Manager")
 +        hal_manager = dbus.Interface(hal_manager, "org.freedesktop.Hal.Manager")
 + 
 +        print hal_manager
 +        devices = hal_manager.FindDeviceStringMatch("alsa.type", "capture")
 + 
 +        identifiers = []
 + 
 +        for dev in devices:
 +            device = bus.get_object("org.freedesktop.Hal", dev)
 + 
 +            card = device.GetAllProperties(dbus_interface="org.freedesktop.Hal.Device")
 +            if card["alsa.card"] not in identifiers:
 +                print "%d. %s" % (card["alsa.card"], card["alsa.card_id"])
 +                identifiers.append(card["alsa.card"])
 + 
 +        self.mic = identifiers[0] 
 +        
 +        """
 +        @attention: this is important it initializes softfare playtrought (audioconvert is not nesesity)
 +        @summary: takes stream from mic to autosink
 +        """
 +        self.pipeline = gst.parse_launch("""alsasrc device=hw:%d  ! audioconvert ! autoaudiosink location=%s""" % (self.mic, sink))
 +                   
 +        
 +    def rec(self):
 +        """
 +        @summary: sets recording on
 +        """
 +        self.pipeline.set_state(gst.STATE_PLAYING)
 +        print ""
 +        print "recording started"
 +            
 +            
 +    def stoprec(self):    
 +        """
 +        @summary: sets recording off
 +        """  
 +        self.pipeline.set_state(gst.STATE_NULL)
 +        print ""
 +        print "recording, stoped"
 +        
 +        
 +class Prosesor():
 +    """
 +    @summary: Takes care of prossesing the sound
 +    """
 +    
 +    
 +    def __init__(self):
 +        volume=0
 +        gain =0
 +        CutThereshold=0
 +        
 +        
 +    def proses(self,volume, gain, comp):
 +        a=1
 +        
 +        
 +        
 +        
 +class player():
 +    def __init__(self):
 +        """
 +        @summary: player part
 +        """        
 +        self.player = gst.element_factory_make("playbin2", "player")
 +        fakesink = gst.element_factory_make("fakesink", "fakesink")
 +        self.player.set_property("video-sink", fakesink)
 +        
 +        audiosink = gst.element_factory_make("autoaudiosink", "audio-output")
 +        self.recorder=Record(audiosink)
 +        """
 +        @attention: next links raw data from mic to player mekanism of gstreamer 
 +        """
 +        self.player.set_property("audio-sink",audiosink)
 +        self.playmode = True
 +        
 +        bus = self.player.get_bus()
 +        bus.add_signal_watch()
 +        bus.connect("message", self.on_message)
 +        
 +        
 +
 +    def on_message(self, bus, message):
 +        t = message.type
 +        if t == gst.MESSAGE_EOS:
 +            self.player.set_state(gst.STATE_NULL)
 +            self.playmode = False
 +        elif t == gst.MESSAGE_ERROR:
 +            self.player.set_state(gst.STATE_NULL)
 +            err, debug = message.parse_error()
 +            print "Error: %s" % err, debug
 +            self.playmode = False
 +                
 +    def play(self):
 +        self.recorder.rec()
 +        self.player.set_state(gst.STATE_PLAYING)
 +        print "playing"
 +        
 +        
 +    def stop(self):
 +        #self.playmode = False
 +        self.player.set_state(gst.STATE_NULL)
 +        self.recorder.stoprec()
 +        print "stoped"
 +
 +
 +
 +
 +
 +class MeHear(hildon.Program):
 +    def __init__(self):
 +        self.pl= player()  
 +                       
 +        
 +    def amplify_button_clicked(self,button, label):   
 +        buttontext = button.get_label()
 +        text =  buttontext
 +        if text == "AMPlify" :
 +            label.set_text("")
 +            button.set_label("Stop")
 +            self.pl.play()
 +            print "play button pressed"
 +            
 +        if text == "Stop" :
 +            label.set_text("Stopped")
 +            button.set_label("AMPlify")
 +            self.pl.stop()
 +            print "stop button pressed"
 +            
 +        
 +            
 +    def main(self):
 +        win = hildon.StackableWindow()
 +     
 +        # Create and pack labels
 +        vbox = gtk.VBox(False, 10)
 +        hbox = gtk.HBox(False, 10)
 +     
 +        #interface.. buttons, labels ,... etc
 +        labelHeader = gtk.Label("Application header")
 +        labelSubHeader = gtk.Label("-")
 +     
 +#        buttonGTK1 = gtk.Button("Record")
 +#        buttonGTK1.connect("clicked", self.record_button_clicked, labelSubHeader)
 +     
 +        buttonGTK = gtk.Button("AMPlify")
 +        buttonGTK.connect("clicked", self.amplify_button_clicked, labelSubHeader)
 +     
 +#        hbox.pack_start(buttonGTK1, True, True, 0)
 +        hbox.pack_start(buttonGTK, True, True, 0)
 +     
 +        vbox.pack_start(labelHeader, True, True, 0)
 +        vbox.pack_start(labelSubHeader, True, True, 0)
 +        vbox.pack_start(hbox, True, True, 0)
 +        
 +        
 +     
 +        # Add label's box to window
 +        win.add(vbox)
 +     
 +        win.connect("delete_event", gtk.main_quit)
 +     
 +        win.show_all()
 +     
 +        gtk.main()
 +    
 +    
 +if __name__ == "__main__":  
 +    
 +    app = MeHear() 
 +    app.main()
 +</code>
 +
 +
  
 ===== Sending SMS ===== ===== Sending SMS =====