當前位置: 首頁>>代碼示例>>Python>>正文


Python gobject.MainLoop方法代碼示例

本文整理匯總了Python中gobject.MainLoop方法的典型用法代碼示例。如果您正苦於以下問題:Python gobject.MainLoop方法的具體用法?Python gobject.MainLoop怎麽用?Python gobject.MainLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gobject的用法示例。


在下文中一共展示了gobject.MainLoop方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run_agent

# 需要導入模塊: import gobject [as 別名]
# 或者: from 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...") 
開發者ID:ElevenPaths,項目名稱:HomePWN,代碼行數:26,代碼來源:dirtyagent.py

示例2: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def __init__(self, useGtk=True):
        self._simtag = None
        self._reads = set()
        self._writes = set()
        self._sources = {}
        posixbase.PosixReactorBase.__init__(self)
        # pre 2.3.91 the glib iteration and mainloop functions didn't release
        # global interpreter lock, thus breaking thread and signal support.
        if getattr(gobject, "pygtk_version", ()) >= (2, 3, 91) and not useGtk:
            self.context = gobject.main_context_default()
            self.__pending = self.context.pending
            self.__iteration = self.context.iteration
            self.loop = gobject.MainLoop()
            self.__crash = self.loop.quit
            self.__run = self.loop.run
        else:
            import gtk
            self.__pending = gtk.events_pending
            self.__iteration = gtk.main_iteration
            self.__crash = _our_mainquit
            self.__run = gtk.main 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:23,代碼來源:gtk2reactor.py

示例3: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from 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) 
開發者ID:ukBaz,項目名稱:python-bluezero,代碼行數:26,代碼來源:peripheral.py

示例4: _backend_selection

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def _backend_selection():
    """ If rcParams['backend_fallback'] is true, check to see if the
        current backend is compatible with the current running event
        loop, and if not switches to a compatible one.
    """
    backend = rcParams['backend']
    if not rcParams['backend_fallback'] or \
                     backend not in _interactive_bk:
        return
    is_agg_backend = rcParams['backend'].endswith('Agg')
    if 'wx' in sys.modules and not backend in ('WX', 'WXAgg'):
        import wx
        if wx.App.IsMainLoopRunning():
            rcParams['backend'] = 'wx' + 'Agg' * is_agg_backend
    elif 'PyQt4.QtCore' in sys.modules and not backend == 'Qt4Agg':
        import PyQt4.QtGui
        if not PyQt4.QtGui.qApp.startingUp():
            # The mainloop is running.
            rcParams['backend'] = 'qt4Agg'
    elif 'gtk' in sys.modules and not backend in ('GTK', 'GTKAgg',
                                                            'GTKCairo'):
        import gobject
        if gobject.MainLoop().is_running():
            rcParams['backend'] = 'gtk' + 'Agg' * is_agg_backend
    elif 'Tkinter' in sys.modules and not backend == 'TkAgg':
        # import Tkinter
        pass  # what if anything do we need to do for tkinter? 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:29,代碼來源:pyplot.py

示例5: _backend_selection

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def _backend_selection():
    """ If rcParams['backend_fallback'] is true, check to see if the
        current backend is compatible with the current running event
        loop, and if not switches to a compatible one.
    """
    backend = rcParams['backend']
    if not rcParams['backend_fallback'] or \
                     backend not in _interactive_bk:
        return
    is_agg_backend = rcParams['backend'].endswith('Agg')
    if 'wx' in sys.modules and not backend in ('WX', 'WXAgg'):
        import wx
        if wx.App.IsMainLoopRunning():
            rcParams['backend'] = 'wx' + 'Agg' * is_agg_backend
    elif 'PyQt4.QtCore' in sys.modules and not backend == 'Qt4Agg':
        import PyQt4.QtGui
        if not PyQt4.QtGui.qApp.startingUp():
            # The mainloop is running.
            rcParams['backend'] = 'qt4Agg'
    elif 'PyQt5.QtCore' in sys.modules and not backend == 'Qt5Agg':
        import PyQt5.QtWidgets
        if not PyQt5.QtWidgets.qApp.startingUp():
            # The mainloop is running.
            rcParams['backend'] = 'qt5Agg'
    elif ('gtk' in sys.modules
            and backend not in ('GTK', 'GTKAgg', 'GTKCairo')
            and 'gi.repository.GObject' not in sys.modules):
        import gobject
        if gobject.MainLoop().is_running():
            rcParams['backend'] = 'gtk' + 'Agg' * is_agg_backend
    elif 'Tkinter' in sys.modules and not backend == 'TkAgg':
        # import Tkinter
        pass  # what if anything do we need to do for tkinter? 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:35,代碼來源:pyplot.py

