2 # Copyright (C) 2007 Marco Ferragina <marco.ferragina@gmail.com>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 gnome
.sound_init("localhost")
34 # Disable gnome play, see bug https://bugs.launchpad.net/ubuntu/+bug/153704
35 # When the bug will be fixed remember to remove the raise ImportError
45 class __GstPlayThread(threading
.Thread
):
46 def __init__(self
, ply
):
48 threading
.Thread
.__init
__(self
)
50 self
.ply
.set_state(gst
.STATE_PLAYING
)
51 def bus_event(bus
, message
):
53 if t
== gst
.MESSAGE_EOS
:
54 self
.ply
.set_state(gst
.STATE_NULL
)
56 self
.ply
.get_bus().add_watch(bus_event
)
59 def __gstplay(filename
):
62 location
= os
.path
.join(cwd
, filename
)
63 ply
= gst
.element_factory_make("playbin", "player")
64 ply
.set_property("uri", "file://" + location
)
65 pt
= __GstPlayThread(ply
)
70 if ENGINE
== GNOMEPLAY
:
71 def playsnd(filename
):
72 gnome
.sound_play(filename
)
73 elif ENGINE
== GSTPLAY
:
76 def playsnd(filename
):
81 def invoke_subprocess(cmdline
):
83 setsid
= getattr(os
, 'setsid', None)
84 p
= subprocess
.Popen(cmdline
, close_fds
= True, preexec_fn
= setsid
)
86 print "Warning: cannot execute", cmdline
90 def get_default_mail_reader():
91 client
= gconf
.client_get_default()
92 cmd
= client
.get_string("/desktop/gnome/url-handlers/mailto/command")
95 def open_mail_reader():
96 cmdline
= get_default_mail_reader()
97 invoke_subprocess(cmdline
)
99 def open_browser(url
):
100 client
= gconf
.client_get_default()
101 cmd
= client
.get_string("/desktop/gnome/applications/browser/exec")
102 cmdline
= [cmd
.split()[0], url
]
103 invoke_subprocess(cmdline
)
106 if __name__
== "__main__":
108 open_browser("http://google.it")