Форум сайта python.su
0
Собственно, есть такой вот код:
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()
Офлайн
43
Хотя вот такой код отрабатывает как надо:с пробелом перед from чтоли?
from gi.repository import Gio,GObject
del sys.modules['gobject']
Отредактировано sergeek (Авг. 6, 2012 18:53:09)
Офлайн
43
еще
from gi.repository import Gio,GObject
Офлайн
0
sergeekУже разобрался. Gstreamer тоже надо тоже через gir подключать. Видимо, import pygst подгружал pygobject, а Gio из gir'а подгружал свой gobject, опять же, из gir'а. Вот и получался конфликт…Хотя вот такой код отрабатывает как надо:с пробелом перед from чтоли?
в первом примере точно нет import GObject? У вас какой-то модуль загружается с таким же именем
Не знаю как в точности работает система модулей, но глядя на исходники если передвставитьfrom gi.repository import Gio,GObjectэтой ошибки быть не должноdel sys.modules['gobject']
но лучше конечно разберитесь что там за модуль и почему он подключается
Офлайн