Beispiel #1
0
def _get_dbus_bus_from_string(dbus_string):
    if dbus_string == 'session':
        return dbus_handler.get_session_bus()
    elif dbus_string == 'system':
        return dbus_handler.get_system_bus()
    else:
        return dbus_handler.get_custom_bus(dbus_string)
Beispiel #2
0
 def __init__(self):
     matcher_path = '/org/ayatana/bamf/matcher'
     self.matcher_interface_name = 'org.ayatana.bamf.matcher'
     self.matcher_proxy = get_session_bus().get_object(
         _BAMF_BUS_NAME, matcher_path)
     self.matcher_interface = dbus.Interface(self.matcher_proxy,
                                             self.matcher_interface_name)
Beispiel #3
0
    def wait_until_application_is_running(self, desktop_file, timeout):
        """Wait until a given application is running.

        :param string desktop_file: The name of the application desktop file.
        :param integer timeout: The maximum time to wait, in seconds. *If set
         to something less than 0, this method will wait forever.*

        :return: true once the application is found, or false if the
         application was not found until the timeout was reached.
        """
        desktop_file = os.path.split(desktop_file)[1]
        # python workaround since you can't assign to variables in the
        # enclosing scope: see on_timeout_reached below...
        found_app = [True]

        # maybe the app is running already?
        running_applications = self.get_running_applications_by_desktop_file(
            desktop_file)
        if len(running_applications) == 0:
            wait_forever = timeout < 0
            gobject_loop = GLib.MainLoop()

            # No, so define a callback to watch the ViewOpened signal:
            def on_view_added(bamf_path, name):
                if bamf_path.split('/')[-2].startswith('application'):
                    app = Application(bamf_path)
                    if desktop_file == os.path.split(app.desktop_file)[1]:
                        gobject_loop.quit()

            # ...and one for when the user-defined timeout has been reached:
            def on_timeout_reached():
                gobject_loop.quit()
                found_app[0] = False
                return False

            # need a timeout? if so, connect it:
            if not wait_forever:
                GLib.timeout_add(timeout * 1000, on_timeout_reached)
            # connect signal handler:
            get_session_bus().add_signal_receiver(on_view_added, 'ViewOpened')
            # pump the gobject main loop until either the correct signal is
            # emitted, or the timeout happens.
            gobject_loop.run()

        return found_app[0]
Beispiel #4
0
    def __init__(self, window_path):
        self._bamf_win_path = window_path
        self._app_proxy = get_session_bus().get_object(_BAMF_BUS_NAME,
                                                       window_path)
        self._window_iface = dbus.Interface(self._app_proxy,
                                            'org.ayatana.bamf.window')
        self._view_iface = dbus.Interface(self._app_proxy,
                                          'org.ayatana.bamf.view')

        self._xid = int(self._window_iface.GetXid())
        self._x_root_win = get_display().screen().root
        self._x_win = get_display().create_resource_object('window', self._xid)
Beispiel #5
0
 def __init__(self, bamf_app_path):
     self.bamf_app_path = bamf_app_path
     try:
         self._app_proxy = get_session_bus().get_object(
             _BAMF_BUS_NAME, bamf_app_path)
         self._view_iface = dbus.Interface(self._app_proxy,
                                           'org.ayatana.bamf.view')
         self._app_iface = dbus.Interface(self._app_proxy,
                                          'org.ayatana.bamf.application')
     except dbus.DBusException as e:
         e.args += ('bamf_app_path=%r' % (bamf_app_path), )
         raise
Beispiel #6
0
 def SessionBus(connection, object_path):
     """Construct a DBusAddress that backs on to the session bus."""
     return DBusAddress(get_session_bus(), connection, object_path)