~sbaldassin/autopilot/fix_mir

« back to all changes in this revision

Viewing changes to autopilot/input/_X11.py

  • Committer: Tarmac
  • Author(s): Andrea Cerisara
  • Date: 2016-02-29 04:02:17 UTC
  • mfrom: (535.3.7 autopilot)
  • Revision ID: tarmac-20160229040217-kp4cr86nwdbm3agn
Refactored autopilot.input._X11.Mouse.move_to_object. Fixes: https://bugs.launchpad.net/bugs/1308330.

Approved by platform-qa-bot, Nicholas Skaggs, PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
import logging
28
28
 
 
29
from autopilot.input import get_center_point
29
30
from autopilot.display import is_point_on_any_screen, move_mouse_to_screen
30
31
from autopilot.utilities import (
31
32
    EventDelay,
395
396
    def move_to_object(self, object_proxy):
396
397
        """Attempts to move the mouse to 'object_proxy's centre point.
397
398
 
398
 
        It does this by looking for several attributes, in order. The first
399
 
        attribute found will be used. The attributes used are (in order):
400
 
 
401
 
         * globalRect (x,y,w,h)
402
 
         * center_x, center_y
403
 
         * x, y, w, h
404
 
 
405
 
        :raises: **ValueError** if none of these attributes are found, or if an
406
 
         attribute is of an incorrect type.
 
399
        See :py:meth:`~autopilot.input.get_center_point` for details on how
 
400
        the center point is calculated.
407
401
 
408
402
        """
409
 
        try:
410
 
            x, y, w, h = object_proxy.globalRect
411
 
            _logger.debug("Moving to object's globalRect coordinates.")
412
 
            self.move(x+w/2, y+h/2)
413
 
            return
414
 
        except AttributeError:
415
 
            pass
416
 
        except (TypeError, ValueError):
417
 
            raise ValueError(
418
 
                "Object '%r' has globalRect attribute, but it is not of the "
419
 
                "correct type" % object_proxy)
420
 
 
421
 
        try:
422
 
            x, y = object_proxy.center_x, object_proxy.center_y
423
 
            _logger.debug("Moving to object's center_x, center_y coordinates.")
424
 
            self.move(x, y)
425
 
            return
426
 
        except AttributeError:
427
 
            pass
428
 
        except (TypeError, ValueError):
429
 
            raise ValueError(
430
 
                "Object '%r' has center_x, center_y attributes, but they are "
431
 
                "not of the correct type" % object_proxy)
432
 
 
433
 
        try:
434
 
            x, y, w, h = (
435
 
                object_proxy.x, object_proxy.y, object_proxy.w, object_proxy.h)
436
 
            _logger.debug(
437
 
                "Moving to object's center point calculated from x,y,w,h "
438
 
                "attributes.")
439
 
            self.move(x+w/2, y+h/2)
440
 
            return
441
 
        except AttributeError:
442
 
            raise ValueError(
443
 
                "Object '%r' does not have any recognised position "
444
 
                "attributes" % object_proxy)
445
 
        except (TypeError, ValueError):
446
 
            raise ValueError(
447
 
                "Object '%r' has x,y attribute, but they are not of the "
448
 
                "correct type" % object_proxy)
 
403
        x, y = get_center_point(object_proxy)
 
404
        self.move(x, y)
449
405
 
450
406
    def position(self):
451
407
        """