Exemplo n.º 1
0
    def refresh_workspace_information(self):
        """Re-read information about available workspaces from compiz and X11."""
        self._viewport_width = 0
        self._viewport_height = 0

        self._workspaces_wide = get_compiz_option("core", "hsize")
        self._workspaces_high = get_compiz_option("core", "vsize")

        display = Display.create()
        num_screens = display.get_num_screens()

        for screen in range(num_screens):
            _, _, width, height = display.get_screen_geometry(screen)
            self._viewport_width += width
            self._viewport_height += height
Exemplo n.º 2
0
    def drag_icon_to_position(self,
                              icon,
                              pos,
                              target,
                              drag_type=IconDragType.INSIDE,
                              launcher_position=LauncherPosition.LEFT):
        """Drag a launcher icon to a new position.

        'icon' is the icon to move. It must be either a ApplicationLauncherIcon or an
        ExpoLauncherIcon instance. Other values will result in a TypeError being
        raised.

        'pos' must be one of IconDragType.BEFORE or IconDragType.AFTER. If it is
        not one of these, a ValueError will be raised.

        'target' is the target icon.

        'drag_type' must be one of IconDragType.INSIDE or IconDragType.OUTSIDE.
        This specifies whether the icon is gragged inside the launcher, or to the
        right/top of it. The default is to drag inside the launcher. If it is
        specified, and not one of the allowed values, a ValueError will be raised.

        'launcher_position' must be one of LauncherPosition.LEFT or LauncherPosition.BOTTOM.
        This specifies the launcher position when dragging the icon. The default launcher
        position is at left. If it is specified, and not one of the allowed values, a
        ValueError will be raised.

        For example:

        >>> drag_icon_to_position(calc_icon, IconDragType.BEFORE, switcher_icon)

        This will drag the calculator icon to just before the switcher icon.

        Note: This method makes no attempt to sanity-check the requested move.
        For example, it will happily try and move an icon to before the BFB icon,
        if asked.

        """
        if not isinstance(icon, ApplicationLauncherIcon) \
            and not isinstance(icon, ExpoLauncherIcon):
            raise TypeError(
                "Icon to move must be a ApplicationLauncherIcon or ExpoLauncherIcon, not %s"
                % type(icon).__name__)

        if pos not in (IconDragType.BEFORE, IconDragType.AFTER):
            raise ValueError(
                "'pos' parameter must be one of IconDragType.BEFORE, IconDragType.AFTER"
            )

        if not isinstance(target, SimpleLauncherIcon):
            raise TypeError("'target' must be a valid launcher icon, not %s" %
                            type(target).__name__)

        if drag_type not in (IconDragType.INSIDE, IconDragType.OUTSIDE):
            raise ValueError(
                "'drag_type' parameter must be one of IconDragType.INSIDE, IconDragType.OUTSIDE"
            )

        icon_size = get_compiz_option("unityshell", "icon_size")

        self.move_mouse_to_icon(icon)
        self._mouse.press()
        sleep(1)

        if drag_type == IconDragType.OUTSIDE:
            if launcher_position == LauncherPosition.LEFT:
                shift_over = self._mouse.x + (icon_size * 3)
                self._mouse.move(shift_over,
                                 self._mouse.y,
                                 rate=20,
                                 time_between_events=0.005)
            else:
                shift_over = self._mouse.y - (icon_size * 3)
                self._mouse.move(self._mouse.x,
                                 shift_over,
                                 rate=20,
                                 time_between_events=0.005)
            sleep(0.5)

        self.move_mouse_to_icon(target)

        if launcher_position == LauncherPosition.LEFT:
            target_y = target.center.y
            if target_y < icon.center.y:
                target_y += icon_size
            if pos == IconDragType.BEFORE:
                target_y -= icon_size + (icon_size / 2)
            self._mouse.move(self._mouse.x,
                             target_y,
                             rate=20,
                             time_between_events=0.005)
        else:
            target_x = target.center.x
            if target_x < icon.center.x:
                target_x += icon_size
            if pos == IconDragType.BEFORE:
                target_x -= icon_size + (icon_size / 2)
            self._mouse.move(target_x,
                             self._mouse.y,
                             rate=20,
                             time_between_events=0.005)

        sleep(1)
        self._mouse.release()
        self.move_mouse_beside_launcher()
Exemplo n.º 3
0
    def drag_icon_to_position(self, icon, pos, target, drag_type=IconDragType.INSIDE):
        """Drag a launcher icon to a new position.

        'icon' is the icon to move. It must be either a ApplicationLauncherIcon or an
        ExpoLauncherIcon instance. Other values will result in a TypeError being
        raised.

        'pos' must be one of IconDragType.BEFORE or IconDragType.AFTER. If it is
        not one of these, a ValueError will be raised.

        'target' is the target icon.

        'drag_type' must be one of IconDragType.INSIDE or IconDragType.OUTSIDE.
        This specifies whether the icon is gragged inside the launcher, or to the
        right of it. The default is to drag inside the launcher. If it is
        specified, and not one of the allowed values, a ValueError will be raised.

        For example:

        >>> drag_icon_to_position(calc_icon, IconDragType.BEFORE, switcher_icon)

        This will drag the calculator icon to just before the switcher icon.

        Note: This method makes no attempt to sanity-check the requested move.
        For example, it will happily try and move an icon to before the BFB icon,
        if asked.

        """
        if not isinstance(icon, ApplicationLauncherIcon) \
            and not isinstance(icon, ExpoLauncherIcon):
            raise TypeError("Icon to move must be a ApplicationLauncherIcon or ExpoLauncherIcon, not %s"
                % type(icon).__name__)

        if pos not in (IconDragType.BEFORE, IconDragType.AFTER):
            raise ValueError("'pos' parameter must be one of IconDragType.BEFORE, IconDragType.AFTER")

        if not isinstance(target, SimpleLauncherIcon):
            raise TypeError("'target' must be a valid launcher icon, not %s"
                % type(target).__name__)

        if drag_type not in (IconDragType.INSIDE, IconDragType.OUTSIDE):
            raise ValueError("'drag_type' parameter must be one of IconDragType.INSIDE, IconDragType.OUTSIDE")

        icon_height = get_compiz_option("unityshell", "icon_size")

        self.move_mouse_to_icon(icon)
        self._mouse.press()
        sleep(2)

        if drag_type == IconDragType.OUTSIDE:
            shift_over = self._mouse.x + (icon_height * 2)
            self._mouse.move(shift_over, self._mouse.y)
            sleep(0.5)

        self.move_mouse_to_icon(target)

        target_y = target.center.y
        if target_y < icon.center.y:
            target_y += icon_height 
        if pos == IconDragType.BEFORE:
            target_y -= icon_height + (icon_height / 2)

        self._mouse.move(self._mouse.x, target_y)
        sleep(0.5)
        self._mouse.release()
        self.move_mouse_to_right_of_launcher()