def verifytabname(self, window_name, object_name, tab_name):

try:<EOL><INDENT>tab_handle = self._get_tab_handle(window_name, object_name, tab_name)<EOL>if tab_handle.AXValue:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify tab name.

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param tab_name: tab to select
@type data: string

@return: 1 on success 0 on failure
@rtype: integer


def gettabcount(self, window_name, object_name):

children = self._get_tab_children(window_name, object_name)<EOL>return len(children)<EOL>

Get tab count.

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: tab count on success.
@rtype: integer


def gettabname(self, window_name, object_name, tab_index):

children = self._get_tab_children(window_name, object_name)<EOL>length = len(children)<EOL>if tab_index < <NUM_LIT:0> or tab_index > length:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % tab_index)<EOL><DEDENT>tab_handle = children[tab_index]<EOL>if not tab_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>return tab_handle.AXTitle<EOL>

Get tab name

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param tab_index: Index of tab (zero based index)
@type object_name: int

@return: text on success.
@rtype: string


def mouseleftclick(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>self._grabfocus(object_handle)<EOL>x, y, width, height = self._getobjectsize(object_handle)<EOL>object_handle.clickMouseButtonLeft((x + width / <NUM_LIT:2>, y + height / <NUM_LIT:2>))<EOL>return <NUM_LIT:1><EOL>

Mouse left click on an object.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def mouserightclick(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>self._grabfocus(object_handle)<EOL>x, y, width, height = self._getobjectsize(object_handle)<EOL>object_handle.clickMouseButtonRight((x + width / <NUM_LIT:2>, y + height / <NUM_LIT:2>))<EOL>return <NUM_LIT:1><EOL>

Mouse right click on an object.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def generatemouseevent(self, x, y, eventType="<STR_LIT>",<EOL>drag_button_override='<STR_LIT>'):

if drag_button_override not in mouse_click_override:<EOL><INDENT>raise ValueError('<STR_LIT>' %drag_button_override)<EOL><DEDENT>global drag_button_remembered<EOL>point = (x, y)<EOL>button = centre  <EOL>click_type = None<EOL>if eventType == "<STR_LIT>" or eventType == "<STR_LIT>":<EOL><INDENT>if drag_button_override is not '<STR_LIT>':<EOL><INDENT>events = [mouse_click_override[drag_button_override]]<EOL><DEDENT>elif drag_button_remembered:<EOL><INDENT>events = [drag_button_remembered]<EOL><DEDENT>else:<EOL><INDENT>events = [move]<EOL><DEDENT>if eventType == "<STR_LIT>":<EOL><INDENT>point = CGEventGetLocation(CGEventCreate(None))<EOL>point.x += x<EOL>point.y += y<EOL><DEDENT><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_left]<EOL>drag_button_remembered = drag_left<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [release_left]<EOL>drag_button_remembered = None<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_left, release_left]<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_left, release_left]<EOL>click_type = double_click<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_other]<EOL>drag_button_remembered = drag_other<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [release_other]<EOL>drag_button_remembered = None<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_other, release_other]<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_other, release_other]<EOL>click_type = double_click<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_right]<EOL>drag_button_remembered = drag_right<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [release_right]<EOL>drag_button_remembered = None<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_right, release_right]<EOL><DEDENT>elif eventType == "<STR_LIT>":<EOL><INDENT>events = [press_right, release_right]<EOL>click_type = double_click<EOL><DEDENT>else:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % eventType)<EOL><DEDENT>for event in events:<EOL><INDENT>CG_event = CGEventCreateMouseEvent(None, event, point, button)<EOL>if click_type:<EOL><INDENT>CGEventSetIntegerValueField(<EOL>CG_event, kCGMouseEventClickState, click_type)<EOL><DEDENT>CGEventPost(kCGHIDEventTap, CG_event)<EOL>time.sleep(<NUM_LIT>)<EOL><DEDENT>return <NUM_LIT:1><EOL>

Generate mouse event on x, y co-ordinates.

@param x: X co-ordinate
@type x: int
@param y: Y co-ordinate
@type y: int
@param eventType: Mouse click type
@type eventType: str
@param drag_button_override: Any drag_xxx value
        Only relevant for movements, i.e. |type| = "abs" or "rel"
        Quartz is not fully compatible with windows, so for drags
        the drag button must be explicitly defined. generatemouseevent
        will remember the last button pressed by default, and drag
        that button, use this argument to override that.
@type drag_button_override: str

@return: 1 on success.
@rtype: integer


def mousemove(self, window_name, object_name):

raise LdtpServerException("<STR_LIT>")<EOL>

Mouse move on an object.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def doubleclick(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>self._grabfocus(object_handle)<EOL>x, y, width, height = self._getobjectsize(object_handle)<EOL>window = self._get_front_most_window()<EOL>window.doubleClickMouse((x + width / <NUM_LIT:2>, y + height / <NUM_LIT:2>))<EOL>return <NUM_LIT:1><EOL>

Double click on the object

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def simulatemousemove(self, source_x, source_y, dest_x, dest_y, delay=<NUM_LIT:0.0>):

@param source_x: Source X
@type source_x: integer
@param source_y: Source Y
@type source_y: integer
@param dest_x: Dest X
@type dest_x: integer
@param dest_y: Dest Y
@type dest_y: integer
@param delay: Sleep time between the mouse move
@type delay: double

@return: 1 if simulation was successful, 0 if not.
@rtype: integer


def selectitem(self, window_name, object_name, item_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>self._grabfocus(object_handle.AXWindow)<EOL>try:<EOL><INDENT>object_handle.Press()<EOL><DEDENT>except AttributeError:<EOL><INDENT>x, y, width, height = self._getobjectsize(object_handle)<EOL>self.generatemouseevent(x + <NUM_LIT:5>, y + <NUM_LIT:5>, "<STR_LIT>")<EOL>self.wait(<NUM_LIT:5>)<EOL>handle = self._get_sub_menu_handle(object_handle, item_name)<EOL>x, y, width, height = self._getobjectsize(handle)<EOL>self.generatemouseevent(x + <NUM_LIT:5>, y + <NUM_LIT:5>, "<STR_LIT>")<EOL>return <NUM_LIT:1><EOL><DEDENT>self.wait(<NUM_LIT:1>)<EOL>menu_list = re.split("<STR_LIT:;>", item_name)<EOL>try:<EOL><INDENT>menu_handle = self._internal_menu_handler(object_handle, menu_list,<EOL>True)<EOL>self.wait(<NUM_LIT:1>)<EOL>if not menu_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" %menu_list[-<NUM_LIT:1>])<EOL><DEDENT>menu_handle.Press()<EOL><DEDENT>except LdtpServerException:<EOL><INDENT>object_handle.activate()<EOL>object_handle.sendKey(AXKeyCodeConstants.ESCAPE)<EOL>raise<EOL><DEDENT>return <NUM_LIT:1><EOL>

Select combo box / layered pane item

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param item_name: Item name to select
@type object_name: string

@return: 1 on success.
@rtype: integer


def selectindex(self, window_name, object_name, item_index):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>self._grabfocus(object_handle.AXWindow)<EOL>try:<EOL><INDENT>object_handle.Press()<EOL><DEDENT>except AttributeError:<EOL><INDENT>x, y, width, height = self._getobjectsize(object_handle)<EOL>self.generatemouseevent(x + <NUM_LIT:5>, y + <NUM_LIT:5>, "<STR_LIT>")<EOL><DEDENT>self.wait(<NUM_LIT:2>)<EOL>if not object_handle.AXChildren:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>")<EOL><DEDENT>children = object_handle.AXChildren[<NUM_LIT:0>]<EOL>if not children:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>")<EOL><DEDENT>children = children.AXChildren<EOL>tmp_children = []<EOL>for child in children:<EOL><INDENT>role, label = self._ldtpize_accessible(child)<EOL>if label:<EOL><INDENT>tmp_children.append(child)<EOL><DEDENT><DEDENT>children = tmp_children<EOL>length = len(children)<EOL>try:<EOL><INDENT>if item_index < <NUM_LIT:0> or item_index > length:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % item_index)<EOL><DEDENT>menu_handle = children[item_index]<EOL>if not menu_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % menu_list[-<NUM_LIT:1>])<EOL><DEDENT>self._grabfocus(menu_handle)<EOL>x, y, width, height = self._getobjectsize(menu_handle)<EOL>window = object_handle.AXWindow<EOL>"""<STR_LIT>"""<EOL>window.doubleClickMouse((x + <NUM_LIT:5>, y + <NUM_LIT:5>))<EOL>child = None<EOL><DEDENT>finally:<EOL><INDENT>if child:<EOL><INDENT>child.Cancel()<EOL><DEDENT><DEDENT>return <NUM_LIT:1><EOL>

Select combo box item / layered pane based on index

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param item_index: Item index to select
@type object_name: integer

@return: 1 on success.
@rtype: integer


def getallitem(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>object_handle.Press()<EOL>self.wait(<NUM_LIT:1>)<EOL>child = None<EOL>try:<EOL><INDENT>if not object_handle.AXChildren:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>")<EOL><DEDENT>children = object_handle.AXChildren[<NUM_LIT:0>]<EOL>if not children:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>")<EOL><DEDENT>children = children.AXChildren<EOL>items = []<EOL>for child in children:<EOL><INDENT>label = self._get_title(child)<EOL>if label:<EOL><INDENT>items.append(label)<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>if child:<EOL><INDENT>child.Cancel()<EOL><DEDENT><DEDENT>return items<EOL>

Get all combo box item

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: list of string on success.
@rtype: list


