2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
# This is a simple Tkinter program, running a main loop and reacting on keys
|
|
|
|
#
|
|
|
|
# Tested on Windows10 with python 3.9
|
|
|
|
#
|
|
|
|
# https://groups.google.com/g/comp.lang.python/c/dldnjWRX3lE/m/cL69gG3fCAAJ
|
|
|
|
|
|
|
|
#------------------------------------------------------------
|
|
|
|
import tkinter as tk
|
|
|
|
import time
|
|
|
|
import pyPlcWorker
|
2022-11-07 08:21:25 +00:00
|
|
|
from pyPlcModes import *
|
|
|
|
import sys # for argv
|
2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
def storekeyname(event):
|
|
|
|
global nKeystrokes
|
|
|
|
global lastKey
|
|
|
|
nKeystrokes+=1
|
|
|
|
lastKey = event.keysym
|
|
|
|
worker.handleUserAction(lastKey)
|
|
|
|
return 'break' # swallow the event
|
|
|
|
|
|
|
|
def inkey():
|
|
|
|
global lastKey
|
|
|
|
return lastKey
|
|
|
|
lastKey = ''
|
|
|
|
|
|
|
|
def cbAddToTrace(s):
|
|
|
|
print(s)
|
|
|
|
|
2022-10-19 16:52:43 +00:00
|
|
|
def cbShowStatus(s, selection=""):
|
|
|
|
#print(s)
|
|
|
|
if (selection == "mode"):
|
|
|
|
lblMode['text']=s
|
|
|
|
s=""
|
|
|
|
if (selection == "pevmac"):
|
2022-10-24 21:19:45 +00:00
|
|
|
lblPevMac['text']="PEV MAC " + s
|
2022-10-19 16:52:43 +00:00
|
|
|
s=""
|
|
|
|
if (len(s)>0):
|
|
|
|
lblStatus['text']=s
|
2022-10-14 16:11:01 +00:00
|
|
|
root.update()
|
|
|
|
|
2022-11-07 08:21:25 +00:00
|
|
|
myMode = C_LISTEN_MODE
|
|
|
|
if (len(sys.argv) > 1):
|
|
|
|
if (sys.argv[1] == "P"):
|
|
|
|
myMode = C_PEV_MODE
|
|
|
|
else:
|
|
|
|
if (sys.argv[1] == "E"):
|
|
|
|
myMode = C_EVSE_MODE
|
|
|
|
|
|
|
|
if (myMode == C_LISTEN_MODE):
|
|
|
|
print("starting in LISTEN_MODE")
|
|
|
|
if (myMode == C_PEV_MODE):
|
|
|
|
print("starting in PEV_MODE")
|
|
|
|
if (myMode == C_EVSE_MODE):
|
|
|
|
print("starting in EVSE_MODE")
|
|
|
|
|
2022-10-14 16:11:01 +00:00
|
|
|
root = tk.Tk()
|
|
|
|
lastKey = ''
|
2022-10-24 21:19:45 +00:00
|
|
|
lblHelp = tk.Label(root, justify= "left")
|
|
|
|
lblHelp['text']="x=exit \nS=GET_SW \nP=PEV mode \nE=EVSE mode \nL=Listen mode \ns=SET_KEY \nG=GET_KEY (try twice) \nt=SET_KEY modified"
|
2022-10-14 16:11:01 +00:00
|
|
|
lblHelp.pack()
|
|
|
|
lblStatus = tk.Label(root, text="(Status)")
|
|
|
|
lblStatus.pack()
|
2022-10-19 16:52:43 +00:00
|
|
|
lblPevMac = tk.Label(root, text="(pev mac)")
|
|
|
|
lblPevMac.pack()
|
|
|
|
lblMode = tk.Label(root, text="(mode)")
|
|
|
|
lblMode.pack()
|
|
|
|
|
2022-10-14 16:11:01 +00:00
|
|
|
# Bind the keyboard handler to all relevant elements:
|
|
|
|
root.bind('<Key>', storekeyname)
|
|
|
|
cbShowStatus("initialized")
|
|
|
|
root.update()
|
2022-11-07 08:21:25 +00:00
|
|
|
worker=pyPlcWorker.pyPlcWorker(cbAddToTrace, cbShowStatus, myMode)
|
2022-10-14 16:11:01 +00:00
|
|
|
|
|
|
|
nMainloops=0
|
|
|
|
nKeystrokes=0
|
|
|
|
while lastKey!="x":
|
2022-10-18 18:59:22 +00:00
|
|
|
time.sleep(.05) # 'do some calculation'
|
2022-10-14 16:11:01 +00:00
|
|
|
nMainloops+=1
|
|
|
|
# print(str(nMainloops) + " " + str(nKeystrokes)) # show something in the console window
|
|
|
|
root.update()
|
|
|
|
worker.mainfunction()
|
|
|
|
|
|
|
|
#---------------------------------------------------------------
|