How to determine which screen my application is running on?

Asked by Rahul

Hello RaiMan,

I have been using Sikuli for about a week now and I have run into a problem when dealing with multi-monitor environments and would like to ask you for some help.

I have been through this (https://answers.launchpad.net/sikuli/+question/173996) post regarding using Sikuli in multi-monitor environments. The problem I'm facing is that i do not know before hand which screen my application will launch into (the application is started from the Sikuli script itself using subprocess.popen().

In the above post the below lines get the screen of "Chrome":

aChrome = App("Chrome") # to be adapted for Windows
aChrome.focus()
SCR1 = aChrome.window().getScreen()

My question is: is there any way of doing this in Windows 7?

Thanks in advance! :)

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
RaiMan (raimund-hocke) said :
#1

what Sikuli?

Revision history for this message
Rahul (rahul-thakur) said :
#2

Sorry about that ... I'm using Sikuli IDE 1.0.1 on Win 7.

Revision history for this message
Best RaiMan (raimund-hocke) said :
#3

On Windows, the App class is not very helpful with the modern browsers not showing the classic window titels (which is the item on Windows to be used with focus()).

This is especially true for Chrome.

At least this works:

chrome = App.open("path to the chrome executable")
wait(3)
win = chrome.window()

this should give you the frontmost window and only works if Chrome is not already started.

… but surprise:
this might be anything but what you think.

just try this and scratch your head:
for i in range(100):
    r = chrome.window(i)
    if not r: break
    print "%d: %s" % (i, r)

if you somehow find out the window title of a visible Chrome window, then you might bring this window to front:
App.focus("significant part of the window title")

Revision history for this message
Rahul (rahul-thakur) said :
#4

Thanks so much for the quick help! Your solution works for me :) And luckily I'm not using Chrome (it was an example from another post i mentioned earlier)....because the code you sent across does indeed make me scratch my head :P

Thanks again RaiMan! Your help is much appreciated!

Sikuli's rocks!!

Revision history for this message
Rahul (rahul-thakur) said :
#5

Thanks RaiMan, that solved my question.