Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App.focus() on Windows not working with unicode characters in window title --- fixed 2019-03-05 build#220 #53

Closed
SeanKim777 opened this issue Nov 29, 2018 · 12 comments
Assignees
Labels
fixed the problem has been fixed
Milestone

Comments

@SeanKim777
Copy link

SeanKim777 commented Nov 29, 2018

Bug status
currently only workaround --- fix will take time (bug tracking)

App("someApp.exe").focus() will not work, if the title of the 
frontmost app window contains unicode characters.

workaround:
App.focus("part of window title") will only work 
if the given string is ascii-only (no unicode characters),
but it will find and focus also windows, whose title contains Unicode characters.

So currently there is no way to focus apps/windows, whose window titles are completely unicode.

Hi
I've just started to use Sikulix for my task.
I have tested sikulix 1.1.4 2018-11-27_13:43 (Build 137) on Windows 10.
When I tried to focus on app named with Unicode character, it failed with error "App.focus failed: no window for App_name_including_unicode_characters_and_English_also_PID"
I've reviewed Sikulix code and realised that switchApp method in org/sikuli/natives/WinUtil.java line 332 not implemented.
Probably because of this, focus() is not working?
Sorry I'm not actively using Java but Python.
Could you please fix this when you have time?
Also, is there any better way to work around to set focus on the app easily? I assume it can be done with fidn images but except this :)

@SeanKim777 SeanKim777 changed the title focus() on Windows not working App.focus() on Windows not working Nov 29, 2018
@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

Could you paste the offending snippet exactly as you use it?

switchApp method in org/sikuli/natives/WinUtil.java line 332 not implemented

it is indeed implemented, but the code is in the bundled native lib written with C++.

So it might have something to do with the unicode characters.

Also, is there any better way to work around to set focus on the app easily?

Not really. You might try to click on the app symbol in the taskbar. And of course you can find/click some part of the window, that is visible.

@RaiMan RaiMan changed the title App.focus() on Windows not working App.focus() on Windows not working with unicode characters Nov 29, 2018
@RaiMan RaiMan self-assigned this Nov 29, 2018
@RaiMan RaiMan added the bug Something isn't working label Nov 29, 2018
@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

confirmed:
does not work, if window title contains unicode character.

possible workaround:
use a compound part of the window title, that does not contain any unicode characters.

@SeanKim777
Copy link
Author

Thank you for quick reply. below is the my test code. I've tested with # -- coding: utf-8 -- heading but more got more strange result. below code was tested without # -- coding: utf-8 --

def check(app_instance):
    print("%s is running? %s" % (app_instance.getName(), app_instance.isRunning()))
    print("%s has window? %s" % (app_instance.getName(), app_instance.hasWindow()))
    new_app = app_instance.focus()
    print("%s focused ? %s " % (app_instance.getName(), new_app.getName()))

calculator = App("Calculator.exe") 
check(calculator)

chrome = App("Chrome.exe")
check(chrome)

** Result**
Calculator.exe is running? True
Calculator.exe has window? True

[error] App.focus failed: no window for [4668:Calculator.exe (CicMarshalWnd)] Calculator.exe
Calculator.exe focused ? Calculator.exe

Chrome.exe is running? True
Chrome.exe has window? True

Chrome.exe focused ? Chrome.exe

calculator

taskmgr

@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

-- coding: utf-8 -- heading

Not needed, since already set internally before script run. Does not have any influence on strings at script run, only tells the interpreter about the encoding of the script text.

@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

focus() always returns the App instance, but does not guarantee that it worked (currently no reliable check internally).

so this does not really make sense:

    new_app = app_instance.focus()
    print("%s focused ? %s " % (app_instance.getName(), new_app.getName()))

To get all available info about an App instance, simply use

print "myApp:", myApp

App has a rather verbose toString() implementation.

@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

Have a look at the Debug feature in the docs.

For this test for example:

Debug.on(3)
calc = App("Calculator.exe") 
calc.open()
calc.focus()

would have revealed enough information "voluntarily" ;-)

@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

... and for testing short snippets I have added the feature in the IDE, that allows to run only some lines of a larger script (right-mouse on a line number)

@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

... and finally: I have to do some digging, to find out, what can be done or wether it is not possible with the current App implementation.

@RaiMan RaiMan changed the title App.focus() on Windows not working with unicode characters App.focus() on Windows not working with unicode characters in window title Nov 29, 2018
@SeanKim777
Copy link
Author

Thank you for your kind reply 🥇

@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

Hey, gold medal ;-)

In Germany we have a saying: As you shout into a forest, you get it back.

It definitely is the more motivating when answering questions/complains the more the caller shows up with some effort to help me understand the problem and how it came up.

All the best.

@RaiMan RaiMan changed the title App.focus() on Windows not working with unicode characters in window title App.focus() on Windows not working with unicode characters in window title --- workarouind Nov 29, 2018
@RaiMan RaiMan changed the title App.focus() on Windows not working with unicode characters in window title --- workarouind App.focus() on Windows not working with unicode characters in window title --- workaround Nov 29, 2018
@RaiMan
Copy link
Owner

RaiMan commented Nov 29, 2018

Bad news: no quick fix, only a workaround.
See #53 (comment)

@balmma balmma mentioned this issue Mar 4, 2019
@balmma
Copy link
Contributor

balmma commented Mar 4, 2019

Pull request #82 might fix this one. But keep in mind, that if you want to find an App using the window title and the title contains Unicode characters you have to use a Unicode String literal. E.g. App.focus(u"Über.txt - Editor") or App(u"Über.txt - Editor"). focus().

@RaiMan RaiMan changed the title App.focus() on Windows not working with unicode characters in window title --- workaround App.focus() on Windows not working with unicode characters in window title --- fixed 2019-03-05 build#220 Mar 5, 2019
@RaiMan RaiMan added the fixed the problem has been fixed label Mar 5, 2019
@RaiMan RaiMan removed the bug Something isn't working label Sep 13, 2019
@RaiMan RaiMan closed this as completed Oct 11, 2019
@RaiMan RaiMan added this to the 2.0.1 milestone Nov 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed the problem has been fixed
Projects
None yet
Development

No branches or pull requests

3 participants