Various minor changes

This commit is contained in:
markm 2006-05-24 17:43:21 +00:00
parent 95b24c4d14
commit 9dd4006085
5 changed files with 119 additions and 26 deletions

@ -1,6 +1,6 @@
0.3.5 Moved to Metaclass control wrapping
------------------------------------------------------------------
XX-May-2006
24-May-2006
* Moved to a metaclass implementation of control finding. This
removes some cyclic importing that had to be worked around and
other then metaclass magic makes the code a bit simpler.
@ -15,9 +15,13 @@ XX-May-2006
memory (especially for controls that contain a lot of
information). Thanks to Frank Martinez for leading me to this).
*
* Added ListViewWrapper.GetItemRect() to enable retrieving the
rectangle for a particular item in the listview.
* Removed references to _ctrl() method within pywinauto as it
was raising a DeprecationWarning internally even if the user
was not using it.
0.3.4 Fixed issue with latest ctypes, speed gains, other changes
------------------------------------------------------------------

@ -23,7 +23,7 @@ Python package for automating GUI manipulation on Windows
"""
__revision__ = "$Revision$"
__version__ = "0.3.4"
__version__ = "0.3.5"
import findwindows
WindowAmbiguousError = findwindows.WindowAmbiguousError

@ -515,22 +515,8 @@ class WindowSpecification(object):
# warnings.warn(wait_method_deprecation, DeprecationWarning)
# self.WaitNot('exists', timeout, retry_interval)
def PrintControlIdentifiers(self):
"""Prints the 'identifiers'
def _ctrl_identifiers(self):
If you pass in a control then it just prints the identifiers
for that control
If you pass in a dialog then it prints the identiferis for all
controls in the dialog
:Note: The identifiers printed by this method have not been made
unique. So if you have 2 edit boxes, they will both have "Edit"
listed in their identifiers. In reality though the first one
can be refered to as "Edit", "Edit0", "Edit1" and the 2nd
should be refered to as "Edit2".
"""
ctrls = _resolve_control(
self.criteria)
@ -553,6 +539,49 @@ class WindowSpecification(object):
for name, ctrl in name_control_map.items():
control_name_map.setdefault(ctrl, []).append(name)
return control_name_map
def PrintControlIdentifiers(self):
"""Prints the 'identifiers'
If you pass in a control then it just prints the identifiers
for that control
If you pass in a dialog then it prints the identiferis for all
controls in the dialog
:Note: The identifiers printed by this method have not been made
unique. So if you have 2 edit boxes, they will both have "Edit"
listed in their identifiers. In reality though the first one
can be refered to as "Edit", "Edit0", "Edit1" and the 2nd
should be refered to as "Edit2".
"""
#name_control_map = self._ctrl_identifiers()
ctrls = _resolve_control(
self.criteria)
if ctrls[-1].IsDialog():
# dialog controls are all the control on the dialog
dialog_controls = ctrls[-1].Children()
ctrls_to_print = dialog_controls[:]
# filter out hidden controls
ctrls_to_print = [ctrl for ctrl in ctrls_to_print if ctrl.IsVisible()]
else:
dialog_controls = ctrls[-1].TopLevelParent().Children()
ctrls_to_print = [ctrls[-1]]
# build the list of disambiguated list of control names
name_control_map = findbestmatch.build_unique_dict(dialog_controls)
# swap it around so that we are mapped off the controls
control_name_map = {}
for name, ctrl in name_control_map.items():
#print name, ctrl
control_name_map.setdefault(ctrl, []).append(name)
print "Control Identifiers:"
for ctrl in ctrls_to_print:
@ -1029,7 +1058,7 @@ class Application(object):
#raise AppNotConnected(
# "Please use start_ or connect_ before trying anything else")
win_spec = WindowSpecification(self, kwargs)
self.process = win_spec.ctrl_().ProcessID()
self.process = win_spec.WrapperObject().ProcessID()
# add the restriction for this particular process
else:
kwargs['process'] = self.process

@ -244,6 +244,36 @@ class ListViewWrapper(HwndWrapper.HwndWrapper):
"Return a list of all the column widths"
return [col['width'] for col in self.Columns()]
#-----------------------------------------------------------
def GetItemRect(self, item_index):
"Return the bounding rectangle of the list view item"
# set up a memory block in the remote application
remote_mem = _RemoteMemoryBlock(self)
rect = win32structures.RECT()
rect.left = win32defines.LVIR_SELECTBOUNDS
# Write the local RECT structure to the remote memory block
remote_mem.Write(rect)
# Fill in the requested item
retval = self.SendMessage(
win32defines.LVM_GETITEMRECT,
item_index,
remote_mem)
# if it succeeded
if not retval:
del remote_mem
raise RuntimeError("Did not succeed in getting rectable")
rect = remote_mem.Read(rect)
del remote_mem
return rect
#-----------------------------------------------------------
def GetItem(self, item_index, subitem_index = 0):
"Return the item of the list view"
@ -1795,15 +1825,18 @@ class UpDownWrapper(HwndWrapper.HwndWrapper):
#HwndWrapper.HwndWrapper.__init__(self, hwnd)
super(UpDownWrapper, self).__init__(hwnd)
#----------------------------------------------------------------
def GetValue(self):
"Get the current value of the UpDown control"
pos = self.SendMessage(win32defines.UDM_GETPOS)
return win32functions.LoWord(pos)
#----------------------------------------------------------------
def GetBase(self):
"Get the base the UpDown control (either 10 or 16)"
return self.SendMessage(win32defines.UDM_GETBASE)
#----------------------------------------------------------------
def GetRange(self):
"Return the lower, upper range of the up down control"
updown_range = self.SendMessage(win32defines.UDM_GETRANGE)
@ -1813,6 +1846,7 @@ class UpDownWrapper(HwndWrapper.HwndWrapper):
)
return updown_range
#----------------------------------------------------------------
def GetBuddyControl(self):
"Get the buddy control of the updown control"
#from wraphandle import WrapHandle
@ -1820,6 +1854,7 @@ class UpDownWrapper(HwndWrapper.HwndWrapper):
buddy_handle = self.SendMessage(win32defines.UDM_GETBUDDY)
return HwndWrapper.HwndWrapper(buddy_handle)
#----------------------------------------------------------------
def SetValue(self, new_pos):
"Set the value of the of the UpDown control to some integer value"
self.SendMessageTimeout(
@ -1828,6 +1863,7 @@ class UpDownWrapper(HwndWrapper.HwndWrapper):
win32functions.WaitGuiThreadIdle(self)
time.sleep(Timings.after_updownchange_wait)
#----------------------------------------------------------------
def Increment(self):
"Increment the number in the UpDown control by one"
# hmmm - VM_SCROLL and UDN_DELTAPOS don't seem to be working for me :-(
@ -1837,6 +1873,7 @@ class UpDownWrapper(HwndWrapper.HwndWrapper):
win32functions.WaitGuiThreadIdle(self)
time.sleep(Timings.after_updownchange_wait)
#----------------------------------------------------------------
def Decrement(self):
"Decrement the number in the UpDown control by one"
self.SetValue(self.GetValue() - 1)
@ -1852,6 +1889,29 @@ class TrackbarWrapper(HwndWrapper.HwndWrapper):
friendlyclassname = "Trackbar"
windowclasses = ["msctls_trackbar", ]
#
# #----------------------------------------------------------------
# def GetNumTicks(self):
# return self.SendMessage(win32defines.TBM_GETNUMTICS)
#
# #----------------------------------------------------------------
# def GetPos(self):
# return self.SendMessage(win32defines.TBM_GETPOS)
#
# #----------------------------------------------------------------
# def GetRangeMax(self):
# return self.SendMessage(win32defines.TBM_GETRANGEMAX)
#
# #----------------------------------------------------------------
# def GetRangeMin(self):
# return self.SendMessage(win32defines.TBM_GETRANGEMIN)
#
# #----------------------------------------------------------------
# def GetToolTipsControl(self):
# "Return teh tooltip control associated with this control"
# return ToolTipsWrapper(self.SendMessage(win32defines.TBM_GETTOOLTIPS))
#====================================================================
class AnimationWrapper(HwndWrapper.HwndWrapper):
"Class that wraps Windows Animation common control "

@ -139,15 +139,15 @@ def find_windows(class_name = None,
# if the ctrl_index has been specified then just return
# that control
if ctrl_index:
if ctrl_index is not None:
return [windows[ctrl_index]]
if class_name is not None and windows:
if class_name is not None and windows:
windows = [win for win in windows
if class_name == handleprops.classname(win)]
if class_name_re is not None and windows:
if class_name_re is not None and windows:
class_name_regex = re.compile(class_name_re)
windows = [win for win in windows
if class_name_regex.match(handleprops.classname(win))]
@ -160,7 +160,7 @@ def find_windows(class_name = None,
windows = [win for win in windows
if title == handleprops.text(win)]
elif title_re is not None and windows:
elif title_re is not None and windows:
title_regex = re.compile(title_re)
windows = [win for win in windows
if title_regex.match(handleprops.text(win))]
@ -171,7 +171,7 @@ def find_windows(class_name = None,
if enabled_only and windows:
windows = [win for win in windows if handleprops.isenabled(win)]
if best_match is not None and windows:
if best_match is not None and windows:
from controls import WrapHandle
windows = [WrapHandle(win) for win in windows]
windows = findbestmatch.find_best_control_matches(