Macro buttons for CoolTerm, using Python

If you have specific questions or problems with any of my Freeware applications, post them here.

Macro buttons for CoolTerm, using Python

Postby roger » Sat Jun 06, 2020 2:03 pm

With CoolTerm 1.7.0 supporting cross-platform scripting, it is now possible to create macro buttons that work on all supported operating systems, as demonstrated by the following script:

Code: Select all
# Creating Macro Buttons using tkinter
#
# Enter the macro text into the input field and
# press the button next to it to send it.
# use /n, /r, /t to send LF, CR, or TAB, respectively
#
# This example creates 2 buttons. You may add as many
# buttons as you like.
#
# Author: Roger Meier, 06-06-2020
# CoolTerm version: 1.7.0

import CoolTerm
import sys
import os
import tkinter

# --------------------------------------------------------
# CoolTerm Setup
# --------------------------------------------------------
s = CoolTerm.CoolTermSocket()

# Get the ID of the first open window
ID = s.GetWindowID(0)
if ID < 0:
    print("No open windows")
    sys.exit()

# Open the serial port
if not s.Connect(ID):
    print("Not Connected")
    sys.exit()
   
def send(txt):
    txt = txt.replace("\\n","\n") # replace "\n" with LF
    txt = txt.replace("\\r","\r") # replace "\r" with CR
    txt = txt.replace("\\t","\t") # replace "\t" with TAB
    s.Write(ID, txt)
   
# --------------------------------------------------------
# GUI Setup
# --------------------------------------------------------
w = tkinter.Tk()
w.title("CoolTerm Macros")

# BUTTON 1
def send1():
    send(txt1.get())
txt1 = tkinter.Entry(w, width = 20)
txt1.grid(column=0, row=0)
btn1 = tkinter.Button(w, text = "Send", command = send1)
btn1.grid(column=1, row=0)
txt1.focus()

# BUTTON 2
def send2():
    send(txt2.get())
txt2 = tkinter.Entry(w, width = 20)
txt2.grid(column=0, row=1)
btn2 = tkinter.Button(w, text = "Send", command = send2)
btn2.grid(column=1, row=1)

# CLOSE BUTTON
btnClose = tkinter.Button(w, text = "Close Window", command = w.destroy)
btnClose.grid(row=3)

w.mainloop() # Code execution will stop here until w is closed
print("Done")

CoolTerm Macros.png
You do not have the required permissions to view the files attached to this post.
User avatar
roger
Site Admin
 
Posts: 241
Joined: Fri Apr 24, 2009 12:41 am

Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron