Back to index

unity  6.0.0
shortcut_hint.py
Go to the documentation of this file.
00001 # -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
00002 # Copyright 2012 Canonical
00003 # Author: Marco Trevisan (TreviƱo)
00004 #
00005 # This program is free software: you can redistribute it and/or modify it
00006 # under the terms of the GNU General Public License version 3, as published
00007 # by the Free Software Foundation.
00008 #
00009 
00010 from __future__ import absolute_import
00011 
00012 import logging
00013 
00014 from autopilot.keybindings import KeybindingsHelper
00015 
00016 from unity.emulators import UnityIntrospectionObject
00017 
00018 logger = logging.getLogger(__name__)
00019 
00020 class ShortcutView(UnityIntrospectionObject):
00021     """Proxy object for the shortcut view child of the controller."""
00022 
00023 class ShortcutController(UnityIntrospectionObject, KeybindingsHelper):
00024     """ShortcutController proxy class."""
00025 
00026     def get_shortcut_view(self):
00027         views = self.get_children_by_type(ShortcutView)
00028         return views[0] if views else None
00029 
00030     def show(self):
00031         """Push the keys necessary to reveal the shortcut hint, but don't block."""
00032         logger.debug("Revealing shortcut hint with keyboard.")
00033         self.keybinding_hold("shortcuthint/reveal")
00034 
00035     def ensure_visible(self):
00036         """Block until the shortcut hint is visible."""
00037         if not self.visible:
00038             logger.debug("Revealing shortcut hint with keyboard.")
00039             self.keybinding_hold("shortcuthint/reveal")
00040             self.visible.wait_for(True)
00041 
00042     def hide(self):
00043         """Release the keys keeping the shortcut hint open, but don't block."""
00044         logger.debug("Un-revealing shortcut hint with keyboard.")
00045         self.keybinding_release("shortcuthint/reveal")
00046 
00047     def ensure_hidden(self):
00048         """Block until the shortcut hint is hidden."""
00049         if self.visible:
00050             logger.debug("Un-revealing shortcut hint with keyboard.")
00051             self.keybinding_release("shortcuthint/reveal")
00052             self.visible.wait_for(False)
00053 
00054     def cancel(self):
00055         logger.debug("Hide the shortcut hint with keyboard, without releasing the reveal key.")
00056         self.keybinding("shortcuthint/cancel")
00057 
00058     def get_show_timeout(self):
00059         return self.timeout_duration / 1000.0