|
| 1 | +from . sxgateway import * |
| 2 | + |
| 3 | +SX = SXPKG.script.SX |
| 4 | +SXRegion = SXPKG.script.Region |
| 5 | +SXScreen = SXPKG.script.Screen |
| 6 | +SXLocation = SXPKG.script.Location |
| 7 | +SXImage = SXPKG.script.Image |
| 8 | +SXImagePath = SXPKG.script.ImagePath |
| 9 | +SXApp = SXPKG.script.App |
| 10 | + |
| 11 | +class SXBase(): |
| 12 | + |
| 13 | + SXClass = SX |
| 14 | + |
| 15 | + def __init__(self, *args): |
| 16 | + self.instance = self.SXClass.getDefaultInstance4py() |
| 17 | + if len(args) > 0: |
| 18 | + self.instance = self.SXClass.make4py(convertArgs(args)) |
| 19 | + |
| 20 | + def __str__(self): |
| 21 | + return self.instance.toString() |
| 22 | + |
| 23 | + def __getattr__(self, item): |
| 24 | + currentObject = self.instance; |
| 25 | + |
| 26 | + def temp_method(*args, **kwargs): |
| 27 | + mCall = item + "(" |
| 28 | + mCallError = "" + mCall |
| 29 | + countArgs = len(args) |
| 30 | + if countArgs > 0: |
| 31 | + mCall += "args[0]" |
| 32 | + mCallError += "%s" % (args[0]) |
| 33 | + for nArg in range(1, countArgs): |
| 34 | + mCall += ", args[%d]" % (nArg,) |
| 35 | + mCallError += ", %s" % (args[nArg]) |
| 36 | + mCall += ")" |
| 37 | + mCallError += ")" |
| 38 | + try: |
| 39 | + result = eval("currentObject." + mCall, {"currentObject": self.instance, "args": args}) |
| 40 | + return result |
| 41 | + except: |
| 42 | + print("Method missing: %s::%s" % (currentObject, mCallError)) |
| 43 | + return currentObject |
| 44 | + |
| 45 | + return temp_method |
| 46 | + |
| 47 | +class Region(SXBase): |
| 48 | + """ |
| 49 | + Wrapper for org.sikuli.script.Region |
| 50 | +
|
| 51 | + - Region() the region of the primary screen |
| 52 | + - Region(x,y,w,h) a region at (x,y) with size (w,h) cropped to the containing screen |
| 53 | + - Region(otherRegion) make an object-copy of object otherRegion |
| 54 | + """ |
| 55 | + |
| 56 | + SXClass = SXRegion |
| 57 | + |
| 58 | + def hover(self, *args): |
| 59 | + """ |
| 60 | + Move the mouse pointer to the given target (args[0]) |
| 61 | +
|
| 62 | + if the target is |
| 63 | + - not given, it will be lastMatch or center (if no lastMatch) of this Region |
| 64 | + - an image-filename, a Pattern or an Image, it will first be searched and the valid Match's center/targetOffset will be the target |
| 65 | + - a Match: target will be center/targetOffset of the Match |
| 66 | + - a Region: target will be center of the Region |
| 67 | + - a Location: will be the target |
| 68 | +
|
| 69 | + :param args: see above |
| 70 | + :return: int: 1 if done without errors, 0 otherwise |
| 71 | + """ |
| 72 | + if len(args) == 0: |
| 73 | + return self.instance.hover() |
| 74 | + return self.instance.hover(convertArgs(args)) |
| 75 | + |
| 76 | + def click(self, *args): |
| 77 | + if len(args) == 0: |
| 78 | + return self.instance.click() |
| 79 | + return self.instance.click(convertArgs(args)) |
| 80 | + |
| 81 | + def highlight(self, *args): |
| 82 | + """ |
| 83 | + show a colored frame around the region for a given time or switch on/off |
| 84 | + |
| 85 | + - **() or (color)** switch on/off with color (default red) |
| 86 | +
|
| 87 | + - **(number) or (number, color)** show in color (default red) for number seconds (cut to int) |
| 88 | + |
| 89 | + allowed colors given as string |
| 90 | + - a color name out of: black, blue, cyan, gray, green, magenta, orange, pink, red, white, yellow (lowercase and |
| 91 | + uppercase can be mixed, internally transformed to all uppercase) |
| 92 | + - these colornames exactly written: lightGray, LIGHT_GRAY, darkGray and DARK_GRAY |
| 93 | + - a hex value like in HTML: #XXXXXX (max 6 hex digits) |
| 94 | + - an RGB specification as: #rrrgggbbb where rrr, ggg, bbb are integer values in range 0 - 255 |
| 95 | + padded with leading zeros if needed (hence exactly 9 digits) |
| 96 | +
|
| 97 | + :param args: a valid combination (see above) or omitted |
| 98 | + :return: self |
| 99 | + """ |
| 100 | + if len(args) == 0: |
| 101 | + return self.instance.highlight() |
| 102 | + return self.instance.highlight4py(convertArgs(args)) |
| 103 | + |
| 104 | +class Screen(Region): |
| 105 | + |
| 106 | + SXClass = SXScreen |
| 107 | + |
| 108 | +class Location(SXBase): |
| 109 | + |
| 110 | + SXClass = SXLocation |
| 111 | + |
| 112 | +class Image(SXBase): |
| 113 | + |
| 114 | + SXClass = SXImage |
| 115 | + |
| 116 | +SCREEN = Screen() |
| 117 | + |
| 118 | +def addImagePath(path): |
| 119 | + SXImagePath.add(path) |
| 120 | + |
| 121 | +def openApp(app): |
| 122 | + return SXApp(app).open() |
| 123 | + |
| 124 | +def switchApp(app): |
| 125 | + return SXApp(app).focus() |
| 126 | + |
| 127 | +def closeApp(app): |
| 128 | + return SXApp(app).close() |
| 129 | + |
| 130 | +def click(*args): |
| 131 | + return SCREEN.click(*args) |
| 132 | + |
| 133 | +def hover(*args): |
| 134 | + """ |
| 135 | + **SCREEN::hover** Move the mouse pointer to the given target (args[0]) |
| 136 | +
|
| 137 | + if the target is |
| 138 | + - not given, it will be lastMatch or center (if no lastMatch) of this Region |
| 139 | + - an image-filename, a Pattern or an Image, it will first be searched and the valid Match's center/targetOffset will be the target |
| 140 | + - a Match: target will be center/targetOffset of the Match |
| 141 | + - a Region: target will be center of the Region |
| 142 | + - a Location: will be the target |
| 143 | +
|
| 144 | + :param args: see above |
| 145 | + :return: int: 1 if done without errors, 0 otherwise |
| 146 | + """ |
| 147 | + return SCREEN.hover(*args) |
0 commit comments