Problem with Multi-Monitor-Switching (Windows 7)

Asked by CryoGenID

Hello everybody!

We are currently setting up a huge collection of test-scripts.
There we have to work some things on Monitor A and some things on Monitor B and then compare the results.

This is our code so far (stripped down just for testing):
---
from sikuli import *

# Screen switchting only works once here:
#Settings.myScreen = 1 # 0 = left display (Notebook), 1 = middle display, 2 = right display
#SCREEN = Screen(Settings.myScreen)
#dict = globals()
#dict['SCREEN'] = SCREEN
#dict['SCREEN']._exposeAllMethods(__name__)

def prepareScreenForTesting():
    print("prepareScreenForTesting: START")
    # Reposition the cursor to top and reload the website
    type(Key.HOME)
    type(Key.F5)
    # Wait for screen reload
    wait(1)
    inside().wait("Fertig.png",FOREVER)
    #inside().wait("Zertid.png",FOREVER)

    print("prepareScreenForTesting: DONE")

def Test_Q():
    popup("Run Test Q")

def Test_T():
    popup("Run Test T")

def Compare():
    popup("Starting comparison")

def runModule():
    Settings.myScreen = 1 # 0 = left display (Notebook), 1 = middle display, 2 = right display
    SCREEN = Screen(Settings.myScreen)
    dict = globals()
    dict['SCREEN'] = SCREEN
    dict['SCREEN']._exposeAllMethods(__name__)
    prepareScreenForTesting()
    Test_Q()

    Settings.myScreen = 0 # 0 = left display (Notebook), 1 = middle display, 2 = right display
    SCREEN = Screen(Settings.myScreen)
    dict = globals()
    dict['SCREEN'] = SCREEN
    dict['SCREEN']._exposeAllMethods(__name__)
    prepareScreenForTesting()
    Test_T()

    Compare()

runModule()
---

As you can see, runModule should switch the screen, run the Q-Tests and then switch the screen and run the P-Tests.
Unfortunately that doesn't work...
It only works once if we put the code for the screen-switching to the top. Even though we have to quit sikuli and re-open
the test whenever we change the number of the screen.

And as you might already have guessed: We need HELP :-(

Thanks already in advance for your help!

Best regards,

Christian

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

--- Even though we have to quit sikuli and re-open the test whenever we change the number of the screen.
This currently is a feature ;-)
Monitor configuration is only checked once at IDE startup or when the script starts from command line.

--- switching SCREEN
Iguess, this is your problem: since SCREEN is a global variable, you have to tell Python in def()'s, that it is global, if you have it on left side - otherwise it is a local variable and I think, then the effect does not happen (global SCREEN remains unchanged).

so try:
def runModule():
    global SCREEN
    # your code ....

Revision history for this message
CryoGenID (cryo-t) said :
#2

Raimund,

thanks a lot for your reply!
That seems to have worked, THANK YOU :-)

Best regards,

Christian

Revision history for this message
CryoGenID (cryo-t) said :
#3

Thanks RaiMan, that solved my question.