示例6: timeout_handler

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def timeout_handler(signum, frame):
    while gobject.MainLoop().get_context().pending():
        gobject.MainLoop().get_context().iteration(False) 
開發者ID:liamw9534,項目名稱:bt-manager,代碼行數:5,代碼來源:demo.py

示例7: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def __init__(self):
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        self.bus = dbus.SystemBus()
        self._mainloop = GObject.MainLoop()

        self.wifi_manager = WiFiControl()

        self.callbacks = {}

        self.current_state = self.OFF_STATE
        self.current_ssid = None 
開發者ID:emlid,項目名稱:pywificontrol,代碼行數:13,代碼來源:wifimonitor.py

示例8: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def __init__(self):
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        self.mainloop = GObject.MainLoop()
        self.bus = BleTools.get_bus()
        self.path = "/"
        self.services = []
        self.next_index = 0
        dbus.service.Object.__init__(self, self.bus, self.path) 
開發者ID:Douglas6,項目名稱:cputemp,代碼行數:10,代碼來源:service.py

示例9: install_gobject_iteration

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def install_gobject_iteration():
    '''Import and install gobject context iteration inside our event loop.
    This is used as soon as gobject is used (like gstreamer).
    '''

    from kivy.clock import Clock

    try:
        from gi.repository import GObject as gobject
    except ImportError:
        import gobject

    if hasattr(gobject, '_gobject_already_installed'):
        # already installed, don't do it twice.
        return

    gobject._gobject_already_installed = True

    # get gobject mainloop / context
    loop = gobject.MainLoop()
    gobject.threads_init()
    context = loop.get_context()

    # schedule the iteration each frame
    def _gobject_iteration(*largs):
        # XXX we need to loop over context here, otherwise, we might have a lag
        loop = 0
        while context.pending() and loop < 10:
            context.iteration(False)
            loop += 1
    Clock.schedule_interval(_gobject_iteration, 0)


# -----------------------------------------------------------------------------
# Android support
# ----------------------------------------------------------------------------- 
開發者ID:BillBillBillBill,項目名稱:Tickeys-linux,代碼行數:38,代碼來源:support.py

示例10: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def __init__(self, useGtk=True):
        self.context = gobject.main_context_default()
        self.loop = gobject.MainLoop()
        posixbase.PosixReactorBase.__init__(self)
        # pre 2.3.91 the glib iteration and mainloop functions didn't release
        # global interpreter lock, thus breaking thread and signal support.
        if (hasattr(gobject, "pygtk_version") and gobject.pygtk_version >= (2, 3, 91)
            and not useGtk):
            self.__pending = self.context.pending
            self.__iteration = self.context.iteration
            self.__crash = self.loop.quit
            self.__run = self.loop.run
        else:
            import gtk
            self.__pending = gtk.events_pending
            self.__iteration = gtk.main_iteration
            self.__crash = _our_mainquit
            self.__run = gtk.main

    # The input_add function in pygtk1 checks for objects with a
    # 'fileno' method and, if present, uses the result of that method
    # as the input source. The pygtk2 input_add does not do this. The
    # function below replicates the pygtk1 functionality.

    # In addition, pygtk maps gtk.input_add to _gobject.io_add_watch, and
    # g_io_add_watch() takes different condition bitfields than
    # gtk_input_add(). We use g_io_add_watch() here in case pygtk fixes this
    # bug. 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:30,代碼來源:gtk2reactor.py

