-
Notifications
You must be signed in to change notification settings - Fork 698
Add focus() function to set application to be in focus in foreground [done] #478
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
Comments
Hi @Vic-Lau!
|
Hi @kensoh Mr.kensoh, Please forgive my description, these are not problems, just some suggestions~ :
|
Hi @Vic-Lau, how is it for 1? For 2, I don't think Chrome API allows making the Chrome browser in focus, that has to be done from OS level. Can you try to r.wait() for some time before doing the keyboard shortcuts? Alternatively, consider editing the tagui_config.txt file to set the browser window size. File found in the tagui/src or .tagui/src folder under r.tagui_location() For 3, popup() can only set the context but it doesn't make it appear in front, I don't think that can be controlled from Chrome API. Thus only keyboard to send Alt+Tab or using visual automation to click onto it will bring it in front. Automation can still continue without the tab being in front. |
Closing issue for now because there isn't anything actionable, but do let me know your thoughts so I can see if something can be improved within the constraints of Chrome API or other workaround. |
Hi @kensoh Mr.Kensoh emm... 1 is not clear yet~~~, 2 and 3 I have also compared some RPA products in the past few days. I think it is correct that this Query is closed, because although 2 and 3 are solved in some RPA products, But TagUI as an RPA engine or the RPA language, It only needs to provide the most basic implementation, and it should not involve product requirement solutions, so I will consider using TagUI and Python to encapsulation general method to implement similar requirement in the future, So thank you for your reply. Best Wishes~
|
What other RPA products did you try? Many RPA tools are based on Windows, so the complexity is lesser than solution like rpa package that can run on Windows, Mac, Linux. I think you can use r.run() to run some Windows command to set an application to be in focus. Check out the link below and try, should be doable. https://stackoverflow.com/questions/35988863/using-command-line-batch-to-switch-to-focus-on-app |
Aliyun-RPA,iS-RPA etc... iS-RPA link: https://support.i-search.com.cn/article/1608274445197
|
Do both aliyun rpa and is rpa run on mac and Linux too? That will increase software complexity by a lot to stay consistent across OSes. But anyway, hard to compete with China commercial products. China tech products that can survive the national competition would have to be very very good. |
No, Both only support Windows OS, So TagUI has better scalability, Also very awesome👍! |
Mac and Windows both seem to support this from OS level commands without adding dependencies. I'll take a look to see if it makes sense to add something. |
Linux seems to require users to have wmctrl installed |
Adding dev note Mac is quite straightforward, though only activate window, not select tab
|
For Windows, to try using sendKeys.bat by possibly uploading to https://github.com/tebelorg/Tump/releases/tag/v1.0.0 and downloading on first run on Windows and store in tagui_location() + '/tagui/src' folder. Need to check if below works
Verified to work. Returns 0 if valid app name and 1 if otherwise. Not case sensitive. Need full name of app. |
Thank you for your understanding and support, Best Wishes~ |
@Vic-Lau you try install v1.49 then you can use the following, for example, to make Google Chrome in focus:
I'm running a promotion this year when a feature suggestion is accepted there is 100 USD gift voucher. Shall you pick a vendor so that I can get the gift voucher for you for this new feature suggestion? Thanks for the suggestion!! |
Hi @Vic-Lau yes paypal is ok. You can pick a vendor or make some voucher purchase or online purchase around 100 USD, then share screenshot of purchase to me either here or other channels. You can also choose more expensive things above 100 USD and pay the rest yourself. |
@kensoh Mr.Kensoh, I'm not clear, Is it possible to transfer money directly? Or, for example I have to buy something on Amazon and send you a screenshot of order? Because I have never done this in China. |
Yes buy something or some voucher online so that I can transfer you. If the appreciation gift is cash, it can attract other wrong users to raise irrelevant bugs and feature suggestions to this project for cash money. |
Oh I see. Can I choose an online shopping mall in China? Such as Taobao, Jingdong. |
Yes of course! Any vendor or website is ok you can choose. I use Taobao too last time when in Singapore. |
haha, Taobao is very good~ OK, I will take my family on a trip to Japan, Here is the screenshot of the order~ Thx |
Oh nice, is this the visa document that you need to buy to visit Japan? Cool, I'll transfer you over the weekend |
Yes, we will apply for a Japanese visa through a travel agency and we will go to Fukuoka to taste food, Thank you for your reward~ lol~ |
Hi @Vic-Lau i've sent you to your paypal email. There is some issue there is no CNY option in the target currency. So I transferred you 111 USD instead. 111 USD because Paypal is a greedy company and will deduct about 5.5% from what you I send you as middleman fee. And from USD when you convert to CNY I think paypal from googling charge another 4.5% to you. So 111 USD will end up to be 100 USD worth by the time the money actually reach your bank account. |
(And 111 USD is not even the amount I get charged, I get charged around 115 USD because they also charge commission for converting my base currency to USD .... T_T Anyway that's paypal. There's another app called TransferWise / Wise with good conversion commission and fees but is that common in China?) |
Oh no... Paypal is so greedy!!! I want to return it, Do you have Alipay?
|
I don't have Alipay. No need, don't try to return because I don't think I will get back 115 USD. Don't worry about it :) |
OK~ Thx~ 这段话用中文,我的FB账号申诉回来了,添加了你的好友,如果可以的话。哈哈,再次感谢大神的慷慨~ |
I deleted now, the only sensitive info is your email, u need to edit to delete your message earlier with your email. |
Yes will add you back! |
Hi @kensoh Mr.Kensoh, focus() is working!!! Thx. But there is a little problem, I use pack() to upgrade, everything is ok except need to download https://github.com/tebelorg/Tump/releases/download/v1.0.0/sendKeys.bat, would you consider putting sendKeys.bat into pack()? |
Hi @Vic-Lau I understand what you mean. Let me think over it what is the best way to distribute that file with pack() |
In the meantime, you can just copy the sendKeys file over to your destination PC. As long as the file is in the same working directory where you run your Python script, it should work without trying to download. I'll think over what is elegant way to ship with pack() or update(). It's a bit tricky because this is an executable I'm cautious not to put it together with other source files. Otherwise you can get into issues with unique user environment situation like having a space in path name and it can potentially break the sendKeys function for those users. Escaping with double quotes could also cause problem because that command is meant to use with double quotes around the application name. |
Another option could be embedding that file as part of the Python package, just like below javascript file. But this will add another 60 lines of code to tagui.py (3% more lines of code). So asking all users from Linux, Mac, Windows who are not using this focus() function to pay this price is somewhat a bad choice. |
I think copy the sendKeys file is acceptable and I suggest explain clearly where the file is stored. |
Will add a comment here so folks looking at release notes or search for issues will know |
Added in RPA for Python v1.49 and available with To use the feature on Windows or Mac, use Note - For Windows users using |
Hi @kensoh Mr.Kensoh, After I tested the sendKeys.bat, I confirmed the sendKeys.bat have some compatibility issues, it doesn't work on some Windows OS, So I implemented focus() use Python pywin32 (pip install pywin32). hope for it have some value. import win32com
import win32com.client
import win32gui
import win32con
"""Get all windows hwnd titiles.
Returns:
titles (dict): all titles dict.
"""
def get_titles():
titles = {}
def callback(hwnd, extra):
if(win32gui.IsWindow(hwnd) and
win32gui.IsWindowEnabled(hwnd) and
win32gui.IsWindowVisible(hwnd)):
titles.update({hwnd: win32gui.GetWindowText(hwnd)})
return True
win32gui.EnumWindows(callback, None)
print(titles)
return titles
"""Set application to be in focus in foregroud.
Args:
title (str): application title.
"""
def focus(title):
assert title, "title is not null."
titles = get_titles()
for h, t in titles.items():
if t:
if title in t:
print(str(h) + ": " + t)
# solved error: (0, 'SetForegroundWindow', 'No error message is available').
shell = win32com.client.Dispatch("WScript.Shell")
shell.SendKeys("%")
# foregroud window.
win32gui.SetForegroundWindow(h)
# window maximize.
win32gui.ShowWindow(h, win32con.SW_MAXIMIZE)
if __name__ == "__main__":
focus("Chrome") |
Thanks @Vic-Lau! This is good! I'll find a place to weave this into the github main page readme. (but not make it default because this requires installing another python package) |
Thanks @Vic-Lau ! Added a segment at API reference - https://github.com/tebelorg/RPA-Python#api-reference "Use focus() to make Windows/Mac application windows to be in focus (see here for pywin32 alternative)." |
Hi @kensoh Mr.Kensoh, As the title:
r.close()
can't close chrome, How can I ensure that chrome will be closed?The text was updated successfully, but these errors were encountered: