meta data for this page
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| maemo:shared_code [2011/08/18 19:38] – [Template] japskua | maemo:shared_code [2011/08/18 23:19] (current) – 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:// | ||
| + | |||
| + | 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> | ||
| + | def main(self): | ||
| + | # place where fin info about pygtk http:// | ||
| + | win = hildon.StackableWindow() | ||
| + | |||
| + | # Create and pack labels | ||
| + | vbox = gtk.VBox(False, | ||
| + | hbox = gtk.HBox(False, | ||
| + | |||
| + | # | ||
| + | labelHeader = gtk.Label(" | ||
| + | labelSubHeader = gtk.Label(" | ||
| + | |||
| + | # buttonGTK1 = gtk.Button(" | ||
| + | # buttonGTK1.connect(" | ||
| + | |||
| + | buttonGTK = gtk.ToggleButton(" | ||
| + | buttonGTK.connect(" | ||
| + | | ||
| + | #a= gtk.CheckButton(" | ||
| + | # | ||
| + | | ||
| + | #b= gtk.ToggleButton(" | ||
| + | # | ||
| + | | ||
| + | #c = gtk.RadioButton(None, | ||
| + | # | ||
| + | | ||
| + | #adjus = gtk.Adjustment(value=60, | ||
| + | #d = gtk.SpinButton(adjustment= adjus, climb_rate=0.1, | ||
| + | # | ||
| + | #hscrollbar = gtk.HSscrollbar(adjustment) | ||
| + | | ||
| + | # | ||
| + | combo = gtk.Combo() | ||
| + | combo.entry.set_text(" | ||
| + | slist = [ " | ||
| + | combo.set_popdown_strings(slist) | ||
| + | hbox.pack_start(combo, | ||
| + | | ||
| + | hbox.pack_start(buttonGTK, | ||
| + | |||
| + | vbox.pack_start(labelHeader, | ||
| + | vbox.pack_start(labelSubHeader, | ||
| + | vbox.pack_start(hbox, | ||
| + | | ||
| + | | ||
| + | |||
| + | # Add label' | ||
| + | win.add(vbox) | ||
| + | |||
| + | win.connect(" | ||
| + | |||
| + | win.show_all() | ||
| + | |||
| + | gtk.main() | ||
| + | </ | ||
| + | |||
| + | ===== Software playtrought ===== | ||
| + | |||
| + | * Group: Esa-Petri and Hilmi | ||
| + | * Description: | ||
| + | |||
| + | |||
| + | <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, | ||
| + | """ | ||
| + | @summary: The Constructor class, that searches for the microphone on initialization | ||
| + | """ | ||
| + | bus = dbus.SystemBus() | ||
| + | hal_manager = bus.get_object(" | ||
| + | "/ | ||
| + | hal_manager = dbus.Interface(hal_manager, | ||
| + | |||
| + | print hal_manager | ||
| + | devices = hal_manager.FindDeviceStringMatch(" | ||
| + | |||
| + | identifiers = [] | ||
| + | |||
| + | for dev in devices: | ||
| + | device = bus.get_object(" | ||
| + | |||
| + | card = device.GetAllProperties(dbus_interface=" | ||
| + | if card[" | ||
| + | print "%d. %s" % (card[" | ||
| + | identifiers.append(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(""" | ||
| + | |||
| + | | ||
| + | def rec(self): | ||
| + | """ | ||
| + | @summary: sets recording on | ||
| + | """ | ||
| + | self.pipeline.set_state(gst.STATE_PLAYING) | ||
| + | print "" | ||
| + | print " | ||
| + | | ||
| + | | ||
| + | def stoprec(self): | ||
| + | """ | ||
| + | @summary: sets recording off | ||
| + | """ | ||
| + | self.pipeline.set_state(gst.STATE_NULL) | ||
| + | print "" | ||
| + | print " | ||
| + | | ||
| + | | ||
| + | class Prosesor(): | ||
| + | """ | ||
| + | @summary: Takes care of prossesing the sound | ||
| + | """ | ||
| + | | ||
| + | | ||
| + | def __init__(self): | ||
| + | volume=0 | ||
| + | gain =0 | ||
| + | CutThereshold=0 | ||
| + | | ||
| + | | ||
| + | def proses(self, | ||
| + | a=1 | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | class player(): | ||
| + | def __init__(self): | ||
| + | """ | ||
| + | @summary: player part | ||
| + | """ | ||
| + | self.player = gst.element_factory_make(" | ||
| + | fakesink = gst.element_factory_make(" | ||
| + | self.player.set_property(" | ||
| + | | ||
| + | audiosink = gst.element_factory_make(" | ||
| + | self.recorder=Record(audiosink) | ||
| + | """ | ||
| + | @attention: next links raw data from mic to player mekanism of gstreamer | ||
| + | """ | ||
| + | self.player.set_property(" | ||
| + | self.playmode = True | ||
| + | | ||
| + | bus = self.player.get_bus() | ||
| + | bus.add_signal_watch() | ||
| + | bus.connect(" | ||
| + | | ||
| + | | ||
| + | |||
| + | def on_message(self, | ||
| + | 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 " | ||
| + | self.playmode = False | ||
| + | | ||
| + | def play(self): | ||
| + | self.recorder.rec() | ||
| + | self.player.set_state(gst.STATE_PLAYING) | ||
| + | print " | ||
| + | | ||
| + | | ||
| + | def stop(self): | ||
| + | # | ||
| + | self.player.set_state(gst.STATE_NULL) | ||
| + | self.recorder.stoprec() | ||
| + | print " | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | |||
| + | class MeHear(hildon.Program): | ||
| + | def __init__(self): | ||
| + | self.pl= player() | ||
| + | |||
| + | | ||
| + | def amplify_button_clicked(self, | ||
| + | buttontext = button.get_label() | ||
| + | text = buttontext | ||
| + | if text == " | ||
| + | label.set_text("" | ||
| + | button.set_label(" | ||
| + | self.pl.play() | ||
| + | print "play button pressed" | ||
| + | | ||
| + | if text == " | ||
| + | label.set_text(" | ||
| + | button.set_label(" | ||
| + | self.pl.stop() | ||
| + | print "stop button pressed" | ||
| + | | ||
| + | | ||
| + | | ||
| + | def main(self): | ||
| + | win = hildon.StackableWindow() | ||
| + | |||
| + | # Create and pack labels | ||
| + | vbox = gtk.VBox(False, | ||
| + | hbox = gtk.HBox(False, | ||
| + | |||
| + | # | ||
| + | labelHeader = gtk.Label(" | ||
| + | labelSubHeader = gtk.Label(" | ||
| + | |||
| + | # buttonGTK1 = gtk.Button(" | ||
| + | # buttonGTK1.connect(" | ||
| + | |||
| + | buttonGTK = gtk.Button(" | ||
| + | buttonGTK.connect(" | ||
| + | |||
| + | # hbox.pack_start(buttonGTK1, | ||
| + | hbox.pack_start(buttonGTK, | ||
| + | |||
| + | vbox.pack_start(labelHeader, | ||
| + | vbox.pack_start(labelSubHeader, | ||
| + | vbox.pack_start(hbox, | ||
| + | | ||
| + | | ||
| + | |||
| + | # Add label' | ||
| + | win.add(vbox) | ||
| + | |||
| + | win.connect(" | ||
| + | |||
| + | win.show_all() | ||
| + | |||
| + | gtk.main() | ||
| + | | ||
| + | | ||
| + | if __name__ == " | ||
| + | | ||
| + | app = MeHear() | ||
| + | app.main() | ||
| + | </ | ||
| + | |||
| + | |||
| ===== Sending SMS ===== | ===== Sending SMS ===== | ||