| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
"""VLC Widget classes. |
|---|
| 4 |
|
|---|
| 5 |
This module provides two helper classes, to ease the embedding of a |
|---|
| 6 |
VLC component inside a pygtk application. |
|---|
| 7 |
|
|---|
| 8 |
VLCWidget is a simple VLC widget. |
|---|
| 9 |
|
|---|
| 10 |
DecoratedVLCWidget provides simple player controls. |
|---|
| 11 |
|
|---|
| 12 |
$Id$ |
|---|
| 13 |
""" |
|---|
| 14 |
|
|---|
| 15 |
import gtk |
|---|
| 16 |
import sys |
|---|
| 17 |
import vlc |
|---|
| 18 |
|
|---|
| 19 |
from gettext import gettext as _ |
|---|
| 20 |
|
|---|
| 21 |
class VLCWidget(gtk.DrawingArea): |
|---|
| 22 |
"""Simple VLC widget. |
|---|
| 23 |
|
|---|
| 24 |
Its player can be controlled through the 'player' attribute, which |
|---|
| 25 |
is a MediaControl instance. |
|---|
| 26 |
""" |
|---|
| 27 |
def __init__(self, *p): |
|---|
| 28 |
gtk.DrawingArea.__init__(self) |
|---|
| 29 |
self.player=vlc.MediaControl(*p) |
|---|
| 30 |
def handle_embed(*p): |
|---|
| 31 |
if sys.platform == 'win32': |
|---|
| 32 |
xidattr='handle' |
|---|
| 33 |
else: |
|---|
| 34 |
xidattr='xid' |
|---|
| 35 |
self.player.set_visual(getattr(self.window, xidattr)) |
|---|
| 36 |
return True |
|---|
| 37 |
self.connect("map-event", handle_embed) |
|---|
| 38 |
self.set_size_request(320, 200) |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
class DecoratedVLCWidget(gtk.VBox): |
|---|
| 42 |
"""Decorated VLC widget. |
|---|
| 43 |
|
|---|
| 44 |
VLC widget decorated with a player control toolbar. |
|---|
| 45 |
|
|---|
| 46 |
Its player can be controlled through the 'player' attribute, which |
|---|
| 47 |
is a MediaControl instance. |
|---|
| 48 |
""" |
|---|
| 49 |
def __init__(self, *p): |
|---|
| 50 |
gtk.VBox.__init__(self) |
|---|
| 51 |
self._vlc_widget=VLCWidget(*p) |
|---|
| 52 |
self.player=self._vlc_widget.player |
|---|
| 53 |
self.pack_start(self._vlc_widget, expand=True) |
|---|
| 54 |
self._toolbar = self.get_player_control_toolbar() |
|---|
| 55 |
self.pack_start(self._toolbar, expand=False) |
|---|
| 56 |
|
|---|
| 57 |
def get_player_control_toolbar(self): |
|---|
| 58 |
"""Return a player control toolbar |
|---|
| 59 |
""" |
|---|
| 60 |
tb=gtk.Toolbar() |
|---|
| 61 |
tb.set_style(gtk.TOOLBAR_ICONS) |
|---|
| 62 |
|
|---|
| 63 |
def on_play(b): |
|---|
| 64 |
self.player.start(0) |
|---|
| 65 |
return True |
|---|
| 66 |
|
|---|
| 67 |
def on_stop(b): |
|---|
| 68 |
self.player.stop(0) |
|---|
| 69 |
return True |
|---|
| 70 |
|
|---|
| 71 |
def on_pause(b): |
|---|
| 72 |
self.player.pause(0) |
|---|
| 73 |
return True |
|---|
| 74 |
|
|---|
| 75 |
tb_list = ( |
|---|
| 76 |
(_("Play"), _("Play"), gtk.STOCK_MEDIA_PLAY, |
|---|
| 77 |
on_play), |
|---|
| 78 |
(_("Pause"), _("Pause"), gtk.STOCK_MEDIA_PAUSE, |
|---|
| 79 |
on_pause), |
|---|
| 80 |
(_("Stop"), _("Stop"), gtk.STOCK_MEDIA_STOP, |
|---|
| 81 |
on_stop), |
|---|
| 82 |
) |
|---|
| 83 |
|
|---|
| 84 |
for text, tooltip, stock, callback in tb_list: |
|---|
| 85 |
b=gtk.ToolButton(stock) |
|---|
| 86 |
b.connect("clicked", callback) |
|---|
| 87 |
tb.insert(b, -1) |
|---|
| 88 |
tb.show_all() |
|---|
| 89 |
return tb |
|---|
| 90 |
|
|---|
| 91 |
class VideoPlayer: |
|---|
| 92 |
"""Example video player. |
|---|
| 93 |
""" |
|---|
| 94 |
def __init__(self): |
|---|
| 95 |
self.vlc = DecoratedVLCWidget() |
|---|
| 96 |
|
|---|
| 97 |
def main(self, fname): |
|---|
| 98 |
self.vlc.player.set_mrl(fname) |
|---|
| 99 |
self.popup() |
|---|
| 100 |
gtk.main() |
|---|
| 101 |
|
|---|
| 102 |
def popup(self): |
|---|
| 103 |
w=gtk.Window() |
|---|
| 104 |
w.add(self.vlc) |
|---|
| 105 |
w.show_all() |
|---|
| 106 |
w.connect("destroy", gtk.main_quit) |
|---|
| 107 |
return w |
|---|
| 108 |
|
|---|
| 109 |
if __name__ == '__main__': |
|---|
| 110 |
if not sys.argv[1:]: |
|---|
| 111 |
print "You must provide a movie filename" |
|---|
| 112 |
sys.exit(1) |
|---|
| 113 |
p=VideoPlayer() |
|---|
| 114 |
p.main(sys.argv[1]) |
|---|