#!/usr/bin/env python import time import Image import LtMacroAPI import sys import os pid = str(os.getpid()) pidfile = open("./ltmacros/running.pid", 'w') pidfile.write(pid) pidfile.close() ########################################################## # USAGE: # automatic endu tasks # Pin the window of the building/task with endurance timer # Run this macro and clic on the action in the menu # macro then keep clic, wait for END to disapear and so on # Mostly inspired from SlatePicker ########################################################## ########################################################## # constants : # I determined that approximative position of "END" is dx = 25 # from right of window (25 for 1st icon, 75 for the 2nd icon from right, 50 pixels/icon) dy = 115 # from top ########################################################## # Program : # Tell me where is the pinned window :) # get the coords of a mouseclick ((window, relative x, relative y), (root window, absolute screen x, absolute screen y)) (target_hit, root_hit) = LtMacroAPI.getwindowclick() # calcul of atitd window position wx = root_hit[1] - target_hit[1] wy = root_hit[2] - target_hit[2] # Get Window attributes (attr.width, attr.height) attr = target_hit[0].get_geometry() # Now we know where to watch for "END" disappearing : watchX = attr.width-dx watchY = dy print target_hit, watchX, watchY state = 1 # initial click to get "END" picture try: LtMacroAPI.clickwindow(target_hit) # click it except LtMacroAPI.GrabFailed: print "**** can't do initial clic (user interacting?), dying .." raise # little pause to let "END" picture appear time.sleep(1) i1 = LtMacroAPI.getimage(target_hit[0], watchX, watchY, 5, 5) while True: # check the 10x10 image patch we selected above try: i2 = LtMacroAPI.getimage(target_hit[0], watchX, watchY, 5, 5) except LtMacroAPI.GetImageFailed: print "window went out of view, could survive this easily, but more fun to die ;)" raise # if the image patch is identical to our stored one, we should click it if((state==1) and (not LtMacroAPI.compare_raw_images(i1, i2))): state=2 print " - hit!" try: LtMacroAPI.clickwindow(target_hit) # click it except LtMacroAPI.GrabFailed: state=1 print "**** can't grab mouse (user interacting?), aborting this hit" time.sleep(1) # leave a time gap so we don't hammer the slate button repeatedly until ATITD notices elif((state==2) and (LtMacroAPI.compare_raw_images(i1, i2))): print "icon has reappared..ok!" state=1 time.sleep(0.1) # 100ms pause so we don't eat all the CPU