[1.1.0] build 2015-05-22: having a problem getting the region of an open window in 1.1

Asked by Jitendra Patel

I am trying to see if a window is open and gets its region if its not then start it and get the region. here is what i have.

myApp = ("Charlie")

if not myApp.window():
    vBox = App.open("c:\\Program Files\\Oracle\\VirtualBox.exe")
    charlieVM = App.open("c:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe startvm Charlie")
    vbox.close()
myApp.focus()
regCharlie = Region(charlieVM.focusedWindow())
setROI(regCharlie)
...

if the window doesnt exist it start its up and gets the correct region however if the window is already open i get
an incorrect region. (-200,-200,100,100). the window is not minimized if that matters

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

a problem one faces with many modern Windows apps: there might be "hidden" windows, that are outside the visible screen or have a width and height <= 1.

currently the only hack:

for nw in range(100):
    w = Region(someApp.window(nw))
    if not w: break
    print nw, w # for debugging only
    if (w.x < 0 or w.y < 0 or w.w < 100 or w.h < 100): continue
if not w:
    print "no window"
    exit(1)

-- comments

----might be a typo:
myApp = ("Charlie")

should be
myApp = App("Charlie")

--- regCharlie = Region(charlieVM.focusedWindow())

focusedWindow()
is a class method and should be used as

App.focusedWindow()

it simply returns the window, that currently is the frontmost (owned by whatever app)

Revision history for this message
Jitendra Patel (soul88) said :
#2

my apologies for the typo it was myApp = App("Charlie") and i had it as App.focusedWindow() to begin and now i have changed it back to that. The problem still exists.

I moved the script to my 1.01 folder and it worked as expected. however under 1.1 it only works if no window exists and it starts the app if the window already exists then an incorrect region is returned.

the code is still the same as above with the following exception

regCharlie = Region(charlieVM.focusedWindow())
changed to
regCharlie = Region(App.focusedWindow())

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

do you have the latest build of 1.1.0.
I have revised;-) the App class the last week.

I guess, that "Charlie" is some text in the Window title.

instead of:
if not myApp.window():

try:
if not myApp.isRunning():

If this does not work:
I have to check tomorrow on my Windows system with VitualBox.

Revision history for this message
Jitendra Patel (soul88) said :
#4

yes i saw the revision mentioned in the changelog and installed sikulixsetup-1.1.0-20150522.231039-82-forsetup.jar

the title of the window is Charlie [Running] - Oracle VM VirtualBox

there is no problem with the if statement as its commands are executed when Charlie vm is not running and skipped when the vm is running

when the vm is stopped it gets started and the correct region is found

[log] App.focus: [1652:VBoxManage.exe (!C:\Program Files\Oracle\VirtualBox\VBoxManage.exe startvm Charlie)] C:\Program Files\Oracle\VirtualBox\VBoxManage.exe startvm Charlie
R[1184,103 496x880]@S(0)[0,0 1920x1080] E:Y, T:3.0

when the vm is running the window is focused however the region returned is not the region shown above. i didn't move the window so it should have the same region as the one shown above

[log] App.focus: [2356:VirtualBox.exe (Charlie [Running] - Oracle VM VirtualBox)] Charlie
[error] Region(-200,-200,100,100) outside any screen - subsequent actions might not work as expected
[error] Region(-200,-200,100,100) outside any screen - subsequent actions might not work as expected
R[-200,-200 100x100]@Screen null E:Y, T:3.0

hope that helps clear things up. I'll be busy the rest of the day but I'll check back with you tomorrow

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

ok, thanks for the input.

I will try tomorrow, to get behind the magic ;-)

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

ok, just tested:

this works in the moment:

myApp = App("Charlie")
if not myApp.isRunning:
    # this is sufficient, no need for the extra
    #App.open("c:\\Program Files\\Oracle\\VirtualBox.exe")
    App.open("c:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe startvm Charlie")
    while not App("Charlie").isRunning(): # refresh the App instance
        wait(1)
    myApp = App("Charlie") # refresh the App instance

App("Charlie").focus()
regCharlie = Region(App.focusedWindow())
setROI(regCharlie)
# … more
App("Charlie").close()

--- this will work after the build 2015-05-25+:

myApp = App("Charlie")
if not myApp.isRunning:
    App.open("c:\\Program Files\\Oracle\\VirtualBox\\VBoxManage.exe startvm Charlie")
    while not myApp.isRunning(): # refreshing the App instance done internally
        wait(1)

myApp.focus()
regCharlie = Region(App.focusedWindow())
setROI(regCharlie)
# … more
myApp.close()

Revision history for this message
Jitendra Patel (soul88) said :
#7

Thanks RaiMan, that solved my question.