Skip to content

Commit 62f574c

Browse files
committed
some things are working (see example)
1 parent 466adce commit 62f574c

File tree

5 files changed

+45
-40
lines changed

5 files changed

+45
-40
lines changed

img.png

8.61 KB
Loading

sikulix4python/sxclasses.py

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ def temp_method(*args, **kwargs):
3131
mCall += "args[0]"
3232
mCallError += "%s" % (args[0])
3333
for nArg in range(1, countArgs):
34-
mCall += ", args[%d]" % (nArg,)
34+
mCall += ", args[%d]" % nArg
3535
mCallError += ", %s" % (args[nArg])
3636
mCall += ")"
3737
mCallError += ")"
3838
try:
39-
result = eval("currentObject." + mCall, {"currentObject": self.instance, "args": args})
39+
toEval = "currentObject." + mCall
40+
result = eval(toEval, {"currentObject": self.instance, "args": args})
4041
return result
4142
except:
4243
print("Method missing: %s::%s" % (currentObject, mCallError))
@@ -112,36 +113,3 @@ class Location(SXBase):
112113
class Image(SXBase):
113114

114115
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)

sikulix4python/sxundotted.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22

33
SCREEN = Screen()
44

5-
def addImagePath(path):
6-
SXImagePath.add(path)
5+
def setBundlePath():
6+
addImagePath()
7+
8+
def addImagePath(*path):
9+
if len(path) == 0:
10+
import inspect
11+
stack = inspect.stack()
12+
aPath = os.path.dirname(stack[1].filename)
13+
SXImagePath.setBundlePath(aPath)
14+
print("setBundlePath:", aPath)
15+
else:
16+
aPath = path[0]
17+
SXImagePath.add(aPath)
718

819
def openApp(app):
920
return SXApp(app).open()

testSikulix4python

Lines changed: 0 additions & 3 deletions
This file was deleted.

testSikulix4python.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# https://www.python.org should be opened in Safari
2+
3+
# build the bridge to SikuliX
4+
from sikulix4python import *
5+
6+
# make images available in the folder of the script
7+
addImagePath()
8+
9+
switchApp("Safari")
10+
11+
hover() # undotted uses SCREEN object (sxundotted)
12+
13+
scr = Screen()
14+
15+
# getCenter() is found auto-magically,
16+
# though not defined in the Python class Screen
17+
# see sxclasses::__getattr__
18+
# one gets method missing, if signatures do not fit
19+
scr.getCenter().grow(100).highlight(2)
20+
21+
img = "img.png" # located via ImagePath
22+
23+
# a Match object is completely handled at the Java level
24+
# not defined at the Python level
25+
match = scr.exists(img, 3) # method missing, wrong signature
26+
match = scr.exists(img, 3.0) # number must be float/double
27+
if match:
28+
match.highlight(2)
29+
match.click()

0 commit comments

Comments
 (0)