Package elisa :: Package plugins :: Package bad :: Package dvd :: Module sample
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.dvd.sample

  1  # -*- mode: python; coding: utf-8 -*- 
  2  # 
  3  # Pigment Python binding image example 
  4  # 
  5  # Copyright © 2006-2008 Fluendo Embedded S.L. 
  6  # 
  7  # This library is free software; you can redistribute it and/or 
  8  # modify it under the terms of the GNU Lesser General Public 
  9  # License as published by the Free Software Foundation; either 
 10  # version 2 of the License, or (at your option) any later version. 
 11  # 
 12  # This library is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
 15  # Lesser General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU Lesser General Public 
 18  # License along with this library; if not, write to the 
 19  # Free Software Foundation, Inc., 59 Temple Place - Suite 330, 
 20  # Boston, MA 02111-1307, USA. 
 21  # 
 22  # Author: Loïc Molinari <loic@fluendo.com> 
 23   
 24   
 25  import pygtk 
 26  pygtk.require('2.0') 
 27   
 28  import pygst 
 29  pygst.require('0.10') 
 30   
 31  import gst 
 32  from elisa.core.media_uri import MediaUri 
 33  import sys, os, pgm, gobject 
 34  from dvd_player import * 
 35  gobject.threads_init()  
 36   
 37  # Update the viewport on an expose event 
38 -def on_expose(viewport, event):
39 viewport.update()
40 41 # Terminate the mainloop on a delete event
42 -def on_delete(viewport, event):
43 pgm.main_quit()
44 45
46 -def on_key_pressed(port, event, player):
47 if event.type == pgm.KEY_PRESS: 48 if event.keyval == pgm.keysyms.Escape or \ 49 event.keyval == pgm.keysyms.q: 50 pgm.main_quit() 51 52 elif event.keyval == pgm.keysyms.m: 53 player.fire_action(DVD_ACTION_MENU_ROOT_OR_RESUME) 54 elif event.keyval == pgm.keysyms.Up: 55 player.fire_action(DVD_ACTION_BUTTON_UP) 56 elif event.keyval == pgm.keysyms.Down: 57 player.fire_action(DVD_ACTION_BUTTON_DOWN) 58 elif event.keyval == pgm.keysyms.Right: 59 player.fire_action(DVD_ACTION_BUTTON_RIGHT) 60 elif event.keyval == pgm.keysyms.Left: 61 player.fire_action(DVD_ACTION_BUTTON_LEFT) 62 elif event.keyval == pgm.keysyms.Return: 63 player.fire_action(DVD_ACTION_BUTTON_ACTIVATE) 64 elif event.keyval == pgm.keysyms.r: 65 player.fire_action(DVD_R)
66
67 -def main(args):
68 # OpenGL viewport creation 69 factory = pgm.ViewportFactory('opengl') 70 gl = factory.create() 71 gl.title = 'Image' 72 73 # Canvas and image drawable creation 74 cvs = pgm.Canvas() 75 gl.set_canvas(cvs) 76 77 img = pgm.Image() 78 79 # Load an image 80 #img.set_from_file('fluendo.png') 81 img.bg_color = (255, 255, 255, 0) 82 83 # Center the image 84 img.position = (0.0, 0.0, 0.0) 85 img.size = (4.0, 3.0) 86 87 # A drawable needs to be shown 88 img.show() 89 90 # Add it to the middle layer of the canvas 91 cvs.add(pgm.DRAWABLE_MIDDLE, img) 92 93 # Let's connect our callbacks and start the mainloop 94 gl.connect('expose-event', on_expose) 95 gl.connect('delete-event', on_delete) 96 97 gl.show() 98 gl.update() 99 100 if len(args) > 0: 101 path = args[0] 102 else: 103 path = 'dvd://' 104 105 player = ElisaDVDPlayer() 106 vsink = gst.parse_bin_from_description ( \ 107 "ffmpegcolorspace ! pgmimagesink name=pgm_sink qos=false max-lateness=-1", True) 108 109 img.set_from_file('elisa/plugins/dvd/fluendo.png') 110 pgm_sink = vsink.get_by_name('pgm_sink') 111 pgm_sink.set_property('image', img) 112 player.video_sink = vsink 113 114 player.load_uri(MediaUri(path)) 115 player.play() 116 gobject.timeout_add(35, gl.update) 117 gl.connect('key-press-event', on_key_pressed, player) 118 pgm.main()
119 120 if __name__ == '__main__': 121 sys.exit(main(sys.argv[1:])) 122