Import Question

Asked by Mike Praeuner on 2019-05-08

Starting here & here:
https://sikulix-2014.readthedocs.io/en/latest/scripting.html?highlight=import%20*
https://answers.launchpad.net/sikuli/+faq/2446

--testpad.sikuli--
from sikuli import *
# the path containing your stuff - choose your own naming
# on Windows
myScriptPath = "D:\\MikE\\Sikuli Scripts"
# all systems (avoids double entries in sys.path)
addImportPath(myScriptPath)
# supposing there is a testpad2.sikuli
import testpad2
reload(testpad2)
from testpad2 import *
setShowActions (True)
# testpad
# Start script with functions
# supposing myLib.sikuli contains a function "def myFunction():"
testpad2.launchNox()
testpad2.openUE()
#
#
# end of script
exit(1)

--testpad2.sikuli--
# Testing Global Functions
# Launch Nox
def launchNox():
    app = App("D:\\Program Files\\Nox\\bin\\Nox.exe")
    app.open(5) # does the focus as well
    reg = app.window(0)
    if exists("1555433103893.png"):
        hover("1555433103893.png")
    else:
        sleep(0)
#function open UE app (default account)
def openUE():
    wait("1555426342139.png", 60)
    if exists("1555426342139.png"):
        click("1555426342139.png")
    else:
         sleep(0)
    wait("1556061400286.png", 30)
    hover("1556061400286.png")

and I get this error:
[error] script [ testpad ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "D:\MikE\Sikuli Scripts\testpad.sikuli\testpad.py", line 15, in <module> testpad2.launchNox() File "D:\MikE\Sikuli Scripts\testpad2.sikuli\testpad2.py", line 2, in launchNox app = App("D:\\Program Files\\Nox\\bin\\Nox.exe") NameError: global name 'App' is not defined

If I comment out line 15 I see this:
[error] script [ testpad ] stopped with error at line --unknown--
[error] Error caused by: Traceback (most recent call last): File "D:\MikE\Sikuli Scripts\testpad.sikuli\testpad.py", line 16, in <module> testpad2.openUE() File "D:\MikE\Sikuli Scripts\testpad2.sikuli\testpad2.py", line 13, in openUE wait("1555426342139.png", 60) NameError: global name 'wait' is not defined

Still out of my depth, but making steady progress :D (trying to eliminate any repeat code / reuse as much as possible)

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
Mike Praeuner
Solved:
2019-05-09
Last query:
2019-05-09
Last reply:
2019-05-09
RaiMan (raimund-hocke) said : #1

from sikuli import *

need not be in main script (done internally automatically)

but MUST be in EVERY imported script

BTW: with 1.1.4+

import testpad2
reload(testpad2)
from testpad2 import *

can be only:

from testpad2 import *

(the reload is done internally automatically)

Mike Praeuner (eris667) said : #2

I tried to setup 1.1.4 - but having issues (win10) will try again later when I have more time to troubleshoot (1.1.3 is installed)
when I launch (1.1.4) sikulix.jar it deletes the jruby and jython files but never launches (Java8u211)
https://raiman.github.io/SikuliX1/downloads.html

Everything is working as expected now that I have the header on the correct script :P

I did notive that this:
    testpad2.launchNox()
and this
    launchNox()

both work - I am assuming the correct syntax is testpad2.launchNox(), but since the other works as well does that mean you can redefine a function on a script that loads the original function from another script (probably all sorts of issues with that - but just curious)

RaiMan (raimund-hocke) said : #3

--- 1.1.4
the jruby and jython jars are moved to SikuliX extension folder.

-- import

with only
import testpad2

only
testpad2.launchNox()
works

when using
from testpad2 import *

all global names (defined at the indent level null) are now known in the current context

so
launchNox()
works

... and
testpad2.launchNox()

of course too

with import * one must be careful and have a naming convention, since imported names overwrite existing names withou notice

Mike Praeuner (eris667) said : #4

on very first run I was told I needed jython, so I grabbed that file (+ ruby) and have not gotten any messages or seen the IDE since....
I did try to run via command line

C:\Users\MikE\Desktop>java -jar sikulix.jar
Exception in thread "main" org.sikuli.script.SikuliXception: fatal: Java arch must be 64 Bit (java 8 version 1.8 vm 25.211-b12 class 52.0 arch null)
        at org.sikuli.script.support.RunTime.terminate(RunTime.java:548)
        at org.sikuli.script.support.RunTime.get(RunTime.java:751)
        at org.sikuli.ide.SikulixIDE.main(SikulixIDE.java:59)
IDE terminated: returned: 1

so I downloaded this:
https://javadl.oracle.com/webapps/download/AutoDL?BundleId=238729_478a62b7d4e34b78b671c754eaaf38ab

Which resolved the issue with v1.1.4