File: multi-window.py

package info (click to toggle)
gnome-boxes 49.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,836 kB
  • sloc: python: 883; ansic: 802; sh: 487; xml: 327; makefile: 14
file content (50 lines) | stat: -rw-r--r-- 1,486 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: UTF-8 -*-

from __future__ import unicode_literals
from behave import step
from dogtail.rawinput import pressKey
from dogtail import predicate
from time import sleep
from utils import get_showing_node_rolename, get_showing_node_name

def find_window(context, name):
    target = None
    for window in context.app.children:
        if window.name == name:
            target = window

            break

    if target == None:
        raise Exception("Window for %s was not found" %vm_name)

    return target

@step('Focus "{window}" window')
def focus_window(context, window):
    if window == 'main':
        context.app.findChildren(lambda x: x.name == 'New' and x.showing and x.sensitive)[0].grabFocus()
    else:
        core = find_window(context, window)
        button = core.findChildren(lambda x: x.roleName == 'toggle button' and x.showing)[1]
        button.grabFocus()
        sleep(0.5)
        pressKey('Tab')
        sleep(0.5)

@step('Open "{vm_names_list}" in new windows')
def open_new_windows(context, vm_names_list):
    vm_names = vm_names_list.split(', ')

    if len(vm_names) == 1:
        button = 'Open in new window'
    else:
        button = "Open in %s new windows" %len(vm_names)

    # Click open in new windows
    context.app.findChildren(lambda x: x.name == button and x.showing and x.sensitive)[0].click()
    sleep(3)

    for vm_name in vm_names:
        # Ensure we have a window for each box
        find_window(context, vm_name)