Page 1 of 1

CoolTerm Python integration with pip

Posted: Mon Nov 13, 2023 1:14 pm
by wellys
I created a repository which allows one to install CoolTerm.py using a local pip install. The instructions are in the README. This is my first of this attempt at pip integration, so it's not fully baked. I've tested it on my Mac, and will attempt to test on windows in the next few days.

The value pip integration brings is the ability to have it as part of your Python framework. I also have two examples which can be called from the command line "ct_conn" and "ct_disc", which will connect and disconnect CoolTerm from the serial port, respectively.

The Python scripting capabilities of CoolTerm are outstanding and I want to thank you, Roger, for making this happen.

My question is "how do I activate the CoolTerm window once reconnected?" in Windows. I use AppleScript to do it in macOS...

https://github.com/lkoepsel/CoolTerm_pip

As with all pip installs, you want to be careful with what you install. The CoolTerm.py file is the same file which Roger includes in his installation. The two additional scripts are short enough, you can review to ensure the code is not mailicious.

Happy to answer any questions on this.
Lief

Re: CoolTerm Python integration with pip

Posted: Mon Nov 13, 2023 4:53 pm
by roger
Thanks for posting this. Nice work!
wellys wrote: Mon Nov 13, 2023 1:14 pm My question is "how do I activate the CoolTerm window once reconnected?" in Windows. I use AppleScript to do it in macOS...
By "activate", do you mean, bring a specific window to the foreground? I suppose I could add a "SetFrontmostWindow(ID)" command to the next release.

Roger

Re: CoolTerm Python integration with pip

Posted: Mon Nov 13, 2023 7:25 pm
by roger

Re: CoolTerm Python integration with pip

Posted: Tue Nov 14, 2023 8:05 am
by wellys
Yes, by activate "bring the CoolTerm window to the foreground" so a user could immediately begin to interact with CoolTerm. At present, in Windows, the focus remains in the editor, Sublime Text, which is processing the script.

I'll try some of the suggestions and let you know how it goes. If you beat me to it and add it to CoolTerm...I won't be upset. ;)


I did test this on a second Mac and it worked well. I continually forget to set the scripting checkbox...that's my bad.

I also tested in Windows 11, and the CoolTerm scripting works. My Sublime Text workflows do not. More on this later.
Lief

Re: CoolTerm Python integration with pip

Posted: Tue Nov 14, 2023 9:40 am
by roger
Cool. I'll see if I have some time dig into this and get something working in CoolTerm. I may ask you to do some alpha testing once I think I have something that could work.

Re: CoolTerm Python integration with pip

Posted: Wed Nov 15, 2023 5:56 pm
by wellys
I'd be happy to alpha test!

I did some work on Windows using pygetwindow and pyautogui...it does work, however, it becomes more complex. The script needs to know the name of the window and it is probably better if I use the same process for all three macOS, Windows and Linux.

I'll continue to work on it.

Re: CoolTerm Python integration with pip

Posted: Thu Nov 16, 2023 9:44 am
by roger
I should have something ready to test by the weekend.

Re: CoolTerm Python integration with pip

Posted: Thu Nov 16, 2023 10:24 am
by roger
Meanwhile, you should be able to achieve this by temporarily toggling the "Always Keep Window on Top" property, like this:

Code: Select all

s.SetParameter(ID,"KeepOnTop","True")
s.SetParameter(ID,"KeepOnTop","False")
where ID is the ID of the window you want to bring to the front.

Re: CoolTerm Python integration with pip

Posted: Thu Nov 16, 2023 12:07 pm
by wellys
Thanks!

I did figure out how to regain focus in Windows. I updated the repository to reflect how to do it.
Its a bit of a kludge...one needs to comment out the macOS parts and uncomment the Window sections in a particular file, however, it appears to work on both macOS and Windows.

I chose to retain using AppleScript on macOS as it is so clean and works well (thanks to your excellent integration).

I am using the older pygetwindow and pyautogui (instead of the newer pywinctl) as the latter provides too many windows...for example, pywinctl will show the 4 different CoolTerm windows...

Still interested in testing your solution, as I admit, mine is a bit of a hack for two different OS's.