~sbaldassin/autopilot/fix_mir

« back to all changes in this revision

Viewing changes to autopilot/_fixtures.py

  • Committer: Christopher Lee
  • Date: 2015-07-16 04:27:38 UTC
  • mfrom: (563.2.9 add_osk_show_workaround)
  • Revision ID: chris.lee@canonical.com-20150716042738-kwdpl85vkpm1t5z2
Add fixture that forces a gsetting for unity8 so that OSK is shown even when a UInput keyboard is present.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#
19
19
 
20
20
from fixtures import Fixture
 
21
import logging
 
22
import subprocess
 
23
 
 
24
 
 
25
logger = logging.getLogger(__name__)
21
26
 
22
27
 
23
28
class FixtureWithDirectAddDetail(Fixture):
40
45
        """
41
46
        super().__init__()
42
47
        self.caseAddDetail = caseAddDetail or self.addDetail
 
48
 
 
49
 
 
50
class OSKAlwaysEnabled(Fixture):
 
51
    """Enable the OSK to be shown regardless of if there is a keyboard (virtual
 
52
    or real) plugged in.
 
53
 
 
54
    This is a workaround for bug lp:1474444
 
55
 
 
56
    """
 
57
 
 
58
    osk_schema = 'com.canonical.keyboard.maliit'
 
59
    osk_show_key = 'stay-hidden'
 
60
 
 
61
    def __init__(self):
 
62
        super().__init__()
 
63
        self._original_value = get_gsettings_value(
 
64
            self.osk_schema,
 
65
            self.osk_show_key
 
66
        )
 
67
 
 
68
    def setUp(self):
 
69
        super().setUp()
 
70
        set_gsettings_value(self.osk_schema, self.osk_show_key, 'false')
 
71
        self.addCleanup(
 
72
            set_gsettings_value,
 
73
            self.osk_schema,
 
74
            self.osk_show_key,
 
75
            self._original_value
 
76
        )
 
77
 
 
78
 
 
79
def get_gsettings_value(schema, key):
 
80
    """Return the output of gsettings get as a string or None if the call
 
81
    fails.
 
82
 
 
83
    """
 
84
    command = ['/usr/bin/gsettings', 'get', schema, key]
 
85
    try:
 
86
        output = subprocess.check_output(
 
87
            command,
 
88
            stderr=subprocess.PIPE,
 
89
            universal_newlines=True
 
90
        )
 
91
        return output.rstrip('\n')
 
92
    except subprocess.CalledProcessError as e:
 
93
        logger.warning(
 
94
            'Failed to get gsettings value for {schema}/{key}: {error}'.format(
 
95
                schema=schema, key=key, error=e.output
 
96
            )
 
97
        )
 
98
 
 
99
 
 
100
def set_gsettings_value(schema, key, value):
 
101
    command = ['/usr/bin/gsettings', 'set', schema, key, value]
 
102
    try:
 
103
        subprocess.check_output(command, stderr=subprocess.PIPE)
 
104
    except subprocess.CalledProcessError as e:
 
105
        logger.warning(
 
106
            'Failed to set gsettings value {sch}/{key} to {v}: {error}'.format(
 
107
                sch=schema, key=key, v=value, error=e.output
 
108
            )
 
109
        )