Skip to content

Commit b941440

Browse files
committed
some things are working (see example)
1 parent f6969b0 commit b941440

File tree

6 files changed

+135
-108
lines changed

6 files changed

+135
-108
lines changed

sikulix4python/sxbase.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
success = True;
17+
try:
18+
self.instance = self.SXClass.getDefaultInstance4py()
19+
if len(args) > 0:
20+
self.instance = self.SXClass.make4py(convertArgs(args))
21+
except:
22+
success = False
23+
if not success:
24+
raise Exception("Class not prepared for SikuliX")
25+
exit(1)
26+
27+
def __str__(self):
28+
return self.instance.toString()
29+
30+
def __getattr__(self, item):
31+
currentObject = self.instance;
32+
33+
def temp_method(*args, **kwargs):
34+
mCall = item + "("
35+
mCallError = "" + mCall
36+
countArgs = len(args)
37+
if countArgs > 0:
38+
mCall += "args[0]"
39+
mCallError += "%s" % (args[0])
40+
for nArg in range(1, countArgs):
41+
mCall += ", args[%d]" % nArg
42+
mCallError += ", %s" % (args[nArg])
43+
mCall += ")"
44+
mCallError += ")"
45+
try:
46+
toEval = "currentObject." + mCall
47+
result = eval(toEval, {"currentObject": self.instance, "args": args})
48+
return result
49+
except:
50+
print("Method missing: %s::%s" % (currentObject, mCallError))
51+
return currentObject
52+
53+
return temp_method
54+

sikulix4python/sxclasses.py

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,5 @@
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-
toEval = "currentObject." + mCall
40-
result = eval(toEval, {"currentObject": self.instance, "args": args})
41-
return result
42-
except:
43-
print("Method missing: %s::%s" % (currentObject, mCallError))
44-
return currentObject
45-
46-
return temp_method
47-
48-
class Region(SXBase):
49-
"""
50-
Wrapper for org.sikuli.script.Region
51-
52-
- Region() the region of the primary screen
53-
- Region(x,y,w,h) a region at (x,y) with size (w,h) cropped to the containing screen
54-
- Region(otherRegion) make an object-copy of object otherRegion
55-
"""
56-
57-
SXClass = SXRegion
58-
59-
def hover(self, *args):
60-
"""
61-
Move the mouse pointer to the given target (args[0])
62-
63-
if the target is
64-
- not given, it will be lastMatch or center (if no lastMatch) of this Region
65-
- an image-filename, a Pattern or an Image, it will first be searched and the valid Match's center/targetOffset will be the target
66-
- a Match: target will be center/targetOffset of the Match
67-
- a Region: target will be center of the Region
68-
- a Location: will be the target
69-
70-
:param args: see above
71-
:return: int: 1 if done without errors, 0 otherwise
72-
"""
73-
if len(args) == 0:
74-
return self.instance.hover()
75-
return self.instance.hover(convertArgs(args))
76-
77-
def click(self, *args):
78-
if len(args) == 0:
79-
return self.instance.click()
80-
return self.instance.click(convertArgs(args))
81-
82-
def highlight(self, *args):
83-
"""
84-
show a colored frame around the region for a given time or switch on/off
85-
86-
- **() or (color)** switch on/off with color (default red)
87-
88-
- **(number) or (number, color)** show in color (default red) for number seconds (cut to int)
89-
90-
allowed colors given as string
91-
- a color name out of: black, blue, cyan, gray, green, magenta, orange, pink, red, white, yellow (lowercase and
92-
uppercase can be mixed, internally transformed to all uppercase)
93-
- these colornames exactly written: lightGray, LIGHT_GRAY, darkGray and DARK_GRAY
94-
- a hex value like in HTML: #XXXXXX (max 6 hex digits)
95-
- an RGB specification as: #rrrgggbbb where rrr, ggg, bbb are integer values in range 0 - 255
96-
padded with leading zeros if needed (hence exactly 9 digits)
97-
98-
:param args: a valid combination (see above) or omitted
99-
:return: self
100-
"""
101-
if len(args) == 0:
102-
return self.instance.highlight()
103-
return self.instance.highlight4py(convertArgs(args))
1+
from . sxbase import *
2+
from . sxregion import Region
1043

1054
class Screen(Region):
1065

