1# -*- mode: python -*- 2 3from gi.repository import GLib, Gio 4 5from dogtail.utils import isA11yEnabled, enableA11y 6if not isA11yEnabled(): 7 enableA11y(True) 8 9from dogtail import tree 10from dogtail import utils 11from dogtail.predicate import * 12from dogtail.procedural import * 13 14import os, sys 15import subprocess 16 17APPLICATION_ID = "org.gnome.Characters" 18 19_bus = None 20 21class IsTextEqual(Predicate): 22 """Predicate subclass that looks for top-level windows""" 23 def __init__(self, text): 24 self.text = text 25 26 def satisfiedByNode(self, node): 27 try: 28 textIface = node.queryText() 29 #print textIface.getText(0, -1) 30 return textIface.getText(0, -1) == self.text 31 except NotImplementedError: 32 return False 33 34 def describeSearchResult(self): 35 return '%s text node' % self.text 36 37def _do_bus_call(method, params): 38 global _bus 39 40 if _bus == None: 41 _bus = Gio.bus_get_sync(Gio.BusType.SESSION) 42 _bus.call_sync(APPLICATION_ID, '/' + APPLICATION_ID.replace('.', '/'), 43 'org.freedesktop.Application', 44 method, params, None, 45 Gio.DBusCallFlags.NONE, 46 -1, None) 47 48def start(): 49 builddir = os.environ.get('G_TEST_BUILDDIR', None) 50 if builddir and not 'TESTUTIL_DONT_START' in os.environ: 51 subprocess.Popen([os.path.join(builddir, '..', 'src', APPLICATION_ID)], 52 cwd=os.path.join(builddir, '..')) 53 else: 54 _do_bus_call("Activate", GLib.Variant('(a{sv})', ([],))) 55 utils.doDelay(3) 56 57 app = tree.root.application(APPLICATION_ID) 58 focus.application(APPLICATION_ID) 59 60 return app 61 62def init(): 63 pass 64def fini(): 65 _do_bus_call("ActivateAction", GLib.Variant('(sava{sv})', ('quit', [], []))) 66