Import Question

Asked by Mike Praeuner on 2019-05-08

Starting here & here:*

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)
# supposing there is a testpad2.sikuli
import testpad2
from testpad2 import *
setShowActions (True)
# testpad
# Start script with functions
# supposing myLib.sikuli contains a function "def myFunction():"
# end of script

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

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\", line 15, in <module> testpad2.launchNox() File "D:\MikE\Sikuli Scripts\testpad2.sikuli\", 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\", line 16, in <module> testpad2.openUE() File "D:\MikE\Sikuli Scripts\testpad2.sikuli\", 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

English Edit question
Sikuli Edit question
No assignee Edit question
Solved by:
Mike Praeuner
Last query:
Last reply:
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
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)

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

I did notive that this:
and this

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


when using
from testpad2 import *

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


... and

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.ide.SikulixIDE.main(
IDE terminated: returned: 1

so I downloaded this:

Which resolved the issue with v1.1.4