本文整理汇总了Python中gi.repository.GObject.MainLoop方法的典型用法代码示例。如果您正苦于以下问题:Python GObject.MainLoop方法的具体用法?Python GObject.MainLoop怎么用?Python GObject.MainLoop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gi.repository.GObject
的用法示例。
在下文中一共展示了GObject.MainLoop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def main():
global args
args = argparser.parse_args()
bluez = Bluez()
adapt = bluez.getAdapter(args.adapter)
if not adapt:
print("Adapter " + args.adapter + " not found")
return
adapt.powerSet(True)
adapt.discoverableSet(True)
adapt.mediaEndpointRegisterSBC()
if args.aac_enabled:
adapt.mediaEndpointRegisterAAC()
Gst.init(None)
GObject.threads_init()
mainloop = GObject.MainLoop()
mainloop.run()
return
示例2: __init__
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def __init__(self):
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
setproctitle.setproctitle('pulseaudio-daemon')
self.mainloop = GObject.MainLoop()
self.processes = []
self.check_id = None
self.is_checking = False
self._check_processes()
signals = (
('NameOwnerChanged', 'org.freedesktop.DBus.{}',
self.on_name_owner_changed),
)
self.bus = dbus.SystemBus()
self.core = self.bus.get_object('org.freedesktop.DBus', '/')
for sig_name, interface, sig_handler in signals:
self.bus.add_signal_receiver(sig_handler, sig_name)
示例3: run
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def run(self, ttl=None):
if self.host:
self.zeroconf = zeroconf.Zeroconf(interfaces=[self.host])
else:
self.zeroconf = zeroconf.Zeroconf()
zeroconf.ServiceBrowser(self.zeroconf, self.domain, MDNSHandler(self))
if ttl:
GObject.timeout_add(ttl * 1000, self.shutdown)
self.__running = True
self.__mainloop = GObject.MainLoop()
context = self.__mainloop.get_context()
try:
while self.__running:
if context.pending():
context.iteration(True)
else:
time.sleep(0.01)
except KeyboardInterrupt:
pass
self.zeroconf.close()
logger.info('MDNSListener.run()')
示例4: serve_forever
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def serve_forever(self, poll_interval=0.5):
self.__running = False
self.__mainloop = GObject.MainLoop()
if hasattr(self, 'socket'):
GObject.io_add_watch(
self, GObject.IO_IN | GObject.IO_PRI, self._on_new_request)
context = self.__mainloop.get_context()
try:
while not self.__running:
if context.pending():
context.iteration(True)
else:
time.sleep(0.01)
except KeyboardInterrupt:
pass
logger.info('SSDPListener.serve_forever()')
示例5: __init__
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def __init__(self):
self.fd = None
self.mainloop = gobject.MainLoop()
# This creates a playbin pipeline and using the appsrc source
# we can feed it our stream data
self.pipeline = gst.ElementFactory.make("playbin", None)
self.pipeline.set_property("uri", "appsrc://")
# When the playbin creates the appsrc source it will call
# this callback and allow us to configure it
self.pipeline.connect("source-setup", self.on_source_setup)
# Creates a bus and set callbacks to receive errors
self.bus = self.pipeline.get_bus()
self.bus.add_signal_watch()
self.bus.connect("message::eos", self.on_eos)
self.bus.connect("message::error", self.on_error)
示例6: setUpClass
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def setUpClass(cls):
decoder_conf = {"model" : "test/models/estonian/nnet2_online_ivector/final.mdl",
"word-syms" : "test/models/estonian/nnet2_online_ivector/words.txt",
"fst" : "test/models/estonian/nnet2_online_ivector/HCLG.fst",
"mfcc-config" : "test/models/estonian/nnet2_online_ivector/conf/mfcc.conf",
"ivector-extraction-config": "test/models/estonian/nnet2_online_ivector/conf/ivector_extractor.conf",
"max-active": 7000,
"beam": 11.0,
"lattice-beam": 6.0,
"do-endpointing" : True,
"endpoint-silence-phones":"1:2:3:4:5:6:7:8:9:10"}
cls.decoder_pipeline = DecoderPipeline2({"decoder" : decoder_conf})
cls.final_hyps = []
cls.finished = False
cls.decoder_pipeline.set_result_handler(cls.result_getter)
cls.decoder_pipeline.set_eos_handler(cls.set_finished, cls.finished)
loop = GObject.MainLoop()
thread.start_new_thread(loop.run, ())
示例7: run_agent
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def run_agent():
if GObject:
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
capability = "NoInputNoOutput"
path = "/test/agent"
agent = Agent(bus, path)
mainloop = GObject.MainLoop()
obj = bus.get_object(BUS_NAME, "/org/bluez")
manager = dbus.Interface(obj, "org.bluez.AgentManager1")
manager.RegisterAgent(path, capability)
print("\n\n[+] Agent registered in background ")
manager.RequestDefaultAgent(path)
try:
mainloop.run()
except:
print("\n[-] The agent has finished ")
else:
print("No agent running...")
示例8: __init__
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def __init__(self, device_id=None):
"""Default initialiser.
1. Initialises the program loop using ``GObject``.
2. Registers the Application on the D-Bus.
3. Initialises the list of services offered by the application.
"""
# Initialise the loop that the application runs in
GObject.threads_init()
dbus.mainloop.glib.threads_init()
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
self.mainloop = GObject.MainLoop()
# Initialise the D-Bus path and register it
self.bus = dbus.SystemBus()
self.path = '/ukBaz/bluezero/application{}'.format(id(self))
self.bus_name = dbus.service.BusName('ukBaz.bluezero', self.bus)
dbus.service.Object.__init__(self, self.bus_name, self.path)
# Initialise services within the application
self.services = []
self.dongle = adapter.Adapter(device_id)
示例9: __init__
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def __init__(self):
self.mainloop = GObject.MainLoop()
#Creating the gst pipeline we're going to add elements to and use to play the file
self.pipeline = Gst.Pipeline.new("mypipeline")
#creating the filesrc element, and adding it to the pipeline
self.filesrc = Gst.ElementFactory.make("filesrc", "filesrc")
self.filesrc.set_property("location", """/path/to/mysoundfile.mp3""")
self.pipeline.add(self.filesrc)
#creating and adding the decodebin element , an "automagic" element able to configure itself to decode pretty much anything
self.decode = Gst.ElementFactory.make("decodebin", "decode")
self.pipeline.add(self.decode)
#connecting the decoder's "pad-added" event to a handler: the decoder doesn't yet have an output pad (a source), it's created at runtime when the decoders starts receiving some data
self.decode.connect("pad-added", self.decode_src_created)
#setting up (and adding) the alsasin, which is actually going to "play" the sound it receives
self.sink = Gst.ElementFactory.make("alsasink", "sink")
self.pipeline.add(self.sink)
#linking elements one to another (here it's just the filesrc - > decoder link , the decoder -> sink link's going to be set up later)
self.filesrc.link(self.decode)
#handler taking care of linking the decoder's newly created source pad to the sink
示例10: __init__
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def __init__(self):
# logging.basicConfig(level=logging.INFO)
# voxforge/tri2b_mmi_b0.05 model:
decoder_conf = {
"model": ENGLISH_MODEL_PATH + "final.mdl",
"lda-mat": ENGLISH_MODEL_PATH + "final.mat",
"word-syms": ENGLISH_MODEL_PATH + "words.txt",
"fst": ENGLISH_MODEL_PATH + "HCLG.fst",
"silence-phones": "6"
}
self.decoder_pipeline = DecoderPipeline({"decoder": decoder_conf})
self.__class__.words = []
self.__class__.finished = False
self.decoder_pipeline.set_word_handler(self.word_getter)
self.decoder_pipeline.set_eos_handler(self.set_finished, self.finished)
GObject.threads_init()
self.loop = GObject.MainLoop()
self.gi_thread = Thread(target=self.loop.run, args=())
self.gi_thread.start()
示例11: setUpClass
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def setUpClass(cls):
# voxforge/tri2b_mmi_b0.05 model:
decoder_conf = {
"model": "models/english/final.mdl",
"lda-mat": "models/english/final.mat",
"word-syms": "models/english/words.txt",
"fst": "models/english/HCLG.fst",
"silence-phones": "6"
}
cls.decoder_pipeline = DecoderPipeline({"decoder": decoder_conf})
cls.words = []
cls.finished = False
cls.decoder_pipeline.set_word_handler(cls.word_getter)
cls.decoder_pipeline.set_eos_handler(cls.set_finished, cls.finished)
loop = GObject.MainLoop()
thread.start_new_thread(loop.run, ())
示例12: run
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def run(self):
"""
Starts the main loop that is necessary to receive Bluetooth events from the Bluetooth adapter.
This call blocks until you call `stop()` to stop the main loop.
"""
if self._main_loop:
return
self._interface_added_signal = self._bus.add_signal_receiver(
self._interfaces_added,
dbus_interface='org.freedesktop.DBus.ObjectManager',
signal_name='InterfacesAdded')
# TODO: Also listen to 'interfaces removed' events?
self._properties_changed_signal = self._bus.add_signal_receiver(
self._properties_changed,
dbus_interface=dbus.PROPERTIES_IFACE,
signal_name='PropertiesChanged',
arg0='org.bluez.Device1',
path_keyword='path')
def disconnect_signals():
for device in self._devices.values():
device.invalidate()
self._properties_changed_signal.remove()
self._interface_added_signal.remove()
self._main_loop = GObject.MainLoop()
try:
self._main_loop.run()
disconnect_signals()
except Exception:
disconnect_signals()
raise
示例13: serve_forever
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def serve_forever(self, poll_interval=0.5):
mainloop = GObject.MainLoop()
if hasattr(self, 'socket'):
GObject.io_add_watch(
self, GObject.IO_IN | GObject.IO_PRI, self._on_new_request)
if hasattr(self, 'stream_queue'):
GObject.io_add_watch(
self.stream_queue._reader, GObject.IO_IN | GObject.IO_PRI,
self._on_new_message)
try:
mainloop.run()
except KeyboardInterrupt:
self.shutdown()
示例14: run
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def run(self):
signal.signal(signal.SIGTERM, self.shutdown)
if self.proc_title:
setproctitle.setproctitle(self.proc_title)
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
signals = (
('NewPlaybackStream', 'org.PulseAudio.Core1.{}',
self.on_new_playback_stream),
('PlaybackStreamRemoved', 'org.PulseAudio.Core1.{}',
self.on_playback_stream_removed),
('FallbackSinkUpdated', 'org.PulseAudio.Core1.{}',
self.on_fallback_sink_updated),
('DeviceUpdated', 'org.PulseAudio.Core1.Stream.{}',
self.on_device_updated),
)
self._connect(signals)
self.update()
self.default_sink = self.fallback_sink
self.thread_pool = concurrent.futures.ThreadPoolExecutor(max_workers=1)
mainloop = GObject.MainLoop()
GObject.io_add_watch(
self.pulse_queue._reader, GObject.IO_IN | GObject.IO_PRI,
self._on_new_message)
try:
mainloop.run()
except KeyboardInterrupt:
self.shutdown()
示例15: __init__
# 需要导入模块: from gi.repository import GObject [as 别名]
# 或者: from gi.repository.GObject import MainLoop [as 别名]
def __init__(self):
""" Initialize app src. """
self._mainloop = GObject.MainLoop()
self._pipeline = Gst.Pipeline()
# Make elements.
self._src = Gst.ElementFactory.make('appsrc', 'appsrc')
decode = Gst.ElementFactory.make("decodebin", "decode")
self._queueaudio = Gst.ElementFactory.make('queue', 'queueaudio')
audioconvert = Gst.ElementFactory.make('audioconvert', 'audioconvert')
sink = Gst.ElementFactory.make('alsasink', 'sink')
self._src.set_property('stream-type', 'stream')
# Add to pipeline.
self._pipeline.add(self._src)
self._pipeline.add(decode)
self._pipeline.add(self._queueaudio)
self._pipeline.add(audioconvert)
self._pipeline.add(sink)
# Link elements.
self._src.link(decode)
self._queueaudio.link(audioconvert)
audioconvert.link(sink)
decode.connect('pad-added', self._decode_src_created)