import names
def main():
startApplication('my_eclipse_or_rcp_application')
# Initially recorded, but object name has/relies
# on occurrence, so look up ToolItem via its text
# instead
#mouseClick(waitForObject(names.Debug_ToolItem_2), 35, 8, 0, Button.Button1)
mouseClick(find_first_swt_toolitem("Debug"), 35, 8, 0, Button.Button1)
def find_first_swt_toolitem(item_text=None, item_tooltiptext=None):
if item_text is None and item_tooltiptext is None:
test.fatal("ERROR: Must specify item_text or item_tooltiptext!")
return None
# At least wait for any ToolBar instance; you still may
# need to snooze() before calling this function
waitForObject({"isvisible": True, "type": "org.eclipse.swt.widgets.ToolBar"})
snooze(2)
i = 0
while True:
n = {"isvisible": True, "type": "org.eclipse.swt.widgets.ToolBar", "occurrence": i}
if not object.exists(n):
break
o = findObject(n)
children = object.children(o)
for c in children:
if item_text is not None and item_text != c.text:
continue
if item_tooltiptext is not None and item_tooltiptext != c.tooltiptext:
continue
return c
i += 1
test.fatal('ERROR: Could not find ToolItem with text "' + str(item_text) + '" and tooltiptext "' + str(item_tooltiptext) + '"'")
return None