CoolTerm Python integration with pip

If you have specific questions or problems with any of my Open Source Projects, post them here.
Post Reply
wellys
Posts: 11
Joined: Sun Sep 24, 2023 10:04 am

CoolTerm Python integration with pip

Post 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
User avatar
roger
Site Admin
Posts: 434
Joined: Fri Apr 24, 2009 12:41 am
Contact:

Re: CoolTerm Python integration with pip

Post 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
wellys
Posts: 11
Joined: Sun Sep 24, 2023 10:04 am

Re: CoolTerm Python integration with pip

Post 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
User avatar
roger
Site Admin
Posts: 434
Joined: Fri Apr 24, 2009 12:41 am
Contact:

Re: CoolTerm Python integration with pip

Post 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.
wellys
Posts: 11
Joined: Sun Sep 24, 2023 10:04 am

Re: CoolTerm Python integration with pip

Post 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.
User avatar
roger
Site Admin
Posts: 434
Joined: Fri Apr 24, 2009 12:41 am
Contact:

Re: CoolTerm Python integration with pip

Post by roger »

I should have something ready to test by the weekend.
User avatar
roger
Site Admin
Posts: 434
Joined: Fri Apr 24, 2009 12:41 am
Contact:

Re: CoolTerm Python integration with pip

Post 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.
wellys
Posts: 11
Joined: Sun Sep 24, 2023 10:04 am

Re: CoolTerm Python integration with pip

Post 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.
Post Reply