import sys, os import pygst import gst from gi.repository import Gio,GObject class DealWithGsettings: def __init__(self): self.TolkCLC_Schema = "apps.talkinclock" def getAudioFilePath(self): schema = Gio.Settings.new(self.TolkCLC_Schema) return schema.get_string('audiofile') def getVolume(self): schema = Gio.Settings.new(self.TolkCLC_Schema) return schema.get_int('volume') playloop = gobject.MainLoop() player = gst.element_factory_make("playbin2") gsettings = DealWithGsettings() def on_eos(bus, msg): player.set_state(gst.STATE_NULL) playloop.quit() def play(): player.set_property('volume', (gsettings.getVolume() / 100)) player.set_property("uri", "file://" + gsettings.getAudioFilePath()) print "Playing: " + gsettings.getAudioFilePath() player.set_state(gst.STATE_PLAYING) bus = player.get_bus() bus.add_signal_watch() bus.connect('message::eos', on_eos) playloop.run() print "That's all, folks!" play()
Результат выполнения:
Traceback (most recent call last): File "./talkinclockd.py", line 5, in <module> from gi.repository import Gio,GObject File "/usr/lib/python2.7/dist-packages/gi/__init__.py", line 23, in <module> from ._gi import _API, Repository ImportError: could not import gobject (error was: ImportError('When using gi.repository you must not import static modules like "gobject". Please change all occurrences of "import gobject" to "from gi.repository import GObject".',))
.Хотя вот такой код отрабатывает как надо:
from gi.repository import Gio,GObject class DealWithGsettings: def __init__(self): self.TolkCLC_Schema = "apps.talkinclock" def getAudioFilePath(self): schema = Gio.Settings.new(self.TolkCLC_Schema) return schema.get_string('audiofile') def getVolume(self): schema = Gio.Settings.new(self.TolkCLC_Schema) return schema.get_int('volume') d = DealWithGsettings() print d.getAudioFilePath() print d.getVolume()