def showlist(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>object_handle.Press()<EOL>return <NUM_LIT:1><EOL>

Show combo box list / menu

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success.
@rtype: integer


def hidelist(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>object_handle.activate()<EOL>object_handle.sendKey(AXKeyCodeConstants.ESCAPE)<EOL>return <NUM_LIT:1><EOL>

Hide combo box list / menu

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success.
@rtype: integer


def verifydropdown(self, window_name, object_name):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled or not object_handle.AXChildren:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>children = object_handle.AXChildren[<NUM_LIT:0>]<EOL>if children:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify drop down list / menu poped up

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success 0 on failure.
@rtype: integer


def verifyshowlist(self, window_name, object_name):

return self.verifydropdown(window_name, object_name)<EOL>


def verifyhidelist(self, window_name, object_name):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>if not object_handle.AXChildren:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>children = object_handle.AXChildren[<NUM_LIT:0>]<EOL>if not children:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>return <NUM_LIT:1><EOL><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify list / menu is hidden in combo box

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success 0 on failure.
@rtype: integer


def verifyselect(self, window_name, object_name, item_name):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>role, label = self._ldtpize_accessible(object_handle)<EOL>title = self._get_title(object_handle)<EOL>if re.match(item_name, title, re.M | re.U | re.L) orre.match(item_name, label, re.M | re.U | re.L) orre.match(item_name, u"<STR_LIT>" % (role, label),<EOL>re.M | re.U | re.L):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify the item selected in combo box

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param item_name: Item name to select
@type object_name: string

@return: 1 on success.
@rtype: integer


def getcombovalue(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>return self._get_title(object_handle)<EOL>

Get current selected combobox value

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: selected item on success, else LdtpExecutionError on failure.
@rtype: string


KeyComboAction(data)<EOL>return <NUM_LIT:1><EOL>

Generates key event to the system, this simulates the best user like
interaction via keyboard.

@param data: data to type.
@type data: string

@return: 1 on success.
@rtype: integer


try:<EOL><INDENT>window = self._get_front_most_window()<EOL><DEDENT>except (IndexError,):<EOL><INDENT>window = self._get_any_window()<EOL><DEDENT>key_press_action = KeyPressAction(window, data)<EOL>return <NUM_LIT:1><EOL>

Press key. NOTE: keyrelease should be called

@param data: data to type.
@type data: string

@return: 1 on success.
@rtype: integer


try:<EOL><INDENT>window = self._get_front_most_window()<EOL><DEDENT>except (IndexError,):<EOL><INDENT>window = self._get_any_window()<EOL><DEDENT>key_release_action = KeyReleaseAction(window, data)<EOL>return <NUM_LIT:1><EOL>

Release key. NOTE: keypress should be called before this

@param data: data to type.
@type data: string

@return: 1 on success.
@rtype: integer


def enterstring(self, window_name, object_name='<STR_LIT>', data='<STR_LIT>'):

if not object_name and not data:<EOL><INDENT>return self.generatekeyevent(window_name)<EOL><DEDENT>else:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>self._grabfocus(object_handle)<EOL>object_handle.sendKeys(data)<EOL>return <NUM_LIT:1><EOL><DEDENT>

Type string sequence.

@param window_name: Window name to focus on, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to focus on, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param data: data to type.
@type data: string

@return: 1 on success.
@rtype: integer


def settextvalue(self, window_name, object_name, data):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>object_handle.AXValue = data<EOL>return <NUM_LIT:1><EOL>

Type string sequence.

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param data: data to type.
@type data: string

@return: 1 on success.
@rtype: integer


def gettextvalue(self, window_name, object_name, startPosition=<NUM_LIT:0>, endPosition=<NUM_LIT:0>):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>return object_handle.AXValue<EOL>

Get text value

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param startPosition: Starting position of text to fetch
@type: startPosition: int
@param endPosition: Ending position of text to fetch
@type: endPosition: int

@return: text on success.
@rtype: string


def inserttext(self, window_name, object_name, position, data):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>existing_data = object_handle.AXValue<EOL>size = len(existing_data)<EOL>if position < <NUM_LIT:0>:<EOL><INDENT>position = <NUM_LIT:0><EOL><DEDENT>if position > size:<EOL><INDENT>position = size<EOL><DEDENT>object_handle.AXValue = existing_data[:position] + data +existing_data[position:]<EOL>return <NUM_LIT:1><EOL>

Insert string sequence in given position.

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param position: position where text has to be entered.
@type data: int
@param data: data to type.
@type data: string

@return: 1 on success.
@rtype: integer


def verifypartialmatch(self, window_name, object_name, partial_text):

Verify partial text

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param partial_text: Partial text to match
@type object_name: string

@return: 1 on success.
@rtype: integer


def verifysettext(self, window_name, object_name, text):

try:<EOL><INDENT>return int(re.match(fnmatch.translate(text),<EOL>self.gettextvalue(window_name,<EOL>object_name)))<EOL><DEDENT>except:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>

Verify text is set correctly

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param text: text to match
@type object_name: string

@return: 1 on success.
@rtype: integer


def istextstateenabled(self, window_name, object_name):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name)<EOL>if object_handle.AXEnabled:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verifies text state enabled or not

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success 0 on failure.
@rtype: integer


def getcharcount(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>return object_handle.AXNumberOfCharacters<EOL>

Get character count

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success.
@rtype: integer


def appendtext(self, window_name, object_name, data):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>object_handle.AXValue += data<EOL>return <NUM_LIT:1><EOL>

Append string sequence.

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param data: data to type.
@type data: string

@return: 1 on success.
@rtype: integer


def getcursorposition(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>return object_handle.AXSelectedTextRange.loc<EOL>

Get cursor position

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: Cursor position on success.
@rtype: integer


def setcursorposition(self, window_name, object_name, cursor_position):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>object_handle.AXSelectedTextRange.loc = cursor_position<EOL>return <NUM_LIT:1><EOL>

Set cursor position

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param cursor_position: Cursor position to be set
@type object_name: string

@return: 1 on success.
@rtype: integer


def cuttext(self, window_name, object_name, start_position, end_position=-<NUM_LIT:1>):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>size = object_handle.AXNumberOfCharacters<EOL>if end_position == -<NUM_LIT:1> or end_position > size:<EOL><INDENT>end_position = size<EOL><DEDENT>if start_position < <NUM_LIT:0>:<EOL><INDENT>start_position = <NUM_LIT:0><EOL><DEDENT>data = object_handle.AXValue<EOL>Clipboard.copy(data[start_position:end_position])<EOL>object_handle.AXValue = data[:start_position] + data[end_position:]<EOL>return <NUM_LIT:1><EOL>

cut text from start position to end position

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param start_position: Start position
@type object_name: integer
@param end_position: End position, default -1
Cut all the text from start position till end
@type object_name: integer

@return: 1 on success.
@rtype: integer


def copytext(self, window_name, object_name, start_position, end_position=-<NUM_LIT:1>):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>size = object_handle.AXNumberOfCharacters<EOL>if end_position == -<NUM_LIT:1> or end_position > size:<EOL><INDENT>end_position = size<EOL><DEDENT>if start_position < <NUM_LIT:0>:<EOL><INDENT>start_position = <NUM_LIT:0><EOL><DEDENT>data = object_handle.AXValue<EOL>Clipboard.copy(data[start_position:end_position])<EOL>return <NUM_LIT:1><EOL>

copy text from start position to end position

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param start_position: Start position
@type object_name: integer
@param end_position: End position, default -1
Copy all the text from start position till end
@type object_name: integer

@return: 1 on success.
@rtype: integer


def deletetext(self, window_name, object_name, start_position, end_position=-<NUM_LIT:1>):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>size = object_handle.AXNumberOfCharacters<EOL>if end_position == -<NUM_LIT:1> or end_position > size:<EOL><INDENT>end_position = size<EOL><DEDENT>if start_position < <NUM_LIT:0>:<EOL><INDENT>start_position = <NUM_LIT:0><EOL><DEDENT>data = object_handle.AXValue<EOL>object_handle.AXValue = data[:start_position] + data[end_position:]<EOL>return <NUM_LIT:1><EOL>

delete text from start position to end position

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param start_position: Start position
@type object_name: integer
@param end_position: End position, default -1
Delete all the text from start position till end
@type object_name: integer

@return: 1 on success.
@rtype: integer


def pastetext(self, window_name, object_name, position=<NUM_LIT:0>):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>size = object_handle.AXNumberOfCharacters<EOL>if position > size:<EOL><INDENT>position = size<EOL><DEDENT>if position < <NUM_LIT:0>:<EOL><INDENT>position = <NUM_LIT:0><EOL><DEDENT>clipboard = Clipboard.paste()<EOL>data = object_handle.AXValue<EOL>object_handle.AXValue = data[:position] + clipboard + data[position:]<EOL>return <NUM_LIT:1><EOL>

paste text from start position to end position

@param window_name: Window name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to type in, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param position: Position to paste the text, default 0
@type object_name: integer

@return: 1 on success.
@rtype: integer


def selectmenuitem(self, window_name, object_name):

menu_handle = self._get_menu_handle(window_name, object_name)<EOL>if not menu_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>menu_handle.Press()<EOL>return <NUM_LIT:1><EOL>

Select (click) a menu item.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def doesmenuitemexist(self, window_name, object_name):

try:<EOL><INDENT>menu_handle = self._get_menu_handle(window_name, object_name,<EOL>False)<EOL>return <NUM_LIT:1><EOL><DEDENT>except LdtpServerException:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>

Check a menu item exist.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string
@param strict_hierarchy: Mandate menu hierarchy if set to True
@type object_name: boolean

@return: 1 on success.
@rtype: integer


def menuitemenabled(self, window_name, object_name):

try:<EOL><INDENT>menu_handle = self._get_menu_handle(window_name, object_name,<EOL>False)<EOL>if menu_handle.AXEnabled:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify a menu item is enabled

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def listsubmenus(self, window_name, object_name):

menu_handle = self._get_menu_handle(window_name, object_name)<EOL>role, label = self._ldtpize_accessible(menu_handle)<EOL>menu_clicked = False<EOL>try:<EOL><INDENT>if not menu_handle.AXChildren:<EOL><INDENT>menu_clicked = True<EOL>try:<EOL><INDENT>menu_handle.Press()<EOL>self.wait(<NUM_LIT:1>)<EOL><DEDENT>except atomac._a11y.ErrorCannotComplete:<EOL><INDENT>pass<EOL><DEDENT>if not menu_handle.AXChildren:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" %label)<EOL><DEDENT><DEDENT>children = menu_handle.AXChildren[<NUM_LIT:0>]<EOL>sub_menus = []<EOL>for current_menu in children.AXChildren:<EOL><INDENT>role, label = self._ldtpize_accessible(current_menu)<EOL>if not label:<EOL><INDENT>continue<EOL><DEDENT>sub_menus.append(u"<STR_LIT>" % (role, label))<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>if menu_clicked:<EOL><INDENT>menu_handle.Cancel()<EOL><DEDENT><DEDENT>return sub_menus<EOL>

List children of menu item

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: menu item in list on success.
@rtype: list


def verifymenucheck(self, window_name, object_name):

try:<EOL><INDENT>menu_handle = self._get_menu_handle(window_name, object_name,<EOL>False)<EOL>try:<EOL><INDENT>if menu_handle.AXMenuItemMarkChar:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except atomac._a11y.Error:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify a menu item is checked

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def verifymenuuncheck(self, window_name, object_name):

try:<EOL><INDENT>menu_handle = self._get_menu_handle(window_name, object_name,<EOL>False)<EOL>try:<EOL><INDENT>if not menu_handle.AXMenuItemMarkChar:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except atomac._a11y.Error:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify a menu item is un-checked

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def menucheck(self, window_name, object_name):

menu_handle = self._get_menu_handle(window_name, object_name)<EOL>if not menu_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>try:<EOL><INDENT>if menu_handle.AXMenuItemMarkChar:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except atomac._a11y.Error:<EOL><INDENT>pass<EOL><DEDENT>menu_handle.Press()<EOL>return <NUM_LIT:1><EOL>

Check (click) a menu item.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


def menuuncheck(self, window_name, object_name):

menu_handle = self._get_menu_handle(window_name, object_name)<EOL>if not menu_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>try:<EOL><INDENT>if not menu_handle.AXMenuItemMarkChar:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except atomac._a11y.Error:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>menu_handle.Press()<EOL>return <NUM_LIT:1><EOL>

Uncheck (click) a menu item.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: 1 on success.
@rtype: integer


if "<STR_LIT>" in os.environ:<EOL><INDENT>_ldtp_debug = True<EOL><DEDENT>else:<EOL><INDENT>_ldtp_debug = False<EOL><DEDENT>_ldtp_debug_file = os.environ.get('<STR_LIT>', None)<EOL>if _ldtp_debug:<EOL><INDENT>print("<STR_LIT>".format(int(parentpid)))<EOL><DEDENT>if _ldtp_debug_file:<EOL><INDENT>with open(unicode(_ldtp_debug_file), "<STR_LIT:a>") as fp:<EOL><INDENT>fp.write("<STR_LIT>".format(int(parentpid)))<EOL><DEDENT><DEDENT>server = LDTPServer(('<STR_LIT>', port), allow_none=True, logRequests=_ldtp_debug,<EOL>requestHandler=RequestHandler)<EOL>server.register_introspection_functions()<EOL>server.register_multicall_functions()<EOL>ldtp_inst = core.Core()<EOL>server.register_instance(ldtp_inst)<EOL>if parentpid:<EOL><INDENT>thread.start_new_thread(notifyclient, (parentpid,))<EOL><DEDENT>try:<EOL><INDENT>server.serve_forever()<EOL><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pass<EOL><DEDENT>except:<EOL><INDENT>if _ldtp_debug:<EOL><INDENT>print(traceback.format_exc())<EOL><DEDENT>if _ldtp_debug_file:<EOL><INDENT>with open(_ldtp_debug_file, "<STR_LIT:a>") as fp:<EOL><INDENT>fp.write(traceback.format_exc())<EOL><DEDENT><DEDENT><DEDENT>

Main entry point. Parse command line options and start up a server.


self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, <NUM_LIT:1>)<EOL>SimpleXMLRPCServer.server_bind(self, *args, **kwargs)<EOL>


app_list = []<EOL>self._update_apps()<EOL>for gui in self._running_apps:<EOL><INDENT>name = gui.localizedName()<EOL>try:<EOL><INDENT>name = unicode(name)<EOL><DEDENT>except NameError:<EOL><INDENT>name = str(name)<EOL><DEDENT>except UnicodeEncodeError:<EOL><INDENT>pass<EOL><DEDENT>app_list.append(name)<EOL><DEDENT>return list(set(app_list))<EOL>

Get all accessibility application name that are currently running

@return: list of appliction name of string type on success.
@rtype: list


return self._get_windows(True).keys()<EOL>

Get all accessibility window that are currently open

@return: list of window names in LDTP format of string type on success.
@rtype: list


return True<EOL>

Client will use this to verify whether the server instance is alive or not.

@return: True on success.
@rtype: boolean


if not self._callback_event:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return self._callback_event.pop()<EOL>

Poll for any registered events or window create events

@return: window name
@rtype: string


if not self._custom_logger.log_events:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>return self._custom_logger.log_events.pop()<EOL>

Returns one line of log at any time, if any available, else empty string

@return: log as string
@rtype: string


def startprocessmonitor(self, process_name, interval=<NUM_LIT:2>):

if process_name in self._process_stats:<EOL><INDENT>self._process_stats[process_name].stop()<EOL><DEDENT>self._process_stats[process_name] = ProcessStats(process_name, interval)<EOL>self._process_stats[process_name].start()<EOL>return <NUM_LIT:1><EOL>

Start memory and CPU monitoring, with the time interval between
each process scan

@param process_name: Process name, ex: firefox-bin.
@type process_name: string
@param interval: Time interval between each process scan
@type interval: double

@return: 1 on success
@rtype: integer


if process_name in self._process_stats:<EOL><INDENT>self._process_stats[process_name].stop()<EOL><DEDENT>return <NUM_LIT:1><EOL>

Stop memory and CPU monitoring

@param process_name: Process name, ex: firefox-bin.
@type process_name: string

@return: 1 on success
@rtype: integer


<EOL>_stat_inst = ProcessStats(process_name)<EOL>_stat_list = []<EOL>for p in _stat_inst.get_cpu_memory_stat():<EOL><INDENT>try:<EOL><INDENT>_stat_list.append(p.get_cpu_percent())<EOL><DEDENT>except psutil.AccessDenied:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return _stat_list<EOL>

get CPU stat for the give process name

@param process_name: Process name, ex: firefox-bin.
@type process_name: string

@return: cpu stat list on success, else empty list
        If same process name, running multiple instance,
        get the stat of all the process CPU usage
@rtype: list


<EOL>_stat_inst = ProcessStats(process_name)<EOL>_stat_list = []<EOL>for p in _stat_inst.get_cpu_memory_stat():<EOL><INDENT>try:<EOL><INDENT>_stat_list.append(round(p.get_memory_percent(), <NUM_LIT:2>))<EOL><DEDENT>except psutil.AccessDenied:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return _stat_list<EOL>

get memory stat

@param process_name: Process name, ex: firefox-bin.
@type process_name: string

@return: memory stat list on success, else empty list
        If same process name, running multiple instance,
        get the stat of all the process memory usage
@rtype: list


try:<EOL><INDENT>window_handle, name, app = self._get_window_handle(window_name, True)<EOL>object_list = self._get_appmap(window_handle, name, True)<EOL><DEDENT>except atomac._a11y.ErrorInvalidUIElement:<EOL><INDENT>self._windows = {}<EOL>window_handle, name, app = self._get_window_handle(window_name, True)<EOL>object_list = self._get_appmap(window_handle, name, True)<EOL><DEDENT>return object_list.keys()<EOL>

Get list of items in given GUI.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string

@return: list of items in LDTP naming convention.
@rtype: list


def getobjectinfo(self, window_name, object_name):

try:<EOL><INDENT>obj_info = self._get_object_map(window_name, object_name,<EOL>wait_for_object=False)<EOL><DEDENT>except atomac._a11y.ErrorInvalidUIElement:<EOL><INDENT>self._windows = {}<EOL>obj_info = self._get_object_map(window_name, object_name,<EOL>wait_for_object=False)<EOL><DEDENT>props = []<EOL>if obj_info:<EOL><INDENT>for obj_prop in obj_info.keys():<EOL><INDENT>if not obj_info[obj_prop] or obj_prop == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT>props.append(obj_prop)<EOL><DEDENT><DEDENT>return props<EOL>

Get object properties.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: list of properties
@rtype: list


def getobjectproperty(self, window_name, object_name, prop):

try:<EOL><INDENT>obj_info = self._get_object_map(window_name, object_name,<EOL>wait_for_object=False)<EOL><DEDENT>except atomac._a11y.ErrorInvalidUIElement:<EOL><INDENT>self._windows = {}<EOL>obj_info = self._get_object_map(window_name, object_name,<EOL>wait_for_object=False)<EOL><DEDENT>if obj_info and prop != "<STR_LIT>" and prop in obj_info:<EOL><INDENT>if prop == "<STR_LIT:class>":<EOL><INDENT>return ldtp_class_type.get(obj_info[prop], obj_info[prop])<EOL><DEDENT>else:<EOL><INDENT>return obj_info[prop]<EOL><DEDENT><DEDENT>raise LdtpServerException('<STR_LIT>' %(prop, object_name))<EOL>

Get object property value.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param prop: property name.
@type prop: string

@return: property
@rtype: string


def getchild(self, window_name, child_name='<STR_LIT>', role='<STR_LIT>', parent='<STR_LIT>'):

matches = []<EOL>if role:<EOL><INDENT>role = re.sub('<STR_LIT:U+0020>', '<STR_LIT:_>', role)<EOL><DEDENT>self._windows = {}<EOL>if parent and (child_name or role):<EOL><INDENT>_window_handle, _window_name =self._get_window_handle(window_name)[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>if not _window_handle:<EOL><INDENT>raise LdtpServerException('<STR_LIT>' %window_name)<EOL><DEDENT>appmap = self._get_appmap(_window_handle, _window_name)<EOL>obj = self._get_object_map(window_name, parent)<EOL>def _get_all_children_under_obj(obj, child_list):<EOL><INDENT>if role and obj['<STR_LIT:class>'] == role:<EOL><INDENT>child_list.append(obj['<STR_LIT:label>'])<EOL><DEDENT>elif child_name and self._match_name_to_appmap(child_name, obj):<EOL><INDENT>child_list.append(obj['<STR_LIT:label>'])<EOL><DEDENT>if obj:<EOL><INDENT>children = obj['<STR_LIT>']<EOL><DEDENT>if not children:<EOL><INDENT>return child_list<EOL><DEDENT>for child in children.split():<EOL><INDENT>return _get_all_children_under_obj(appmap[child],<EOL>child_list)<EOL><DEDENT><DEDENT>matches = _get_all_children_under_obj(obj, [])<EOL>if not matches:<EOL><INDENT>if child_name:<EOL><INDENT>_name = '<STR_LIT>' % child_name<EOL><DEDENT>if role:<EOL><INDENT>_role = '<STR_LIT>' % role<EOL><DEDENT>if parent:<EOL><INDENT>_parent = '<STR_LIT>' % parent<EOL><DEDENT>exception = '<STR_LIT>' % (_name, _role, _parent)<EOL>raise LdtpServerException(exception)<EOL><DEDENT>return matches<EOL><DEDENT>_window_handle, _window_name =self._get_window_handle(window_name)[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>if not _window_handle:<EOL><INDENT>raise LdtpServerException('<STR_LIT>' %window_name)<EOL><DEDENT>appmap = self._get_appmap(_window_handle, _window_name)<EOL>for name in appmap.keys():<EOL><INDENT>obj = appmap[name]<EOL>if role and not child_name and obj['<STR_LIT:class>'] == role:<EOL><INDENT>matches.append(name)<EOL><DEDENT>if parent and child_name and not role andself._match_name_to_appmap(parent, obj):<EOL><INDENT>matches.append(name)<EOL><DEDENT>if child_name and not role andself._match_name_to_appmap(child_name, obj):<EOL><INDENT>return name<EOL>matches.append(name)<EOL><DEDENT>if role and child_name and obj['<STR_LIT:class>'] == role andself._match_name_to_appmap(child_name, obj):<EOL><INDENT>matches.append(name)<EOL><DEDENT><DEDENT>if not matches:<EOL><INDENT>_name = '<STR_LIT>'<EOL>_role = '<STR_LIT>'<EOL>_parent = '<STR_LIT>'<EOL>if child_name:<EOL><INDENT>_name = '<STR_LIT>' % child_name<EOL><DEDENT>if role:<EOL><INDENT>_role = '<STR_LIT>' % role<EOL><DEDENT>if parent:<EOL><INDENT>_parent = '<STR_LIT>' % parent<EOL><DEDENT>exception = '<STR_LIT>' % (_name, _role, _parent)<EOL>raise LdtpServerException(exception)<EOL><DEDENT>return matches<EOL>

Gets the list of object available in the window, which matches
component name or role name or both.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param child_name: Child name to search for.
@type child_name: string
@param role: role name to search for, or an empty string for wildcard.
@type role: string
@param parent: parent name to search for, or an empty string for wildcard.
@type role: string
@return: list of matched children names
@rtype: list


def launchapp(self, cmd, args=[], delay=<NUM_LIT:0>, env=<NUM_LIT:1>, lang="<STR_LIT:C>"):

try:<EOL><INDENT>atomac.NativeUIElement.launchAppByBundleId(cmd)<EOL>return <NUM_LIT:1><EOL><DEDENT>except RuntimeError:<EOL><INDENT>if atomac.NativeUIElement.launchAppByBundlePath(cmd, args):<EOL><INDENT>try:<EOL><INDENT>time.sleep(int(delay))<EOL><DEDENT>except ValueError:<EOL><INDENT>time.sleep(<NUM_LIT:5>)<EOL><DEDENT>return <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % cmd)<EOL><DEDENT><DEDENT>

Launch application.

@param cmd: Command line string to execute.
@type cmd: string
@param args: Arguments to the application
@type args: list
@param delay: Delay after the application is launched
@type delay: int
@param env: GNOME accessibility environment to be set or not
@type env: int
@param lang: Application language to be used
@type lang: string

@return: 1 on success
@rtype: integer

@raise LdtpServerException: When command fails


time.sleep(timeout)<EOL>return <NUM_LIT:1><EOL>

Wait a given amount of seconds.

@param timeout: Wait timeout in seconds
@type timeout: double

@return: 1
@rtype: integer


return self._singleclick(window_name, "<STR_LIT>")<EOL>

Close window.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string

@return: 1 on success.
@rtype: integer


Minimize window.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string

@return: 1 on success.
@rtype: integer


Maximize window.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string

@return: 1 on success.
@rtype: integer


window_handle = self._get_window_handle(window_name)<EOL>self._grabfocus(window_handle)<EOL>return <NUM_LIT:1><EOL>

Activate window.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string

@return: 1 on success.
@rtype: integer


def click(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>size = self._getobjectsize(object_handle)<EOL>self._grabfocus(object_handle)<EOL>self.wait(<NUM_LIT:0.5>)<EOL>self.generatemouseevent(size[<NUM_LIT:0>] + size[<NUM_LIT:2>] / <NUM_LIT:2>, size[<NUM_LIT:1>] + size[<NUM_LIT:3>] / <NUM_LIT:2>, "<STR_LIT>")<EOL>return <NUM_LIT:1><EOL>

Click item.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success.
@rtype: integer


def getallstates(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>_obj_states = []<EOL>if object_handle.AXEnabled:<EOL><INDENT>_obj_states.append("<STR_LIT>")<EOL><DEDENT>if object_handle.AXFocused:<EOL><INDENT>_obj_states.append("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>if object_handle.AXFocused:<EOL><INDENT>_obj_states.append("<STR_LIT>")<EOL><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if re.match("<STR_LIT>", object_handle.AXRole, re.M | re.U | re.L) orre.match("<STR_LIT>", object_handle.AXRole,<EOL>re.M | re.U | re.L):<EOL><INDENT>if object_handle.AXValue:<EOL><INDENT>_obj_states.append("<STR_LIT>")<EOL><DEDENT><DEDENT>return _obj_states<EOL>

Get all states of given object

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: list of string on success.
@rtype: list


def hasstate(self, window_name, object_name, state, guiTimeOut=<NUM_LIT:0>):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name)<EOL>if state == "<STR_LIT>":<EOL><INDENT>return int(object_handle.AXEnabled)<EOL><DEDENT>elif state == "<STR_LIT>":<EOL><INDENT>return int(object_handle.AXFocused)<EOL><DEDENT>elif state == "<STR_LIT>":<EOL><INDENT>return int(object_handle.AXFocused)<EOL><DEDENT>elif state == "<STR_LIT>":<EOL><INDENT>if re.match("<STR_LIT>", object_handle.AXRole,<EOL>re.M | re.U | re.L) orre.match("<STR_LIT>", object_handle.AXRole,<EOL>re.M | re.U | re.L):<EOL><INDENT>if object_handle.AXValue:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

has state

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@type window_name: string
@param state: State of the current object.
@type object_name: string
@param guiTimeOut: Wait timeout in seconds
@type guiTimeOut: integer

@return: 1 on success.
@rtype: integer


def getobjectsize(self, window_name, object_name=None):

if not object_name:<EOL><INDENT>handle, name, app = self._get_window_handle(window_name)<EOL><DEDENT>else:<EOL><INDENT>handle = self._get_object_handle(window_name, object_name)<EOL><DEDENT>return self._getobjectsize(handle)<EOL>

Get object size

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: x, y, width, height on success.
@rtype: list


return self.getobjectsize(window_name)<EOL>

Get window size.

@param window_name: Window name to get size of.
@type window_name: string

@return: list of dimensions [x, y, w, h]
@rtype: list


def grabfocus(self, window_name, object_name=None):

if not object_name:<EOL><INDENT>handle, name, app = self._get_window_handle(window_name)<EOL><DEDENT>else:<EOL><INDENT>handle = self._get_object_handle(window_name, object_name)<EOL><DEDENT>return self._grabfocus(handle)<EOL>

Grab focus.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success.
@rtype: integer


def guiexist(self, window_name, object_name=None):

try:<EOL><INDENT>self._windows = {}<EOL>if not object_name:<EOL><INDENT>handle, name, app = self._get_window_handle(window_name, False)<EOL><DEDENT>else:<EOL><INDENT>handle = self._get_object_handle(window_name, object_name,<EOL>wait_for_object=False,<EOL>force_remap=True)<EOL><DEDENT>return <NUM_LIT:1><EOL><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Checks whether a window or component exists.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success.
@rtype: integer


self._window_timeout = timeout<EOL>return <NUM_LIT:1><EOL>

Change GUI timeout period, default 30 seconds.

@param timeout: timeout in seconds
@type timeout: integer

@return: 1 on success.
@rtype: integer


self._obj_timeout = timeout<EOL>return <NUM_LIT:1><EOL>

Change object timeout period, default 5 seconds.

@param timeout: timeout in seconds
@type timeout: integer

@return: 1 on success.
@rtype: integer


def waittillguiexist(self, window_name, object_name='<STR_LIT>',<EOL>guiTimeOut=<NUM_LIT:30>, state='<STR_LIT>'):

timeout = <NUM_LIT:0><EOL>while timeout < guiTimeOut:<EOL><INDENT>if self.guiexist(window_name, object_name):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>time.sleep(<NUM_LIT:1>)<EOL>timeout += <NUM_LIT:1><EOL><DEDENT>return <NUM_LIT:0><EOL>

Wait till a window or component exists.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param guiTimeOut: Wait timeout in seconds
@type guiTimeOut: integer
@param state: Object state used only when object_name is provided.
@type object_name: string

@return: 1 if GUI was found, 0 if not.
@rtype: integer


def waittillguinotexist(self, window_name, object_name='<STR_LIT>', guiTimeOut=<NUM_LIT:30>):

timeout = <NUM_LIT:0><EOL>while timeout < guiTimeOut:<EOL><INDENT>if not self.guiexist(window_name, object_name):<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>time.sleep(<NUM_LIT:1>)<EOL>timeout += <NUM_LIT:1><EOL><DEDENT>return <NUM_LIT:0><EOL>

Wait till a window does not exist.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string
@param guiTimeOut: Wait timeout in seconds
@type guiTimeOut: integer

@return: 1 if GUI has gone away, 0 if not.
@rtype: integer


def objectexist(self, window_name, object_name):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name)<EOL>return <NUM_LIT:1><EOL><DEDENT>except LdtpServerException:<EOL><INDENT>return <NUM_LIT:0><EOL><DEDENT>

Checks whether a window or component exists.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 if GUI was found, 0 if not.
@rtype: integer


def stateenabled(self, window_name, object_name):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name)<EOL>if object_handle.AXEnabled:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Check whether an object state is enabled or not

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success 0 on failure.
@rtype: integer


def check(self, window_name, object_name):

<EOL>object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>if object_handle.AXValue == <NUM_LIT:1>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>self._grabfocus(object_handle)<EOL>x, y, width, height = self._getobjectsize(object_handle)<EOL>self.generatemouseevent(x + width / <NUM_LIT:2>, y + height / <NUM_LIT:2>, "<STR_LIT>")<EOL>return <NUM_LIT:1><EOL>

Check item.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success.
@rtype: integer


def uncheck(self, window_name, object_name):

object_handle = self._get_object_handle(window_name, object_name)<EOL>if not object_handle.AXEnabled:<EOL><INDENT>raise LdtpServerException(u"<STR_LIT>" % object_name)<EOL><DEDENT>if object_handle.AXValue == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT>self._grabfocus(object_handle)<EOL>x, y, width, height = self._getobjectsize(object_handle)<EOL>self.generatemouseevent(x + width / <NUM_LIT:2>, y + height / <NUM_LIT:2>, "<STR_LIT>")<EOL>return <NUM_LIT:1><EOL>

Uncheck item.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success.
@rtype: integer


def verifycheck(self, window_name, object_name):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name,<EOL>wait_for_object=False)<EOL>if object_handle.AXValue == <NUM_LIT:1>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify check item.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success 0 on failure.
@rtype: integer


def verifyuncheck(self, window_name, object_name):

try:<EOL><INDENT>object_handle = self._get_object_handle(window_name, object_name,<EOL>wait_for_object=False)<EOL>if object_handle.AXValue == <NUM_LIT:0>:<EOL><INDENT>return <NUM_LIT:1><EOL><DEDENT><DEDENT>except LdtpServerException:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>

Verify uncheck item.

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type object_name: string

@return: 1 on success 0 on failure.
@rtype: integer


def getaccesskey(self, window_name, object_name):

<EOL>menu_handle = self._get_menu_handle(window_name, object_name)<EOL>key = menu_handle.AXMenuItemCmdChar<EOL>modifiers = menu_handle.AXMenuItemCmdModifiers<EOL>glpyh = menu_handle.AXMenuItemCmdGlyph<EOL>virtual_key = menu_handle.AXMenuItemCmdVirtualKey<EOL>modifiers_type = "<STR_LIT>"<EOL>if modifiers == <NUM_LIT:0>:<EOL><INDENT>modifiers_type = "<STR_LIT>"<EOL><DEDENT>elif modifiers == <NUM_LIT:1>:<EOL><INDENT>modifiers_type = "<STR_LIT>"<EOL><DEDENT>elif modifiers == <NUM_LIT:2>:<EOL><INDENT>modifiers_type = "<STR_LIT>"<EOL><DEDENT>elif modifiers == <NUM_LIT:3>:<EOL><INDENT>modifiers_type = "<STR_LIT>"<EOL><DEDENT>elif modifiers == <NUM_LIT:4>:<EOL><INDENT>modifiers_type = "<STR_LIT>"<EOL><DEDENT>elif modifiers == <NUM_LIT:6>:<EOL><INDENT>modifiers_type = "<STR_LIT>"<EOL><DEDENT>if virtual_key == <NUM_LIT> and glpyh == <NUM_LIT>:<EOL><INDENT>modifiers = "<STR_LIT>"<EOL>key = "<STR_LIT>"<EOL><DEDENT>elif virtual_key == <NUM_LIT> and glpyh == <NUM_LIT>:<EOL><INDENT>modifiers = "<STR_LIT>"<EOL>key = "<STR_LIT>"<EOL><DEDENT>elif virtual_key == <NUM_LIT> and glpyh == <NUM_LIT>:<EOL><INDENT>modifiers = "<STR_LIT>"<EOL>key = "<STR_LIT>"<EOL><DEDENT>elif virtual_key == <NUM_LIT> and glpyh == <NUM_LIT>:<EOL><INDENT>modifiers = "<STR_LIT>"<EOL>key = "<STR_LIT>"<EOL><DEDENT>elif virtual_key == <NUM_LIT> and glpyh == <NUM_LIT>:<EOL><INDENT>key = "<STR_LIT>"<EOL><DEDENT>elif virtual_key == <NUM_LIT> and glpyh == <NUM_LIT>:<EOL><INDENT>key = "<STR_LIT>"<EOL><DEDENT>elif virtual_key == <NUM_LIT> and glpyh == <NUM_LIT>:<EOL><INDENT>key = "<STR_LIT>"<EOL><DEDENT>elif virtual_key == <NUM_LIT> and glpyh == <NUM_LIT:100>:<EOL><INDENT>key = "<STR_LIT>"<EOL><DEDENT>elif virtual_key == <NUM_LIT> and glpyh == <NUM_LIT>:<EOL><INDENT>key = "<STR_LIT>"<EOL><DEDENT>if not key:<EOL><INDENT>raise LdtpServerException("<STR_LIT>")<EOL><DEDENT>return modifiers_type + key<EOL>

Get access key of given object

@param window_name: Window name to look for, either full name,
LDTP's name convention, or a Unix glob.
@type window_name: string
@param object_name: Object name to look for, either full name,
LDTP's name convention, or a Unix glob. Or menu heirarchy
@type object_name: string

@return: access key in string format on success, else LdtpExecutionError on failure.
@rtype: string


def __init__(self, appname, interval=<NUM_LIT:2>):

if not importPsUtil:<EOL><INDENT>raise LdtpServerException('<STR_LIT>')<EOL><DEDENT>threading.Thread.__init__(self)<EOL>self._appname = appname<EOL>self._interval = interval<EOL>self._stop = False<EOL>self.running = True<EOL>

Start memory and CPU monitoring, with the time interval between
each process scan

@param appname: Process name, ex: firefox-bin.
@type appname: string
@param interval: Time interval between each process scan
@type interval: float


actual_role = self._get_role(acc)<EOL>label = self._get_title(acc)<EOL>if re.match("<STR_LIT>", actual_role, re.M | re.U | re.L):<EOL><INDENT>strip = r"<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>strip = r"<STR_LIT>"<EOL><DEDENT>if label:<EOL><INDENT>label = re.sub(strip, u"<STR_LIT>", label)<EOL><DEDENT>role = abbreviated_roles.get(actual_role, "<STR_LIT>")<EOL>if self._ldtp_debug and role == "<STR_LIT>":<EOL><INDENT>print(actual_role, acc)<EOL><DEDENT>return role, label<EOL>

Get LDTP format accessibile name

@param acc: Accessible handle
@type acc: object

@return: object type, stripped object name (associated / direct),
                associated label
@rtype: tuple


<EOL>return bool(re.match(fnmatch.translate(pattern), string,<EOL>re.M | re.U | re.L))<EOL>

Match given string, by escaping regex characters


self._data = data<EOL>self._dummy_window = NativeUIElement()<EOL>_keyOp = KeyboardOp()<EOL>self._keyvalId = _keyOp.get_keyval_id(data)<EOL>if not self._keyvalId:<EOL><INDENT>raise LdtpServerException("<STR_LIT>")<EOL><DEDENT>self._doCombo()<EOL>

@param data: data to type
@type data: string


<EOL>keyboard_layout = DEFAULT_KEYBOARD<EOL>keyboard_layout.update(specialKeys)<EOL>return keyboard_layout<EOL>

Load a given keyboard mapping (of characters to virtual key codes).

    Default is US keyboard
    Parameters: None (relies on the internationalization settings)
    Returns: A dictionary representing the current keyboard mapping (of
             characters to keycodes)


def runLoopAndExit():<EOL><INDENT>AppHelper.stopEventLoop()<EOL><DEDENT>AppHelper.callLater(<NUM_LIT:1>, runLoopAndExit)<EOL>AppHelper.runConsoleEventLoop()<EOL>ws = AppKit.NSWorkspace.sharedWorkspace()<EOL>apps = ws.runningApplications()<EOL>return apps<EOL>


return _a11y.getAppRefByPid(cls, pid)<EOL>

Get the top level element for the application specified by pid.


ra = AppKit.NSRunningApplication<EOL>apps = ra.runningApplicationsWithBundleIdentifier_(bundleId)<EOL>if len(apps) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError(('<STR_LIT>'<EOL>'<STR_LIT>' % bundleId))<EOL><DEDENT>pid = apps[<NUM_LIT:0>].processIdentifier()<EOL>return cls.getAppRefByPid(pid)<EOL>

Get the top level element for the application with the specified
bundle ID, such as com.vmware.fusion.


<EOL>apps = cls._getRunningApps()<EOL>for app in apps:<EOL><INDENT>if fnmatch.fnmatch(app.localizedName(), name):<EOL><INDENT>pid = app.processIdentifier()<EOL>return cls.getAppRefByPid(pid)<EOL><DEDENT><DEDENT>raise ValueError('<STR_LIT>')<EOL>

Get the top level element for the application with the specified
        localized name, such as VMware Fusion.

        Wildcards are also allowed.


<EOL>apps = cls._getRunningApps()<EOL>for app in apps:<EOL><INDENT>pid = app.processIdentifier()<EOL>ref = cls.getAppRefByPid(pid)<EOL>try:<EOL><INDENT>if ref.AXFrontmost:<EOL><INDENT>return ref<EOL><DEDENT><DEDENT>except (_a11y.ErrorUnsupported,<EOL>_a11y.ErrorCannotComplete,<EOL>_a11y.ErrorAPIDisabled,<EOL>_a11y.ErrorNotImplemented):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>raise ValueError('<STR_LIT>')<EOL>

Get the current frontmost application.

        Raise a ValueError exception if no GUI applications are found.


<EOL>apps = cls._getRunningApps()<EOL>for app in apps:<EOL><INDENT>pid = app.processIdentifier()<EOL>ref = cls.getAppRefByPid(pid)<EOL>if hasattr(ref, '<STR_LIT>') and len(ref.windows()) > <NUM_LIT:0>:<EOL><INDENT>return ref<EOL><DEDENT><DEDENT>raise ValueError('<STR_LIT>')<EOL>

Get a random app that has windows.

        Raise a ValueError exception if no GUI applications are found.


return _a11y.getSystemObject(cls)<EOL>

Get the top level system accessibility object.


return cls.getSystemObject().setTimeout(timeout)<EOL>

Set the system-wide accessibility timeout.

        Optional: timeout (non-negative float; defaults to 0)
                  A value of 0 will reset the timeout to the system default.
        Returns: None.


<EOL>ws = AppKit.NSWorkspace.sharedWorkspace()<EOL>r = ws.launchAppWithBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifier_(<EOL>bundleID,<EOL>AppKit.NSWorkspaceLaunchAllowingClassicStartup,<EOL>AppKit.NSAppleEventDescriptor.nullDescriptor(),<EOL>None)<EOL>if not r[<NUM_LIT:0>]:<EOL><INDENT>raise RuntimeError('<STR_LIT>')<EOL><DEDENT>

Launch the application with the specified bundle ID


if arguments is None:<EOL><INDENT>arguments = []<EOL><DEDENT>bundleUrl = NSURL.fileURLWithPath_(bundlePath)<EOL>workspace = AppKit.NSWorkspace.sharedWorkspace()<EOL>arguments_strings = list(map(lambda a: NSString.stringWithString_(str(a)),<EOL>arguments))<EOL>arguments = NSDictionary.dictionaryWithDictionary_({<EOL>AppKit.NSWorkspaceLaunchConfigurationArguments: NSArray.arrayWithArray_(<EOL>arguments_strings)<EOL>})<EOL>return workspace.launchApplicationAtURL_options_configuration_error_(<EOL>bundleUrl,<EOL>AppKit.NSWorkspaceLaunchAllowingClassicStartup,<EOL>arguments,<EOL>None)<EOL>

Launch app with a given bundle path.

        Return True if succeed.


ra = AppKit.NSRunningApplication<EOL>if getattr(ra, "<STR_LIT>"):<EOL><INDENT>appList = ra.runningApplicationsWithBundleIdentifier_(bundleID)<EOL>if appList and len(appList) > <NUM_LIT:0>:<EOL><INDENT>app = appList[<NUM_LIT:0>]<EOL>return app and app.terminate() and True or False<EOL><DEDENT><DEDENT>return False<EOL>

Terminate app with a given bundle ID.
        Requires 10.6.

        Return True if succeed.


Set the accessibiltiy API timeout on the given reference.

        Optional: timeout (non-negative float; defaults to 0)
                  A value of 0 will reset the timeout to the system-wide
                  value
        Returns: None


while len(self.eventList) > <NUM_LIT:0>:<EOL><INDENT>(nextEvent, args) = self.eventList.popleft()<EOL>nextEvent(*args)<EOL>time.sleep(interval)<EOL><DEDENT>

Private method to post queued events (e.g. Quartz events).

        Each event in queue is a tuple (event call, args to event call).


if hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.eventList.clear()<EOL><DEDENT>


if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.eventList = deque([(event, args)])<EOL>return<EOL><DEDENT>self.eventList.append((event, args))<EOL>

Private method to queue events to run.

        Each event in queue is a tuple (event call, args to event call).


def _addKeyToQueue(self, keychr, modFlags=<NUM_LIT:0>, globally=False):

<EOL>if not keychr:<EOL><INDENT>return<EOL><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.keyboard = AXKeyboard.loadKeyboard()<EOL><DEDENT>if keychr in self.keyboard['<STR_LIT>'] and not modFlags:<EOL><INDENT>self._sendKeyWithModifiers(keychr,<EOL>[AXKeyCodeConstants.SHIFT],<EOL>globally)<EOL>return<EOL><DEDENT>if keychr.isupper() and not modFlags:<EOL><INDENT>self._sendKeyWithModifiers(<EOL>keychr.lower(),<EOL>[AXKeyCodeConstants.SHIFT],<EOL>globally<EOL>)<EOL>return<EOL><DEDENT>if keychr not in self.keyboard:<EOL><INDENT>self._clearEventQueue()<EOL>raise ValueError('<STR_LIT>' % keychr)<EOL><DEDENT>keyDown = Quartz.CGEventCreateKeyboardEvent(None,<EOL>self.keyboard[keychr],<EOL>True)<EOL>keyUp = Quartz.CGEventCreateKeyboardEvent(None,<EOL>self.keyboard[keychr],<EOL>False)<EOL>Quartz.CGEventSetFlags(keyDown, modFlags)<EOL>Quartz.CGEventSetFlags(keyUp, modFlags)<EOL>if not globally:<EOL><INDENT>macVer, _, _ = platform.mac_ver()<EOL>macVer = int(macVer.split('<STR_LIT:.>')[<NUM_LIT:1>])<EOL>if macVer > <NUM_LIT:10>:<EOL><INDENT>appPid = self._getPid()<EOL>self._queueEvent(Quartz.CGEventPostToPid, (appPid, keyDown))<EOL>self._queueEvent(Quartz.CGEventPostToPid, (appPid, keyUp))<EOL><DEDENT>else:<EOL><INDENT>appPsn = self._getPsnForPid(self._getPid())<EOL>self._queueEvent(Quartz.CGEventPostToPSN, (appPsn, keyDown))<EOL>self._queueEvent(Quartz.CGEventPostToPSN, (appPsn, keyUp))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self._queueEvent(Quartz.CGEventPost, (<NUM_LIT:0>, keyDown))<EOL>self._queueEvent(Quartz.CGEventPost, (<NUM_LIT:0>, keyUp))<EOL><DEDENT>

Add keypress to queue.

        Parameters: key character or constant referring to a non-alpha-numeric
                    key (e.g. RETURN or TAB)
                    modifiers
                    global or app specific
        Returns: None or raise ValueError exception.


def _sendKey(self, keychr, modFlags=<NUM_LIT:0>, globally=False):

escapedChrs = {<EOL>'<STR_LIT:\n>': AXKeyCodeConstants.RETURN,<EOL>'<STR_LIT:\r>': AXKeyCodeConstants.RETURN,<EOL>'<STR_LIT:\t>': AXKeyCodeConstants.TAB,<EOL>}<EOL>if keychr in escapedChrs:<EOL><INDENT>keychr = escapedChrs[keychr]<EOL><DEDENT>self._addKeyToQueue(keychr, modFlags, globally=globally)<EOL>self._postQueuedEvents()<EOL>

Send one character with no modifiers.

        Parameters: key character or constant referring to a non-alpha-numeric
                    key (e.g. RETURN or TAB)
                    modifier flags,
                    global or app specific
        Returns: None or raise ValueError exception


for nextChr in keystr:<EOL><INDENT>self._sendKey(nextChr)<EOL><DEDENT>

Send a series of characters with no modifiers.

        Parameters: keystr
        Returns: None or raise ValueError exception


def _pressModifiers(self, modifiers, pressed=True, globally=False):

if not isinstance(modifiers, list):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.keyboard = AXKeyboard.loadKeyboard()<EOL><DEDENT>modFlags = <NUM_LIT:0><EOL>for nextMod in modifiers:<EOL><INDENT>if nextMod not in self.keyboard:<EOL><INDENT>errStr = '<STR_LIT>'<EOL>self._clearEventQueue()<EOL>raise ValueError(errStr % self.keyboard[nextMod])<EOL><DEDENT>modEvent = Quartz.CGEventCreateKeyboardEvent(<EOL>Quartz.CGEventSourceCreate(<NUM_LIT:0>),<EOL>self.keyboard[nextMod],<EOL>pressed<EOL>)<EOL>if not pressed:<EOL><INDENT>Quartz.CGEventSetFlags(modEvent, <NUM_LIT:0>)<EOL><DEDENT>if globally:<EOL><INDENT>self._queueEvent(Quartz.CGEventPost, (<NUM_LIT:0>, modEvent))<EOL><DEDENT>else:<EOL><INDENT>macVer, _, _ = platform.mac_ver()<EOL>macVer = int(macVer.split('<STR_LIT:.>')[<NUM_LIT:1>])<EOL>if macVer > <NUM_LIT:10>:<EOL><INDENT>appPid = self._getPid()<EOL>self._queueEvent(Quartz.CGEventPostToPid, (appPid, modEvent))<EOL><DEDENT>else:<EOL><INDENT>appPsn = self._getPsnForPid(self._getPid())<EOL>self._queueEvent(Quartz.CGEventPostToPSN, (appPsn, modEvent))<EOL><DEDENT><DEDENT>modFlags += AXKeyboard.modKeyFlagConstants[nextMod]<EOL><DEDENT>return modFlags<EOL>

Press given modifiers (provided in list form).

        Parameters: modifiers list, global or app specific
        Optional: keypressed state (default is True (down))
        Returns: Unsigned int representing flags to set


modFlags = self._pressModifiers(modifiers)<EOL>self._postQueuedEvents()<EOL>return modFlags<EOL>

Hold given modifier keys (provided in list form).

        Parameters: modifiers list
        Returns: Unsigned int representing flags to set


def _releaseModifiers(self, modifiers, globally=False):

<EOL>modifiers.reverse()<EOL>modFlags = self._pressModifiers(modifiers, pressed=False,<EOL>globally=globally)<EOL>return modFlags<EOL>

Release given modifiers (provided in list form).

        Parameters: modifiers list
        Returns: None


modFlags = self._releaseModifiers(modifiers)<EOL>self._postQueuedEvents()<EOL>return modFlags<EOL>

Release given modifier keys (provided in list form).

        Parameters: modifiers list
        Returns: Unsigned int representing flags to set


if not keychr:<EOL><INDENT>return False<EOL><DEDENT>if len(keychr) == <NUM_LIT:1>:<EOL><INDENT>return True<EOL><DEDENT>return keychr.count('<STR_LIT:<>') == <NUM_LIT:1> and keychr.count('<STR_LIT:>>') == <NUM_LIT:1> andkeychr[<NUM_LIT:0>] == '<STR_LIT:<>' and keychr[-<NUM_LIT:1>] == '<STR_LIT:>>'<EOL>

Check whether given keyboard character is a single character.

        Parameters: key character which will be checked.
        Returns: True when given key character is a single character.


def _sendKeyWithModifiers(self, keychr, modifiers, globally=False):

if not self._isSingleCharacter(keychr):<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if not hasattr(self, '<STR_LIT>'):<EOL><INDENT>self.keyboard = AXKeyboard.loadKeyboard()<EOL><DEDENT>modFlags = self._pressModifiers(modifiers, globally=globally)<EOL>self._sendKey(keychr, modFlags, globally=globally)<EOL>self._releaseModifiers(modifiers, globally=globally)<EOL>self._postQueuedEvents()<EOL>

Send one character with the given modifiers pressed.

        Parameters: key character, list of modifiers, global or app specific
        Returns: None or raise ValueError exception


def _queueMouseButton(self, coord, mouseButton, modFlags, clickCount=<NUM_LIT:1>,<EOL>dest_coord=None):

<EOL>mouseButtons = {<EOL>Quartz.kCGMouseButtonLeft: '<STR_LIT>',<EOL>Quartz.kCGMouseButtonRight: '<STR_LIT>',<EOL>}<EOL>if mouseButton not in mouseButtons:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>eventButtonDown = getattr(Quartz,<EOL>'<STR_LIT>' % mouseButtons[mouseButton])<EOL>eventButtonUp = getattr(Quartz,<EOL>'<STR_LIT>' % mouseButtons[mouseButton])<EOL>eventButtonDragged = getattr(Quartz,<EOL>'<STR_LIT>' % mouseButtons[<EOL>mouseButton])<EOL>buttonDown = Quartz.CGEventCreateMouseEvent(None,<EOL>eventButtonDown,<EOL>coord,<EOL>mouseButton)<EOL>Quartz.CGEventSetFlags(buttonDown, modFlags)<EOL>Quartz.CGEventSetIntegerValueField(buttonDown,<EOL>Quartz.kCGMouseEventClickState,<EOL>int(clickCount))<EOL>if dest_coord:<EOL><INDENT>buttonDragged = Quartz.CGEventCreateMouseEvent(None,<EOL>eventButtonDragged,<EOL>dest_coord,<EOL>mouseButton)<EOL>Quartz.CGEventSetFlags(buttonDragged, modFlags)<EOL>buttonUp = Quartz.CGEventCreateMouseEvent(None,<EOL>eventButtonUp,<EOL>dest_coord,<EOL>mouseButton)<EOL><DEDENT>else:<EOL><INDENT>buttonUp = Quartz.CGEventCreateMouseEvent(None,<EOL>eventButtonUp,<EOL>coord,<EOL>mouseButton)<EOL><DEDENT>Quartz.CGEventSetFlags(buttonUp, modFlags)<EOL>Quartz.CGEventSetIntegerValueField(buttonUp,<EOL>Quartz.kCGMouseEventClickState,<EOL>int(clickCount))<EOL>self._queueEvent(Quartz.CGEventPost,<EOL>(Quartz.kCGSessionEventTap, buttonDown))<EOL>if dest_coord:<EOL><INDENT>self._queueEvent(Quartz.CGEventPost,<EOL>(Quartz.kCGHIDEventTap, buttonDragged))<EOL><DEDENT>self._queueEvent(Quartz.CGEventPost,<EOL>(Quartz.kCGSessionEventTap, buttonUp))<EOL>

Private method to handle generic mouse button clicking.

        Parameters: coord (x, y) to click, mouseButton (e.g.,
                    kCGMouseButtonLeft), modFlags set (int)
        Optional: clickCount (default 1; set to 2 for double-click; 3 for
                  triple-click on host)
        Returns: None


def _leftMouseDragged(self, stopCoord, strCoord, speed):

<EOL>appPid = self._getPid()<EOL>if strCoord == (<NUM_LIT:0>, <NUM_LIT:0>):<EOL><INDENT>loc = AppKit.NSEvent.mouseLocation()<EOL>strCoord = (loc.x, Quartz.CGDisplayPixelsHigh(<NUM_LIT:0>) - loc.y)<EOL><DEDENT>appPid = self._getPid()<EOL>pressLeftButton = Quartz.CGEventCreateMouseEvent(<EOL>None,<EOL>Quartz.kCGEventLeftMouseDown,<EOL>strCoord,<EOL>Quartz.kCGMouseButtonLeft<EOL>)<EOL>Quartz.CGEventPost(Quartz.CoreGraphics.kCGHIDEventTap, pressLeftButton)<EOL>time.sleep(<NUM_LIT:5>)<EOL>speed = round(<NUM_LIT:1> / float(speed), <NUM_LIT:2>)<EOL>xmoved = stopCoord[<NUM_LIT:0>] - strCoord[<NUM_LIT:0>]<EOL>ymoved = stopCoord[<NUM_LIT:1>] - strCoord[<NUM_LIT:1>]<EOL>if ymoved == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>k = abs(ymoved / xmoved)<EOL><DEDENT>if xmoved != <NUM_LIT:0>:<EOL><INDENT>for xpos in range(int(abs(xmoved))):<EOL><INDENT>if xmoved > <NUM_LIT:0> and ymoved > <NUM_LIT:0>:<EOL><INDENT>currcoord = (strCoord[<NUM_LIT:0>] + xpos, strCoord[<NUM_LIT:1>] + xpos * k)<EOL><DEDENT>elif xmoved > <NUM_LIT:0> and ymoved < <NUM_LIT:0>:<EOL><INDENT>currcoord = (strCoord[<NUM_LIT:0>] + xpos, strCoord[<NUM_LIT:1>] - xpos * k)<EOL><DEDENT>elif xmoved < <NUM_LIT:0> and ymoved < <NUM_LIT:0>:<EOL><INDENT>currcoord = (strCoord[<NUM_LIT:0>] - xpos, strCoord[<NUM_LIT:1>] - xpos * k)<EOL><DEDENT>elif xmoved < <NUM_LIT:0> and ymoved > <NUM_LIT:0>:<EOL><INDENT>currcoord = (strCoord[<NUM_LIT:0>] - xpos, strCoord[<NUM_LIT:1>] + xpos * k)<EOL><DEDENT>dragLeftButton = Quartz.CGEventCreateMouseEvent(<EOL>None,<EOL>Quartz.kCGEventLeftMouseDragged,<EOL>currcoord,<EOL>Quartz.kCGMouseButtonLeft<EOL>)<EOL>Quartz.CGEventPost(Quartz.CoreGraphics.kCGHIDEventTap,<EOL>dragLeftButton)<EOL>time.sleep(speed)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>upLeftButton = Quartz.CGEventCreateMouseEvent(<EOL>None,<EOL>Quartz.kCGEventLeftMouseUp,<EOL>stopCoord,<EOL>Quartz.kCGMouseButtonLeft<EOL>)<EOL>time.sleep(<NUM_LIT:5>)<EOL>Quartz.CGEventPost(Quartz.CoreGraphics.kCGHIDEventTap, upLeftButton)<EOL>

Private method to handle generic mouse left button dragging and
        dropping.

        Parameters: stopCoord(x,y) drop point
        Optional: strCoord (x, y) drag point, default (0,0) get current
                  mouse position
                  speed (int) 1 to unlimit, simulate mouse moving
                  action from some special requirement
        Returns: None


def _waitFor(self, timeout, notification, **kwargs):

callback = self._matchOther<EOL>retelem = None<EOL>callbackArgs = None<EOL>callbackKwargs = None<EOL>if '<STR_LIT>' in kwargs:<EOL><INDENT>callback = kwargs['<STR_LIT>']<EOL>del kwargs['<STR_LIT>']<EOL>if '<STR_LIT:args>' in kwargs:<EOL><INDENT>if not isinstance(kwargs['<STR_LIT:args>'], tuple):<EOL><INDENT>errStr = '<STR_LIT>'<EOL>raise TypeError(errStr)<EOL><DEDENT>callbackArgs = kwargs['<STR_LIT:args>']<EOL>del kwargs['<STR_LIT:args>']<EOL><DEDENT>if '<STR_LIT>' in kwargs:<EOL><INDENT>if not isinstance(kwargs['<STR_LIT>'], dict):<EOL><INDENT>errStr = '<STR_LIT>'<EOL>raise TypeError(errStr)<EOL><DEDENT>callbackKwargs = kwargs['<STR_LIT>']<EOL>del kwargs['<STR_LIT>']<EOL><DEDENT>if kwargs:<EOL><INDENT>if callbackKwargs:<EOL><INDENT>callbackKwargs.update(kwargs)<EOL><DEDENT>else:<EOL><INDENT>callbackKwargs = kwargs<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>callbackArgs = (retelem,)<EOL>callbackKwargs = kwargs<EOL><DEDENT>return self._setNotification(timeout, notification, callback,<EOL>callbackArgs,<EOL>callbackKwargs)<EOL>

Wait for a particular UI event to occur; this can be built
        upon in NativeUIElement for specific convenience methods.


def waitForFocusToMatchCriteria(self, timeout=<NUM_LIT:10>, **kwargs):

def _matchFocused(retelem, **kwargs):<EOL><INDENT>return retelem if retelem._match(**kwargs) else None<EOL><DEDENT>retelem = None<EOL>return self._waitFor(timeout, '<STR_LIT>',<EOL>callback=_matchFocused,<EOL>args=(retelem,),<EOL>**kwargs)<EOL>

Convenience method to wait for focused element to change
        (to element matching kwargs criteria).

        Returns: Element or None


actions = _a11y.AXUIElement._getActions(self)<EOL>return [action[<NUM_LIT:2>:] for action in actions]<EOL>

Retrieve a list of actions supported by the object.


try:<EOL><INDENT>_a11y.AXUIElement._performAction(self, '<STR_LIT>' % action)<EOL><DEDENT>except _a11y.ErrorUnsupported as e:<EOL><INDENT>sierra_ver = '<STR_LIT>'<EOL>if mac_ver()[<NUM_LIT:0>] < sierra_ver:<EOL><INDENT>raise e<EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>


try:<EOL><INDENT>children = self.AXChildren<EOL><DEDENT>except _a11y.Error:<EOL><INDENT>return<EOL><DEDENT>if children:<EOL><INDENT>for child in children:<EOL><INDENT>yield child<EOL><DEDENT><DEDENT>

Generator which yields all AXChildren of the object.


if target is None:<EOL><INDENT>target = self<EOL><DEDENT>try:<EOL><INDENT>children = target.AXChildren<EOL><DEDENT>except _a11y.Error:<EOL><INDENT>return<EOL><DEDENT>if children:<EOL><INDENT>for child in children:<EOL><INDENT>yield child<EOL>for c in self._generateChildrenR(child):<EOL><INDENT>yield c<EOL><DEDENT><DEDENT><DEDENT>

Generator which recursively yields all AXChildren of the object.


for k in kwargs.keys():<EOL><INDENT>try:<EOL><INDENT>val = getattr(self, k)<EOL><DEDENT>except _a11y.Error:<EOL><INDENT>return False<EOL><DEDENT>if sys.version_info[:<NUM_LIT:2>] <= (<NUM_LIT:2>, <NUM_LIT:6>):<EOL><INDENT>if isinstance(val, basestring):<EOL><INDENT>if not fnmatch.fnmatch(unicode(val), kwargs[k]):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if val != kwargs[k]:<EOL><INDENT>return False<EOL><DEDENT><DEDENT><DEDENT>elif sys.version_info[<NUM_LIT:0>] == <NUM_LIT:3>:<EOL><INDENT>if isinstance(val, str):<EOL><INDENT>if not fnmatch.fnmatch(val, str(kwargs[k])):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if val != kwargs[k]:<EOL><INDENT>return False<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if isinstance(val, str) or isinstance(val, unicode):<EOL><INDENT>if not fnmatch.fnmatch(val, kwargs[k]):<EOL><INDENT>return False<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if val != kwargs[k]:<EOL><INDENT>return False<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return True<EOL>

Method which indicates if the object matches specified criteria.

        Match accepts criteria as kwargs and looks them up on attributes.
        Actual matching is performed with fnmatch, so shell-like wildcards
        work within match strings. Examples:

        obj._match(AXTitle='Terminal*')
        obj._match(AXRole='TextField', AXRoleDescription='search text field')


if obj is not None:<EOL><INDENT>if self._findFirstR(**kwargs):<EOL><INDENT>return obj._match(**kwargs)<EOL><DEDENT><DEDENT>return False<EOL>

Perform _match but on another object, not self.


for needle in self._generateChildren():<EOL><INDENT>if needle._match(**kwargs):<EOL><INDENT>yield needle<EOL><DEDENT><DEDENT>

Generator which yields matches on AXChildren.


for needle in self._generateChildrenR():<EOL><INDENT>if needle._match(**kwargs):<EOL><INDENT>yield needle<EOL><DEDENT><DEDENT>

Generator which yields matches on AXChildren and their children.


result = []<EOL>for item in self._generateFind(**kwargs):<EOL><INDENT>result.append(item)<EOL><DEDENT>return result<EOL>

Return a list of all children that match the specified criteria.


result = []<EOL>for item in self._generateFindR(**kwargs):<EOL><INDENT>result.append(item)<EOL><DEDENT>return result<EOL>

Return a list of all children (recursively) that match the specified
        criteria.


for item in self._generateFind(**kwargs):<EOL><INDENT>return item<EOL><DEDENT>

Return the first object that matches the criteria.


for item in self._generateFindR(**kwargs):<EOL><INDENT>return item<EOL><DEDENT>

Search recursively for the first object that matches the criteria.


app = self<EOL>while True:<EOL><INDENT>try:<EOL><INDENT>app = app.AXParent<EOL><DEDENT>except _a11y.ErrorUnsupported:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return app<EOL>

Get the base application UIElement.

        If the UIElement is a child of the application, it will try
        to get the AXParent until it reaches the top application level
        element.


self._activate()<EOL>for item in args:<EOL><INDENT>if menuitem.AXChildren[<NUM_LIT:0>].AXRole == '<STR_LIT>':<EOL><INDENT>menuitem = menuitem.AXChildren[<NUM_LIT:0>]<EOL><DEDENT>role = '<STR_LIT>'<EOL>try:<EOL><INDENT>menuitem = menuitem.AXChildren[int(item)]<EOL><DEDENT>except ValueError:<EOL><INDENT>menuitem = menuitem.findFirst(AXRole='<STR_LIT>',<EOL>AXTitle=item)<EOL><DEDENT><DEDENT>return menuitem<EOL>

Return the specified menu item.

        Example - refer to items by name:

        app._menuItem(app.AXMenuBar, 'File', 'New').Press()
        app._menuItem(app.AXMenuBar, 'Edit', 'Insert', 'Line Break').Press()

        Refer to items by index:

        app._menuitem(app.AXMenuBar, 1, 0).Press()

        Refer to items by mix-n-match:

        app._menuitem(app.AXMenuBar, 1, 'About TextEdit').Press()


ra = AppKit.NSRunningApplication<EOL>app = ra.runningApplicationWithProcessIdentifier_(<EOL>self._getPid())<EOL>app.activateWithOptions_(<NUM_LIT:3>)<EOL>

Activate the application (bringing menus and windows forward).


ra = AppKit.NSRunningApplication<EOL>app = ra.runningApplicationWithProcessIdentifier_(<EOL>self._getPid())<EOL>return app.bundleIdentifier()<EOL>

Return the bundle ID of the application.


return self._getApplication().AXTitle<EOL>

Return the localized name of the application.


if name.startswith('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>attr = self._getAttribute(name)<EOL>return attr<EOL><DEDENT>except AttributeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>actions = []<EOL>try:<EOL><INDENT>actions = self._getActions()<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT>if name.startswith('<STR_LIT>') and (name[<NUM_LIT:2>:] in actions):<EOL><INDENT>errStr = '<STR_LIT>''<STR_LIT>'<EOL>raise AttributeError(errStr)<EOL><DEDENT>if name in actions:<EOL><INDENT>def performSpecifiedAction():<EOL><INDENT>self._activate()<EOL>return self._performAction(name)<EOL><DEDENT>return performSpecifiedAction<EOL><DEDENT>else:<EOL><INDENT>raise AttributeError('<STR_LIT>' % (self, name))<EOL><DEDENT>

Handle attribute requests in several ways:

        1. If it starts with AX, it is probably an a11y attribute. Pass
           it to the handler in _a11y which will determine that for sure.
        2. See if the attribute is an action which can be invoked on the
           UIElement. If so, return a function that will invoke the attribute.


if name.startswith('<STR_LIT>'):<EOL><INDENT>return self._setAttribute(name, value)<EOL><DEDENT>else:<EOL><INDENT>_a11y.AXUIElement.__setattr__(self, name, value)<EOL><DEDENT>


title = repr('<STR_LIT>')<EOL>role = '<STR_LIT>'<EOL>c = repr(self.__class__).partition('<STR_LIT>')[-<NUM_LIT:1>].rpartition('<STR_LIT>')[<NUM_LIT:0>]<EOL>try:<EOL><INDENT>title = repr(self.AXTitle)<EOL><DEDENT>except Exception:<EOL><INDENT>try:<EOL><INDENT>title = repr(self.AXValue)<EOL><DEDENT>except Exception:<EOL><INDENT>try:<EOL><INDENT>title = repr(self.AXRoleDescription)<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>try:<EOL><INDENT>role = self.AXRole<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT>if len(title) > <NUM_LIT:20>:<EOL><INDENT>title = title[:<NUM_LIT:20>] + '<STR_LIT>'<EOL><DEDENT>return '<STR_LIT>' % (c, role, title)<EOL>

Build a descriptive string for UIElements.


return self._getAttributes()<EOL>

Get a list of the attributes available on the element.


return self._getActions()<EOL>

Return a list of the actions available on the element.


return self._setString(attribute, string)<EOL>

Set the specified attribute to the specified string.


return self._findFirst(**kwargs)<EOL>


return self._findFirstR(**kwargs)<EOL>

Search recursively for the first object that matches the
        criteria.


return self._findAll(**kwargs)<EOL>


return self._findAllR(**kwargs)<EOL>

Return a list of all children (recursively) that match
        the specified criteria.


return self._getElementAtPosition(float(coord[<NUM_LIT:0>]), float(coord[<NUM_LIT:1>]))<EOL>

Return the AXUIElement at the given coordinates.

        If self is behind other windows, this function will return self.


return self._activate()<EOL>

Activate the application (bringing menus and windows forward)


return self._getApplication()<EOL>


menuitem = self._getApplication().AXMenuBar<EOL>return self._menuItem(menuitem, *args)<EOL>

Return the specified menu item.

        Example - refer to items by name:

        app.menuItem('File', 'New').Press()
        app.menuItem('Edit', 'Insert', 'Line Break').Press()

        Refer to items by index:

        app.menuitem(1, 0).Press()

        Refer to items by mix-n-match:

        app.menuitem(1, 'About TextEdit').Press()


self.Press()<EOL>time.sleep(<NUM_LIT>)<EOL>return self._menuItem(self, *args)<EOL>

Return the specified item in a pop up menu.


return self._getBundleId()<EOL>


return self._getLocalizedName()<EOL>


return self._sendKey(keychr)<EOL>


return self._sendKey(keychr, globally=True)<EOL>

Send one character without modifiers to the system.

        It will not send an event directly to the application, system will
        dispatch it to the window which has keyboard focus.

        Parameters: keychr - Single keyboard character which will be sent.


return self._sendKeys(keystr)<EOL>

Send a series of characters with no modifiers.


return self._holdModifierKeys(modifiers)<EOL>


return self._releaseModifierKeys(modifiers)<EOL>


def sendKeyWithModifiers(self, keychr, modifiers):

return self._sendKeyWithModifiers(keychr, modifiers, False)<EOL>

Send one character with modifiers pressed

        Parameters: key character, modifiers (list) (e.g. [SHIFT] or
                    [COMMAND, SHIFT] (assuming you've first used
                    from pyatom.AXKeyCodeConstants import *))


def sendGlobalKeyWithModifiers(self, keychr, modifiers):

return self._sendKeyWithModifiers(keychr, modifiers, True)<EOL>

Global send one character with modifiers pressed.

        See sendKeyWithModifiers


def dragMouseButtonLeft(self, coord, dest_coord, interval=<NUM_LIT:0.5>):

modFlags = <NUM_LIT:0><EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags,<EOL>dest_coord=dest_coord)<EOL>self._postQueuedEvents(interval=interval)<EOL>

Drag the left mouse button without modifiers pressed.

        Parameters: coordinates to click on screen (tuple (x, y))
                    dest coordinates to drag to (tuple (x, y))
                    interval to send event of btn down, drag and up
        Returns: None


def doubleClickDragMouseButtonLeft(self, coord, dest_coord, interval=<NUM_LIT:0.5>):

modFlags = <NUM_LIT:0><EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags,<EOL>dest_coord=dest_coord)<EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags,<EOL>dest_coord=dest_coord,<EOL>clickCount=<NUM_LIT:2>)<EOL>self._postQueuedEvents(interval=interval)<EOL>

Double-click and drag the left mouse button without modifiers
        pressed.

        Parameters: coordinates to double-click on screen (tuple (x, y))
                    dest coordinates to drag to (tuple (x, y))
                    interval to send event of btn down, drag and up
        Returns: None


def clickMouseButtonLeft(self, coord, interval=None):

modFlags = <NUM_LIT:0><EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags)<EOL>if interval:<EOL><INDENT>self._postQueuedEvents(interval=interval)<EOL><DEDENT>else:<EOL><INDENT>self._postQueuedEvents()<EOL><DEDENT>

