~marcobiscaro2112/unity/custom-bg

« back to all changes in this revision

Viewing changes to tests/autopilot/unity/emulators/launcher.py

  • Committer: Marco Biscaro
  • Date: 2012-07-12 12:05:07 UTC
  • mfrom: (2353.2.144 unity)
  • Revision ID: marcobiscaro2112@gmail.com-20120712120507-7u9sb43bqon88ifl
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
310
310
        `icon` must be an instance of SimpleLauncherIcon or it's descendants.
311
311
        """
312
312
        if not isinstance(icon, SimpleLauncherIcon):
313
 
            raise TypeError("icon must be a LauncherIcon")
 
313
            raise TypeError("icon must be a LauncherIcon, not %s" % type(icon))
314
314
 
315
315
        logger.debug("Clicking launcher icon %r on monitor %d with mouse button %d",
316
316
            icon, self.monitor, button)
428
428
 
429
429
 
430
430
class LauncherModel(UnityIntrospectionObject):
431
 
    """THe launcher model. Contains all launcher icons as children."""
 
431
    """The launcher model. Contains all launcher icons as children."""
432
432
 
433
433
    def get_bfb_icon(self):
434
434
        icons = BFBLauncherIcon.get_all_instances()
458
458
 
459
459
        return icons
460
460
 
461
 
    def get_icon_by_tooltip_text(self, tooltip_text):
462
 
        """Get a launcher icon given it's tooltip text.
463
 
 
464
 
        Returns None if there is no icon with the specified text.
465
 
        """
466
 
        for icon in self.get_launcher_icons():
467
 
            if icon.tooltip_text == tooltip_text:
468
 
                return icon
469
 
        return None
470
 
 
471
 
    def get_icon_by_desktop_id(self, desktop_id):
472
 
        """Gets a launcher icon with the specified desktop id.
473
 
 
474
 
        Returns None if there is no such launcher icon.
475
 
        """
476
 
        icons = self.get_children_by_type(SimpleLauncherIcon, desktop_id=desktop_id)
477
 
        if len(icons):
478
 
            return icons[0]
479
 
 
480
 
        return None
481
 
 
482
 
    def get_icon_by_window_xid(self, xid):
483
 
        """Gets a launcher icon that controls the specified window xid."""
484
 
        icons = [i for i in self.get_children_by_type(SimpleLauncherIcon) if i.xids.contains(xid)]
485
 
        if (len(icons)):
486
 
            return icons[0]
487
 
 
488
 
        return None
489
 
 
490
 
    def get_icons_by_filter(self, **kwargs):
491
 
        """Get a list of icons that satisfy the given filters.
492
 
 
493
 
        For example:
494
 
 
495
 
        >>> get_icons_by_filter(tooltip_text="My Application")
496
 
        ... [...]
497
 
 
498
 
        Returns an empty list if no icons matched the filter.
499
 
 
500
 
        """
501
 
        return self.get_children_by_type(SimpleLauncherIcon, **kwargs)
 
461
    def get_icon(self, **kwargs):
 
462
        """Get a launcher icon from the model according to some filters.
 
463
 
 
464
        This method accepts keyword argument that are the filters to use when
 
465
        looking for an icon. For example, to find an icon with a particular
 
466
        desktop_id, one might do this from within a test:
 
467
 
 
468
        >>> self.launcher.model.get_icon(desktop_id="gcalctool.desktop")
 
469
 
 
470
        This method returns only one icon. It is the callers responsibility to
 
471
        ensure that the filter matches only one icon.
 
472
 
 
473
        This method will attempt to get the launcher icon, and will retry several
 
474
        times, so the caller can be assured that if this method doesn't find
 
475
        the icon it really does not exist.
 
476
 
 
477
        If no keyword arguments are specified, ValueError will be raised.
 
478
 
 
479
        If no icons are matched, None is returned.
 
480
 
 
481
        """
 
482
 
 
483
        if not kwargs:
 
484
            raise ValueError("You must specify at least one keyword argument to ths method.")
 
485
 
 
486
        for i in range(10):
 
487
            icons = self.get_children_by_type(SimpleLauncherIcon, **kwargs)
 
488
            if len(icons) > 1:
 
489
                logger.warning("Got more than one icon returned using filters=%r. Returning first one", kwargs)
 
490
            if icons:
 
491
                return icons[0]
 
492
            sleep(1)
 
493
        return None
502
494
 
503
495
    def num_launcher_icons(self):
504
496
        """Get the number of icons in the launcher model."""