LJ/configureUI.py
2024-08-15 17:04:23 +02:00

298 lines
9.4 KiB
Python
Executable File

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# -*- mode: Python -*-
'''
LJ
v0.7.0
Config UI
brew install python-tk
LICENCE : CC
'''
import os
import configparser as cp
import tkinter as tk
import configparser
from libs3 import gstt
import ast
import numpy as np
import fileinput
from shutil import copyfile
config = configparser.ConfigParser()
config.read(gstt.ConfigName)
ljpath = r'%s' % os.getcwd().replace('\\','/')
def Write():
print('Saving ',gstt.ConfigName)
updateJSConfig(config)
config.set('General', 'lasernumber', lasernumberVal.get())
config.set('General', 'rediserverip', rediserveripVal.get())
config.set('General', 'wwwip', wwwipVal.get())
config.set('General', 'oscserverip', str(gstt.oscIPin))
config.set('General', 'nozoscip', str(gstt.nozoscIP))
config.set('General', 'debug',debugVal.get())
config.set('General', 'autostart', autostartVal.get())
for i in range(gstt.LaserNumber):
laser = 'laser' + str(i)
config.set(laser, 'ip', str(gstt.lasersIPS[i]))
config.set(laser, 'type', str(gstt.lasertype[i]))
config.set(laser, 'dac_family', str(gstt.dacs[i]))
config.set(laser, 'kpps', str(gstt.kpps[i]))
config.set(laser, 'centerx', str(gstt.centerX[i]))
config.set(laser, 'centery', str(gstt.centerY[i]))
config.set(laser, 'zoomx', str(gstt.zoomX[i]))
config.set(laser, 'zoomy', str(gstt.zoomY[i]))
config.set(laser, 'sizex', str(gstt.sizeX[i]))
config.set(laser, 'sizey', str(gstt.sizeY[i]))
config.set(laser, 'finangle', str(gstt.finANGLE[i]))
config.set(laser, 'swapx', str(gstt.swapX[i]))
config.set(laser, 'swapy', str(gstt.swapY[i]))
config.set(laser, 'warpdest', np.array2string(gstt.warpdest[i], precision=2, separator=',',suppress_small=True))
config.write(open(gstt.ConfigName,'w'))
def Read():
gstt.LaserNumber = config.getint('General', 'lasernumber')
gstt.RediServerIP= config.get('General', 'rediserverip')
gstt.wwwIP= config.get('General', 'wwwip')
gstt.oscIPin = config.get('General', 'oscserverip')
gstt.nozoscIP = config.get('General', 'nozoscip')
gstt.debug = config.get('General', 'debug')
gstt.plugins = ast.literal_eval(config.get('plugins', 'plugins'))
gstt.autostart = config.get('General', 'autostart')
for i in range(4):
laser = 'laser' + str(i)
gstt.lasersIPS[i]= config.get(laser, 'ip')
gstt.lasertype[i]= config.get(laser, 'type')
gstt.kpps[i] = config.getint(laser, 'kpps')
gstt.dacs[i] = config.get(laser, 'dac_family')
#gstt.lasersPLcolor[i] = config.getint(laser, 'color')
gstt.centerX[i]= config.getfloat(laser, 'centerx')
gstt.centerY[i] = config.getfloat(laser, 'centery')
gstt.zoomX[i] = config.getfloat(laser, 'zoomx')
gstt.zoomY[i] = config.getfloat(laser, 'zoomy')
gstt.sizeX[i] = config.getfloat(laser, 'sizex')
gstt.sizeY[i] = config.getfloat(laser, 'sizey')
gstt.finANGLE[i] = config.getfloat(laser, 'finangle')
gstt.swapX[i] = config.getint(laser, 'swapx')
gstt.swapY[i] = config.getint(laser, 'swapy')
gstt.lsteps[i] = ast.literal_eval(config.get(laser, 'lsteps'))
gstt.warpdest[i]= np.array(ast.literal_eval(config.get(laser, 'warpdest')))
#
# UI
#
def UIelements(currentLaser):
tk.Label(UI, text='Lasers', fg='#FFFFB0',width = 10).grid(row=0, column=0)
tk.Label(UI, text='LJ IP',fg='#FFFF90').grid(row=0, column=2)
tk.Label(UI, text='www IP',fg='#FFFF80').grid(row=1, column=0)
tk.Label(UI, text='debug',fg='#FFFF90').grid(row=1, column=2)
tk.Label(UI, text='autostart',fg='#FFFF90').grid(row=2, column=0)
tk.Label(UI, text='Laser').grid(row=3, column=0)
tk.Label(UI, text='IP').grid(row=3, column=2)
tk.Label(UI, text='type').grid(row=4, column=0)
tk.Label(UI, text='dac').grid(row=4, column=2)
tk.Label(UI, text='kpps').grid(row=5, column=0)
tk.Label(UI, text='finangle').grid(row=5, column=2)
tk.Label(UI, text='centerx').grid(row=6, column=0)
tk.Label(UI, text='centery').grid(row=6, column=2)
tk.Label(UI, text='zoomx').grid(row=7, column=0)
tk.Label(UI, text='zoomy').grid(row=7, column=2)
tk.Label(UI, text='sizex').grid(row=8, column=0)
tk.Label(UI, text='sizey').grid(row=8, column=2)
tk.Label(UI, text='swapx').grid(row=9, column=0)
tk.Label(UI, text='swapy').grid(row=9, column=2)
tk.Label(UI, text='lsteps').grid(row=10, column=0)
tk.Label(UI, text='warpdest').grid(row=10, column=2)
tk.Label(UI, text='color').grid(row=11, column=0)
lasernumberVal.set(str(gstt.LaserNumber))
rediserveripVal.set(str(gstt.RediServerIP))
wwwipVal.set(str(gstt.wwwIP))
debugVal.set(str(gstt.debug))
autostartVal.set(str(gstt.autostart))
laserVal.set(str(currentLaser))
lasernumber = tk.Entry(UI,fg='#FFFFA0', textvariable = lasernumberVal)
rediserverip = tk.Entry(UI,textvariable =rediserveripVal)
wwwip = tk.Entry(UI, textvariable =wwwipVal)
oscserverip = tk.Entry(UI)
nozoscip = tk.Entry(UI)
debug = tk.Entry(UI, textvariable =debugVal)
autostart = tk.Entry(UI, textvariable =autostartVal)
dac = tk.Entry(UI, textvariable =dacVal)
laser = tk.Entry(UI, textvariable =laserVal)
#laser.bind('<Return>', validate(laserVal.get()))
#laser.bind('<Enter>', validate(laserVal.get()))
laser.bind('<Return>', (lambda _: validate(laserVal.get())))
laser.bind('<Enter>', (lambda _: validate(laserVal.get())))
#ipVal = tk.StringVar()
ip = tk.Entry(UI, textvariable =ipVal)
ip.bind('<Return>', (lambda _: Update('ip', ipVal.get())))
type = tk.Entry(UI, textvariable =typeVal)
dac = tk.Entry(UI, textvariable =dacVal)
kpps = tk.Entry(UI, textvariable =kppsVal)
color = tk.Entry(UI, textvariable =colorVal)
centerx = tk.Entry(UI, textvariable =centerxVal)
centery = tk.Entry(UI, textvariable =centeryVal)
zoomxVal.set(str(gstt.zoomX[currentLaser]))
zoomx = tk.Entry(UI, textvariable =zoomxVal)
zoomy = tk.Entry(UI, textvariable =zoomyVal)
sizexVal.set(str(gstt.sizeX[currentLaser]))
sizex = tk.Entry(UI, textvariable =sizexVal)
sizey = tk.Entry(UI, textvariable =sizeyVal)
finangle = tk.Entry(UI, textvariable =finangleVal)
swapx = tk.Entry(UI, textvariable =swapxVal)
swapy = tk.Entry(UI, textvariable =swapyVal)
lsteps = tk.Entry(UI, textvariable =lstepsVal)
warpdest = tk.Entry(UI, textvariable =warpdestVal)
lasernumber.grid(row=0, column=1,padx=10)
rediserverip.grid(row=0, column=3,padx=10)
wwwip.grid(row=1, column=1)
debug.grid(row=1, column=3)
autostart.grid(row=2, column=1)
laser.grid(row=3, column=1)
ip.grid(row=3, column=3)
type.grid(row=4, column=1)
dac.grid(row=4, column=3)
kpps.grid(row=5, column=1)
finangle.grid(row=5, column=3)
centerx.grid(row=6, column=1)
centery.grid(row=6, column=3)
zoomx.grid(row=7, column=1)
zoomy.grid(row=7, column=3)
sizex.grid(row=8, column=1)
sizey.grid(row=8, column=3)
swapx.grid(row=9, column=1)
swapy.grid(row=9, column=3)
lsteps.grid(row=10, column=1)
warpdest.grid(row=10, column=3)
color.grid(row=11, column=1)
save = tk.Button(UI, text="Save", command=Write).grid(row=12, column=1)
ok = tk.Button(UI, text="Ok", command=Exit).grid(row=12, column=3)
UI.title(string='LJ config')
def Exit():
UI.destroy()
quit()
def validate(input):
data =str(input)
if data.isdigit():
#print(input+" is digit")
UIpdateLaser(int(data))
return True
elif input == "":
print(input+ "is null")
return True
else:
print(input)
return False
def updateJSConfig(config):
global ljpath
wwwip = config.get('General','wwwip')
wstype = config.get('General','wstype')
wsport = config.get('General','wsport')
# copy template
src = ljpath + "/templates/config.js"
dst = ljpath + "/www/config.js"
copyfile(src, dst)
# Interpolate variables
with fileinput.FileInput(dst, inplace=True) as file:
for line in file:
line = line.replace("%wstype%", wstype)
line = line.replace("%wsport%", wsport)
line = line.replace("%wwwip%", wwwip)
print(line, end='')
print('www UI updated.')
def Updategstt(var, value):
print("modify ",var," with ",value)
#var=value
config.set('laser' + laserVal.get(), var, value)
config.write
def Update(var, value):
print("modify ",var," with ",value)
#var=value
config.set('laser' + laserVal.get(), var, value)
config.write
def UIpdateLaser(number):
#print('updating with laser : ', number)
ipVal.set(str(gstt.lasersIPS[number]))
typeVal.set(str(gstt.lasertype[number]))
dacVal.set(str(gstt.dacs[number]))
kppsVal.set(str(gstt.kpps[number]))
colorVal.set("Not implemented")
dacVal.set(str(gstt.dacs[number]))
centerxVal.set(str(gstt.centerX[number]))
centeryVal.set(str(gstt.centerY[number]))
zoomxVal.set(str(gstt.zoomX[number]))
zoomyVal.set(str(gstt.zoomY[number]))
sizexVal.set(str(gstt.sizeX[number]))
sizeyVal.set(str(gstt.sizeY[number]))
finangleVal.set(str(gstt.finANGLE[number]))
swapxVal.set(str(gstt.swapX[number]))
swapyVal.set(str(gstt.swapY[number]))
lstepsVal.set(str(gstt.lsteps[number]))
warpdestVal.set(str(gstt.warpdest[number]))
UI = tk.Tk()
lasernumberVal = tk.StringVar()
rediserveripVal = tk.StringVar()
wwwipVal = tk.StringVar()
debugVal = tk.StringVar()
autostartVal = tk.StringVar()
laserVal = tk.StringVar()
ipVal = tk.StringVar()
typeVal = tk.StringVar()
dacVal = tk.StringVar()
kppsVal = tk.StringVar()
colorVal = tk.StringVar()
centerxVal = tk.StringVar()
centeryVal = tk.StringVar()
zoomxVal = tk.StringVar()
zoomyVal = tk.StringVar()
sizexVal = tk.StringVar()
sizeyVal = tk.StringVar()
finangleVal = tk.StringVar()
swapxVal = tk.StringVar()
swapyVal = tk.StringVar()
lstepsVal = tk.StringVar()
warpdestVal = tk.StringVar()
currentLaser =0
Read()
UIelements(currentLaser)
UIpdateLaser(currentLaser)
#UI.update_lasernumber(str(gstt.LaserNumber))
UI.mainloop()