1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2013 Canonical Ltd.
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License as published by
7
# the Free Software Foundation; version 3.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
"""Terminal app autopilot helpers."""
19
from time import sleep
22
import ubuntuuitoolkit
25
class TerminalApp(object):
27
"""Autopilot helper object for the terminal application."""
29
def __init__(self, app_proxy):
31
self.main_view = self.app.select_single(MainView)
34
def pointing_device(self):
35
return self.app.pointing_device
38
class MainView(ubuntuuitoolkit.MainView):
40
"""Autopilot custom proxy object for the MainView."""
42
def __init__(self, *args):
43
super(MainView, self).__init__(*args)
44
self.visible.wait_for(True)
46
def get_slider_item(self, slider):
47
return self.wait_select_single("Slider", objectName=slider)
49
def get_control_panel(self):
50
return self.wait_select_single("CtrlKeys", objectName="kbCtrl")
52
def get_function_panel(self):
53
return self.wait_select_single("FnKeys", objectName="kbFn")
55
def get_text_panel(self):
56
return self.wait_select_single("ScrlKeys", objectName="kbScrl")
58
def get_terminal_page(self):
59
return self.wait_select_single("Terminal", objectName="pgTerm")
61
def get_circle_menu(self):
62
return self.wait_select_single("CircleMenu", objectName="cmenu")
64
def long_tap_terminal_center(self):
65
x, y, w, h = self.globalRect
69
# tap in the top third of the screen, to avoid OSK
70
self.pointing_device.move(tap_x, tap_y)
71
self.pointing_device.press()
72
# we can hold the press for a long time without issue
73
# so we'll ensure the app recieves our signal when under load
75
self.pointing_device.release()
77
def drag_horizontal_slider(self, slider, pos):
78
"""Drag slider until value is set"""
79
slItem = self.get_slider_item(slider)
81
slRect = slItem.select_single("SliderStyle")
83
slideMin = int(slItem.minimumValue)
84
slideMax = int(slItem.maximumValue)
87
raise ValueError("Pos cannot be greater than" + str(slideMax))
90
raise ValueError("Pos cannot be less than" + str(slideMin))
92
x, y, w, h = slRect.globalRect
93
# calculate the approximate slide step width
94
# we take half of the theoretical step value just to make
95
# sure we don't miss any values
96
step = w / ((slideMax - slideMin) * 2)
101
# set the slider to minimum value and loop
102
self.pointing_device.move(sx, sy)
103
self.pointing_device.click()
105
# drag through the slider until the pos matches our desired value
106
# in case of bad sliding, loop will also timeout
107
while round(slItem.value) != pos and slItem.value < slideMax \
108
and loop <= (slideMax * 2):
109
valuePos = int(sx + step)
110
self.pointing_device.drag(sx, sy, valuePos, sy)
119
Helper functions for dealing with sqlite databases
123
dbs_path = os.path.expanduser(
124
"~/.local/share/com.ubuntu.terminal/Databases")
125
if not os.path.exists(dbs_path):
128
files = [f for f in os.listdir(dbs_path)
129
if os.path.splitext(f)[1] == ".ini"]
131
ini_path = os.path.join(dbs_path, f)
132
with open(ini_path) as ini:
135
key, val = line.strip().split("=")
136
if key == "Name" and val == "UbuntuTerminalDB":
138
return ini_path.replace(".ini", ".sqlite")
146
self.assertNotEquals(path, None)
152
def get_font_size_from_storage(self):
154
conn = sqlite3.connect(db)
158
cur.execute("SELECT value FROM config WHERE item='fontSize'")
161
self.assertNotEquals(row, None)
164
def get_color_scheme_from_storage(self):
166
conn = sqlite3.connect(db)
170
cur.execute("SELECT value FROM config WHERE item='colorScheme'")
173
self.assertNotEquals(row, None)