Re: dogtail [python-] Closing a window?



Hi Lukas,

On Thu, 2014-08-14 at 09:19 +0200, Lukas Prokop wrote:
Hi,

My suggestion would be to not use predicates if you need to do some more
custom/regexpy searches etc. The whole concept of predicates was I
presume meant for easy use of the most common stuff and is indeed not
completely great for inheritance.

Mhm, okay. I can see that now. I was thinking about the inheritance
approach because I don't not want to hardcode something like
"node.roleName == 'menu'" instead of IsAMenuNamed. But there is not much
magic going on and so I could simply use the lambda approach.

Not much hardcoding, stuff like roleName and name will "always" stay the
same as will the types like menu, push button etc. Especially if you're
working exclusively with QT, you should be good. (Types etc. do differ
pretty much only between frameworks)


Instead you can use lambdas or other python constructs to do pretty much
anything, with properties coming from both dogtail and pyatspi.

So generally of course you can do stuff such as this:

def my_func():
    return [x in root.applications() if 'woot' in x]

Though you may also stick lambdas to the Node.findChildren() method,
that will recognize the lambda (not being predicate) and will
apply that on all (recursively) children of given node. That's something
we've added recently to easily allow custom searches without having to
deal with Predicate. So you can indeed use re or do anything you wish in
the lambda to filter out the nodes you want.

Example:

node.findChildren(lambda x: x.roleName == 'menu item' and x.showing is
True and re.match(r'...) )

Yes, thank you. Apparently I won't be able to use this approach, because
debian still ships dogtail 0.8.2 which does not support that.

Actually, in latter versions the findChildren was merely a wee bit
optimized for lambdas, but if you just stick lambda to findChildren back
in 0.8.2 it works the same. Simply put lambda function in place of
'pred' param. Code-wise that is the same as in 0.9. Example:

In [7]: app.findChildren(lambda x: x.roleName == 'menu item')
Out[7]: 
[<Accessible object at 0x247ef00 (AtspiAccessible at 0x279cd60)>,
 <Accessible object at 0x2412140 (AtspiAccessible at 0x279ce40)>,
 <Accessible object at 0x248c2d0 (AtspiAccessible at 0x279ceb0)>,



Hope this helps. We generally need to keep the API compatible and try
not make significant changes to the existing core behavior for all the
tests and code out there to keep working with newer dogtail versions, as
far as improvement suggestions go. Adding stuff is a go, of course, and
in that respect patches are welcome.

Okay, thank you :-)

[BTW, Alt+F4 works like a charm, but those GErrors can be really annoying
^^ Let's see whether I am again doing something unreasonable]
There's been an issue related to this, fixed in 0.9.
https://bugzilla.redhat.com/show_bug.cgi?id=972257

There will still always be gerrors in situations when the at-spi bus,
simply gets laggy/broken etc., but this was the worst one. You can catch
these random ones, and give it a number of tries before giving up, that
tends to help in some cases.

Cheers,
Vita.


thanks for the discussion,
best regards,
meisterluk





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]