sikulix4python/sxgateway.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def convertArgs(args):
1414
def sxstart():
1515
from py4j.java_gateway import JavaGateway
1616
try:
17-
JG = JavaGateway()
18-
SX = JG.jvm.org.sikuli
19-
return (JG, SX)
17+
JavaGW = JavaGateway()
18+
SXPKG = JavaGW.jvm.org.sikuli
19+
return (JavaGW, SXPKG)
2020
except:
2121
print("sxstart: SikuliX not running")
2222
exit(1)
@@ -25,7 +25,7 @@ def sxstart():
2525

2626
def sxClass(className, pkgName = "script"):
2727
classRef = "SXPKG.%s.%s" % (pkgName, className)
28-
theClass = eval(classRef)
28+
theClass = eval(classRef, {"SXPKG" : SXPKG})
2929
try:
3030
theClass.getDefaultInstance4py()
3131
except:

sikulix4python/sxregion.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from . sxbase import *
2+
3+
class Region(SXBase):
4+
"""
5+
Wrapper for org.sikuli.script.Region
6+
7+
- Region() the region of the primary screen
8+
- Region(x,y,w,h) a region at (x,y) with size (w,h) cropped to the containing screen
9+
- Region(otherRegion) make an object-copy of object otherRegion
10+
"""
11+
12+
SXClass = SXRegion
13+
14+
def hover(self, *args):
15+
"""
16+
Move the mouse pointer to the given target (args[0])
17+
18+
if the target is
19+
- not given, it will be lastMatch or center (if no lastMatch) of this Region
20+
- an image-filename, a Pattern or an Image, it will first be searched and the valid Match's center/targetOffset will be the target
21+
- a Match: target will be center/targetOffset of the Match
22+
- a Region: target will be center of the Region
23+
- a Location: will be the target
24+
25+
:param args: see above
26+
:return: int: 1 if done without errors, 0 otherwise
27+
"""
28+
if len(args) == 0:
29+
return self.instance.hover()
30+
return self.instance.hover(convertArgs(args))
31+
32+
def click(self, *args):
33+
if len(args) == 0:
34+
return self.instance.click()
35+
return self.instance.click(convertArgs(args))
36+
37+
def highlight(self, *args):
38+
"""
39+
show a colored frame around the region for a given time or switch on/off
40+
41+
- **() or (color)** switch on/off with color (default red)
42+
43+
- **(number) or (number, color)** show in color (default red) for number seconds (cut to int)
44+
45+
allowed colors given as string
46+
- a color name out of: black, blue, cyan, gray, green, magenta, orange, pink, red, white, yellow (lowercase and
47+
uppercase can be mixed, internally transformed to all uppercase)
48+
- these colornames exactly written: lightGray, LIGHT_GRAY, darkGray and DARK_GRAY
49+
- a hex value like in HTML: #XXXXXX (max 6 hex digits)
50+
- an RGB specification as: #rrrgggbbb where rrr, ggg, bbb are integer values in range 0 - 255
51+
padded with leading zeros if needed (hence exactly 9 digits)
52+
53+
:param args: a valid combination (see above) or omitted
54+
:return: self
55+
"""
56+
if len(args) == 0:
57+
return self.instance.highlight()
58+
return self.instance.highlight4py(convertArgs(args))

sikulix4python/sxundotted.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
SCREEN = Screen()
44

5+
def reset():
6+
SX().reset()
7+
58
def setBundlePath():
69
addImagePath()
710

@@ -30,14 +33,15 @@ def click(*args):
3033

3134
def hover(*args):
3235
"""
33-
**SCREEN::hover** Move the mouse pointer to the given target (args[0])
36+
**hover** Move the mouse pointer to the given target (args[0])
3437
3538
if the target is
3639
- not given, it will be lastMatch or center (if no lastMatch) of this Region
3740
- an image-filename, a Pattern or an Image, it will first be searched and the valid Match's center/targetOffset will be the target
3841
- a Match: target will be center/targetOffset of the Match
3942
- a Region: target will be center of the Region
4043
- a Location: will be the target
44+
- (int, int): explicit target coordinates
4145
4246
:param args: see above
4347
:return: int: 1 if done without errors, 0 otherwise

testSikulix4python.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22

33
# build the bridge to SikuliX
44
from sikulix4python import *
5+
reset()
6+
7+
#print(sxClassHelp("Region")); exit()
8+
9+
reg = Region()
10+
print(reg)
11+
reg.setX(100).setW(300)
12+
print(reg)
13+
hover()
14+
hover(reg)
15+
16+
exit()
517

618
# make images available in the folder of the script
719
addImagePath()

0 commit comments

Comments
 (0)