示例11: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def __init__(self, adapter_addr, device_addr):
        """Default initialiser.

        Creates object for the specified remote Bluetooth device.
        This is on the specified adapter specified.

        :param adapter_addr: Address of the local Bluetooth adapter.
        :param device_addr: Address of the remote Bluetooth device.
        """
        self.bus = dbus.SystemBus()
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        self.mainloop = GObject.MainLoop()

        device_path = dbus_tools.get_dbus_path(adapter_addr, device_addr)
        if not device_path:
            raise ValueError("Cannot find a device: " + device_addr +
                             " using adapter: " + adapter_addr)

        self.remote_device_path = device_path
        self.remote_device_obj = self.bus.get_object(
            constants.BLUEZ_SERVICE_NAME,
            self.remote_device_path)
        self.remote_device_methods = dbus.Interface(
            self.remote_device_obj,
            constants.DEVICE_INTERFACE)
        self.remote_device_props = dbus.Interface(self.remote_device_obj,
                                                  dbus.PROPERTIES_IFACE) 
開發者ID:ukBaz,項目名稱:python-bluezero,代碼行數:29,代碼來源:device.py

示例12: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def __init__(self):
        self.mainloop = GObject.MainLoop() 
開發者ID:ukBaz,項目名稱:python-bluezero,代碼行數:4,代碼來源:async_tools.py

示例13: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def __init__(self, tcp_port_in=8043, tcp_port_out=None, channel=1):
        self._spp = SerialPort(channel)
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        dbus.service.Object.__init__(
            self, dbus.SystemBus(), self._spp.profile_path)
        self.tcp_port_in = tcp_port_in
        self.tcp_port_out = tcp_port_out
        self._mainloop = GObject.MainLoop() 
開發者ID:emlid,項目名稱:bluetool,代碼行數:10,代碼來源:blueserver.py

示例14: __init__

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def __init__(
            self, client_class, timeout=180, capability="KeyboardDisplay",
            path="/org/bluez/my_bluetooth_agent"):
        dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
        self.client_class = client_class
        self.timeout = timeout
        self.capability = capability
        self.path = path
        self._bus = dbus.SystemBus()
        self._mainloop = GObject.MainLoop()
        _bluetooth.make_discoverable(False) 
開發者ID:emlid,項目名稱:bluetool,代碼行數:13,代碼來源:agent.py

示例15: mainInit

# 需要導入模塊: import gobject [as 別名]
# 或者: from gobject import MainLoop [as 別名]
def mainInit():
    os.system('sudo service bluetooth stop')

    global mainloop

    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    bus = dbus.SystemBus()

    service_manager = get_service_manager(bus)
    ad_manager = get_ad_manager(bus)

    app = BLEApplication(bus)

    # Create advertisement
    test_advertisement = BLEAdvertisement(bus, 0)

    mainloop = GObject.MainLoop()

    # Register gatt services
    service_manager.RegisterApplication(app.get_path(), {},
                                        reply_handler=register_app_cb,
                                        error_handler=register_app_error_cb)

    # Register advertisement
    ad_manager.RegisterAdvertisement(test_advertisement.get_path(), {},
                                     reply_handler=register_ad_cb,
                                     error_handler=register_ad_error_cb)

    try:
        mainloop.run()
    except KeyboardInterrupt:
        BLINKER_LOG ("exit")

# class BlinkerBLEService(Thread): 
開發者ID:blinker-iot,項目名稱:blinker-py,代碼行數:37,代碼來源:BlinkerBLE.py


注:本文中的gobject.MainLoop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。