Click the left mouse button without modifiers pressed.

        Parameters: coordinates to click on screen (tuple (x, y))
        Returns: None


modFlags = <NUM_LIT:0><EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonRight, modFlags)<EOL>self._postQueuedEvents()<EOL>

Click the right mouse button without modifiers pressed.

        Parameters: coordinates to click on scren (tuple (x, y))
        Returns: None


def clickMouseButtonLeftWithMods(self, coord, modifiers, interval=None):

modFlags = self._pressModifiers(modifiers)<EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags)<EOL>self._releaseModifiers(modifiers)<EOL>if interval:<EOL><INDENT>self._postQueuedEvents(interval=interval)<EOL><DEDENT>else:<EOL><INDENT>self._postQueuedEvents()<EOL><DEDENT>

Click the left mouse button with modifiers pressed.

        Parameters: coordinates to click; modifiers (list) (e.g. [SHIFT] or
                    [COMMAND, SHIFT] (assuming you've first used
                    from pyatom.AXKeyCodeConstants import *))
        Returns: None


def clickMouseButtonRightWithMods(self, coord, modifiers):

modFlags = self._pressModifiers(modifiers)<EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonRight, modFlags)<EOL>self._releaseModifiers(modifiers)<EOL>self._postQueuedEvents()<EOL>

