#! /usr/bin/python
# -*- coding: utf-8 -*-
"""
This file is part of LibreLight.
LibreLight is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
LibreLight is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LibreLight. If not, see .
(c) 2012 micha.rathfelder@gmail.com
"""
import random
rnd_id = random.randint(1000,9000)
try:
xtitle = __file__
except:
xtitle = "__file__"
if "/" in xtitle:
xtitle = xtitle.split("/")[-1]
import sys
sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title
import json
import time
import sys
import _thread as thread
import traceback
import tkinter
import tkinter as tk
from tkinter import font
import lib.chat as chat
import lib.motion as motion
from collections import OrderedDict
show_name = "GloryCamp2021"
show_name = "GloryCamp2021"
#show_name = "Dimmer"
CUES = OrderedDict()
groups = OrderedDict()
class Modes():
def __init__(self):
self.modes = {}
self.__cfg = {}
self.__cd = None
def val(self,mode,value=None):
if value is not None:
return self.set(mode,value)
elif mode in self.modes:
return self.modes[mode]
def get(self,mode,value=None):
return slef.val(mode,value)
def __check(self,mode):
if mode not in self.modes:
self.modes[mode] = 0
self.__cfg[mode] = 0
def cfg(self,mode,data={}):
self.__check(mode)
if type(data) is dict:
for k in data:
v = data[k]
if v not in self.__cfg:
self.__cfg[k] = v
return 1
elif type(data) is str:
if data in self.__cfg:
return self.__cfg[data]
def set(self,mode,value):
self.__check(mode)
if mode == "CLEAR":
self.modes["STORE"] = 0
self.callback("STORE")
self.modes[mode] = value
return value
def callback(self,mode):
if self.__cb is not None and mode in self.modes:
value = self.modes[mode]
self.__cb(mode=mode,value=value)
modes = Modes()
modes.modes["BLIND"] = 0
modes.modes["STORE "] = 0
modes.modes["FLASH"] = 0
modes.modes["STONY_FX"] = 0
modes.modes["SELECT"] = 0
modes.modes["ACTIVATE"] = 0
modes.modes["CFG_BTN"] = 0
modes.modes["LABEL"] = 0
POS = ["PAN","TILT","MOTION"]
COLOR = ["RED","GREEN","BLUE","COLOR"]
BEAM = ["GOBO","G-ROT","PRISMA","P-ROT","FOCUS","SPEED"]
INT = ["DIM","SHUTTER","STROBE","FUNC"]
client = chat.tcp_sender()
fade = 2 #2 #0.1 #1.13
fade_on = 1
fx_prm = {"SIZE":20,"SPEED":100,"OFFSET":50,"BASE":"-","START":0}
def build_cmd(dmx,val,args=[fade],flash=0,xpfx="",attr=""):
cmd=""
if xpfx:
pfx=xpfx
elif flash:
pfx ="df"
else:
pfx ="d"
if type(val) is float or type(val) is int:
cmd += ",{}{}:{:0.4f}".format(pfx,dmx,val)
else:
cmd += ",{}{}:{}".format(pfx,dmx,val)
if flash:
cmd += ":0:0"#.format(val)
else:
for val in args:
if type(val) is float or type(val) is int:
cmd += ":{:0.4f}".format(val)
else:
cmd += ":{}".format(val)
if attr:
cmd += ":"+str(attr)
return cmd
def update_raw_dmx(data ,value=None,args=[fade],flash=0,pfx="d",fx=0):
cmd = []
if flash:
pfx += "f"
for row in data:
if fx:
if value is not None:
# z.b. flush off
xcmd = str(value)+":"+row["FX"].split(":",1)[-1]
else:
xcmd = row["FX"]
else:
if row["VALUE"] is None:
xcmd = ""
else:
if value is not None:
if type(value) is float:
xcmd = "{:0.4f}".format(value)
else:
xcmd = "{}".format(value)
else:
xcmd = "{:0.4f}".format(row["VALUE"])
for arg in args:
if type(arg) is float:
xcmd += ":{}".format(arg)
else:
xcmd += ":{:0.4f}".format(arg)
#print( "pack: FIX",row["FIX"],row["ATTR"], xcmd)
#xcmd += ":{}".format(row["ATTR"])
cmd.append( xcmd)
return cmd
def update_dmx(attr,data,value=None,args=[fade],flash=0,pfx=""):
#global modes #BLIND
dmx = data["DMX"]
val = None
cmd=""
try:
if attr == "DIM" and data["ATTRIBUT"][attr]["NR"] < 0: #VDIM
#print( "VDIM")
for attr in data["ATTRIBUT"]:
dmx = data["DMX"]
if data["ATTRIBUT"][attr]["NR"] < 0: #virtual channels
continue
dmx += data["ATTRIBUT"][attr]["NR"]-1
mode = ""
if "MODE" in data["ATTRIBUT"][attr]:
mode = data["ATTRIBUT"][attr]["MODE"]
#print(attr)
val = data["ATTRIBUT"][attr]["VALUE"]
if data["ATTRIBUT"][attr]["MASTER"]:
val = val * (data["ATTRIBUT"]["DIM"]["VALUE"] / 255.)
if val is not None:
#cmd += ",d{}:{:0.4f}".format(dmx,int(val))
if value is not None:
val = value
if mode == "F": #FADE
cmd += build_cmd(dmx,val,args=args,flash=flash,xpfx=pfx,attr=attr)
else:
cmd += build_cmd(dmx,val,args=[0],flash=flash,xpfx=pfx,attr=attr)
#print("cmd",cmd)
elif data["ATTRIBUT"][attr]["NR"] > 0:
dmx += data["ATTRIBUT"][attr]["NR"]-1
val = data["ATTRIBUT"][attr]["VALUE"]
mode = ""
if "MODE" in data["ATTRIBUT"][attr]:
mode = data["ATTRIBUT"][attr]["MODE"]
if data["ATTRIBUT"][attr]["MASTER"]:
#if "VDIM" in data["ATTRIBUT"]:
if "DIM" in data["ATTRIBUT"] and data["ATTRIBUT"]["DIM"]["NR"] < 0: #VDIM
val = val * (data["ATTRIBUT"]["DIM"]["VALUE"] / 255.)
if val is not None:
#cmd += ",d{}:{}".format(dmx,int(val))
if value is not None:
val = value
if mode == "F": #FADE
cmd += build_cmd(dmx,val,args=args,flash=flash,xpfx=pfx,attr=attr)
else:
cmd += build_cmd(dmx,val,args=[0],flash=flash,xpfx=pfx,attr=attr)
#print("cmd",cmd)
if modes.val("BLIND"):
cmd=""
return cmd
except Exception as e:
print("== cb EXCEPT",e)
print("Error on line {}".format(sys.exc_info()[-1].tb_lineno))
raise e
class dummy_event():
def __init__(self):
self.num =0
class Xevent():
def __init__(self,fix,elem,attr=None,data=None,mode=None):
self.data=data
self.attr = attr
self.elem = elem
self.mode = mode
def encoder(self,fix,attr,data,elem,action=""):
if action == "click":
if self.data["ATTRIBUT"][attr]["ACTIVE"]:
self.data["ATTRIBUT"][attr]["ACTIVE"] = 0
self.elem["bg"] = "grey"
else:
self.data["ATTRIBUT"][attr]["ACTIVE"] = 1
self.elem["bg"] = "yellow"
return 1
v2=data["ATTRIBUT"][attr]["VALUE"]
change=0
increment = 4.11
if action == "+":
v2+= increment
v = "+{:0.4f}".format( increment ) #) #4.11"
change=1
elif action == "-":
v2-= 4.11
v = "-{:0.4f}".format( increment ) #) #4.11"
change=1
if v2 < 0:
v2=0
elif v2 > 256:
v2=256
if change:
data["ATTRIBUT"][attr]["ACTIVE"] = 1
elem["bg"] = "yellow"
#v2 = v
#v = data["ATTRIBUT"][attr]["VALUE"]
data["ATTRIBUT"][attr]["VALUE"] = v2
elem["text"] = "{} {:0.2f}".format(attr,v2)
#worker.fade_dmx(fix,attr,data,v,v2,ft=0)
cmd=update_dmx(attr=attr,data=data,args=[0])
#data["ATTRIBUT"][attr]["VALUE"] = v2
if cmd and not modes.val("BLIND"):
client.send(cmd)
def cb(self,event):
#print("cb",self,event,data)
print("cb",self.attr,self.mode,event)
print(["type",event.type,"num",event.num])
#print(dir(event.type))
#print(dir(event),[str(event.type)])#.keys())
try:
#v = self.data["ATTRIBUT"][self.attr]
#global modes
#global STORE
#global BLIND
#global FLASH
#global STONY_FX
#global LABEL
#global SELECT
#global ACTIVATE
#global CFG_BTN
change = 0
if self.mode == "COMMAND":
if self.attr == "CLEAR":
if event.num == 1:
if modes.val("STORE"):
self.data.val_commands["STORE"] = 0
modes.val("STORE",0)# = 0
self.data.elem_commands["STORE"]["bg"] = "grey"
else:
for fix in self.data.FIXTURES.fixtures:
print( "clr",fix)
data = self.data.FIXTURES.fixtures[fix]
#print("elm",self.data.elem_attr[fix])
for attr in data["ATTRIBUT"]:
if attr.endswith("-FINE"):
continue
self.data.elem_attr[fix][attr]["bg"] = "grey"
data["ATTRIBUT"][attr]["ACTIVE"] = 0
#print(data["ATTRIBUT"])
print( "CB CLEAR" )
if self.attr.startswith("SZ:"):#SIN":
#global fx_prm
k = "SIZE"
if event.num == 1:
pass
elif event.num == 2:
pass
elif event.num == 4:
if fx_prm[k] <= 0:
fx_prm[k] = 1
fx_prm[k] *=1.2
elif event.num == 5:
fx_prm[k] /=1.2
#fx_prm[k] =int(fx_prm[k])
if fx_prm[k] > 4000:
fx_prm[k] = 4000
if fx_prm[k] < 0:
fx_prm[k] =0
self.data.elem_fx_commands[self.attr]["text"] = "SZ:{:0.0f}".format(fx_prm[k])
if self.attr.startswith("SP:"):#SIN":
#global fx_prm
k = "SPEED"
if event.num == 1:
pass
elif event.num == 2:
pass
elif event.num == 4:
if fx_prm[k] <= 0:
fx_prm[k] = 1
fx_prm[k] *=1.2
elif event.num == 5:
fx_prm[k] /=1.2
#fx_prm[k] =int(fx_prm[k])
if fx_prm[k] > 4000:
fx_prm[k] = 4000
if fx_prm[k] < 0:
fx_prm[k] =0
if fx_prm[k] < 0.1:
self.data.elem_fx_commands[self.attr]["text"] = "SP:off".format(fx_prm[k])
else:
self.data.elem_fx_commands[self.attr]["text"] = "SP:{:0.0f}".format(fx_prm[k])
if self.attr.startswith("ST:"):#SIN":
#global fx_prm
k = "START"
if event.num == 1:
pass
elif event.num == 2:
pass
elif event.num == 4:
if fx_prm[k] <= 0:
fx_prm[k] = 1
fx_prm[k] *=1.2
elif event.num == 5:
fx_prm[k] /=1.2
#fx_prm[k] =int(fx_prm[k])
if fx_prm[k] > 4000:
fx_prm[k] = 4000
if fx_prm[k] < 0:
fx_prm[k] =0
self.data.elem_fx_commands[self.attr]["text"] = "ST:{:0.0f}".format(fx_prm[k])
if self.attr.startswith("OF:"):#SIN":
#global fx_prm
k = "OFFSET"
if event.num == 1:
pass
elif event.num == 2:
pass
elif event.num == 4:
if fx_prm[k] <= 0:
fx_prm[k] = 1
fx_prm[k] *=1.2
elif event.num == 5:
fx_prm[k] /=1.2
#fx_prm[k] =int(fx_prm[k])
if fx_prm[k] > 1024:
fx_prm[k] = 1024
if fx_prm[k] < 0:
fx_prm[k] =0
self.data.elem_fx_commands[self.attr]["text"] = "OF:{:0.0f}".format(fx_prm[k])
if self.attr.startswith("BS:"):
k = "BASE"
if event.num == 1:
fx_prm[k] = "0"
elif event.num == 2:
pass
elif event.num == 4:
fx_prm[k] = "+"
elif event.num == 5:
fx_prm[k] = "-"
self.data.elem_fx_commands[self.attr]["text"] = "BS:{}".format(fx_prm[k])
if self.attr.startswith("FX:"):#SIN":
if event.num == 1:
cmd = ""
offset = 0
offset_flag=0
start = fx_prm["START"]
base = fx_prm["BASE"]
for fix in self.data.FIXTURES.fixtures:
data = self.data.FIXTURES.fixtures[fix]
#print( "ADD FX",fix)
for attr in data["ATTRIBUT"]:
if attr.endswith("-FINE"):
continue
fx=""
if "SIN" in self.attr:
fx = "sinus"
elif "FD" in self.attr:
fx = "fade"
elif "ON2" in self.attr:
fx = "on2"
elif "ON" in self.attr:
fx = "on"
elif "BUM2" in self.attr:
fx = "bump2"
elif "BUM" in self.attr:
fx = "bump"
elif "COS" in self.attr:
fx = "cosinus"
if fx:
if fx_prm["SPEED"] < 0.1:
fx = "off"
else:
if "DIM" in self.attr:
base=""
if attr == "DIM":
if fx_prm["SPEED"] < 0.1:
fx = "off"
else:
fx = "fade"
elif "TILT" in self.attr:
base=""
if attr == "PAN":
fx = "off"
if attr == "TILT":
if fx_prm["SPEED"] < 0.1:
fx = "off"
else:
fx = "sinus"
elif "PAN" in self.attr:
base=""
if attr == "PAN":
if fx_prm["SPEED"] < 0.1:
fx = "off"
else:
fx = "cosinus"
if attr == "TILT":
fx = "off"
elif "CIR" in self.attr:
base=""
if attr == "PAN":
if fx_prm["SPEED"] < 0.1:
fx = "off"
else:
fx = "cosinus"
if attr == "TILT":
if fx_prm["SPEED"] < 0.1:
fx = "off"
else:
fx = "sinus"
if fx:
fx += ":{:0.0f}:{:0.0f}:{:0.0f}:{:0.0f}:{}:".format(fx_prm["SIZE"],fx_prm["SPEED"],start,offset,base)
offset_flag=1
if "FX" not in data["ATTRIBUT"][attr]:
data["ATTRIBUT"][attr]["FX"] =""
print("ADD FX",fix,attr,fx,data["ATTRIBUT"][attr]["ACTIVE"])
if data["ATTRIBUT"][attr]["ACTIVE"] and fx:
print("++ADD FX",fix,attr,fx)
data["ATTRIBUT"][attr]["FX"] = fx #"sinus:40:100:10"
cmd+=update_dmx(attr,data,pfx="fx",value=fx)#,flash=FLASH)
if fx_prm["OFFSET"] > 0.5 and offset_flag:
offset_flag=0
offset += fx_prm["OFFSET"] # add offset on next fixture
#print("offset",offset)
if cmd and not modes.val("BLIND"):
client.send(cmd)
elif self.attr == "FX OFF":
if event.num == 1:
client.send("fx0:alloff:,fxf:alloff:")
self.data.elem_fx_commands[self.attr]["bg"] = "magenta"
for fix in self.data.FIXTURES.fixtures:
data = self.data.FIXTURES.fixtures[fix]
for attr in data["ATTRIBUT"]:
data["ATTRIBUT"][attr]["FX"] = ""
elif self.attr == "FLASH":
if event.num == 1:
if modes.val("FLASH"):
modes.val("FLASH",0)# = 0
self.data.elem_commands[self.attr]["bg"] = "grey"
else:
modes.val("FLASH",1)# = 1
self.data.elem_commands[self.attr]["bg"] = "green"
elif self.attr == "BLIND":
if event.num == 1:
if self.data.val_commands[self.attr]:
self.data.val_commands[self.attr] = 0
modes.val("BLIND",0)# = 0
self.data.elem_commands[self.attr]["bg"] = "grey"
else:
self.data.val_commands[self.attr] = 1
modes.val("BLIND",1)# = 1
self.data.elem_commands[self.attr]["bg"] = "red"
print("BLIND",self.data.val_commands)
elif self.attr == "FADE":
global fade
global fade_on
if fade < 0.01:
fade = 0.01
elif fade > 100.0:
fade = 100
if event.num == 4:
fade *= 1.1
elif event.num == 5:
fade /= 1.1
elif event.num == 1:
if fade_on:
fade_on = 0
self.data.elem_commands[self.attr]["bg"] = "grey"
else:
fade_on = 1
self.data.elem_commands[self.attr]["bg"] = "green"
elif event.num == 2:
if fade > 1 and fade < 4:
fade = 4
elif fade > 3 and fade < 6:
fade = 6
elif fade > 5 and fade < 7:
fade = 8
elif fade > 7 and fade < 9:
fade = 10
elif fade > 9:
fade = 0.01
elif fade < 1:
fade = 1.1
self.data.elem_commands[self.attr]["text"] = "Fade{:0.2f}".format(fade)
elif self.attr == "CFG-BTN":
#global modes #CFG_BTN
if event.num == 1:
if modes.val("CFG_BTN"):
modes.val("CFG_BTN",0)# = 0
self.data.elem_commands[self.attr]["bg"] = "lightgrey"
else:
modes.val("CFG_BTN",1)# = 1
self.data.elem_commands[self.attr]["bg"] = "red"
elif self.attr == "ACTIVATE":
#global modes# ACTIVATE
if event.num == 1:
if modes.val("ACTIVATE"):
modes.val("ACTIVATE",0)# = 0
self.data.elem_commands[self.attr]["bg"] = "lightgrey"
else:
modes.val("ACTIVATE",1)# = 1
self.data.elem_commands[self.attr]["bg"] = "red"
elif self.attr == "SELECT":
#global modes# SELECT
#global CFG_BTN
if event.num == 1:
if modes.val("SELECT"):
modes.val("SELECT",0)# = 0
self.data.elem_commands[self.attr]["bg"] = "lightgrey"
else:
modes.val("SELECT",1)# = 1
self.data.elem_commands[self.attr]["bg"] = "red"
elif self.attr == "LABEL":
#global modes #LABEL
#global CFG_BTN
if event.num == 1:
if modes.val("LABEL"):
modes.val("LABEL", 0)
self.data.elem_commands[self.attr]["bg"] = "lightgrey"
else:
modes.val("LABEL", 1)
self.data.elem_commands[self.attr]["bg"] = "red"
elif self.attr == "STONY_FX":
if event.num == 1:
if modes.val("STONY_FX"):
modes.val("STONY_FX", 0)
self.data.elem_fx_commands[self.attr]["bg"] = "grey"
else:
modes.val("STONY_FX", 1)
self.data.elem_fx_commands[self.attr]["bg"] = "red"
elif self.attr == "STORE":
if event.num == 1:
if self.data.val_commands[self.attr]:
self.data.val_commands[self.attr] = 0
modes.val("STORE",0)
self.data.elem_commands[self.attr]["bg"] = "lightgrey"
else:
self.data.val_commands[self.attr] = 1
modes.val("STORE", 1)
self.data.elem_commands[self.attr]["bg"] = "red"
print("BLIND",self.data.val_commands)
elif self.attr == "BACKUP":
self.data.PRESETS.backup_presets()
self.data.FIXTURES.backup_patch()
return 0
elif self.mode == "ROOT":
if event.keysym=="Escape":
pass
#STORE = 0
#LABEL = 0
elif self.mode == "INPUT":
print("INP",self.data.entry.get())
if event.keycode == 36:
x=self.data.entry.get()
client.send(x)
#self.data.entry.clean()
#self.data
#chat.send("")
elif self.mode == "INPUT2":
print("INP2",self.data.entry2.get())
if event.keycode == 36:
x=self.data.entry2.get()
client.send(x)
#self.data.entry.clean()
elif self.mode == "INPUT3":
print("INP3",self.data.entry3.get())
if event.keycode == 36:
x=self.data.entry3.get()
client.send(x)
#self.data.entry.clean()
#self.data
#chat.send("")
elif self.mode == "PRESET":
nr = self.attr #int(self.attr.split(":")[1])-1
#print( "RRR", [str(event.type) , event.type] )
#print( "PRESET EVENT",event.num)
if event.num == 1:
if str(event.type) == '4': #4 ButtonPress
#if str(event.type) == "ButtonRelease" or event.type == '5':
if modes.val("STORE"):
self.data.preset_store(nr)
elif modes.val("CFG_BTN"):
import tkinter.simpledialog
txt = tkinter.simpledialog.askstring("CFG-BTN","GO,FLASH,TOGGLE,SWOP\n EXE:"+str(nr))
if "CFG" not in self.data.PRESETS.val_presets[nr]:
self.data.PRESETS.val_presets[nr]["CFG"] = OrderedDict()
if "BUTTON" not in self.data.PRESETS.val_presets[nr]["CFG"]:
self.data.PRESETS.val_presets[nr]["CFG"]["BUTTON"] = ""
self.data.PRESETS.val_presets[nr]["CFG"]["BUTTON"] = txt
sdata=self.data.PRESETS.val_presets[nr]
BTN="go"
if "CFG" in sdata:#["BUTTON"] = "GO"
if "BUTTON" in sdata["CFG"]:
BTN = sdata["CFG"]["BUTTON"]
label = self.data.PRESETS.label_presets[nr] # = label
txt=str(nr)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+label
self.data.elem_presets[nr]["text"] = txt
modes.val("CFG_BTN",0)# = 0
self.data.elem_commands["CFG-BTN"]["bg"] = "grey"
elif modes.val("LABEL"):#else:
label = "lalaal"
import tkinter.simpledialog
label = tkinter.simpledialog.askstring("LABEL","Preset "+str(nr))
if label is not None:
self.data.elem_presets[nr]["text"] = label
self.data.PRESETS.label_presets[nr] = label
sdata=self.data.PRESETS.val_presets[nr]
BTN="go"
if "CFG" in sdata:#["BUTTON"] = "GO"
if "BUTTON" in sdata["CFG"]:
BTN = sdata["CFG"]["BUTTON"]
txt=str(nr)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+label
#txt = "Preset:"+str(nr)+":\n"+str(len(l))+":"+label
self.data.elem_presets[nr]["text"] = txt
modes.val("LABEL", 0)
self.data.elem_commands["LABEL"]["bg"] = "lightgrey"
elif modes.val("ACTIVATE"):
self.data.preset_select(nr)
self.data.preset_go(nr,xfade=0,event=event)
modes.val("ACTIVATE", 0)
self.data.elem_commands["ACTIVATE"]["bg"] = "lightgrey"
elif modes.val("SELECT"):
self.data.preset_select(nr)
else:
self.data.preset_go(nr,event=event)
else:
self.data.preset_go(nr,event=event)
if event.num == 3:
if not modes.val("STORE"):
self.data.preset_go(nr,xfade=0,event=event)
return 0
elif self.mode == "INPUT":
return 0
if self.mode == "ENCODER":
#if self.attr == "VDIM":
# self.attr = "DIM"
for fix in self.data.FIXTURES.fixtures:
data = self.data.FIXTURES.fixtures[fix]
for attr in data["ATTRIBUT"]:
if attr.endswith("-FINE"):
continue
elem = self.data.elem_attr[fix][attr]
if self.attr != attr:
continue
if event.num == 1:
#self#encoder(attr=attr,data=data,elem=elem,action="click")
data["ATTRIBUT"][attr]["ACTIVE"] = 1
elem["bg"] = "yellow"
if "FX" in data["ATTRIBUT"][attr]:#["FX"]:# = 1
if data["ATTRIBUT"][attr]["FX"]:# = 1
elem["fg"] = "blue"
else:
elem["fg"] = "blue"
elem["fg"] = "black"
if not data["ATTRIBUT"][attr]["ACTIVE"]:
continue
if event.num == 4:
self.encoder(fix=fix,attr=attr,data=data,elem=elem,action="+")
#if attr == "DIM":
# self.encoder(attr="VDIM",data=data,elem=elem,action="+")
elif event.num == 5:
self.encoder(fix=fix,attr=attr,data=data,elem=elem,action="-")
#if attr == "DIM":
# self.encoder(attr="VDIM",data=data,elem=elem,action="-")
return 0
if event.num == 1:
self.encoder(fix=0,attr=self.attr,data=self.data,elem=self.elem,action="click")
elif event.num == 4:
self.encoder(fix=0,attr=self.attr,data=self.data,elem=self.elem,action="+")
elif event.num == 5:
self.encoder(fix=0,attr=self.attr,data=self.data,elem=self.elem,action="-")
#finally:
# pass
except Exception as e:
print("== cb EXCEPT",e)
print("Error on line {}".format(sys.exc_info()[-1].tb_lineno))
traceback.print_exc()
#print(self.elem["text"],self.attr,self.data)
def wheel(event,d=None):
print("wheel",event,d)
import copy
class Element():
def __init__(self):
self.__data = {}
def set(self,key,val):
self.__data[key] = val
class Base():
def __init__(self):
pass
def _load(self,filename):
xfname = "show/"+show_name+"/"+str(filename)+".sav"
print("load",xfname)
f = open(xfname,"r")
lines = f.readlines()
f.close()
data = OrderedDict()
labels = OrderedDict()
for line in lines:
key,label,rdata = line.split("\t",2)
key = int(key)
#print(xfname,"load",key,label)
#print(line)
jdata = json.loads(rdata,object_pairs_hook=OrderedDict)
nrnull = 0
if "ATTRIBUT" in jdata: # translate old FIXTURES.fixtures start with 0 to 1
for attr in jdata["ATTRIBUT"]:
if "NR" in jdata["ATTRIBUT"][attr]:
nr = jdata["ATTRIBUT"][attr]["NR"]
if nr == 0:
nrnull = 1
break
if nrnull:
print("DMX NR IS NULL",attr,"CHANGE +1")
for attr in jdata["ATTRIBUT"]:
if "NR" in jdata["ATTRIBUT"][attr]:
nr = jdata["ATTRIBUT"][attr]["NR"]
if nr >= 0:
jdata["ATTRIBUT"][attr]["NR"] +=1
data[key] = jdata
labels[key] = label
return data,labels
def _backup(self,filename,data,labels):
#fixture
xfname = "show/"+show_name+"/"+str(filename)+".sav"
print("backup",xfname)
f = open(xfname,"w")
for key in data:
line = data[key]
#print(line)
label = "label"
if key in labels:
label = labels[key]
if label == "Name-"+str(key):
label = ""
#print(xfname,"load",key,label,len(line))
f.write( "{}\t{}\t{}\n".format( key,label,json.dumps(line) ) )
f.close()
class GUIHandler():
def __init__(self):
pass
def update(self,fix,attr,args={}):
#print("GUIHandler",fix,attr,args)
for i,k in enumerate(args):
v = args[k]
#print("GUI-H", i,k,v)
class Fixtures(Base):
def __init__(self):
super().__init__()
#self.load()
self.fixtures = OrderedDict()
self.gui = GUIHandler()
def load_patch(self):
filename="patch"
d,l = self._load(filename)
self.fixtures = OrderedDict()
for i in l:
sdata = d[i]
for attr in sdata["ATTRIBUT"]:
sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
print("load",filename,sdata)
#if "CFG" not in sdata:
# sdata["CFG"] = OrderedDict()
self.fixtures[str(i)] = sdata
#self.PRESETS.label_presets = l
def backup_patch(self):
filename = "patch"
data = self.fixtures
labels = {}
for k in data:
labels[k] = k
self._backup(filename,data,labels)
def update_raw(self,rdata):
#print("update_raw",rdata)
cmd = []
for i,d in enumerate(rdata):
xcmd = {"DMX":""}
#print("fix:",i,d)
fix = d["FIX"]
attr = d["ATTR"]
v2 = d["VALUE"]
v2_fx = d["FX"]
if fix not in self.fixtures:
continue
sdata = self.fixtures[fix] #shortcat
ATTR = sdata["ATTRIBUT"]
sDMX = 0
if sdata["DMX"] > 0:
sDMX = sdata["DMX"]
if attr not in ATTR:
continue
if ATTR[attr]["NR"] >= 0:
DMX = sDMX+ATTR[attr]["NR"]-1
xcmd["DMX"] = str(DMX)
else:
if attr == "DIM" and ATTR[attr]["NR"] < 0:
xcmd["VIRTUAL"] = {}
for a in ATTR:
if ATTR[a]["MASTER"]:
xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
#print( "VIRTUAL",xcmd)
cmd.append(xcmd)
v=ATTR[attr]["VALUE"]
if v2 is not None:
ATTR[attr]["VALUE"] = v2
#self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
text = str(attr)+' '+str(round(v,2))
self.gui.update(fix,attr,args={"text":text})
return cmd
class Presets(Base):
def __init__(self):
super().__init__()
#self.load()
def load_presets(self):
filename="presets"
d,l = self._load(filename)
for i in d:
sdata = d[i]
if "CFG" not in sdata:
sdata["CFG"] = OrderedDict()
if "FADE" not in sdata["CFG"]:
sdata["CFG"]["FADE"] = 4
if "DELAY" not in sdata["CFG"]:
sdata["CFG"]["DELAY"] = 0
if "BUTTON" not in sdata["CFG"]:
sdata["CFG"]["BUTTON"] = "GO"
self.val_presets = d
self.label_presets = l
def backup_presets(self):
filename = "presets"
data = self.val_presets
labels = self.label_presets
self._backup(filename,data,labels)
def get_cfg(self,nr):
if nr not in self.val_presets:
print(self,"error get_cfg no nr:",nr)
return {}
if "CFG" in self.val_presets[nr]:
return self.val_presets[nr]["CFG"]
def get_raw_map(self,nr):
print("get_raw_map",nr)
if nr not in self.val_presets:
self.val_presets[nr] = OrderedDict()
self.val_presets[nr]["VALUE"] = 0
self.val_presets[nr]["FX"] = ""
sdata = self.val_presets[nr]
cmd = ""
out = []
dmx=-1
for fix in sdata:
if fix == "CFG":
#print("CFG",nr,sdata[fix])
continue
for attr in sdata[fix]:
x = {}
#print("RAW",attr)
x["FIX"] = fix
x["ATTR"] = attr
x["VALUE"] = sdata[fix][attr]["VALUE"]
x["FX"] = sdata[fix][attr]["FX"]
#x["DMX"] = sdata[fix][attr]["NR"]
out.append(x)
return out
class GUI_grid():
def __init__(self,root,data,title="tilte",width=800):
self.data = data
self.frame = tk.Frame(root,bg="black",width=width)
self.frame.pack(fill=tk.BOTH, side=tk.LEFT)
r=0
c=0
i=1
for row in data:
self.b = tk.Button(self.frame,bg="lightblue", text=row["text"],width=11,height=4)
#self.b.bind("