~townsend/autopilot/fix-gcalctool-desktop-file

« back to all changes in this revision

Viewing changes to autopilot/input/_X11.py

  • Committer: CI bot
  • Author(s): Thomi Richards, Max Brustkern
  • Date: 2014-04-08 00:29:44 UTC
  • mfrom: (459.6.5 logger-privatization)
  • Revision ID: ps-jenkins@lists.canonical.com-20140408002944-hkq216cwlrrbg3k7
Make logger objects within autopilot private. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
_PRESSED_KEYS = []
48
48
_PRESSED_MOUSE_BUTTONS = []
49
49
_DISPLAY = None
50
 
logger = logging.getLogger(__name__)
 
50
_logger = logging.getLogger(__name__)
51
51
 
52
52
 
53
53
def get_display():
142
142
        """
143
143
        if not isinstance(keys, six.string_types):
144
144
            raise TypeError("'keys' argument must be a string.")
145
 
        logger.debug("Pressing keys %r with delay %f", keys, delay)
 
145
        _logger.debug("Pressing keys %r with delay %f", keys, delay)
146
146
        for key in self.__translate_keys(keys):
147
147
            self.__perform_on_key(key, X.KeyPress)
148
148
            sleep(delay)
161
161
        """
162
162
        if not isinstance(keys, six.string_types):
163
163
            raise TypeError("'keys' argument must be a string.")
164
 
        logger.debug("Releasing keys %r with delay %f", keys, delay)
 
164
        _logger.debug("Releasing keys %r with delay %f", keys, delay)
165
165
        # release keys in the reverse order they were pressed in.
166
166
        keys = self.__translate_keys(keys)
167
167
        keys.reverse()
197
197
        """
198
198
        if not isinstance(string, six.string_types):
199
199
            raise TypeError("'keys' argument must be a string.")
200
 
        logger.debug("Typing text %r", string)
 
200
        _logger.debug("Typing text %r", string)
201
201
        for key in string:
202
202
            # Don't call press or release here, as they translate keys to
203
203
            # keysyms.
216
216
        """
217
217
        global _PRESSED_KEYS
218
218
        for keycode in _PRESSED_KEYS:
219
 
            logger.warning(
 
219
            _logger.warning(
220
220
                "Releasing key %r as part of cleanup call.", keycode)
221
221
            fake_input(get_display(), X.KeyRelease, keycode)
222
222
        _PRESSED_KEYS = []
234
234
            fake_input(get_display(), event, 50)
235
235
 
236
236
        if event == X.KeyPress:
237
 
            logger.debug("Sending press event for key: %s", key)
 
237
            _logger.debug("Sending press event for key: %s", key)
238
238
            _PRESSED_KEYS.append(keycode)
239
239
        elif event == X.KeyRelease:
240
 
            logger.debug("Sending release event for key: %s", key)
 
240
            _logger.debug("Sending release event for key: %s", key)
241
241
            if keycode in _PRESSED_KEYS:
242
242
                _PRESSED_KEYS.remove(keycode)
243
243
            else:
244
 
                logger.warning(
 
244
                _logger.warning(
245
245
                    "Generating release event for keycode %d that was not "
246
246
                    "pressed.", keycode)
247
247
 
264
264
        keysym = self.__get_keysym(key)
265
265
        keycode = get_display().keysym_to_keycode(keysym)
266
266
        if keycode == 0:
267
 
            logger.warning("Sorry, can't map '%s'", key)
 
267
            _logger.warning("Sorry, can't map '%s'", key)
268
268
 
269
269
        if (self.__is_shifted(key)):
270
270
            shift_mask = X.ShiftMask
302
302
 
303
303
    def press(self, button=1):
304
304
        """Press mouse button at current mouse location."""
305
 
        logger.debug("Pressing mouse button %d", button)
 
305
        _logger.debug("Pressing mouse button %d", button)
306
306
        _PRESSED_MOUSE_BUTTONS.append(button)
307
307
        fake_input(get_display(), X.ButtonPress, button)
308
308
        get_display().sync()
309
309
 
310
310
    def release(self, button=1):
311
311
        """Releases mouse button at current mouse location."""
312
 
        logger.debug("Releasing mouse button %d", button)
 
312
        _logger.debug("Releasing mouse button %d", button)
313
313
        if button in _PRESSED_MOUSE_BUTTONS:
314
314
            _PRESSED_MOUSE_BUTTONS.remove(button)
315
315
        else:
316
 
            logger.warning(
 
316
            _logger.warning(
317
317
                "Generating button release event or button %d that was not "
318
318
                "pressed.", button)
319
319
        fake_input(get_display(), X.ButtonRelease, button)
345
345
            sleep(time_between_events)
346
346
 
347
347
        dest_x, dest_y = int(x), int(y)
348
 
        logger.debug(
 
348
        _logger.debug(
349
349
            "Moving mouse to position %d,%d %s animation.", dest_x, dest_y,
350
350
            "with" if animate else "without")
351
351
 
405
405
        """
406
406
        try:
407
407
            x, y, w, h = object_proxy.globalRect
408
 
            logger.debug("Moving to object's globalRect coordinates.")
 
408
            _logger.debug("Moving to object's globalRect coordinates.")
409
409
            self.move(x+w/2, y+h/2)
410
410
            return
411
411
        except AttributeError:
417
417
 
418
418
        try:
419
419
            x, y = object_proxy.center_x, object_proxy.center_y
420
 
            logger.debug("Moving to object's center_x, center_y coordinates.")
 
420
            _logger.debug("Moving to object's center_x, center_y coordinates.")
421
421
            self.move(x, y)
422
422
            return
423
423
        except AttributeError:
430
430
        try:
431
431
            x, y, w, h = (
432
432
                object_proxy.x, object_proxy.y, object_proxy.w, object_proxy.h)
433
 
            logger.debug(
 
433
            _logger.debug(
434
434
                "Moving to object's center point calculated from x,y,w,h "
435
435
                "attributes.")
436
436
            self.move(x+w/2, y+h/2)
487
487
        """Put mouse in a known safe state."""
488
488
        global _PRESSED_MOUSE_BUTTONS
489
489
        for btn in _PRESSED_MOUSE_BUTTONS:
490
 
            logger.debug("Releasing mouse button %d as part of cleanup", btn)
 
490
            _logger.debug("Releasing mouse button %d as part of cleanup", btn)
491
491
            fake_input(get_display(), X.ButtonRelease, btn)
492
492
        _PRESSED_MOUSE_BUTTONS = []
493
493
        move_mouse_to_screen(0)