Click the right mouse button with modifiers pressed.

        Parameters: coordinates to click; modifiers (list)
        Returns: None


def leftMouseDragged(self, stopCoord, strCoord=(<NUM_LIT:0>, <NUM_LIT:0>), speed=<NUM_LIT:1>):

self._leftMouseDragged(stopCoord, strCoord, speed)<EOL>

Click the left mouse button and drag object.

        Parameters: stopCoord, the position of dragging stopped
                    strCoord, the position of dragging started
                    (0,0) will get current position
                    speed is mouse moving speed, 0 to unlimited
        Returns: None


modFlags = <NUM_LIT:0><EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags)<EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags,<EOL>clickCount=<NUM_LIT:2>)<EOL>self._postQueuedEvents()<EOL>

Double-click primary mouse button.

        Parameters: coordinates to click (assume primary is left button)
        Returns: None


def doubleMouseButtonLeftWithMods(self, coord, modifiers):

modFlags = self._pressModifiers(modifiers)<EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags)<EOL>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags,<EOL>clickCount=<NUM_LIT:2>)<EOL>self._releaseModifiers(modifiers)<EOL>self._postQueuedEvents()<EOL>

Click the left mouse button with modifiers pressed.

        Parameters: coordinates to click; modifiers (list)
        Returns: None


