code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def Scroll(self, horizontalAmount: int, verticalAmount: int, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationScrollPattern::Scroll. Scroll the visible region of the content area horizontally and vertically. horizontalAmount: int, a value in ScrollAmount. verticalAmount: int, a value in ScrollAmount. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-scroll """ ret = self.pattern.Scroll(horizontalAmount, verticalAmount) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationScrollPattern::Scroll. Scroll the visible region of the content area horizontally and vertically. horizontalAmount: int, a value in ScrollAmount. verticalAmount: int, a value in ScrollAmount. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-scroll
Scroll
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def SetScrollPercent(self, horizontalPercent: float, verticalPercent: float, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationScrollPattern::SetScrollPercent. Set the horizontal and vertical scroll positions as a percentage of the total content area within the UI Automation element. horizontalPercent: float or int, a value in [0, 100] or ScrollPattern.NoScrollValue(-1) if no scroll. verticalPercent: float or int, a value in [0, 100] or ScrollPattern.NoScrollValue(-1) if no scroll. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-setscrollpercent """ ret = self.pattern.SetScrollPercent(horizontalPercent, verticalPercent) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationScrollPattern::SetScrollPercent. Set the horizontal and vertical scroll positions as a percentage of the total content area within the UI Automation element. horizontalPercent: float or int, a value in [0, 100] or ScrollPattern.NoScrollValue(-1) if no scroll. verticalPercent: float or int, a value in [0, 100] or ScrollPattern.NoScrollValue(-1) if no scroll. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-setscrollpercent
SetScrollPercent
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def AddToSelection(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationSelectionItemPattern::AddToSelection. Add the current element to the collection of selected items. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-addtoselection """ ret = self.pattern.AddToSelection() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationSelectionItemPattern::AddToSelection. Add the current element to the collection of selected items. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-addtoselection
AddToSelection
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def RemoveFromSelection(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationSelectionItemPattern::RemoveFromSelection. Remove this element from the selection. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-removefromselection """ ret = self.pattern.RemoveFromSelection() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationSelectionItemPattern::RemoveFromSelection. Remove this element from the selection. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-removefromselection
RemoveFromSelection
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Select(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationSelectionItemPattern::Select. Clear any selected items and then select the current element. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-select """ ret = self.pattern.Select() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationSelectionItemPattern::Select. Clear any selected items and then select the current element. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-select
Select
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetSelection(self) -> List['Control']: """ Call IUIAutomationSelectionPattern::GetCurrentSelection. Return List[Control], a list of `Control` subclasses, the selected elements in the container.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionpattern-getcurrentselection """ eleArray = self.pattern.GetCurrentSelection() if eleArray: controls = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) con = Control.CreateControlFromElement(element=ele) if con: controls.append(con) return controls return []
Call IUIAutomationSelectionPattern::GetCurrentSelection. Return List[Control], a list of `Control` subclasses, the selected elements in the container.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionpattern-getcurrentselection
GetSelection
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetAnnotationObjects(self) -> List['Control']: """ Call IUIAutomationSelectionPattern::GetCurrentAnnotationObjects. Return List[Control], a list of `Control` subclasses representing the annotations associated with this spreadsheet cell. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationspreadsheetitempattern-getcurrentannotationobjects """ eleArray = self.pattern.GetCurrentAnnotationObjects() if eleArray: controls = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) con = Control.CreateControlFromElement(element=ele) if con: controls.append(con) return controls return []
Call IUIAutomationSelectionPattern::GetCurrentAnnotationObjects. Return List[Control], a list of `Control` subclasses representing the annotations associated with this spreadsheet cell. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationspreadsheetitempattern-getcurrentannotationobjects
GetAnnotationObjects
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetColumnHeaderItems(self) -> List['Control']: """ Call IUIAutomationTableItemPattern::GetCurrentColumnHeaderItems. Return List[Control], a list of `Control` subclasses, the column headers associated with a table item or cell. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtableitempattern-getcurrentcolumnheaderitems """ eleArray = self.pattern.GetCurrentColumnHeaderItems() if eleArray: controls = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) con = Control.CreateControlFromElement(element=ele) if con: controls.append(con) return controls return []
Call IUIAutomationTableItemPattern::GetCurrentColumnHeaderItems. Return List[Control], a list of `Control` subclasses, the column headers associated with a table item or cell. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtableitempattern-getcurrentcolumnheaderitems
GetColumnHeaderItems
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetRowHeaderItems(self) -> List['Control']: """ Call IUIAutomationTableItemPattern::GetCurrentRowHeaderItems. Return List[Control], a list of `Control` subclasses, the row headers associated with a table item or cell. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtableitempattern-getcurrentrowheaderitems """ eleArray = self.pattern.GetCurrentRowHeaderItems() if eleArray: controls = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) con = Control.CreateControlFromElement(element=ele) if con: controls.append(con) return controls return []
Call IUIAutomationTableItemPattern::GetCurrentRowHeaderItems. Return List[Control], a list of `Control` subclasses, the row headers associated with a table item or cell. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtableitempattern-getcurrentrowheaderitems
GetRowHeaderItems
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetColumnHeaders(self) -> List['Control']: """ Call IUIAutomationTablePattern::GetCurrentColumnHeaders. Return List[Control], a list of `Control` subclasses, representing all the column headers in a table.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtablepattern-getcurrentcolumnheaders """ eleArray = self.pattern.GetCurrentColumnHeaders() if eleArray: controls = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) con = Control.CreateControlFromElement(element=ele) if con: controls.append(con) return controls return []
Call IUIAutomationTablePattern::GetCurrentColumnHeaders. Return List[Control], a list of `Control` subclasses, representing all the column headers in a table.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtablepattern-getcurrentcolumnheaders
GetColumnHeaders
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetRowHeaders(self) -> List['Control']: """ Call IUIAutomationTablePattern::GetCurrentRowHeaders. Return List[Control], a list of `Control` subclasses, representing all the row headers in a table. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtablepattern-getcurrentrowheaders """ eleArray = self.pattern.GetCurrentRowHeaders() if eleArray: controls = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) con = Control.CreateControlFromElement(element=ele) if con: controls.append(con) return controls return []
Call IUIAutomationTablePattern::GetCurrentRowHeaders. Return List[Control], a list of `Control` subclasses, representing all the row headers in a table. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtablepattern-getcurrentrowheaders
GetRowHeaders
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def AddToSelection(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTextRange::AddToSelection. Add the text range to the collection of selected text ranges in a control that supports multiple, disjoint spans of selected text. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-addtoselection """ ret = self.textRange.AddToSelection() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTextRange::AddToSelection. Add the text range to the collection of selected text ranges in a control that supports multiple, disjoint spans of selected text. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-addtoselection
AddToSelection
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def ExpandToEnclosingUnit(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTextRange::ExpandToEnclosingUnit. Normalize the text range by the specified text unit. The range is expanded if it is smaller than the specified unit, or shortened if it is longer than the specified unit. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-expandtoenclosingunit """ ret = self.textRange.ExpandToEnclosingUnit() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTextRange::ExpandToEnclosingUnit. Normalize the text range by the specified text unit. The range is expanded if it is smaller than the specified unit, or shortened if it is longer than the specified unit. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-expandtoenclosingunit
ExpandToEnclosingUnit
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def FindAttribute(self, textAttributeId: int, val, backward: bool) -> 'TextRange': """ Call IUIAutomationTextRange::FindAttribute. textAttributeID: int, a value in class `TextAttributeId`. val: COM VARIANT according to textAttributeId? todo. backward: bool, True if the last occurring text range should be returned instead of the first; otherwise False. return `TextRange` or None, a text range subset that has the specified text attribute value. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-findattribute """ textRange = self.textRange.FindAttribute(textAttributeId, val, int(backward)) if textRange: return TextRange(textRange=textRange)
Call IUIAutomationTextRange::FindAttribute. textAttributeID: int, a value in class `TextAttributeId`. val: COM VARIANT according to textAttributeId? todo. backward: bool, True if the last occurring text range should be returned instead of the first; otherwise False. return `TextRange` or None, a text range subset that has the specified text attribute value. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-findattribute
FindAttribute
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def FindText(self, text: str, backward: bool, ignoreCase: bool) -> 'TextRange': """ Call IUIAutomationTextRange::FindText. text: str, backward: bool, True if the last occurring text range should be returned instead of the first; otherwise False. ignoreCase: bool, True if case should be ignored; otherwise False. return `TextRange` or None, a text range subset that contains the specified text. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-findtext """ textRange = self.textRange.FindText(text, int(backward), int(ignoreCase)) if textRange: return TextRange(textRange=textRange)
Call IUIAutomationTextRange::FindText. text: str, backward: bool, True if the last occurring text range should be returned instead of the first; otherwise False. ignoreCase: bool, True if case should be ignored; otherwise False. return `TextRange` or None, a text range subset that contains the specified text. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-findtext
FindText
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetBoundingRectangles(self) -> List[Rect]: """ Call IUIAutomationTextRange::GetBoundingRectangles. textAttributeId: int, a value in class `TextAttributeId`. Return List[Rect], a list of `Rect`. bounding rectangles for each fully or partially visible line of text in a text range.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-getboundingrectangles for rect in textRange.GetBoundingRectangles(): print(rect.left, rect.top, rect.right, rect.bottom, rect.width(), rect.height(), rect.xcenter(), rect.ycenter()) """ floats = self.textRange.GetBoundingRectangles() rects = [] for i in range(len(floats) // 4): rect = Rect(int(floats[i * 4]), int(floats[i * 4 + 1]), int(floats[i * 4]) + int(floats[i * 4 + 2]), int(floats[i * 4 + 1]) + int(floats[i * 4 + 3])) rects.append(rect) return rects
Call IUIAutomationTextRange::GetBoundingRectangles. textAttributeId: int, a value in class `TextAttributeId`. Return List[Rect], a list of `Rect`. bounding rectangles for each fully or partially visible line of text in a text range.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-getboundingrectangles for rect in textRange.GetBoundingRectangles(): print(rect.left, rect.top, rect.right, rect.bottom, rect.width(), rect.height(), rect.xcenter(), rect.ycenter())
GetBoundingRectangles
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetChildren(self) -> List['Control']: """ Call IUIAutomationTextRange::GetChildren. textAttributeId: int, a value in class `TextAttributeId`. Return List[Control], a list of `Control` subclasses, embedded objects that fall within the text range.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-getchildren """ eleArray = self.textRange.GetChildren() if eleArray: controls = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) con = Control.CreateControlFromElement(element=ele) if con: controls.append(con) return controls return []
Call IUIAutomationTextRange::GetChildren. textAttributeId: int, a value in class `TextAttributeId`. Return List[Control], a list of `Control` subclasses, embedded objects that fall within the text range.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-getchildren
GetChildren
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Move(self, unit: int, count: int, waitTime: float = OPERATION_WAIT_TIME) -> int: """ Call IUIAutomationTextRange::Move. Move the text range forward or backward by the specified number of text units. unit: int, a value in class `TextUnit`. count: int, the number of text units to move. A positive value moves the text range forward. A negative value moves the text range backward. Zero has no effect. waitTime: float. Return: int, the number of text units actually moved. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-move """ ret = self.textRange.Move(unit, count) time.sleep(waitTime) return ret
Call IUIAutomationTextRange::Move. Move the text range forward or backward by the specified number of text units. unit: int, a value in class `TextUnit`. count: int, the number of text units to move. A positive value moves the text range forward. A negative value moves the text range backward. Zero has no effect. waitTime: float. Return: int, the number of text units actually moved. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-move
Move
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def MoveEndpointByRange(self, srcEndPoint: int, textRange: 'TextRange', targetEndPoint: int, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTextRange::MoveEndpointByRange. Move one endpoint of the current text range to the specified endpoint of a second text range. srcEndPoint: int, a value in class `TextPatternRangeEndpoint`. textRange: `TextRange`. targetEndPoint: int, a value in class `TextPatternRangeEndpoint`. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-moveendpointbyrange """ ret = self.textRange.MoveEndpointByRange(srcEndPoint, textRange.textRange, targetEndPoint) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTextRange::MoveEndpointByRange. Move one endpoint of the current text range to the specified endpoint of a second text range. srcEndPoint: int, a value in class `TextPatternRangeEndpoint`. textRange: `TextRange`. targetEndPoint: int, a value in class `TextPatternRangeEndpoint`. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-moveendpointbyrange
MoveEndpointByRange
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def MoveEndpointByUnit(self, endPoint: int, unit: int, count: int, waitTime: float = OPERATION_WAIT_TIME) -> int: """ Call IUIAutomationTextRange::MoveEndpointByUnit. Move one endpoint of the text range the specified number of text units within the document range. endPoint: int, a value in class `TextPatternRangeEndpoint`. unit: int, a value in class `TextUnit`. count: int, the number of units to move. A positive count moves the endpoint forward. A negative count moves backward. A count of 0 has no effect. waitTime: float. Return int, the count of units actually moved. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-moveendpointbyunit """ ret = self.textRange.MoveEndpointByUnit(endPoint, unit, count) time.sleep(waitTime) return ret
Call IUIAutomationTextRange::MoveEndpointByUnit. Move one endpoint of the text range the specified number of text units within the document range. endPoint: int, a value in class `TextPatternRangeEndpoint`. unit: int, a value in class `TextUnit`. count: int, the number of units to move. A positive count moves the endpoint forward. A negative count moves backward. A count of 0 has no effect. waitTime: float. Return int, the count of units actually moved. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-moveendpointbyunit
MoveEndpointByUnit
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def RemoveFromSelection(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTextRange::RemoveFromSelection. Remove the text range from an existing collection of selected text in a text container that supports multiple, disjoint selections. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-removefromselection """ ret = self.textRange.RemoveFromSelection() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTextRange::RemoveFromSelection. Remove the text range from an existing collection of selected text in a text container that supports multiple, disjoint selections. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-removefromselection
RemoveFromSelection
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def ScrollIntoView(self, alignTop: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTextRange::ScrollIntoView. Cause the text control to scroll until the text range is visible in the viewport. alignTop: bool, True if the text control should be scrolled so that the text range is flush with the top of the viewport; False if it should be flush with the bottom of the viewport. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-scrollintoview """ ret = self.textRange.ScrollIntoView(int(alignTop)) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTextRange::ScrollIntoView. Cause the text control to scroll until the text range is visible in the viewport. alignTop: bool, True if the text control should be scrolled so that the text range is flush with the top of the viewport; False if it should be flush with the bottom of the viewport. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-scrollintoview
ScrollIntoView
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Select(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTextRange::Select. Select the span of text that corresponds to this text range, and remove any previous selection. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-select """ ret = self.textRange.Select() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTextRange::Select. Select the span of text that corresponds to this text range, and remove any previous selection. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-select
Select
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetActiveComposition(self) -> TextRange: """ Call IUIAutomationTextEditPattern::GetActiveComposition. Return `TextRange` or None, the active composition. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtexteditpattern-getactivecomposition """ textRange = self.pattern.GetActiveComposition() if textRange: return TextRange(textRange=textRange)
Call IUIAutomationTextEditPattern::GetActiveComposition. Return `TextRange` or None, the active composition. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtexteditpattern-getactivecomposition
GetActiveComposition
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetConversionTarget(self) -> TextRange: """ Call IUIAutomationTextEditPattern::GetConversionTarget. Return `TextRange` or None, the current conversion target range.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtexteditpattern-getconversiontarget """ textRange = self.pattern.GetConversionTarget() if textRange: return TextRange(textRange=textRange)
Call IUIAutomationTextEditPattern::GetConversionTarget. Return `TextRange` or None, the current conversion target range.. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtexteditpattern-getconversiontarget
GetConversionTarget
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetSelection(self) -> List[TextRange]: """ Call IUIAutomationTextPattern::GetSelection. Return List[TextRange], a list of `TextRange`, represents the currently selected text in a text-based control. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-getselection """ eleArray = self.pattern.GetSelection() if eleArray: textRanges = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) textRanges.append(TextRange(textRange=ele)) return textRanges return []
Call IUIAutomationTextPattern::GetSelection. Return List[TextRange], a list of `TextRange`, represents the currently selected text in a text-based control. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-getselection
GetSelection
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetVisibleRanges(self) -> List[TextRange]: """ Call IUIAutomationTextPattern::GetVisibleRanges. Return List[TextRange], a list of `TextRange`, disjoint text ranges from a text-based control where each text range represents a contiguous span of visible text. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-getvisibleranges """ eleArray = self.pattern.GetVisibleRanges() if eleArray: textRanges = [] for i in range(eleArray.Length): ele = eleArray.GetElement(i) textRanges.append(TextRange(textRange=ele)) return textRanges return []
Call IUIAutomationTextPattern::GetVisibleRanges. Return List[TextRange], a list of `TextRange`, disjoint text ranges from a text-based control where each text range represents a contiguous span of visible text. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-getvisibleranges
GetVisibleRanges
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def RangeFromChild(self, child) -> TextRange: """ Call IUIAutomationTextPattern::RangeFromChild. child: `Control` or its subclass. Return `TextRange` or None, a text range enclosing a child element such as an image, hyperlink, Microsoft Excel spreadsheet, or other embedded object. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-rangefromchild """ textRange = self.pattern.RangeFromChild(Control.Element) if textRange: return TextRange(textRange=textRange)
Call IUIAutomationTextPattern::RangeFromChild. child: `Control` or its subclass. Return `TextRange` or None, a text range enclosing a child element such as an image, hyperlink, Microsoft Excel spreadsheet, or other embedded object. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-rangefromchild
RangeFromChild
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def RangeFromPoint(self, x: int, y: int) -> TextRange: """ Call IUIAutomationTextPattern::RangeFromPoint. child: `Control` or its subclass. Return `TextRange` or None, the degenerate (empty) text range nearest to the specified screen coordinates. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-rangefrompoint """ textRange = self.pattern.RangeFromPoint(ctypes.wintypes.POINT(x, y)) if textRange: return TextRange(textRange=textRange)
Call IUIAutomationTextPattern::RangeFromPoint. child: `Control` or its subclass. Return `TextRange` or None, the degenerate (empty) text range nearest to the specified screen coordinates. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-rangefrompoint
RangeFromPoint
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Toggle(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTogglePattern::Toggle. Cycle through the toggle states of the control. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtogglepattern-toggle """ ret = self.pattern.Toggle() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTogglePattern::Toggle. Cycle through the toggle states of the control. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtogglepattern-toggle
Toggle
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Move(self, x: int, y: int, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTransformPattern::Move. Move the UI Automation element. x: int. y: int. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-move """ ret = self.pattern.Move(x, y) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTransformPattern::Move. Move the UI Automation element. x: int. y: int. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-move
Move
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Resize(self, width: int, height: int, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTransformPattern::Resize. Resize the UI Automation element. width: int. height: int. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-resize """ ret = self.pattern.Resize(width, height) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTransformPattern::Resize. Resize the UI Automation element. width: int. height: int. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-resize
Resize
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Rotate(self, degrees: int, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTransformPattern::Rotate. Rotates the UI Automation element. degrees: int. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-rotate """ ret = self.pattern.Rotate(degrees) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTransformPattern::Rotate. Rotates the UI Automation element. degrees: int. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-rotate
Rotate
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Zoom(self, zoomLevel: float, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTransformPattern2::Zoom. Zoom the viewport of the control. zoomLevel: float for int. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-zoom """ ret = self.pattern.Zoom(zoomLevel) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTransformPattern2::Zoom. Zoom the viewport of the control. zoomLevel: float for int. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-zoom
Zoom
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def ZoomByUnit(self, zoomUnit: int, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTransformPattern2::ZoomByUnit. Zoom the viewport of the control by the specified unit. zoomUnit: int, a value in class `ZoomUnit`. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-zoombyunit """ ret = self.pattern.ZoomByUnit(zoomUnit) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTransformPattern2::ZoomByUnit. Zoom the viewport of the control by the specified unit. zoomUnit: int, a value in class `ZoomUnit`. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-zoombyunit
ZoomByUnit
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def SetValue(self, value: str, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationTransformPattern2::IUIAutomationValuePattern::SetValue. Set the value of the element. value: str. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationvaluepattern-setvalue """ ret = self.pattern.SetValue(value) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationTransformPattern2::IUIAutomationValuePattern::SetValue. Set the value of the element. value: str. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationvaluepattern-setvalue
SetValue
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Realize(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationVirtualizedItemPattern::Realize. Create a full UI Automation element for a virtualized item. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationvirtualizeditempattern-realize """ ret = self.pattern.Realize() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationVirtualizedItemPattern::Realize. Create a full UI Automation element for a virtualized item. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationvirtualizeditempattern-realize
Realize
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Close(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationWindowPattern::Close. Close the window. waitTime: float. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-close """ ret = self.pattern.Close() == S_OK time.sleep(waitTime) return ret
Call IUIAutomationWindowPattern::Close. Close the window. waitTime: float. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-close
Close
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def SetWindowVisualState(self, state: int, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Call IUIAutomationWindowPattern::SetWindowVisualState. Minimize, maximize, or restore the window. state: int, a value in class `WindowVisualState`. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-setwindowvisualstate """ ret = self.pattern.SetWindowVisualState(state) == S_OK time.sleep(waitTime) return ret
Call IUIAutomationWindowPattern::SetWindowVisualState. Minimize, maximize, or restore the window. state: int, a value in class `WindowVisualState`. waitTime: float. Return bool, True if succeed otherwise False. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-setwindowvisualstate
SetWindowVisualState
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def CreatePattern(patternId: int, pattern: ctypes.POINTER(comtypes.IUnknown)): """Create a concreate pattern by pattern id and pattern(POINTER(IUnknown)).""" subPattern = pattern.QueryInterface(GetPatternIdInterface(patternId)) if subPattern: return PatternConstructors[patternId](pattern=subPattern)
Create a concreate pattern by pattern id and pattern(POINTER(IUnknown)).
CreatePattern
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def __init__(self, searchFromControl: 'Control' = None, searchDepth: int = 0xFFFFFFFF, searchInterval: float = SEARCH_INTERVAL, foundIndex: int = 1, element=None, **searchProperties): """ searchFromControl: `Control` or its subclass, if it is None, search from root control(Desktop). searchDepth: int, max search depth from searchFromControl. foundIndex: int, starts with 1, >= 1. searchInterval: float, wait searchInterval after every search in self.Refind and self.Exists, the global timeout is TIME_OUT_SECOND. element: `ctypes.POINTER(IUIAutomationElement)`, internal use only. searchProperties: defines how to search, the following keys can be used: ControlType: int, a value in class `ControlType`. ClassName: str. AutomationId: str. Name: str. SubName: str, a part str in Name. RegexName: str, supports regex using re.match. You can only use one of Name, SubName, RegexName in searchProperties. Depth: int, only search controls in relative depth from searchFromControl, ignore controls in depth(0~Depth-1), if set, searchDepth will be set to Depth too. Compare: Callable[[Control, int], bool], custom compare function(control: Control, depth: int) -> bool. `Control` wraps IUIAutomationElement. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nn-uiautomationclient-iuiautomationelement """ self._element = element self._elementDirectAssign = True if element else False self.searchFromControl = searchFromControl self.searchDepth = searchProperties.get('Depth', searchDepth) self.searchInterval = searchInterval self.foundIndex = foundIndex self.searchProperties = searchProperties regName = searchProperties.get('RegexName', '') self.regexName = re.compile(regName) if regName else None self._supportedPatterns = {}
searchFromControl: `Control` or its subclass, if it is None, search from root control(Desktop). searchDepth: int, max search depth from searchFromControl. foundIndex: int, starts with 1, >= 1. searchInterval: float, wait searchInterval after every search in self.Refind and self.Exists, the global timeout is TIME_OUT_SECOND. element: `ctypes.POINTER(IUIAutomationElement)`, internal use only. searchProperties: defines how to search, the following keys can be used: ControlType: int, a value in class `ControlType`. ClassName: str. AutomationId: str. Name: str. SubName: str, a part str in Name. RegexName: str, supports regex using re.match. You can only use one of Name, SubName, RegexName in searchProperties. Depth: int, only search controls in relative depth from searchFromControl, ignore controls in depth(0~Depth-1), if set, searchDepth will be set to Depth too. Compare: Callable[[Control, int], bool], custom compare function(control: Control, depth: int) -> bool. `Control` wraps IUIAutomationElement. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nn-uiautomationclient-iuiautomationelement
__init__
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def CreateControlFromElement(element) -> 'Control': """ Create a concreate `Control` from a com type `IUIAutomationElement`. element: `ctypes.POINTER(IUIAutomationElement)`. Return a subclass of `Control`, an instance of the control's real type. """ if element: controlType = element.CurrentControlType if controlType in ControlConstructors: return ControlConstructors[controlType](element=element) else: Logger.WriteLine("element.CurrentControlType returns {}, invalid ControlType!".format(controlType), ConsoleColor.Red) #rarely happens
Create a concreate `Control` from a com type `IUIAutomationElement`. element: `ctypes.POINTER(IUIAutomationElement)`. Return a subclass of `Control`, an instance of the control's real type.
CreateControlFromElement
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def AddSearchProperties(self, **searchProperties) -> None: """ Add search properties using `dict.update`. searchProperties: dict, same as searchProperties in `Control.__init__`. """ self.searchProperties.update(searchProperties) if 'Depth' in searchProperties: self.searchDepth = searchProperties['Depth'] if 'RegexName' in searchProperties: regName = searchProperties['RegexName'] self.regexName = re.compile(regName) if regName else None
Add search properties using `dict.update`. searchProperties: dict, same as searchProperties in `Control.__init__`.
AddSearchProperties
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def RemoveSearchProperties(self, **searchProperties) -> None: """ searchProperties: dict, same as searchProperties in `Control.__init__`. """ for key in searchProperties: del self.searchProperties[key] if key == 'RegexName': self.regexName = None
searchProperties: dict, same as searchProperties in `Control.__init__`.
RemoveSearchProperties
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetColorfulSearchPropertiesStr(self, keyColor='DarkGreen', valueColor='DarkCyan') -> str: """keyColor, valueColor: str, color name in class ConsoleColor""" strs = ['<Color={}>{}</Color>: <Color={}>{}</Color>'.format(keyColor if k in Control.ValidKeys else 'DarkYellow', k, valueColor, ControlTypeNames[v] if k == 'ControlType' else repr(v)) for k, v in self.searchProperties.items()] return '{' + ', '.join(strs) + '}'
keyColor, valueColor: str, color name in class ConsoleColor
GetColorfulSearchPropertiesStr
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def BoundingRectangle(self) -> Rect: """ Property BoundingRectangle. Call IUIAutomationElement::get_CurrentBoundingRectangle. Return `Rect`. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentboundingrectangle rect = control.BoundingRectangle print(rect.left, rect.top, rect.right, rect.bottom, rect.width(), rect.height(), rect.xcenter(), rect.ycenter()) """ rect = self.Element.CurrentBoundingRectangle return Rect(rect.left, rect.top, rect.right, rect.bottom)
Property BoundingRectangle. Call IUIAutomationElement::get_CurrentBoundingRectangle. Return `Rect`. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentboundingrectangle rect = control.BoundingRectangle print(rect.left, rect.top, rect.right, rect.bottom, rect.width(), rect.height(), rect.xcenter(), rect.ycenter())
BoundingRectangle
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def ScreenShot(self, savePath: str=None) -> str: """ Save the control's screenshot to savePath. savePath: str, the path to save the screenshot. Return str, the path of the saved screenshot. """ rect = self.Element.CurrentBoundingRectangle bbox = (rect.left, rect.top, rect.right, rect.bottom) img = ImageGrab.grab(bbox=bbox, all_screens=True) if savePath is None: savePath = os.path.join(os.getcwd(), 'ControlScreenShot.png') img.save(savePath) return savePath
Save the control's screenshot to savePath. savePath: str, the path to save the screenshot. Return str, the path of the saved screenshot.
ScreenShot
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def NativeWindowHandle(self) -> str: """ Property NativeWindowHandle. Call IUIAutomationElement::get_CurrentNativeWindowHandle. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentnativewindowhandle """ handle = self.Element.CurrentNativeWindowHandle return 0 if handle is None else handle
Property NativeWindowHandle. Call IUIAutomationElement::get_CurrentNativeWindowHandle. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentnativewindowhandle
NativeWindowHandle
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetClickablePoint(self) -> Tuple[int, int, bool]: """ Call IUIAutomationElement::GetClickablePoint. Return Tuple[int, int, bool], three items tuple (x, y, gotClickable), such as (20, 10, True) Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getclickablepoint """ point, gotClickable = self.Element.GetClickablePoint() return (point.x, point.y, bool(gotClickable))
Call IUIAutomationElement::GetClickablePoint. Return Tuple[int, int, bool], three items tuple (x, y, gotClickable), such as (20, 10, True) Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getclickablepoint
GetClickablePoint
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetPattern(self, patternId: int): """ Call IUIAutomationElement::GetCurrentPattern. Get a new pattern by pattern id if it supports the pattern. patternId: int, a value in class `PatternId`. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcurrentpattern """ try: pattern = self.Element.GetCurrentPattern(patternId) if pattern: subPattern = CreatePattern(patternId, pattern) self._supportedPatterns[patternId] = subPattern return subPattern except comtypes.COMError as ex: pass
Call IUIAutomationElement::GetCurrentPattern. Get a new pattern by pattern id if it supports the pattern. patternId: int, a value in class `PatternId`. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcurrentpattern
GetPattern
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def SetFocus(self) -> bool: """ Call IUIAutomationElement::SetFocus. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-setfocus """ try: return self.Element.SetFocus() == S_OK except comtypes.COMError as ex: return False
Call IUIAutomationElement::SetFocus. Refer https://docs.microsoft.com/en-us/windows/desktop/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-setfocus
SetFocus
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Element(self): """ Property Element. Return `ctypes.POINTER(IUIAutomationElement)`. """ if not self._element: self.Refind(maxSearchSeconds=TIME_OUT_SECOND, searchIntervalSeconds=self.searchInterval) return self._element
Property Element. Return `ctypes.POINTER(IUIAutomationElement)`.
Element
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetCachedPattern(self, patternId: int, cache: bool): """ Get a pattern by patternId. patternId: int, a value in class `PatternId`. Return a pattern if it supports the pattern else None. cache: bool, if True, store the pattern for later use, if False, get a new pattern by `self.GetPattern`. """ if cache: pattern = self._supportedPatterns.get(patternId, None) if pattern: return pattern else: pattern = self.GetPattern(patternId) if pattern: self._supportedPatterns[patternId] = pattern return pattern else: pattern = self.GetPattern(patternId) if pattern: self._supportedPatterns[patternId] = pattern return pattern
Get a pattern by patternId. patternId: int, a value in class `PatternId`. Return a pattern if it supports the pattern else None. cache: bool, if True, store the pattern for later use, if False, get a new pattern by `self.GetPattern`.
GetCachedPattern
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetAncestorControl(self, condition: Callable[['Control', int], bool]) -> 'Control': """ Get an ancestor control that matches the condition. condition: Callable[[Control, int], bool], function(control: Control, depth: int) -> bool, depth starts with -1 and decreses when search goes up. Return `Control` subclass or None. """ ancestor = self depth = 0 while True: ancestor = ancestor.GetParentControl() depth -= 1 if ancestor: if condition(ancestor, depth): return ancestor else: break
Get an ancestor control that matches the condition. condition: Callable[[Control, int], bool], function(control: Control, depth: int) -> bool, depth starts with -1 and decreses when search goes up. Return `Control` subclass or None.
GetAncestorControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetSiblingControl(self, condition: Callable[['Control'], bool], forward: bool = True) -> 'Control': """ Get a sibling control that matches the condition. forward: bool, if True, only search next siblings, if False, search pervious siblings first, then search next siblings. condition: Callable[[Control], bool], function(control: Control) -> bool. Return `Control` subclass or None. """ if not forward: prev = self while True: prev = prev.GetPreviousSiblingControl() if prev: if condition(prev): return prev else: break next_ = self while True: next_ = next_.GetNextSiblingControl() if next_: if condition(next_): return next_ else: break
Get a sibling control that matches the condition. forward: bool, if True, only search next siblings, if False, search pervious siblings first, then search next siblings. condition: Callable[[Control], bool], function(control: Control) -> bool. Return `Control` subclass or None.
GetSiblingControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetChildControl(self, index: int, control_type: str = None) -> 'Control': """ Get the nth child control. index: int, starts with 0. control_type: `Control` or its subclass, if not None, only return the nth control that matches the control_type. Return `Control` subclass or None. """ children = self.GetChildren() if control_type: children = [child for child in children if child.ControlTypeName == control_type] if index < len(children): return children[index] else: return None
Get the nth child control. index: int, starts with 0. control_type: `Control` or its subclass, if not None, only return the nth control that matches the control_type. Return `Control` subclass or None.
GetChildControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetAllProgeny(self) -> List[List['Control']]: """ Get all progeny controls. Return List[List[Control]], a list of list of `Control` subclasses. """ all_elements = [] def find_all_elements(element, depth=0): children = element.GetChildren() if depth == len(all_elements): all_elements.append([]) all_elements[depth].append(element) for child in children: find_all_elements(child, depth+1) return all_elements return find_all_elements(self)
Get all progeny controls. Return List[List[Control]], a list of list of `Control` subclasses.
GetAllProgeny
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetProgenyControl(self, depth: int=1, index: int=0, control_type: str = None) -> 'Control': """ Get the nth control in the mth depth. depth: int, starts with 0. index: int, starts with 0. control_type: `Control` or its subclass, if not None, only return the nth control that matches the control_type. Return `Control` subclass or None. """ progeny = self.GetAllProgeny() try: controls = progeny[depth] if control_type: controls = [child for child in controls if child.ControlTypeName == control_type] if index < len(controls): return controls[index] except IndexError: return
Get the nth control in the mth depth. depth: int, starts with 0. index: int, starts with 0. control_type: `Control` or its subclass, if not None, only return the nth control that matches the control_type. Return `Control` subclass or None.
GetProgenyControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetChildren(self) -> List['Control']: """ Return List[Control], a list of `Control` subclasses. """ children = [] child = self.GetFirstChildControl() while child: children.append(child) child = child.GetNextSiblingControl() return children
Return List[Control], a list of `Control` subclasses.
GetChildren
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def _CompareFunction(self, control: 'Control', depth: int) -> bool: """ Define how to search. control: `Control` or its subclass. depth: int, tree depth from searchFromControl. Return bool. """ for key, value in self.searchProperties.items(): if 'ControlType' == key: if value != control.ControlType: return False elif 'ClassName' == key: if value != control.ClassName: return False elif 'AutomationId' == key: if value != control.AutomationId: return False elif 'Depth' == key: if value != depth: return False elif 'Name' == key: if value != control.Name: return False elif 'SubName' == key: if value not in control.Name: return False elif 'RegexName' == key: if not self.regexName.match(control.Name): return False elif 'Compare' == key: if not value(control, depth): return False return True
Define how to search. control: `Control` or its subclass. depth: int, tree depth from searchFromControl. Return bool.
_CompareFunction
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Exists(self, maxSearchSeconds: float = 5, searchIntervalSeconds: float = SEARCH_INTERVAL, printIfNotExist: bool = False) -> bool: """ maxSearchSeconds: float searchIntervalSeconds: float Find control every searchIntervalSeconds seconds in maxSearchSeconds seconds. Return bool, True if find """ if self._element and self._elementDirectAssign: #if element is directly assigned, not by searching, just check whether self._element is valid #but I can't find an API in UIAutomation that can directly check rootElement = GetRootControl().Element if self._element == rootElement: return True else: parentElement = _AutomationClient.instance().ViewWalker.GetParentElement(self._element) if parentElement: return True else: return False #find the element if len(self.searchProperties) == 0: raise LookupError("control's searchProperties must not be empty!") self._element = None startTime = ProcessTime() # Use same timeout(s) parameters for resolve all parents prev = self.searchFromControl if prev and not prev._element and not prev.Exists(maxSearchSeconds, searchIntervalSeconds): if printIfNotExist or DEBUG_EXIST_DISAPPEAR: Logger.ColorfullyLog(self.GetColorfulSearchPropertiesStr() + '<Color=Red> does not exist.</Color>') return False startTime2 = ProcessTime() if DEBUG_SEARCH_TIME: startDateTime = datetime.datetime.now() while True: control = FindControl(self.searchFromControl, self._CompareFunction, self.searchDepth, False, self.foundIndex) if control: self._element = control.Element control._element = 0 # control will be destroyed, but the element needs to be stroed in self._element if DEBUG_SEARCH_TIME: Logger.ColorfullyLog('{} TraverseControls: <Color=Cyan>{}</Color>, SearchTime: <Color=Cyan>{:.3f}</Color>s[{} - {}]'.format( self.GetColorfulSearchPropertiesStr(), control.traverseCount, ProcessTime() - startTime2, startDateTime.time(), datetime.datetime.now().time())) return True else: remain = startTime + maxSearchSeconds - ProcessTime() if remain > 0: time.sleep(min(remain, searchIntervalSeconds)) else: if printIfNotExist or DEBUG_EXIST_DISAPPEAR: Logger.ColorfullyLog(self.GetColorfulSearchPropertiesStr() + '<Color=Red> does not exist.</Color>') return False
maxSearchSeconds: float searchIntervalSeconds: float Find control every searchIntervalSeconds seconds in maxSearchSeconds seconds. Return bool, True if find
Exists
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Disappears(self, maxSearchSeconds: float = 5, searchIntervalSeconds: float = SEARCH_INTERVAL, printIfNotDisappear: bool = False) -> bool: """ maxSearchSeconds: float searchIntervalSeconds: float Check if control disappears every searchIntervalSeconds seconds in maxSearchSeconds seconds. Return bool, True if control disappears. """ global DEBUG_EXIST_DISAPPEAR start = ProcessTime() while True: temp = DEBUG_EXIST_DISAPPEAR DEBUG_EXIST_DISAPPEAR = False # do not print for Exists if not self.Exists(0, 0, False): DEBUG_EXIST_DISAPPEAR = temp return True DEBUG_EXIST_DISAPPEAR = temp remain = start + maxSearchSeconds - ProcessTime() if remain > 0: time.sleep(min(remain, searchIntervalSeconds)) else: if printIfNotDisappear or DEBUG_EXIST_DISAPPEAR: Logger.ColorfullyLog(self.GetColorfulSearchPropertiesStr() + '<Color=Red> does not disappear.</Color>') return False
maxSearchSeconds: float searchIntervalSeconds: float Check if control disappears every searchIntervalSeconds seconds in maxSearchSeconds seconds. Return bool, True if control disappears.
Disappears
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Refind(self, maxSearchSeconds: float = TIME_OUT_SECOND, searchIntervalSeconds: float = SEARCH_INTERVAL, raiseException: bool = True) -> bool: """ Refind the control every searchIntervalSeconds seconds in maxSearchSeconds seconds. maxSearchSeconds: float. searchIntervalSeconds: float. raiseException: bool, if True, raise a LookupError if timeout. Return bool, True if find. """ if not self.Exists(maxSearchSeconds, searchIntervalSeconds, False if raiseException else DEBUG_EXIST_DISAPPEAR): if raiseException: # Logger.ColorfullyLog('<Color=Red>Find Control Timeout: </Color>' + self.GetColorfulSearchPropertiesStr()) raise LookupError('Find Control Timeout: ' + self.GetSearchPropertiesStr()) else: return False return True
Refind the control every searchIntervalSeconds seconds in maxSearchSeconds seconds. maxSearchSeconds: float. searchIntervalSeconds: float. raiseException: bool, if True, raise a LookupError if timeout. Return bool, True if find.
Refind
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def MoveCursorToInnerPos(self, x: int = None, y: int = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True) -> Tuple[int, int]: """ Move cursor to control's internal position, default to center. x: int, if < 0, move to self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, move to self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool. Return Tuple[int, int], two ints tuple (x, y), the cursor positon relative to screen(0, 0) after moving or None if control's width or height is 0. """ rect = self.BoundingRectangle if rect.width() == 0 or rect.height() == 0: Logger.ColorfullyLog('<Color=Yellow>Can not move cursor</Color>. {}\'s BoundingRectangle is {}. SearchProperties: {}'.format( self.ControlTypeName, rect, self.GetColorfulSearchPropertiesStr())) return if x is None: x = rect.left + int(rect.width() * ratioX) else: x = (rect.left if x >= 0 else rect.right) + x if y is None: y = rect.top + int(rect.height() * ratioY) else: y = (rect.top if y >= 0 else rect.bottom) + y if simulateMove and MAX_MOVE_SECOND > 0: MoveTo(x, y, waitTime=0) else: SetCursorPos(x, y) return x, y
Move cursor to control's internal position, default to center. x: int, if < 0, move to self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, move to self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool. Return Tuple[int, int], two ints tuple (x, y), the cursor positon relative to screen(0, 0) after moving or None if control's width or height is 0.
MoveCursorToInnerPos
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Click(self, x: int = None, y: int = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> None: """ x: int, if < 0, click self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, click self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool, if True, first move cursor to control smoothly. waitTime: float. Click(), Click(ratioX=0.5, ratioY=0.5): click center. Click(10, 10): click left+10, top+10. Click(-10, -10): click right-10, bottom-10. """ point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove) if point: Click(point[0], point[1], waitTime)
x: int, if < 0, click self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, click self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool, if True, first move cursor to control smoothly. waitTime: float. Click(), Click(ratioX=0.5, ratioY=0.5): click center. Click(10, 10): click left+10, top+10. Click(-10, -10): click right-10, bottom-10.
Click
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def MiddleClick(self, x: int = None, y: int = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> None: """ x: int, if < 0, middle click self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, middle click self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool, if True, first move cursor to control smoothly. waitTime: float. MiddleClick(), MiddleClick(ratioX=0.5, ratioY=0.5): middle click center. MiddleClick(10, 10): middle click left+10, top+10. MiddleClick(-10, -10): middle click right-10, bottom-10. """ point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove) if point: MiddleClick(point[0], point[1], waitTime)
x: int, if < 0, middle click self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, middle click self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool, if True, first move cursor to control smoothly. waitTime: float. MiddleClick(), MiddleClick(ratioX=0.5, ratioY=0.5): middle click center. MiddleClick(10, 10): middle click left+10, top+10. MiddleClick(-10, -10): middle click right-10, bottom-10.
MiddleClick
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def RightClick(self, x: int = None, y: int = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> None: """ x: int, if < 0, right click self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, right click self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool, if True, first move cursor to control smoothly. waitTime: float. RightClick(), RightClick(ratioX=0.5, ratioY=0.5): right click center. RightClick(10, 10): right click left+10, top+10. RightClick(-10, -10): right click right-10, bottom-10. """ point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove) if point: RightClick(point[0], point[1], waitTime)
x: int, if < 0, right click self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, right click self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool, if True, first move cursor to control smoothly. waitTime: float. RightClick(), RightClick(ratioX=0.5, ratioY=0.5): right click center. RightClick(10, 10): right click left+10, top+10. RightClick(-10, -10): right click right-10, bottom-10.
RightClick
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def DoubleClick(self, x: int = None, y: int = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> None: """ x: int, if < 0, right click self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, right click self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool, if True, first move cursor to control smoothly. waitTime: float. DoubleClick(), DoubleClick(ratioX=0.5, ratioY=0.5): double click center. DoubleClick(10, 10): double click left+10, top+10. DoubleClick(-10, -10): double click right-10, bottom-10. """ x, y = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove) Click(x, y, GetDoubleClickTime() * 1.0 / 2000) Click(x, y, waitTime)
x: int, if < 0, right click self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, right click self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. simulateMove: bool, if True, first move cursor to control smoothly. waitTime: float. DoubleClick(), DoubleClick(ratioX=0.5, ratioY=0.5): double click center. DoubleClick(10, 10): double click left+10, top+10. DoubleClick(-10, -10): double click right-10, bottom-10.
DoubleClick
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def WheelDown(self, x: int = None, y: int = None, ratioX: float = 0.5, ratioY: float = 0.5, wheelTimes: int = 1, interval: float = 0.05, waitTime: float = OPERATION_WAIT_TIME) -> None: """ Make control have focus first, move cursor to the specified position and mouse wheel down. x: int, if < 0, move x cursor to self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, move y cursor to self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. wheelTimes: int. interval: float. waitTime: float. """ cursorX, cursorY = GetCursorPos() self.SetFocus() self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove=False) WheelDown(wheelTimes, interval, waitTime) SetCursorPos(cursorX, cursorY)
Make control have focus first, move cursor to the specified position and mouse wheel down. x: int, if < 0, move x cursor to self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, move y cursor to self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. wheelTimes: int. interval: float. waitTime: float.
WheelDown
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def WheelUp(self, x: int = None, y: int = None, ratioX: float = 0.5, ratioY: float = 0.5, wheelTimes: int = 1, interval: float = 0.05, waitTime: float = OPERATION_WAIT_TIME) -> None: """ Make control have focus first, move cursor to the specified position and mouse wheel up. x: int, if < 0, move x cursor to self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, move y cursor to self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. wheelTimes: int. interval: float. waitTime: float. """ cursorX, cursorY = GetCursorPos() self.SetFocus() self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove=False) WheelUp(wheelTimes, interval, waitTime) SetCursorPos(cursorX, cursorY)
Make control have focus first, move cursor to the specified position and mouse wheel up. x: int, if < 0, move x cursor to self.BoundingRectangle.right + x, if not None, ignore ratioX. y: int, if < 0, move y cursor to self.BoundingRectangle.bottom + y, if not None, ignore ratioY. ratioX: float. ratioY: float. wheelTimes: int. interval: float. waitTime: float.
WheelUp
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def ShowWindow(self, cmdShow: int, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Get a native handle from self or ancestors until valid and call native `ShowWindow` with cmdShow. cmdShow: int, a value in in class `SW`. waitTime: float. Return bool, True if succeed otherwise False. """ handle = self.NativeWindowHandle if not handle: control = self while not handle: control = control.GetParentControl() handle = control.NativeWindowHandle if handle: ret = ShowWindow(handle, cmdShow) time.sleep(waitTime) return ret
Get a native handle from self or ancestors until valid and call native `ShowWindow` with cmdShow. cmdShow: int, a value in in class `SW`. waitTime: float. Return bool, True if succeed otherwise False.
ShowWindow
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def MoveWindow(self, x: int, y: int, width: int, height: int, repaint: bool = True) -> bool: """ Call native MoveWindow if control has a valid native handle. x: int. y: int. width: int. height: int. repaint: bool. Return bool, True if succeed otherwise False. """ handle = self.NativeWindowHandle if handle: return MoveWindow(handle, x, y, width, height, int(repaint)) return False
Call native MoveWindow if control has a valid native handle. x: int. y: int. width: int. height: int. repaint: bool. Return bool, True if succeed otherwise False.
MoveWindow
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetWindowText(self) -> str: """ Call native GetWindowText if control has a valid native handle. """ handle = self.NativeWindowHandle if handle: return GetWindowText(handle)
Call native GetWindowText if control has a valid native handle.
GetWindowText
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def SetWindowText(self, text: str) -> bool: """ Call native SetWindowText if control has a valid native handle. """ handle = self.NativeWindowHandle if handle: return SetWindowText(handle, text) return False
Call native SetWindowText if control has a valid native handle.
SetWindowText
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def SendKeys(self, text: str, interval: float = 0.01, waitTime: float = OPERATION_WAIT_TIME, charMode: bool = True) -> None: """ Make control have focus first and type keys. `self.SetFocus` may not work for some controls, you may need to click it to make it have focus. text: str, keys to type, see the docstring of `SendKeys`. interval: float, seconds between keys. waitTime: float. charMode: bool, if False, the text typied is depend on the input method if a input method is on. """ self.SetFocus() SendKeys(text, interval, waitTime, charMode)
Make control have focus first and type keys. `self.SetFocus` may not work for some controls, you may need to click it to make it have focus. text: str, keys to type, see the docstring of `SendKeys`. interval: float, seconds between keys. waitTime: float. charMode: bool, if False, the text typied is depend on the input method if a input method is on.
SendKeys
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetPixelColor(self, x: int, y: int) -> int: """ Call native `GetPixelColor` if control has a valid native handle. Use `self.ToBitmap` if control doesn't have a valid native handle or you get many pixels. x: int, internal x position. y: int, internal y position. Return int, a color value in bgr. r = bgr & 0x0000FF g = (bgr & 0x00FF00) >> 8 b = (bgr & 0xFF0000) >> 16 """ handle = self.NativeWindowHandle if handle: return GetPixelColor(x, y, handle)
Call native `GetPixelColor` if control has a valid native handle. Use `self.ToBitmap` if control doesn't have a valid native handle or you get many pixels. x: int, internal x position. y: int, internal y position. Return int, a color value in bgr. r = bgr & 0x0000FF g = (bgr & 0x00FF00) >> 8 b = (bgr & 0xFF0000) >> 16
GetPixelColor
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def ToBitmap(self, x: int = 0, y: int = 0, width: int = 0, height: int = 0) -> Bitmap: """ Capture control to a Bitmap object. x, y: int, the point in control's internal position(from 0,0). width, height: int, image's width and height from x, y, use 0 for entire area. If width(or height) < 0, image size will be control's width(or height) - width(or height). """ bitmap = Bitmap() bitmap.FromControl(self, x, y, width, height) return bitmap
Capture control to a Bitmap object. x, y: int, the point in control's internal position(from 0,0). width, height: int, image's width and height from x, y, use 0 for entire area. If width(or height) < 0, image size will be control's width(or height) - width(or height).
ToBitmap
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def CaptureToImage(self, savePath: str, x: int = 0, y: int = 0, width: int = 0, height: int = 0) -> bool: """ Capture control to a image file. savePath: str, should end with .bmp, .jpg, .jpeg, .png, .gif, .tif, .tiff. x, y: int, the point in control's internal position(from 0,0). width, height: int, image's width and height from x, y, use 0 for entire area. If width(or height) < 0, image size will be control's width(or height) - width(or height). Return bool, True if succeed otherwise False. """ bitmap = Bitmap() if bitmap.FromControl(self, x, y, width, height): return bitmap.ToFile(savePath) return False
Capture control to a image file. savePath: str, should end with .bmp, .jpg, .jpeg, .png, .gif, .tif, .tiff. x, y: int, the point in control's internal position(from 0,0). width, height: int, image's width and height from x, y, use 0 for entire area. If width(or height) < 0, image size will be control's width(or height) - width(or height). Return bool, True if succeed otherwise False.
CaptureToImage
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def IsTopLevel(self) -> bool: """Determine whether current control is top level.""" handle = self.NativeWindowHandle if handle: return GetAncestor(handle, GAFlag.Root) == handle return False
Determine whether current control is top level.
IsTopLevel
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def GetTopLevelControl(self) -> 'Control': """ Get the top level control which current control lays. If current control is top level, return self. If current control is root control, return None. Return `PaneControl` or `WindowControl` or None. """ handle = self.NativeWindowHandle if handle: topHandle = GetAncestor(handle, GAFlag.Root) if topHandle: if topHandle == handle: return self else: return ControlFromHandle(topHandle) else: #self is root control pass else: control = self while True: control = control.GetParentControl() handle = control.NativeWindowHandle if handle: topHandle = GetAncestor(handle, GAFlag.Root) return ControlFromHandle(topHandle)
Get the top level control which current control lays. If current control is top level, return self. If current control is root control, return None. Return `PaneControl` or `WindowControl` or None.
GetTopLevelControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Select(self, itemName: str = '', condition: Callable[[str], bool] = None, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Show combobox's popup menu and select a item by name. itemName: str. condition: Callable[[str], bool], function(comboBoxItemName: str) -> bool, if condition is valid, ignore itemName. waitTime: float. Some comboboxs doesn't support SelectionPattern, here is a workaround. This method tries to add selection support. It may not work for some comboboxes, such as comboboxes in older Qt version. If it doesn't work, you should write your own version Select, or it doesn't support selection at all. """ expandCollapsePattern = self.GetExpandCollapsePattern() if expandCollapsePattern: expandCollapsePattern.Expand() else: #Windows Form's ComboBoxControl doesn't support ExpandCollapsePattern self.Click(x=-10, ratioY=0.5, simulateMove=False) find = False if condition: listItemControl = self.ListItemControl(Compare=lambda c, d: condition(c.Name)) else: listItemControl = self.ListItemControl(Name=itemName) if listItemControl.Exists(1): scrollItemPattern = listItemControl.GetScrollItemPattern() if scrollItemPattern: scrollItemPattern.ScrollIntoView(waitTime=0.1) listItemControl.Click(waitTime=waitTime) find = True else: #ComboBox's popup window is a child of root control listControl = ListControl(searchDepth= 1) if listControl.Exists(1): if condition: listItemControl = listControl.ListItemControl(Compare=lambda c, d: condition(c.Name)) else: listItemControl = listControl.ListItemControl(Name=itemName) if listItemControl.Exists(0, 0): scrollItemPattern = listItemControl.GetScrollItemPattern() if scrollItemPattern: scrollItemPattern.ScrollIntoView(waitTime=0.1) listItemControl.Click(waitTime=waitTime) find = True if not find: Logger.ColorfullyLog('Can\'t find <Color=Cyan>{}</Color> in ComboBoxControl or it does not support selection.'.format(itemName), ConsoleColor.Yellow) if expandCollapsePattern: expandCollapsePattern.Collapse(waitTime) else: self.Click(x=-10, ratioY=0.5, simulateMove=False, waitTime=waitTime) return find
Show combobox's popup menu and select a item by name. itemName: str. condition: Callable[[str], bool], function(comboBoxItemName: str) -> bool, if condition is valid, ignore itemName. waitTime: float. Some comboboxs doesn't support SelectionPattern, here is a workaround. This method tries to add selection support. It may not work for some comboboxes, such as comboboxes in older Qt version. If it doesn't work, you should write your own version Select, or it doesn't support selection at all.
Select
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def SetTopmost(self, isTopmost: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Set top level window topmost. isTopmost: bool. waitTime: float. """ if self.IsTopLevel(): ret = SetWindowTopmost(self.NativeWindowHandle, isTopmost) time.sleep(waitTime) return ret return False
Set top level window topmost. isTopmost: bool. waitTime: float.
SetTopmost
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def Restore(self, waitTime: float = OPERATION_WAIT_TIME) -> bool: """ Restore window to normal state. Similar to SwitchToThisWindow. """ if self.IsTopLevel(): return self.ShowWindow(SW.Restore, waitTime) return False
Restore window to normal state. Similar to SwitchToThisWindow.
Restore
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def MetroClose(self, waitTime: float = OPERATION_WAIT_TIME) -> None: """ Only work on Windows 8/8.1, if current window is Metro UI. waitTime: float. """ if self.ClassName == METRO_WINDOW_CLASS_NAME: screenWidth, screenHeight = GetScreenSize() MoveTo(screenWidth // 2, 0, waitTime=0) DragDrop(screenWidth // 2, 0, screenWidth // 2, screenHeight, waitTime=waitTime) else: Logger.WriteLine('Window is not Metro!', ConsoleColor.Yellow)
Only work on Windows 8/8.1, if current window is Metro UI. waitTime: float.
MetroClose
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def SetGlobalSearchTimeout(seconds: float) -> None: """ seconds: float. To make this available, you need explicitly import uiautomation: from uiautomation import uiautomation as auto auto.SetGlobalSearchTimeout(10) """ global TIME_OUT_SECOND TIME_OUT_SECOND = seconds
seconds: float. To make this available, you need explicitly import uiautomation: from uiautomation import uiautomation as auto auto.SetGlobalSearchTimeout(10)
SetGlobalSearchTimeout
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def WalkTree(top, getChildren: Callable[[TreeNode], List[TreeNode]] = None, getFirstChild: Callable[[TreeNode], TreeNode] = None, getNextSibling: Callable[[TreeNode], TreeNode] = None, yieldCondition: Callable[[TreeNode, int], bool] = None, includeTop: bool = False, maxDepth: int = 0xFFFFFFFF): """ Walk a tree not using recursive algorithm. top: a tree node. getChildren: Callable[[TreeNode], List[TreeNode]], function(treeNode: TreeNode) -> List[TreeNode]. getNextSibling: Callable[[TreeNode], TreeNode], function(treeNode: TreeNode) -> TreeNode. getNextSibling: Callable[[TreeNode], TreeNode], function(treeNode: TreeNode) -> TreeNode. yieldCondition: Callable[[TreeNode, int], bool], function(treeNode: TreeNode, depth: int) -> bool. includeTop: bool, if True yield top first. maxDepth: int, enum depth. If getChildren is valid, ignore getFirstChild and getNextSibling, yield 3 items tuple: (treeNode, depth, remain children count in current depth). If getChildren is not valid, using getFirstChild and getNextSibling, yield 2 items tuple: (treeNode, depth). If yieldCondition is not None, only yield tree nodes that yieldCondition(treeNode: TreeNode, depth: int)->bool returns True. For example: def GetDirChildren(dir_): if os.path.isdir(dir_): return [os.path.join(dir_, it) for it in os.listdir(dir_)] for it, depth, leftCount in WalkTree('D:\\', getChildren= GetDirChildren): print(it, depth, leftCount) """ if maxDepth <= 0: return depth = 0 if getChildren: if includeTop: if not yieldCondition or yieldCondition(top, 0): yield top, 0, 0 children = getChildren(top) childList = [children] while depth >= 0: #or while childList: lastItems = childList[-1] if lastItems: if not yieldCondition or yieldCondition(lastItems[0], depth + 1): yield lastItems[0], depth + 1, len(lastItems) - 1 if depth + 1 < maxDepth: children = getChildren(lastItems[0]) if children: depth += 1 childList.append(children) del lastItems[0] else: del childList[depth] depth -= 1 elif getFirstChild and getNextSibling: if includeTop: if not yieldCondition or yieldCondition(top, 0): yield top, 0 child = getFirstChild(top) childList = [child] while depth >= 0: #or while childList: lastItem = childList[-1] if lastItem: if not yieldCondition or yieldCondition(lastItem, depth + 1): yield lastItem, depth + 1 child = getNextSibling(lastItem) childList[depth] = child if depth + 1 < maxDepth: child = getFirstChild(lastItem) if child: depth += 1 childList.append(child) else: del childList[depth] depth -= 1
Walk a tree not using recursive algorithm. top: a tree node. getChildren: Callable[[TreeNode], List[TreeNode]], function(treeNode: TreeNode) -> List[TreeNode]. getNextSibling: Callable[[TreeNode], TreeNode], function(treeNode: TreeNode) -> TreeNode. getNextSibling: Callable[[TreeNode], TreeNode], function(treeNode: TreeNode) -> TreeNode. yieldCondition: Callable[[TreeNode, int], bool], function(treeNode: TreeNode, depth: int) -> bool. includeTop: bool, if True yield top first. maxDepth: int, enum depth. If getChildren is valid, ignore getFirstChild and getNextSibling, yield 3 items tuple: (treeNode, depth, remain children count in current depth). If getChildren is not valid, using getFirstChild and getNextSibling, yield 2 items tuple: (treeNode, depth). If yieldCondition is not None, only yield tree nodes that yieldCondition(treeNode: TreeNode, depth: int)->bool returns True. For example: def GetDirChildren(dir_): if os.path.isdir(dir_): return [os.path.join(dir_, it) for it in os.listdir(dir_)] for it, depth, leftCount in WalkTree('D:\', getChildren= GetDirChildren): print(it, depth, leftCount)
WalkTree
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def ControlFromCursor() -> Control: """ Call ControlFromPoint with current cursor point. Return `Control` subclass. """ x, y = GetCursorPos() return ControlFromPoint(x, y)
Call ControlFromPoint with current cursor point. Return `Control` subclass.
ControlFromCursor
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def ControlFromCursor2() -> Control: """ Call ControlFromPoint2 with current cursor point. Return `Control` subclass. """ x, y = GetCursorPos() return ControlFromPoint2(x, y)
Call ControlFromPoint2 with current cursor point. Return `Control` subclass.
ControlFromCursor2
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def WalkControl(control: Control, includeTop: bool = False, maxDepth: int = 0xFFFFFFFF): """ control: `Control` or its subclass. includeTop: bool, if True, yield (control, 0) first. maxDepth: int, enum depth. Yield 2 items tuple (control: Control, depth: int). """ if includeTop: yield control, 0 if maxDepth <= 0: return depth = 0 child = control.GetFirstChildControl() controlList = [child] while depth >= 0: lastControl = controlList[-1] if lastControl: yield lastControl, depth + 1 child = lastControl.GetNextSiblingControl() controlList[depth] = child if depth + 1 < maxDepth: child = lastControl.GetFirstChildControl() if child: depth += 1 controlList.append(child) else: del controlList[depth] depth -= 1
control: `Control` or its subclass. includeTop: bool, if True, yield (control, 0) first. maxDepth: int, enum depth. Yield 2 items tuple (control: Control, depth: int).
WalkControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def LogControl(control: Control, depth: int = 0, showAllName: bool = True, showPid: bool = False) -> None: """ Print and log control's properties. control: `Control` or its subclass. depth: int, current depth. showAllName: bool, if False, print the first 30 characters of control.Name. """ def getKeyName(theDict, theValue): for key in theDict: if theValue == theDict[key]: return key indent = ' ' * depth * 4 Logger.Write('{0}ControlType: '.format(indent)) Logger.Write(control.ControlTypeName, ConsoleColor.DarkGreen) Logger.Write(' ClassName: ') Logger.Write(control.ClassName, ConsoleColor.DarkGreen) Logger.Write(' AutomationId: ') Logger.Write(control.AutomationId, ConsoleColor.DarkGreen) Logger.Write(' Rect: ') Logger.Write(control.BoundingRectangle, ConsoleColor.DarkGreen) Logger.Write(' Name: ') Logger.Write(control.Name, ConsoleColor.DarkGreen, printTruncateLen=0 if showAllName else 30) Logger.Write(' Handle: ') Logger.Write('0x{0:X}({0})'.format(control.NativeWindowHandle), ConsoleColor.DarkGreen) Logger.Write(' Depth: ') Logger.Write(depth, ConsoleColor.DarkGreen) if showPid: Logger.Write(' ProcessId: ') Logger.Write(control.ProcessId, ConsoleColor.DarkGreen) supportedPatterns = list(filter(lambda t: t[0], ((control.GetPattern(id_), name) for id_, name in PatternIdNames.items()))) for pt, name in supportedPatterns: if isinstance(pt, ValuePattern): Logger.Write(' ValuePattern.Value: ') Logger.Write(pt.Value, ConsoleColor.DarkGreen, printTruncateLen=0 if showAllName else 30) elif isinstance(pt, RangeValuePattern): Logger.Write(' RangeValuePattern.Value: ') Logger.Write(pt.Value, ConsoleColor.DarkGreen) elif isinstance(pt, TogglePattern): Logger.Write(' TogglePattern.ToggleState: ') Logger.Write('ToggleState.' + getKeyName(ToggleState.__dict__, pt.ToggleState), ConsoleColor.DarkGreen) elif isinstance(pt, SelectionItemPattern): Logger.Write(' SelectionItemPattern.IsSelected: ') Logger.Write(pt.IsSelected, ConsoleColor.DarkGreen) elif isinstance(pt, ExpandCollapsePattern): Logger.Write(' ExpandCollapsePattern.ExpandCollapseState: ') Logger.Write('ExpandCollapseState.' + getKeyName(ExpandCollapseState.__dict__, pt.ExpandCollapseState), ConsoleColor.DarkGreen) elif isinstance(pt, ScrollPattern): Logger.Write(' ScrollPattern.HorizontalScrollPercent: ') Logger.Write(pt.HorizontalScrollPercent, ConsoleColor.DarkGreen) Logger.Write(' ScrollPattern.VerticalScrollPercent: ') Logger.Write(pt.VerticalScrollPercent, ConsoleColor.DarkGreen) elif isinstance(pt, GridPattern): Logger.Write(' GridPattern.RowCount: ') Logger.Write(pt.RowCount, ConsoleColor.DarkGreen) Logger.Write(' GridPattern.ColumnCount: ') Logger.Write(pt.ColumnCount, ConsoleColor.DarkGreen) elif isinstance(pt, GridItemPattern): Logger.Write(' GridItemPattern.Row: ') Logger.Write(pt.Column, ConsoleColor.DarkGreen) Logger.Write(' GridItemPattern.Column: ') Logger.Write(pt.Column, ConsoleColor.DarkGreen) elif isinstance(pt, TextPattern): # issue 49: CEF Control as DocumentControl have no "TextPattern.Text" property, skip log this part. # https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-get_documentrange try: Logger.Write(' TextPattern.Text: ') Logger.Write(pt.DocumentRange.GetText(30), ConsoleColor.DarkGreen) except comtypes.COMError as ex: pass Logger.Write(' SupportedPattern:') for pt, name in supportedPatterns: Logger.Write(' ' + name, ConsoleColor.DarkGreen) Logger.Write('\n')
Print and log control's properties. control: `Control` or its subclass. depth: int, current depth. showAllName: bool, if False, print the first 30 characters of control.Name.
LogControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def EnumAndLogControl(control: Control, maxDepth: int = 0xFFFFFFFF, showAllName: bool = True, showPid: bool = False, startDepth: int = 0) -> None: """ Print and log control and its descendants' propertyies. control: `Control` or its subclass. maxDepth: int, enum depth. showAllName: bool, if False, print the first 30 characters of control.Name. startDepth: int, control's current depth. """ for c, d in WalkControl(control, True, maxDepth): LogControl(c, d + startDepth, showAllName, showPid)
Print and log control and its descendants' propertyies. control: `Control` or its subclass. maxDepth: int, enum depth. showAllName: bool, if False, print the first 30 characters of control.Name. startDepth: int, control's current depth.
EnumAndLogControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def EnumAndLogControlAncestors(control: Control, showAllName: bool = True, showPid: bool = False) -> None: """ Print and log control and its ancestors' propertyies. control: `Control` or its subclass. showAllName: bool, if False, print the first 30 characters of control.Name. """ lists = [] while control: lists.insert(0, control) control = control.GetParentControl() for i, control in enumerate(lists): LogControl(control, i, showAllName, showPid)
Print and log control and its ancestors' propertyies. control: `Control` or its subclass. showAllName: bool, if False, print the first 30 characters of control.Name.
EnumAndLogControlAncestors
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def FindControl(control: Control, compare: Callable[[Control, int], bool], maxDepth: int = 0xFFFFFFFF, findFromSelf: bool = False, foundIndex: int = 1) -> Control: """ control: `Control` or its subclass. compare: Callable[[Control, int], bool], function(control: Control, depth: int) -> bool. maxDepth: int, enum depth. findFromSelf: bool, if False, do not compare self. foundIndex: int, starts with 1, >= 1. Return `Control` subclass or None if not find. """ foundCount = 0 if not control: control = GetRootControl() traverseCount = 0 for child, depth in WalkControl(control, findFromSelf, maxDepth): traverseCount += 1 if compare(child, depth): foundCount += 1 if foundCount == foundIndex: child.traverseCount = traverseCount return child
control: `Control` or its subclass. compare: Callable[[Control, int], bool], function(control: Control, depth: int) -> bool. maxDepth: int, enum depth. findFromSelf: bool, if False, do not compare self. foundIndex: int, starts with 1, >= 1. Return `Control` subclass or None if not find.
FindControl
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def WaitHotKeyReleased(hotkey: Tuple[int, int]) -> None: """hotkey: Tuple[int, int], two ints tuple (modifierKey, key)""" mod = {ModifierKey.Alt: Keys.VK_MENU, ModifierKey.Control: Keys.VK_CONTROL, ModifierKey.Shift: Keys.VK_SHIFT, ModifierKey.Win: Keys.VK_LWIN } while True: time.sleep(0.05) if IsKeyPressed(hotkey[1]): continue for k, v in mod.items(): if k & hotkey[0]: if IsKeyPressed(v): break else: break
hotkey: Tuple[int, int], two ints tuple (modifierKey, key)
WaitHotKeyReleased
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def RunByHotKey(keyFunctions: Dict[Tuple[int, int], Callable], stopHotKey: Tuple[int, int] = None, exitHotKey: Tuple[int, int] = (ModifierKey.Control, Keys.VK_D), waitHotKeyReleased: bool = True) -> None: """ Bind functions with hotkeys, the function will be run or stopped in another thread when the hotkey is pressed. keyFunctions: Dict[Tuple[int, int], Callable], such as {(uiautomation.ModifierKey.Control, uiautomation.Keys.VK_1) : function} stopHotKey: hotkey tuple exitHotKey: hotkey tuple waitHotKeyReleased: bool, if True, hotkey function will be triggered after the hotkey is released def main(stopEvent): while True: if stopEvent.is_set(): # must check stopEvent.is_set() if you want to stop when stop hotkey is pressed break print(n) n += 1 stopEvent.wait(1) print('main exit') uiautomation.RunByHotKey({(uiautomation.ModifierKey.Control, uiautomation.Keys.VK_1) : main} , (uiautomation.ModifierKey.Control | uiautomation.ModifierKey.Shift, uiautomation.Keys.VK_2)) """ import traceback def getModName(theDict, theValue): name = '' for key in theDict: if isinstance(theDict[key], int) and theValue & theDict[key]: if name: name += '|' name += key return name def getKeyName(theDict, theValue): for key in theDict: if theValue == theDict[key]: return key def releaseAllKey(): for key, value in Keys.__dict__.items(): if isinstance(value, int) and key.startswith('VK'): if IsKeyPressed(value): ReleaseKey(value) def threadFunc(function, stopEvent, hotkey, hotkeyName): if waitHotKeyReleased: WaitHotKeyReleased(hotkey) try: function(stopEvent) except Exception as ex: Logger.ColorfullyWrite('Catch an exception <Color=Red>{}</Color> in thread for hotkey <Color=DarkCyan>{}</Color>\n'.format( ex.__class__.__name__, hotkeyName), writeToFile=False) print(traceback.format_exc()) finally: releaseAllKey() #need to release keys if some keys were pressed Logger.ColorfullyWrite('{} for function <Color=DarkCyan>{}</Color> exits, hotkey <Color=DarkCyan>{}</Color>\n'.format( threading.currentThread(), function.__name__, hotkeyName), ConsoleColor.DarkYellow, writeToFile=False) stopHotKeyId = 1 exitHotKeyId = 2 hotKeyId = 3 registed = True id2HotKey = {} id2Function = {} id2Thread = {} id2Name = {} for hotkey in keyFunctions: id2HotKey[hotKeyId] = hotkey id2Function[hotKeyId] = keyFunctions[hotkey] id2Thread[hotKeyId] = None modName = getModName(ModifierKey.__dict__, hotkey[0]) keyName = getKeyName(Keys.__dict__, hotkey[1]) id2Name[hotKeyId] = str((modName, keyName)) if ctypes.windll.user32.RegisterHotKey(0, hotKeyId, hotkey[0], hotkey[1]): Logger.ColorfullyWrite('Register hotkey <Color=Cyan>{}</Color> successfully\n'.format((modName, keyName)), writeToFile=False) else: registed = False Logger.ColorfullyWrite('Register hotkey <Color=Cyan>{}</Color> unsuccessfully, maybe it was allready registered by another program\n'.format((modName, keyName)), writeToFile=False) hotKeyId += 1 if stopHotKey and len(stopHotKey) == 2: modName = getModName(ModifierKey.__dict__, stopHotKey[0]) keyName = getKeyName(Keys.__dict__, stopHotKey[1]) if ctypes.windll.user32.RegisterHotKey(0, stopHotKeyId, stopHotKey[0], stopHotKey[1]): Logger.ColorfullyWrite('Register stop hotkey <Color=DarkYellow>{}</Color> successfully\n'.format((modName, keyName)), writeToFile=False) else: registed = False Logger.ColorfullyWrite('Register stop hotkey <Color=DarkYellow>{}</Color> unsuccessfully, maybe it was allready registered by another program\n'.format((modName, keyName)), writeToFile=False) if not registed: return if exitHotKey and len(exitHotKey) == 2: modName = getModName(ModifierKey.__dict__, exitHotKey[0]) keyName = getKeyName(Keys.__dict__, exitHotKey[1]) if ctypes.windll.user32.RegisterHotKey(0, exitHotKeyId, exitHotKey[0], exitHotKey[1]): Logger.ColorfullyWrite('Register exit hotkey <Color=DarkYellow>{}</Color> successfully\n'.format((modName, keyName)), writeToFile=False) else: Logger.ColorfullyWrite('Register exit hotkey <Color=DarkYellow>{}</Color> unsuccessfully\n'.format((modName, keyName)), writeToFile=False) funcThread = None livingThreads = [] stopEvent = threading.Event() msg = ctypes.wintypes.MSG() while ctypes.windll.user32.GetMessageW(ctypes.byref(msg), ctypes.c_void_p(0), ctypes.c_uint(0), ctypes.c_uint(0)) != 0: if msg.message == 0x0312: # WM_HOTKEY=0x0312 if msg.wParam in id2HotKey: if msg.lParam & 0x0000FFFF == id2HotKey[msg.wParam][0] and msg.lParam >> 16 & 0x0000FFFF == id2HotKey[msg.wParam][1]: Logger.ColorfullyWrite('----------hotkey <Color=Cyan>{}</Color> pressed----------\n'.format(id2Name[msg.wParam]), writeToFile=False) if not id2Thread[msg.wParam]: stopEvent.clear() funcThread = threading.Thread(None, threadFunc, args=(id2Function[msg.wParam], stopEvent, id2HotKey[msg.wParam], id2Name[msg.wParam])) funcThread.start() id2Thread[msg.wParam] = funcThread else: if id2Thread[msg.wParam].is_alive(): Logger.WriteLine('There is a {} that is already running for hotkey {}'.format(id2Thread[msg.wParam], id2Name[msg.wParam]), ConsoleColor.Yellow, writeToFile=False) else: stopEvent.clear() funcThread = threading.Thread(None, threadFunc, args=(id2Function[msg.wParam], stopEvent, id2HotKey[msg.wParam], id2Name[msg.wParam])) funcThread.start() id2Thread[msg.wParam] = funcThread elif stopHotKeyId == msg.wParam: if msg.lParam & 0x0000FFFF == stopHotKey[0] and msg.lParam >> 16 & 0x0000FFFF == stopHotKey[1]: Logger.Write('----------stop hotkey pressed----------\n', ConsoleColor.DarkYellow, writeToFile=False) stopEvent.set() for id_ in id2Thread: if id2Thread[id_]: if id2Thread[id_].is_alive(): livingThreads.append((id2Thread[id_], id2Name[id_])) id2Thread[id_] = None elif exitHotKeyId == msg.wParam: if msg.lParam & 0x0000FFFF == exitHotKey[0] and msg.lParam >> 16 & 0x0000FFFF == exitHotKey[1]: Logger.Write('Exit hotkey pressed. Exit\n', ConsoleColor.DarkYellow, writeToFile=False) stopEvent.set() for id_ in id2Thread: if id2Thread[id_]: if id2Thread[id_].is_alive(): livingThreads.append((id2Thread[id_], id2Name[id_])) id2Thread[id_] = None break for thread, hotkeyName in livingThreads: if thread.is_alive(): Logger.Write('join {} triggered by hotkey {}\n'.format(thread, hotkeyName), ConsoleColor.DarkYellow, writeToFile=False) thread.join(2) os._exit(0)
Bind functions with hotkeys, the function will be run or stopped in another thread when the hotkey is pressed. keyFunctions: Dict[Tuple[int, int], Callable], such as {(uiautomation.ModifierKey.Control, uiautomation.Keys.VK_1) : function} stopHotKey: hotkey tuple exitHotKey: hotkey tuple waitHotKeyReleased: bool, if True, hotkey function will be triggered after the hotkey is released def main(stopEvent): while True: if stopEvent.is_set(): # must check stopEvent.is_set() if you want to stop when stop hotkey is pressed break print(n) n += 1 stopEvent.wait(1) print('main exit') uiautomation.RunByHotKey({(uiautomation.ModifierKey.Control, uiautomation.Keys.VK_1) : main} , (uiautomation.ModifierKey.Control | uiautomation.ModifierKey.Shift, uiautomation.Keys.VK_2))
RunByHotKey
python
cluic/wxauto
wxauto/uiautomation.py
https://github.com/cluic/wxauto/blob/master/wxauto/uiautomation.py
Apache-2.0
def check_setuptools_features(): """Check if setuptools is up to date.""" import pkg_resources try: list(pkg_resources.parse_requirements('foo~=1.0')) except ValueError: sys.exit('Your Python distribution comes with an incompatible version ' 'of `setuptools`. Please run:\n' ' $ pip3 install --upgrade setuptools\n' 'and then run this command again')
Check if setuptools is up to date.
check_setuptools_features
python
bigchaindb/bigchaindb
setup.py
https://github.com/bigchaindb/bigchaindb/blob/master/setup.py
Apache-2.0
def map_leafs(func, mapping): """Map a function to the leafs of a mapping.""" def _inner(mapping, path=None): if path is None: path = [] for key, val in mapping.items(): if isinstance(val, collections.abc.Mapping): _inner(val, path + [key]) else: mapping[key] = func(val, path=path+[key]) return mapping return _inner(copy.deepcopy(mapping))
Map a function to the leafs of a mapping.
map_leafs
python
bigchaindb/bigchaindb
bigchaindb/config_utils.py
https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/config_utils.py
Apache-2.0
def update(d, u): """Recursively update a mapping (i.e. a dict, list, set, or tuple). Conceptually, d and u are two sets trees (with nodes and edges). This function goes through all the nodes of u. For each node in u, if d doesn't have that node yet, then this function adds the node from u, otherwise this function overwrites the node already in d with u's node. Args: d (mapping): The mapping to overwrite and add to. u (mapping): The mapping to read for changes. Returns: mapping: An updated version of d (updated by u). """ for k, v in u.items(): if isinstance(v, collections.abc.Mapping): r = update(d.get(k, {}), v) d[k] = r else: d[k] = u[k] return d
Recursively update a mapping (i.e. a dict, list, set, or tuple). Conceptually, d and u are two sets trees (with nodes and edges). This function goes through all the nodes of u. For each node in u, if d doesn't have that node yet, then this function adds the node from u, otherwise this function overwrites the node already in d with u's node. Args: d (mapping): The mapping to overwrite and add to. u (mapping): The mapping to read for changes. Returns: mapping: An updated version of d (updated by u).
update
python
bigchaindb/bigchaindb
bigchaindb/config_utils.py
https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/config_utils.py
Apache-2.0
def file_config(filename=None): """Returns the config values found in a configuration file. Args: filename (str): the JSON file with the configuration values. If ``None``, CONFIG_DEFAULT_PATH will be used. Returns: dict: The config values in the specified config file (or the file at CONFIG_DEFAULT_PATH, if filename == None) """ logger.debug('On entry into file_config(), filename = {}'.format(filename)) if filename is None: filename = CONFIG_DEFAULT_PATH logger.debug('file_config() will try to open `{}`'.format(filename)) with open(filename) as f: try: config = json.load(f) except ValueError as err: raise exceptions.ConfigurationError( 'Failed to parse the JSON configuration from `{}`, {}'.format(filename, err) ) logger.info('Configuration loaded from `{}`'.format(filename)) return config
Returns the config values found in a configuration file. Args: filename (str): the JSON file with the configuration values. If ``None``, CONFIG_DEFAULT_PATH will be used. Returns: dict: The config values in the specified config file (or the file at CONFIG_DEFAULT_PATH, if filename == None)
file_config
python
bigchaindb/bigchaindb
bigchaindb/config_utils.py
https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/config_utils.py
Apache-2.0
def env_config(config): """Return a new configuration with the values found in the environment. The function recursively iterates over the config, checking if there is a matching env variable. If an env variable is found, the func updates the configuration with that value. The name of the env variable is built combining a prefix (``BIGCHAINDB``) with the path to the value. If the ``config`` in input is: ``{'database': {'host': 'localhost'}}`` this function will try to read the env variable ``BIGCHAINDB_DATABASE_HOST``. """ def load_from_env(value, path): var_name = CONFIG_SEP.join([CONFIG_PREFIX] + list(map(lambda s: s.upper(), path))) return os.environ.get(var_name, value) return map_leafs(load_from_env, config)
Return a new configuration with the values found in the environment. The function recursively iterates over the config, checking if there is a matching env variable. If an env variable is found, the func updates the configuration with that value. The name of the env variable is built combining a prefix (``BIGCHAINDB``) with the path to the value. If the ``config`` in input is: ``{'database': {'host': 'localhost'}}`` this function will try to read the env variable ``BIGCHAINDB_DATABASE_HOST``.
env_config
python
bigchaindb/bigchaindb
bigchaindb/config_utils.py
https://github.com/bigchaindb/bigchaindb/blob/master/bigchaindb/config_utils.py
Apache-2.0