dogtail-devel [PATCH] Have focus() return bool indicating success
- From: Cole Robinson <crobinso redhat com>
- To: dogtail-devel-list gnome org
- Subject: dogtail-devel [PATCH] Have focus() return bool indicating success
- Date: Wed, 26 Sep 2007 16:33:56 -0400
Hi all,
This patch provides functionality I talked about in the previous thread.
Focus returns a boolean value indicating whether or not it managed to
focus on the specified component.
I think this is a useful thing to have but upon reevaluation its
probably not the cleanest way to determine if a gui component has been
created yet, since trying to focus on a non-existing widget causes (by
default) a lengthy backoff-retry loop. I wasn't hitting this in my
original crack at this patch as I was only testing with applications and
frames which don't have the backoff.
Regardless, this is still useful for test purposes. I have also attached
a small script to test this capability and show a basic usecase. Also in
this patch is a small change to the failure message when we do not
manage to focus on a component, making it more verbose.
Thanks,
Cole
--
Cole Robinson
crobinso redhat com
Index: dogtail/procedural.py
===================================================================
--- dogtail/procedural.py (revision 333)
+++ dogtail/procedural.py (working copy)
@@ -26,8 +26,8 @@
pass
import errors
-def focusFailed():
- errors.warn('The requested object was not found')
+def focusFailed(type, name):
+ errors.warn('The requested %s \'%s\' could not be focused.' % (type, name))
ENOARGS = "At least one argument is needed"
@@ -67,12 +67,13 @@
except tree.SearchError, desc:
if config.fatalErrors: raise FocusError, name
else:
- focusFailed()
- return
+ focusFailed('Application', name)
+ return False
if app:
FocusApplication.node = app
FocusDialog.node = None
FocusWidget.node = None
+ return True
class FocusDesktop (FocusBase):
"""
@@ -99,8 +100,9 @@
else:
if config.fatalErrors: raise FocusError, predicate.debugName
else:
- focusFailed()
- return
+ focusFailed('Dialog', name)
+ return False
+ return True
class FocusWidget (FocusBase):
"""
@@ -132,15 +134,16 @@
except AttributeError:
if config.fatalErrors: raise FocusError, name
else:
- focusFailed()
- return
+ focusFailed(roleName, name)
+ return False
if result == None:
FocusWidget.node = result
if config.fatalErrors: raise FocusError, predicate.debugName
else:
- focusFailed()
- return
+ focusFailed(roleName, name)
+ return False
+ return True
class Focus (FocusBase):
"""
@@ -165,55 +168,55 @@
"""
A shortcut to self.widget(name, roleName = 'push button')
"""
- self.widget(name = name, roleName = 'push button')
+ return self.widget(name = name, roleName = 'push button')
def frame (self, name):
"""
A shortcut to self.widget(name, roleName = 'frame')
"""
- self.widget(name = name, roleName = 'frame')
+ return self.widget(name = name, roleName = 'frame')
def icon (self, name):
"""
A shortcut to self.widget(name, roleName = 'icon')
"""
- self.widget(name = name, roleName = 'icon')
+ return self.widget(name = name, roleName = 'icon')
def menu (self, name):
"""
A shortcut to self.widget(name, roleName = 'menu')
"""
- self.widget(name = name, roleName = 'menu')
+ return self.widget(name = name, roleName = 'menu')
def menuItem (self, name):
"""
A shortcut to self.widget(name, roleName = 'menu item')
"""
- self.widget(name = name, roleName = 'menu item')
+ return self.widget(name = name, roleName = 'menu item')
def table (self, name = ''):
"""
A shortcut to self.widget(name, roleName 'table')
"""
- self.widget(name = name, roleName = 'table')
+ return self.widget(name = name, roleName = 'table')
def tableCell (self, name = ''):
"""
A shortcut to self.widget(name, roleName 'table cell')
"""
- self.widget(name = name, roleName = 'table cell')
+ return self.widget(name = name, roleName = 'table cell')
def text (self, name = ''):
"""
A shortcut to self.widget(name, roleName = 'text')
"""
- self.widget(name = name, roleName = 'text')
+ return self.widget(name = name, roleName = 'text')
def window (self, name):
"""
A shortcut to self.widget(name, roleName = 'window')
"""
- self.widget(name = name, roleName = 'window')
+ return self.widget(name = name, roleName = 'window')
class Action (FocusWidget):
"""
#!/usr/bin/env python
import dogtail
from dogtail.procedural import click, focus
from dogtail.utils import run
from dogtail.config import config
config.searchBackoffDuration = .5
config.searchCutoffCount = 2
config.debugSearching = False
run("gedit", timeout=2, dumb=True)
focus.application("gedit")
click("File")
click("Open Location...")
res = focus.dialog("Open Location")
if res != True:
print "Error: 'Open Location' didn't pop up. res = %s" % res
click("Cancel")
# Ensure dialog has closed and is gone
res = focus.dialog("Open Location")
if res != False:
print "Error: 'Open Location' didn't close as expected. res = %s" % res
else
print "\nSuccess!"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]