<EOL>modFlags = <NUM_LIT:0><EOL>for i in range(<NUM_LIT:2>):<EOL><INDENT>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags)<EOL><DEDENT>self._queueMouseButton(coord, Quartz.kCGMouseButtonLeft, modFlags,<EOL>clickCount=<NUM_LIT:3>)<EOL>self._postQueuedEvents()<EOL>

Triple-click primary mouse button.

        Parameters: coordinates to click (assume primary is left button)
        Returns: None


def waitFor(self, timeout, notification, **kwargs):

return self._waitFor(timeout, notification, **kwargs)<EOL>

Generic wait for a UI event that matches the specified
        criteria to occur.

        For customization of the callback, use keyword args labeled
        'callback', 'args', and 'kwargs' for the callback fn, callback args,
        and callback kwargs, respectively.  Also note that on return,
        the observer-returned UI element will be included in the first
        argument if 'args' are given.  Note also that if the UI element is
        destroyed, callback should not use it, otherwise the function will
        hang.


def waitForCreation(self, timeout=<NUM_LIT:10>, notification='<STR_LIT>'):

callback = AXCallbacks.returnElemCallback<EOL>retelem = None<EOL>args = (retelem,)<EOL>return self.waitFor(timeout, notification, callback=callback,<EOL>args=args)<EOL>

Convenience method to wait for creation of some UI element.

        Returns: The element created


def waitForWindowToAppear(self, winName, timeout=<NUM_LIT:10>):

return self.waitFor(timeout, '<STR_LIT>', AXTitle=winName)<EOL>

Convenience method to wait for a window with the given name to
        appear.

        Returns: Boolean