12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476 |
- #! /usr/bin/python
- # -*- coding: utf-8 -*-
- """
- (c) 2012 micha@librelight.de
- SPDX-License-Identifier: GPL-2.0-only
- """
- import random
- import subprocess
- import string
- import copy
- import traceback
- import json
- import time
- import sys
- import os
- import _thread as thread
- IS_GUI = 0
- if __name__ == "__main__":
- IS_GUI = 1
- import tool.movewin as movewin
- import lib.fixlib as fixlib
- import lib.libwin as libwin
- rnd_id = str(random.randint(100,900))
- rnd_id += " beta"
- rnd_id2 = ""
- rnd_id3 = ""
- _ENCODER_WINDOW = None
- import tool.git as git
- rnd_id += git.get_all()
- try:
- xtitle = __file__
- except:
- xtitle = "__file__"
- if "/" in xtitle:
- xtitle = xtitle.split("/")[-1]
- sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title
- HOME = os.getenv('HOME')
- space_font = None
- if IS_GUI:
- import tkinter
- import tkinter as tk
- from tkinter import font
- import tkinter.simpledialog
- from idlelib.tooltip import Hovertip
- INIT_OK = 0
- _global_short_key = 1
- path = "/home/user/LibreLight/"
- #os.chdir(path)
- f = open(path+"init.txt","r")
- lines=f.readlines()
- f.close()
- out = []
- for line in lines:
- if line != "EASY\n":
- out.append(line)
- f = open(path+"init.txt","w")
- f.writelines(out)
- f.close()
- if "--easy" in sys.argv:
- f = open(path+"init.txt","a")
- f.write("EASY\n")
- f.close()
- if not os.path.isdir(path+"show/EASY"):
- cmd = "cp -vrf '/opt/LibreLight/Xdesk/home/LibreLight/show/EASY' '{}/show/EASY' ".format(path)
- print(cmd)
- #input()
- os.system(cmd)
- # check if EASY show exist !
- from lib.cprint import *
- cprint("________________________________")
-
- import lib.zchat as chat
- import lib.motion as motion
- from collections import OrderedDict
- _FIX_FADE_ATTR = ["PAN","TILT","DIM","RED","GREEN","BLUE","WHITE","CYAN","YELLOW","MAGENTA","FOCUS","ZOOM","FROST"]
- _POS_LEFT = 0
- _POS_TOP = 15
- _config = []
- try:
- h = os.environ["HOME"]
- lines = [{}]
- try:
- f = open(h +"/LibreLight/config.json")
- lines = f.readlines()
- except FileNotFoundError as e: #Exception as e:
- f = open(h +"/LibreLight/config.json","w")
- f.write('{"POS_TOP":0}\n{"POS_LEFT":0}')
- f.close()
- cprint("Exception:",e)
- cprint("config read")
- for line in lines:
- line=line.strip()
- print(" config:",line)
- row = json.loads(line)
- _config.append(row)
- except Exception as e:
- cprint("Exception:",e)
- try:
- for row in _config:
- #print(" config:",row)
- if "POS_LEFT" in row:
- _POS_LEFT = int(row["POS_LEFT"])
- if "POS_TOP" in row:
- _POS_TOP = int(row["POS_TOP"])
- except Exception as e:
- cprint("Exception:",e)
- CUES = OrderedDict()
- groups = OrderedDict()
- class Modes():
- def __init__(self):
- self.modes = {}
- self.__cfg = {}
- self.__cb = None
- def val(self,mode,value=None): #like jquery
- 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 self.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):
- protected = ["BLIND","CLEAR","REC-FX"]
- self.__check(mode)
- if mode == "CLEAR":
- return 1
- elif mode == "ESC":
- for m in self.modes:
- cprint("ESC",m)
- if m == "COPY":
- PRESETS.clear_copy()
- if m == "MOVE":
- PRESETS.clear_move()
- if m != "BLIND":
- self.modes[m] = 0
- self.callback(m)
- return 1
- if value:
- for m in self.modes:
- if m not in protected and mode not in protected and m != mode:
- #cprint("-#-# clear mode",mode,m,value,color="red")
- if self.modes[m]:
- self.modes[m]= 0
- self.callback(m)
- if self.modes[mode] and value == 1:
- if modes == "MOVE":
- PRESETS.clear_move()
- if modes == "COPY":
- PRESETS.clear_copy()
- self.modes[mode] = 0 # value
- else:
- self.modes[mode] = value #1 #value
- else:
- self.modes[mode] = 0 #value
- if modes == "COPY":
- PRESETS.clear_copy()
- if modes == "MOVE":
- PRESETS.clear_move()
- self.callback(mode)
- return value
- def set_cb(self,cb):
- if cb:
- self.__cb = cb
- 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.val("BLIND", 0)
- #modes.modes["BLIND"] = 0
- modes.modes["ESC"] = 0
- modes.modes["REC"] = 0
- modes.modes["EDIT"] = 0
- modes.modes["MOVE"] = 0
- modes.modes["FLASH"] = 0
- modes.modes["GO"] = 0
- modes.modes["DEL"] = 0
- modes.modes["REC-FX"] = 0
- modes.modes["SELECT"] = 0
- modes.modes["CFG-BTN"] = 0
- modes.modes["LABEL"] = 0
- def xcb(mode,value=None):
- cprint("xcb","MODE CALLBACK",mode,value)
- if mode == "REC-FX":
- cprint("xcb",modes.val("REC-FX"))
- #modes.set_cb(xcb)
- 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(port=50001)
- def set_exec_fader_cfg(nr,val,label="",color=""):
- exec_wing = window_manager.get_obj(name="EXEC-WING")
- if not exec_wing:
- return
- try:
- if len(exec_wing.fader_elem) > nr:
- exec_wing.fader_elem[nr].attr["text"] = label
- cfg = get_exec_btn_cfg(nr+80)
- if cfg:
- exec_wing.fader_elem[nr].attr["bg"] = cfg["bg"]
- exec_wing.fader_elem[nr].attr["fg"] = cfg["fg"]
- exec_wing.fader_elem[nr].attr["fx"] = cfg["fx"]
- except Exception as e:
- cprint("- exception:",e)
- print(nr,val,label)
- def set_exec_fader(nr,val,label="",color="",info="info",change=0):
- exec_wing = window_manager.get_obj(name="EXEC-WING")
- if not exec_wing:
- return
- try:
- exec_wing.set_fader(nr,val,color=color,info=info,change=change)
- except Exception as e:
- pass
- cprint("- exception:",e)
- print(nr,val,label)
- raise e
-
- def set_exec_fader_all():
- print()
- cprint( "set_exec_fader_all()",color="green")
- for nr in range(10):
- _label = PRESETS.label_presets[nr+80] # = label
- print(" _label",_label)
- set_exec_fader(nr,0,label=_label)
- set_exec_fader_cfg(nr,0,label=_label)
- def refresh_exec_fader_cfg():
- cprint( "set_exec_fader_all()",color="green")
- for nr in range(10):
- _label = PRESETS.label_presets[nr+80] # = label
- #print("_label",_label)
- set_exec_fader_cfg(nr,0,label=_label)
- # remote input - start (memcached)
- def JCB(x,sock=None):
- for i in x:
- jv = x[i]
- try:
- jv = json.loads(jv)
- jv = jv[0]
- #print(jv)
- v = jv["iVAL"]
- #exec_wing.set_fader(0,v)
- set_exec_fader(0,v)
- set_exec_fader(1,200-v)
- set_exec_fader(2,int(v/2+10))
- except Exception as e:
- cprint("exception",e)
- print(sys.exc_info()[2])
- #print("remote in:",round(time.time(),0),"x",i,v)
- if __name__ == "__main__":
- r1_server = chat.Server(port=30002)
- def server1_loop():
- while 1:
- r1_server.poll(cb=JCB)
- time.sleep(1/90)
- thread.start_new_thread(server1_loop,()) # SERVER
- # remote input - end
- #chat.dbg=1
- class DEVENT():
- def __init__(self):
- #if "keysym" in dir(event):
- #if "Escape" ==
- #event.keysym:
- #event.num == 1:
- self.keysym = ""
- self.num = 1
- self.type = ""
- import lib.jsbc as JSBC
- if __name__ == "__main__":
- # external GUI
- r_server = chat.Server(port=30003,cb=JSBC.JSCB)
- def server_loop():
- while 1:
- r_server.poll(cb=JSBC.JSCB)
- #time.sleep(1/90)
- thread.start_new_thread(server_loop,()) # SERVER
- # read memcachd
- memcache = None
- try:
- import memcache
- except Exception as e:
- cprint("Exception IMPORT ERROR",e)
-
- class MC_FIX():
- def __init__(self,server="127.0.0.1",port=11211):
- cprint("MC.init() ----------" ,server,port,color="red")
- try:
- #self.mc = memcache.Client(['127.0.0.1:11211'], debug=0)
- self.mc = memcache.Client(['{}:{}'.format(server,port)], debug=0)
- #self.init()
- except Exception as e:
- cprint("-- Exception",e)
- def set(self,index="fix",data=[]):
- #time.sleep(5)
- if 1: #while 1:
- #print("MC.send",index) #,data)
- index = self.mc.get("index")
- #if index:
- # for i in index:
- # print(" key",i)
- self.mc.set("fix", data)
- #examles
- #self.mc.set("some_key", "Some value")
- #self.value = mc.get("some_key")
- #self.mc.set("another_key", 3)
- #self.mc.delete("another_key")
- class MC():
- def __init__(self,server="127.0.0.1",port=11211):
- cprint("MC.init() ----------" ,server,port,color="red")
- try:
- #self.mc = memcache.Client(['127.0.0.1:11211'], debug=0)
- self.mc = memcache.Client(['{}:{}'.format(server,port)], debug=0)
- #self.init()
- except Exception as e:
- cprint("-- Exception",e)
- # def init(self):
- data = {}
- start = time.time()
- delta = start
- index = self.mc.get("index")
- if index:
- for i in index:
- print(" key",i)
- self.last_fader_val = [-1]*512
- self.fader_map = []
- for i in range(30+1):
- self.fader_map.append({"UNIV":0,"DMX":0})
- try:
- fname = HOME + "/LibreLight/fader.json"
- f = open(fname)
- lines = f.readlines()
- cprint("FADER MAP",fname)
- for i,line in enumerate(lines):
- jdata = json.loads(line)
- print(" fader_map ->>",i,jdata)
- self.fader_map[i] = jdata
- except Exception as e:
- cprint("-- Except Fader_map",e)
- #exit()
- def ok(self):
- if self.mc:
- return 1
- return 0
- def test(self):
- if not self.ok():
- return
- self.mc.set("some_key", "Some value")
- self.value = mc.get("some_key")
- self.mc.set("another_key", 3)
- self.mc.delete("another_key")
- def loop(self):
- thread.start_new_thread(self._loop,())
- if not self.ok():
- return
- def _loop(self):
- cprint("++++++++++ start.memcachd read loop",self )
- while 1:
- send = 0
- #print("+")
- try:
- ip="10.10.10.13:0"
- #ip="ltp-out:0"
- #print(ip)
- x=self.mc.get(ip)
-
- if x:
- #print(ip,x)
- #val = x[501-1]
- #val = x[141-1]
- for i, line in enumerate(self.fader_map):
- try:
- #print(i,line)
- dmx = int(line["DMX"])
- if dmx > 0:
- val = x[dmx-1]
- #print("mc val",val)
- #print("dmx_in change:",[i,val])
- change = 0
- if i < len(self.last_fader_val):
- if self.last_fader_val[i] != val:
- self.last_fader_val[i] = val
- print("dmx_in change:",[i,val])
- change = 1
- set_exec_fader(nr=i,val=val,color="#aaa",info="dmx_in",change=change)
- except Exception as e:
- cprint("MC exc:",e,color="red")
- traceback.print_exc()
- pass
- time.sleep(1/10)
- except Exception as e:
- cprint("exc", e)
- time.sleep(1)
- _mc=MC()
- _mc.loop()
- console = chat.Client() #port=50001)
- def jclient_send(data):
- t_start = time.time()
- jtxt = data
- jdatas = []
- for jdata in data:
- if "CMD" in jdata:
- try:
- jdatas.append(jdata)
- except Exception as e:
- cprint("jclient_send, Exception DMX ",color="red")
- cprint("",jdata,color="red")
- cprint("-----",color="red")
- elif "DMX" in jdata:
- try:
- jdata["DMX"] = int(jdata["DMX"])
- dmx = jdata["DMX"]
- if "ATTR" not in jdata:
- # for fx off
- jdatas.append(jdata)
- else:
- fix = "00000"
- attr = "00000"
- if "FIX" in jdata:
- fix = jdata["FIX"]
- if "ATTR" in jdata:
- attr = jdata["ATTR"]
- dmx_fine = FIXTURES.get_dmx(fix,attr+"-FINE")
- if jdata["DMX"] != dmx_fine and dmx > 0 and dmx_fine > 0:
- jdata["DMX-FINE"] = dmx_fine
- if "DMX-FINE" in jdata:
- if jdata["DMX-FINE"] <= 0:
- del jdata["DMX-FINE"]
-
-
- if jdata["ATTR"].startswith("_"):
- pass # ignore attr._ACTIVE
- else:#
- jdata["time"] = t_start
- jdatas.append(jdata)
-
- #cprint("-- ",jdata,color="red")
- except Exception as e:
- cprint("jclient_send, Exception DMX ",color="red")
- cprint("",jdata,color="red")
- cprint(e,color="red")
- cprint("-----",color="red")
-
- jtxt = jdatas
- jtxt = json.dumps(jtxt)
- jtxt = jtxt.encode()
- console.send( jtxt ) #b"\00 ")
- cprint("{:0.04} sec.".format(time.time()-t_start),color="yellow")
- cprint("{:0.04} tick".format(time.time()),color="yellow")
- def _highlight(fix,_attr="DIM"):
- " patch test button "
- cprint("highlight",fix,"1")
- if fix not in FIXTURES.fixtures:
- return None
- d = FIXTURES.fixtures[fix]
- #for k,v in d.items():
- # cprint("-",k,v)
- DMX = d["DMX"] + d["UNIVERS"]*512
- if "ATTRIBUT" in d:
- ATTR= d["ATTRIBUT"]
- data = {"VALUE":200,"DMX":1}
- attr = ""
- if _attr in ATTR:
- attr = _attr
- else:
- return #stop
-
-
- cprint(attr,ATTR[attr])
- old_val = ATTR[attr]["VALUE"]
- data["DMX"] = DMX + ATTR[attr]["NR"]-1
- cprint(attr,ATTR[attr])
- cprint(data)
- for i in range(3):
- cprint("highlight",fix,"0")
- data["VALUE"] = 100
- jclient_send([data])
- time.sleep(0.1)
- cprint("highlight",fix,"1")
- data["VALUE"] = 234
- jclient_send([data])
- time.sleep(0.3)
-
- cprint("highlight",fix,"0")
- data["VALUE"] = old_val
- jclient_send([data])
- def highlight2(fix,attr="DIM"):
- def x():
- highlight(fix,attr=attr)
- return x
- def highlight(fix):
- cprint("highlight",fix)
- thread.start_new_thread(_highlight,(fix,"DIM"))
- thread.start_new_thread(_highlight,(fix,"RED"))
- thread.start_new_thread(_highlight,(fix,"GREEN"))
- thread.start_new_thread(_highlight,(fix,"BLUE"))
- class ValueBuffer():
- def __init__(self,_min=0,_max=255):
- self._value = 2
- self._on = 1
- self._min=_min
- self._max=_max
- def check(self):
- if self._value < self._min:
- self._value = self._min
- elif self._value > self._max:
- self._value = self._max
- def inc(self,value=None):
- if value is not None:
- if type(value) is float:
- self._value += round(value,4)
- else:
- self._value += value
- self.check()
- return self._value
- def val(self,value=None):
- if value is not None:
- if type(value) is float:
- self._value = round(value,4)
- else:
- self._value = value
- self.check()
- return self._value
- def on(self):
- self._on = 1
- def off(self):
- self._on = 0
- def _is(self):
- if self._on:
- return 1
- return 0
- FADE = ValueBuffer() #2 #0.1 #1.13
- FADE.val(2.0)
- FADE_move = ValueBuffer() #2 #0.1 #1.13
- FADE_move.val(4.0)
- DELAY = ValueBuffer() #2 #0.1 #1.13
- DELAY.off()
- DELAY.val(0.2)
- fx_prm_main = {}
- fx_prm_move = {"SIZE":40,"SPEED":8,"OFFSET":100,"BASE":"0","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":0,"WING":2,"WIDTH":100}
- fx_color = {"A":"red","B":"blue"}
- fx_prm = {"SIZE":255,"SPEED":10,"OFFSET":100,"BASE":"-","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":1,"SHUFFLE":0,"WING":2,"WIDTH":25,"2D-X":1,"2D:MODE":0}
- fx_x_modes = ["spiral","left","right","up","down","left_right","up_down"]
- fx_modes = ["RED","GREEN","BLUE","MAG","YELLOW","CYAN"]
- fx_mo = ["fade","on","rnd","ramp","ramp2","cosinus","sinus","static"]
- class FX_handler():
- def __init__():
- pass
- class dummy_event():
- def __init__(self):
- self.num =0
- self.type = 4 #press 5 release
- self.set_value=-1
- from lib import matrix
- import lib.fxlib as fxlib
- def process_matrix(xfixtures):
- fx_x = fx_prm["2D-X"]
- fx_mod = fx_x_modes[fx_prm["2D:MODE"]]
- r = _process_matrix(xfixtures,fx_x,fx_mod)
- return r
- def _process_matrix(xfixtures,fx_x,fx_mod):
- fix_count = len(xfixtures)
- cprint("----",fx_x,fx_mod)
- if fx_x > 1 and fix_count > fx_x:
- try:
- w=fx_x
- h=int(fix_count/fx_x)
- if fx_mod == "spiral":
- _map = matrix.spiral(w,h)
- elif fx_mod == "up_down":
- _map = matrix.up_down(w,h)
- elif fx_mod == "left_right":
- _map = matrix.left_right(w,h)
- elif fx_mod == "left":
- _map = matrix.left(w,h)
- elif fx_mod == "right":
- _map = matrix.right(w,h)
- elif fx_mod == "up":
- _map = matrix.up(w,h)
- elif fx_mod == "down":
- _map = matrix.down(w,h)
- else:
- return xfixtures # do nothing
- matrix.mprint(xfixtures,w,h)
- out = ["0"]*(w*h)
- for i,f in enumerate(xfixtures):
- if i < w*h:
- j = int(_map[i])
- cprint(["i:",i,"f:",f,"j:",j])
- out[j] = f
- matrix.mprint(out,w,h)
- xfixtures = out
- except Exception as e:
- cprint("matrix exception",e)
- return xfixtures
- class Xevent_fx():
- """ global input event Handeler for short cut's ... etc
- """
- def __init__(self,fix,elem,attr=None,data=None,mode=None):
- self.fix = fix
- self.data = data
- self.attr = attr
- self.elem = elem
- self.mode = mode
- def fx(self,event):
- cprint("Xevent.fx",self.attr,self.fix,event)
- fx2 = {}
- if self.attr == "FX:RED":
- if event.num == 4:
- cprint("FX:COLOR CHANGE",fx_prm,color="red")
- txt = "FX:RED"
- fx_prm["MODE"] += 1
- if fx_prm["MODE"] >= len(fx_modes):
- fx_prm["MODE"]=0
- txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
- master.fx_color.elem["FX:RED"]["text"] = txt
- elif event.num == 5:
- cprint("FX:COLOR CHANGE",fx_prm,color="red")
- txt = "FX:RED"
- fx_prm["MODE"] -= 1
- if fx_prm["MODE"] < 0:
- fx_prm["MODE"]= len(fx_modes)-1
- txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
- master.fx_color.elem["FX:RED"]["text"] = txt
- if self.attr.startswith("2D"):
- if event.num == 4:
- cprint("2D-X: CHANGE",fx_prm,color="red")
- txt = "2D-X:"
- fx_prm["2D:MODE"] += 1
- if fx_prm["2D:MODE"] >= len(fx_x_modes):
- fx_prm["2D:MODE"]=0
- txt = "2D:MODE\n"+fx_x_modes[fx_prm["2D:MODE"]]
- master.fx.elem["2D:MODE"]["text"] = txt
- elif event.num == 5:
- cprint("2D-X: CHANGE",fx_prm,color="red")
- txt = "2D-X:"
- fx_prm["2D:MODE"] -= 1
- if fx_prm["2D:MODE"] < 0:
- fx_prm["2D:MODE"]= len(fx_x_modes)-1
- txt = "2D:MODE\n"+fx_x_modes[fx_prm["2D:MODE"]]
- master.fx.elem["2D:MODE"]["text"] = txt
- elif event.num == 1:
- xfixtures = []
- fix_active =FIXTURES.get_active()
- for fix in fix_active:
- if fix == "CFG":
- continue
- xfixtures.append(fix)
- if not xfixtures:
- cprint("470 fx() ... init no fixture selected",color="red")
- return 0
-
-
- xfixtures = process_matrix(xfixtures)
- wing_buffer = fxlib.process_wings(xfixtures,fx_prm)
- fxlib.process_effect(wing_buffer,fx_prm,fx_prm_move,modes,jclient_send,master,FIXTURES,fx_name=self.attr)
- def command(self,event,mode=""):
- cprint("fx_command",self.mode)
- if self.mode == "FX":
- prm = fx_prm
- ct = self.data.fx
- if self.mode == "FX-MOVE":
- prm = fx_prm_move
- ct = self.data.fx_moves
- if 1:
- if self.attr.startswith("SIZE:"):#SIN":
- #global fx_prm
- k = "SIZE"
- if event.num == 1:
- _stats = [0,30,100,255]
- if prm[k] in _stats:
- idx = _stats.index(prm[k])+1
- if idx > len(_stats)-1: #rotate
- idx = 0
- prm[k] = _stats[idx]
- else:
- prm[k] = _stats[1]
- elif event.num == 3:
- prm[k] =100
- elif event.num == 4:
- if prm[k] <= 0:
- prm[k] = 1
- prm[k] +=5
- elif event.num == 5:
- prm[k] -=5
- #prm[k] =int(prm[k])
-
- if prm[k] > 4000:
- prm[k] = 4000
- if prm[k] < 0:
- prm[k] =0
- if prm[k] == 6: #bug
- prm[k] =5
- ct.elem[self.attr]["text"] = "SIZE:\n{:0.0f}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("SPEED:"):#SIN":
- #global prm
- k = "SPEED"
- if event.num == 1:
- _stats = [0,5,25,30,100,255]
- if prm[k] in _stats:
- idx = _stats.index(prm[k])+1
- if idx > len(_stats)-1: #rotate
- idx = 0
- prm[k] = _stats[idx]
- else:
- prm[k] = 0
- elif event.num == 3:
- prm[k] = 10
- elif event.num == 4:
- if prm[k] <= 0:
- prm[k] = 0.06
- elif prm[k] < 5:
- prm[k] *=1.2
- else:
- prm[k] +=5 #1.1
- elif event.num == 5:
- if prm[k] <= 5:
- prm[k] *=0.8
- else:
- prm[k] -= 5 #1.1
- #prm[k] =int(prm[k])
-
- if prm[k] > 4000:
- prm[k] = 4000
- if prm[k] < 0.05:
- prm[k] =0
- if prm[k] > 5 and prm[k] < 10: #bug
- prm[k] =5
- if prm[k] < 0:
- ct.elem[self.attr]["text"] = "SPEED:\noff".format(prm[k])
- else:
- ct.elem[self.attr]["text"] = "SPEED:\n{:0.02f}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("START:"):#SIN":
- #global prm
- k = "START"
- if event.num == 1:
- pass
- elif event.num == 2:
- pass
- elif event.num == 4:
- if prm[k] <= 0:
- prm[k] = 1
- prm[k] += 5 #1.1
- elif event.num == 5:
- prm[k] -= 5 #1.1
- #prm[k] =int(prm[k])
-
- if prm[k] > 4000:
- prm[k] = 4000
- if prm[k] < 5:
- prm[k] =0
- if prm[k] == 6: #bug
- prm[k] =5
- ct.elem[self.attr]["text"] = "START:\n{:0.0f}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("WIDTH:"):#SIN":
- #global prm
- k = "WIDTH"
- if event.num == 1:
- _stats = [0,25,50,75,10]
- if prm[k] in _stats:
- idx = _stats.index(prm[k])+1
- if idx > len(_stats)-1: #rotate
- idx = 0
- prm[k] = _stats[idx]
- else:
- prm[k] = 25
- elif event.num == 2:
- prm[k] = 50
- elif event.num == 3:
- prm[k] = 100
- elif event.num == 4:
- if prm[k] <= 0:
- prm[k] = 1
- elif prm[k] == 50:
- prm[k] = 100
- elif prm[k] == 5:
- prm[k] = 25
- elif prm[k] == 25:
- prm[k] = 50
- else:
- prm[k] += 5 #*=1.1
- elif event.num == 5:
- if prm[k] == 10:
- prm[k] = 5
- elif prm[k] == 25:
- prm[k] = 10
- elif prm[k] == 50:
- prm[k] = 25
- elif prm[k] == 100:
- prm[k] = 50
- #else:
- # prm[k] -=5 #/=1.1
-
- #prm[k] =int(prm[k])
-
- if prm[k] < 0:
- prm[k] = 0
- if prm[k] > 100:
- prm[k] = 100
- if prm[k] == 6: #bug
- prm[k] =5
- if prm[k] > 25 and prm[k] < 50: #bug
- prm[k] =50
- if prm[k] > 50 and prm[k] < 75: #bug
- prm[k] =75
- if prm[k] > 75 and prm[k] < 100: #bug
- prm[k] =100
- ct.elem[self.attr]["text"] = "WIDTH:\n{:0.0f}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("DIR:"):#SIN":
- #global prm
- k = "DIR"
- if event.num == 1:
- prm[k] = 1
- elif event.num == 3:
- prm[k] = -1
- elif event.num == 4:
- prm[k] = 1
- elif event.num == 5:
- prm[k] =-1
- txt = prm[k]
- ct.elem[self.attr]["text"] = "DIR:\n{}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("SHUFFLE:"):#SIN":
- #global prm
- k = "SHUFFLE"
- if event.num == 1:
- prm[k] = 0
- elif event.num == 3:
- prm[k] = 1
- elif event.num == 4:
- prm[k] = 1
- elif event.num == 5:
- prm[k] =0
- if prm[k] == 6: #bug ?
- prm[k] =5
- ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("INVERT:"):#SIN":
- #global prm
- k = "INVERT"
- if event.num == 1:
- prm[k] = 0
- elif event.num == 3:
- prm[k] = 1
- elif event.num == 4:
- prm[k] = 1
- elif event.num == 5:
- prm[k] =0
- if prm[k] == 6: #bug ?
- prm[k] =5
- ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("2D-X:"):#SIN":
- #global prm
- k = "2D-X"
- if event.num == 1:
- prm[k] = 1
- elif event.num == 3:
- prm[k] = 2
- elif event.num == 4:
- prm[k] += 1
- elif event.num == 5:
- prm[k] -=1
- if prm[k] > 100:
- prm[k] = 100
- if prm[k] < 1:
- prm[k] =1
-
- txt = prm[k]
- ct.elem[self.attr]["text"] = "2D-X:\n{}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("WING:"):#SIN":
- #global prm
- k = "WING"
- if event.num == 1:
- prm[k] = 1
- elif event.num == 3:
- prm[k] = 2
- elif event.num == 4:
- prm[k] += 1
- elif event.num == 5:
- prm[k] -=1
- if prm[k] > 100:
- prm[k] = 100
- if prm[k] < 1:
- prm[k] =1
-
- txt = prm[k]
- ct.elem[self.attr]["text"] = "WING:\n{}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("OFFSET:"):#SIN":
- #global prm
- k = "OFFSET"
- if event.num == 1:
- prm[k] = 50
- elif event.num == 2:
- prm[k] *= 2
- elif event.num == 3:
- prm[k] = 100
- elif event.num == 4:
- if prm[k] <= 0:
- prm[k] = 1
- prm[k] +=5 #*=1.1
- elif event.num == 5:
- prm[k] -=5 #/=1.1
- #prm[k] =int(prm[k])
-
- #if prm[k] > 512:
- # prm[k] = 512
- if prm[k] < 5:
- prm[k] =0
- if prm[k] == 6: #bug
- prm[k] =5
- ct.elem[self.attr]["text"] = "OFFSET:\n{:0.0f}".format(prm[k])
- cprint(prm)
- elif self.attr.startswith("BASE:"):
- k = "BASE"
- if event.num == 1:
- prm[k] = "-"
- elif event.num == 3:
- prm[k] = "0"
- elif event.num == 4:
- prm[k] = "+"
- elif event.num == 5:
- prm[k] = "0"
- ct.elem[self.attr]["text"] = "BASE:\n{}".format(prm[k])
- elif self.attr.startswith("2D:"):#SIN":
- self.fx(event)
- elif self.attr.startswith("FX:"):#SIN":
- self.fx(event)
- elif self.attr == "FX OFF":
- if event.num == 1:
- FIXTURES.fx_off("all")
- CONSOLE.fx_off("all")
- CONSOLE.flash_off("all")
- master._refresh_fix()
- return 0
- #if event.num == 1:
- elif self.attr == "REC-FX":
- cprint("ELSE",self.attr)
- modes.val(self.attr,1)
- return 0
-
- def cb(self,event):
- cprint("EVENT_fx cb",self.attr,self.mode,event,color='yellow')
- cprint(["type",event.type,"num",event.num])
- try:
- change = 0
- if self.mode.startswith("FX"):
- self.command(event)
- return 0
- except Exception as e:
- cprint("== cb EXCEPT",e,color="red")
- cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
- cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
- return 1
-
- class BLINKI():
- def __init__(self,e):
- self.e = e
- def blink(self):
- e = self.e
- e.config(bg='green')
- duration = 150
- for i in range(8):
- d = i * duration
- if i % 2 == 0:
- e.after(d, lambda: e.config(bg='white')) # after 1000ms
- e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
- else:
- e.after(d, lambda: e.config(bg='orange')) # after 1000ms
- e.after(d, lambda: e.config(activebackground='orange')) # after 1000ms
- i+=1
- duration = 150
- e.after(d, lambda: e.config(bg='white')) # after 1000ms
- e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
- class Xevent():
- """ global input event Handeler for short cut's ... etc
- """
- def __init__(self,fix,elem,attr=None,data=None,mode=None):
- self.fix = fix
- self.data=data
- self.attr = attr
- self.elem = elem
- self.mode = mode
- def _save_show(self):
- self.elem["bg"] = "orange"
- self.elem["text"] = "SAVING..."
- self.elem["bg"] = "red"
- self.elem.config(activebackground="orange")
- modes.val(self.attr,1)
- PRESETS.backup_presets()
- FIXTURES.backup_patch()
- libwin.save_window_position()
- self.elem["bg"] = "lightgrey"
- self.elem.config(activebackground="lightgrey")
- b = BLINKI(self.elem)
- b.blink()
- self.elem["text"] = "SAVE\nSHOW"
- def setup(self,event):
- cprint("xevent.SETUP",[self.mode,self.attr],color="red")
- if self.mode == "SETUP":
- if self.attr == "SAVE\nSHOW":
- self._save_show()
- elif self.attr == "LOAD\nSHOW":
- name = "LOAD-SHOW"
- base = baselib.Base()
- line1 = "PATH: "+base.show_path1 +base.show_name
- line2 = "DATE: "+ time.strftime("%Y-%m-%d %X", time.localtime(time.time()))
- class cb():
- def __init__(self,name=""):
- self.name=name
- cprint(" LOAD-SHOW.init",name)
- def cb(self,event=None,**args):
- cprint(" LOAD-SHOW.cdb",self.name,event,args)
- if self.name != "<exit>":
- cprint("-----------------------:")
- LOAD_SHOW_AND_RESTART(self.name).cb()
- pw = libtk.PopupList(name,cb=cb)
- print(line1,line2)
- frame = pw.sframe(line1=line1,line2=line2)
- r = frame_of_show_list(frame,cb=cb)
- elif self.attr == "NEW\nSHOW":
- base = baselib.Base()
- #def _cb(fname):
- def _cb(data):
- if not data:
- cprint("err443",self,"_cb",data)
- return None
- fname = data["Value"]
- cprint(self,"save_show._cb()",fname)
- fpath,fname = base.build_path(fname)
- cprint("SAVE NEW SHOW",fpath,fname)
- if base._create_path(fpath):
- a=PRESETS.backup_presets(save_as=fpath,new=1)
- b=FIXTURES.backup_patch(save_as=fpath,new=1)
- #base._set(fname)
-
- libwin.save_window_position(save_as=fpath)
- LOAD_SHOW_AND_RESTART(fname).cb()
- dialog._cb = _cb
- dialog.askstring("CREATE NEW SHOW","CREATE NEW SHOW:")
- elif self.attr == "SAVE\nSHOW AS":
- base = baselib.Base()
- #def _cb(fname):
- def _cb(data):
- if not data:
- cprint("err443",self,"_cb",data)
- return None
- fname = data["Value"]
- cprint(self,"save_show._cb()",fname)
- fpath,fname = base.build_path(fname)
- cprint("SAVE AS",fpath,fname)
- if base._create_path(fpath):
- a=PRESETS.backup_presets(save_as=fpath)
- b=FIXTURES.backup_patch(save_as=fpath)
- #base._set(fname)
-
- libwin.save_window_position(save_as=fpath)
- LOAD_SHOW_AND_RESTART(fname).cb()
- dialog._cb = _cb
- dialog.askstring("SAVE SHOW AS","SAVE SHOW AS:")
- elif self.attr == "SAVE &\nRESTART":
- self.elem["bg"] = "orange"
- self.elem["text"] = "SAVING..."
- self.elem["bg"] = "red"
- self.elem.config(activebackground="orange")
- modes.val(self.attr,1)
- PRESETS.backup_presets()
- FIXTURES.backup_patch()
- libwin.save_window_position()
- self.elem["text"] = "RESTARTING..."
- self.elem["bg"] = "lightgrey"
- self.elem.config(activebackground="lightgrey")
- LOAD_SHOW_AND_RESTART("").cb(force=1)
- elif self.attr == "DRAW\nGUI":
- old_text = self.elem["text"]
- window_manager.top("PATCH")
- gui_patch.draw(FIXTURES)
- gui_fix.draw(FIXTURES)
- window_manager.top("FIXTURES")
- master._refresh_exec()
- self.elem["text"] = old_text
- elif self.attr == "PRO\nMODE":
- self._save_show()
- import lib.restart as restart
- restart.pro()
- elif self.attr == "EASY\nMODE":
- self._save_show()
- import lib.restart as restart
- restart.easy()
- else:
- if IS_GUI:
- r=tkinter.messagebox.showwarning(message="{}\nnot implemented".format(self.attr.replace("\n"," ")),parent=None)
- return 1
- def live(self,event):
- if self.mode == "LIVE":
-
- if "FADE" in self.attr or "DELAY" in self.attr:
-
- if self.attr == "FADE":
- ct = FADE
- if self.attr == "DELAY":
- ct = DELAY
- if "PAN/TILT\nFADE" in self.attr:
- ct = FADE_move
- value = ct.val()
- #print("EVENT CHANGE ",[self.attr])
- cprint("EVENT CHANGE:",self.mode,value,self.attr)
- if value < 0.01:
- ct.val(0.01)
- elif value > 100.0:
- pass #value = 100
- if event.num == 4:
- value *= 1.1
- elif event.num == 5:
- value /= 1.1
- elif event.num == 1:
- if ct._is():
- ct.off()# = 0
- self.data.commands.elem[self.attr]["bg"] = "grey"
- self.elem.config(activebackground="grey")
- else:
- ct.on()# = 1
- self.data.commands.elem[self.attr]["bg"] = "green"
- self.elem.config(activebackground="lightgreen")
- elif event.num == 2:
- if value > 1 and value < 4:
- value = 4
- elif value > 3 and value < 6:
- value = 6
- elif value > 5 and value < 7:
- value = 8
- elif value > 7 and value < 9:
- value = 10
- elif value > 9:
- value = 0.01
- elif value < 1:
- value = 1.1
- value = round(value,3)
- value = ct.val(value)
- if self.attr == "FADE":
- self.data.commands.elem[self.attr]["text"] = "FADE:\n{:0.2f}".format(value)
- if self.attr == "DELAY":
- self.data.commands.elem[self.attr]["text"] = "DELAY:\n{:0.3f}".format(value)
- if "PAN/TILT\nFADE" in self.attr:
- self.data.commands.elem[self.attr]["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
- def command(self,event):
- if self.mode == "COMMAND":
-
- if self.attr == "CLEAR":
- if event.num == 1:
- ok = FIXTURES.clear()
- if ok:
- master._refresh_fix()
- modes.val(self.attr,0)
- elif self.attr == "SAVE":
- modes.val(self.attr,1)
- PRESETS.backup_presets()
- FIXTURES.backup_patch()
- #time.sleep(1)
- modes.val(self.attr,0)
- elif self.attr == "S-KEY":
- global _global_short_key
- if _global_short_key:
- _global_short_key = 0
- master.commands.elem["S-KEY"]["bg"] = "red"
- master.commands.elem["S-KEY"]["activebackground"] = "red"
- else:
- _global_short_key = 1
- master.commands.elem["S-KEY"]["bg"] = "green"
- master.commands.elem["S-KEY"]["activebackground"] = "green"
- cprint("s-key",_global_short_key)
- else:
- if event.num == 1:
- cprint("ELSE",self.attr)
- modes.val(self.attr,1)
- return 0
- def encoder(self,event):
- global _shift_key
- cprint("Xevent","ENC",self.fix,self.attr,self.mode)
- cprint("SHIFT_KEY",_shift_key,"??????????")
- if self.mode == "ENCODER":
- if self._encoder(event):
- master.refresh_fix() # delayed
- refresher_fix.reset() # = Refresher()
- if self.mode == "ENCODER2":
- if self._encoder(event):
- master.refresh_fix() # delayed
- refresher_fix.reset() # = Refresher()
- if self.mode == "INVERT":
- cprint("INVERT",event)
- if self._encoder(event):
- master.refresh_fix() # delayed
- refresher_fix.reset() # = Refresher()
- def _encoder(self,event):
- global _shift_key
- if 1: #self.mode == "ENCODER" or self.mode == "ENCODER2":
- cprint("-- Xevent","_ENC",self.fix,self.attr,self.mode)
- cprint("-- SHIFT_KEY",_shift_key,"??????????")
- #cprint(self.data)
- val=""
- if event.num == 1:
- val ="click"
- elif event.num == 4:
- val ="++"
- if _shift_key:
- val = "+"
- elif event.num == 5:
- val ="--"
- if _shift_key:
- val = "-"
- #print("SHIFT",val,_shift_key)
- if val:
- FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
- return 1
-
- def cb(self,event):
- cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
- cprint(["type",event.type,"num",event.num])
- global INIT_OK
- INIT_OK = 1
- try:
- change = 0
- if "keysym" in dir(event):
- if "Escape" == event.keysym:
- ok = FIXTURES.clear()
- master._refresh_fix()
- cprint()
- return 0
- if self.mode == "SETUP":
- self.setup(event)
- elif self.mode == "COMMAND":
- self.command(event)
- elif self.mode == "LIVE":
- self.live(event)
- elif self.mode == "ENCODER":
- self.encoder(event)
- master.refresh_fix()
- elif self.mode == "ENCODER2":
- self.encoder(event)
- elif self.mode == "INVERT":
- self.encoder(event)
- elif self.mode == "FX":
- cprint("Xevent CALLING FX WRONG EVENT OBJECT !!",color="red")
- elif self.mode == "ROOT":
- if event.keysym=="Escape":
- pass
- elif self.mode == "INPUT":
- cprint("INP",self.data.entry.get())
- if event.keycode == 36:
- x=self.data.entry.get()
- #client.send(x)
- elif self.mode == "INPUT2":
- cprint("INP2",self.data.entry2.get())
- if event.keycode == 36:
- x=self.data.entry2.get()
- #client.send(x)
- elif self.mode == "INPUT3":
- cprint("INP3",self.data.entry3.get())
- if event.keycode == 36:
- x=self.data.entry3.get()
- #client.send(x)
- elif self.mode == "PRESET":
- nr = self.attr #int(self.attr.split(":")[1])-1
- if event.num == 3: # right click for testing
- if str(event.type) == '4': #4 ButtonPress
- if modes.val("CFG-BTN"):
- master.btn_cfg(nr,testing=1)
- if event.num == 1:
- if str(event.type) == '4': #4 ButtonPress
- if modes.val("REC"):
- self.data.preset_rec(nr)
- modes.val("REC",0)
- time.sleep(0.05)
- master._refresh_exec(nr=nr)
- elif modes.val("DEL"):
- ok=PRESETS.delete(nr)
- if ok:
- modes.val("DEL",0)
- #master.refresh_exec()
- master._refresh_exec(nr=nr)
- elif modes.val("COPY"):
- ok=PRESETS.copy(nr)
- if ok:
- modes.val("COPY",0)
- master._refresh_exec(nr=nr)
- elif modes.val("MOVE"):
- ok,cnr,bnr=PRESETS.move(nr)
- if ok:
- #modes.val("MOVE",0) # keep MOVE on
- master._refresh_exec(nr=nr)
- master._refresh_exec(nr=bnr)
- elif modes.val("CFG-BTN"):
- master.btn_cfg(nr)
- #master._refresh_exec(nr=nr)
- elif modes.val("LABEL"):#else:
- master.label(nr)
- #master._refresh_exec(nr=nr)
- elif modes.val("EDIT"):
- FIXTURES.clear()
- self.data.preset_select(nr)
- self.data.preset_go(nr,xfade=0,event=event,val=255,button="go")
- modes.val("EDIT", 0)
- master.refresh_fix()
- refresher_fix.reset() # = Refresher()
- elif modes.val("SELECT"):
- self.data.preset_select(nr)
- else:
- self.data.preset_go(nr,event=event,val=255)
- else:
- self.data.preset_go(nr,xfade=0,event=event,val=0)
- cprint(" == "*10)
- master.refresh_fix()
- refresher_fix.reset() # = Refresher()
-
- if event.num == 3:
- if not modes.val("REC"):
- if str(event.type) == '4': #4 ButtonPress
- self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=255)
- else:
- self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=0)
-
- cprint()
- return 0
- elif self.mode == "INPUT":
- cprint()
- return 0
- except Exception as e:
- cprint("== cb EXCEPT",e,color="red")
- cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
- cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
- cprint()
- return 1
-
- def wheel(event,d=None):
- cprint("wheel",event,d)
-
- class Element():
- def __init__(self):
- self.__data = {}
- def set(self,key,val):
- self.__data[key] = val
-
- def _clean_path(fpath):
- _path=[]
- for i in fpath:
- fpath = fpath.replace(" ","_")
- if i in string.ascii_letters+string.digits+"äöüßÖÄÜ_-":
- _path.append(i)
- path = "".join(_path)
- return path
- #import lib.base as _base
- import lib.baselib as baselib
- def hex_to_rgb(hex):
- return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
- class cb():
- def __init__(self,win):
- self.win = win
- def _callback(self,event):
- clobj=event.widget
- ## undermouse=find_withtag(master.CURRENT)
- undermouse=self.win.find_closest(self.win.CURRENT)
- cprint( repr(undermouse))
- def callback(self,event):
- cprint(__file__,self,"callback",event)
- cnv = self.win
- item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
- tags = cnv.gettags(item)
- #cnv.itemconfigure(self.tag, text=tags[0])
- cprint(tags,item)
- color = cnv.itemcget(item, "fill")
- cnv.itemconfig("all", width=1)#filla="green")
- cnv.itemconfig(item, width=3)#filla="green")
- cprint(color)
- cprint( hex_to_rgb(color[1:]))
- def get_exec_btn_cfg(nr):
- #b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
- #for k in PRESETS.val_presets:
- k = nr
- if 1:
-
- _bg = "grey"
- _ba = "grey"
- _fg = "lightgrey"
- _text = "N/V"
- if nr >= 0:
- #if self._nr_ok:
- # return #pass#abreak
- if nr != k:
- return #continue
- #else:
- # self._nr_ok = 1
- label = ""
- #if k not in self.elem_presets:
- # cprint("ERROR",k ,"not in elem_presets continue")
- # return #continue
- if k in PRESETS.label_presets:
- label = PRESETS.label_presets[k]
- #print([label])
- #b = self.elem_presets[k]
-
- ifval = 0
- fx_only = 0
- fx_color = 0
- if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
- sdata = PRESETS.val_presets[k]
- #print("sdata7654",sdata)
- BTN="go"
- if "CFG" in sdata:#["BUTTON"] = "GO"
- if "BUTTON" in sdata["CFG"]:
- BTN = sdata["CFG"]["BUTTON"]
- #txt=str(k+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+label
- txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
- _text = txt
- #if b.text != txt: # TODO
- # #txt+=str(self._XX)
- # #b.configure(text= txt)
- # _text = txt
- # _bg="yellow"
- # _ba="yellow"
- if len(sdata) > 1:
- ifval = 1
- val_color = 0
- for fix in sdata:
- if fix == "CFG":
- continue
- #print( "$$$$",fix,sdata[fix])
- for attr in sdata[fix]:
- if "FX2" in sdata[fix][attr]:
- if sdata[fix][attr]["FX2"]:
- fx_color = 1
- if "FX" in sdata[fix][attr]:
- if sdata[fix][attr]["FX"]:
- fx_color = 1
- if "VALUE" in sdata[fix][attr]:
- if sdata[fix][attr]["VALUE"] is not None:
- val_color = 1
- #try:b.configure(fg= "black")
- #except:pass
- if val_color:
- _bg = "gold"
- _ba = "#ffaa55"
- if fx_color:
- _fg = "blue"
- else:
- if fx_color:
- fx_only = 1
- else:
- _bg = "grey"
- _ba = "#aaa"
- if "\n" in txt:
- txt1 = txt.split("\n")[0]
- _fg = "black"
- if ifval:
- if fx_only:
- _bg = "cyan"
- _ba = "#55d4ff"
- if "SEL" in txt1:
- #b.configure(bg="#77f")
- _bg = "#77f"
- else:
- _bg = "grey"
- _fg = "darkgrey"
- if "SEL" in txt1:
- _fg = "blue"
- elif "ON" in txt1:
- _fg = "#040"
- elif "GO" in txt1:
- _fg = "#555"
- if "FL" in txt1:
- _fg = "#00e"
-
- out = {}
-
- out["fx"] = fx_color
- out["bg"] = _bg
- out["ba"] = _ba
- out["fg"] = _fg
- #if fx_color:
- # out["fg"] = "red"
- out["text"] = _text
-
- return out
- #b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
- class Elem_Container():
- def __init__(self):
- self.commands = []
- self.val = {}
- self.elem = {}
- import lib.execlib as execlib
- class MASTER():
- def __init__(self):
- #super().__init__()
- self.base = baselib.Base ()
- self.load()
- self._XX = 0
- self.all_attr =["DIM","PAN","TILT"]
- self.elem_attr = {}
-
- self.setup_elem = {} # Elem_Container()
- self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI","PRO\nMODE"]
- self.fx_main = Elem_Container()
- self.fx_main.commands =["REC-FX","FX OFF","\n"]
- self.fx_moves = Elem_Container()
- self.fx_moves.commands =[
- "FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
- "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
- ]
- #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
- self.fx = Elem_Container()
- self.fx.commands =[
- "FX:DIM"," ", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
- ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","2D-X:\n-","2D:MODE"
- ]
- self.fx_generic = Elem_Container()
- self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","FX:STATIC"]
- self.fx_color = Elem_Container()
- self.fx_color.commands =["FX:RED","FX-C:A","FX-C:B"]
- self.commands = Elem_Container()
- self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
- ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
- ,"BLIND","CLEAR","REC","EDIT","COPY",".","\n"
- ]
- self.elem_presets = {}
-
- for i in range(8*8*8):
- if i not in PRESETS.val_presets:
- name = "Preset:"+str(i+1)+":\nXYZ"
- #self.presets[i] = [i]
- PRESETS.val_presets[i] = OrderedDict() # FIX
- PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
- PRESETS.label_presets[i] = "-"
- modes.set_cb(self.xcb)
- def jclient_send(self,data):
- # namespace wraper
- if not modes.val("BLIND"):
- jclient_send(data)
- def button_refresh(self,name,color,color2=None,text="",fg=None):
- cprint("button_refresh",name,color)
- #if color == "gold":
- # color2 = "yellow"
- try:
- if color2 is None:
- color2 = color
- if text:
- text = "\n"+str(text)
- if name in self.commands.elem:
- self.commands.elem[name]["bg"] = color
- self.commands.elem[name]["text"] = name+ text
- self.commands.elem[name].config(activebackground=color2)
- if fg:
- self.commands.elem[name]["fg"] = fg
- elif name in self.fx.elem:
- #todo
- self.fx.elem[name]["bg"] = color
- self.fx.elem[name].config(activebackground=color2)
- if fg:
- self.fx.elem[name]["fg"] = fg
- # new version
- for elems in [self.fx_moves]:
- if name in elems.elem:
- elem = elems.elem[name]
- cprint("elem",elem)
- elem.config(bg = color)
- elem.config(text = name+text)
- elem.config(activebackground=color2)
- if fg and "fg" in elem:
- elem["fg"] = fg
- except Exception as e:cprint("exc",self,e)
- def btn_cfg(self,nr,testing=0):
- cfg = PRESETS._btn_cfg(nr)
- button = PRESETS.btn_cfg(nr)
- label = PRESETS.label(nr)
- def _cb(data):
- if not data:
- cprint("err443",self,"_cb",data)
- return None
- cprint(self,"btn_cfg._cb()",data)
- if data:
- if "Button" in data and type(data["Button"]) is str:
- txt = data["Button"]
- PRESETS.btn_cfg(nr,txt)
- self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
- if "Label" in data and type(data["Label"]) is str:
- txt = data["Label"]
- PRESETS.label(nr,txt)
- self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
- if "Delay" in data and type(data["Delay"]) is str:
- txt = data["Delay"]
- try:
- txt = float(txt)
- if "DELAY" in cfg:
- cfg["DELAY"] = round(txt,2)
- except e as Exception:
- print("DELAY Exception",e)
- if "in-Fade" in data and type(data["in-Fade"]) is str:
- txt = data["in-Fade"]
- try:
- txt = float(txt)
- if "FADE" in cfg:
- cfg["FADE"] = round(txt,2)
- except e as Exception:
- print("in-Fade Exception",e)
- if "out-Fade" in data and type(data["out-Fade"]) is str:
- txt = data["out-Fade"]
- try:
- txt = float(txt)
- #if "OUT-FADE" in cfg:
- cfg["OUT-FADE"] = round(txt,2)
- except e as Exception:
- print("out-Fade Exception",e)
- modes.val("CFG-BTN",0)
- master._refresh_exec(nr=nr)
- dialog._cb = _cb
- if 1: # testing:
- dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
- else:
- dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
- def label(self,nr):
- txt = PRESETS.label(nr)
- def _cb(data):
- if not data:
- cprint("err443",self,"_cb",data)
- return None
- txt = data["Value"]
- cprint(self,"label._cb()",nr,txt)
- if txt:
- PRESETS.label(nr,txt)
- self.elem_presets[nr].configure(text = PRESETS.get_btn_txt(nr))
- modes.val("LABEL", 0)
- master._refresh_exec(nr=nr)
- dialog._cb= _cb #_x(nr)
- dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
- def xcb(self,mode,value=None):
- cprint("MODE CALLBACK",mode,value,color="green",end="")
- #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
- if value:
- cprint("===== ON ======",color="red")
- txt = ""
- if mode == "REC-FX":
- modes.val("REC",0)
- modes.val("REC",1)
- if value == 2:
- if mode in ["MOVE","COPY"]:
- txt="to"
- self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
- else:
- if mode in ["MOVE","COPY"]:
- txt="from"
- self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
- else:
- cprint("===== OFF ======",color="red")
- if mode == "REC-FX":
- modes.val("REC",0)
- self.button_refresh(mode,color="lightgrey")#,fg="black")
- def load(self,fname=""):
- pass
- def exit(self):
- cprint("__del__",self)
- PRESETS.backup_presets()
- #print("********************************************************")
- FIXTURES.backup_patch()
- #print("*********del",self,"***********************************************")
- def refresh_exec(self):
- refresher_exec.reset() # = Refresher()
- def _refresh_exec(self,nr=-1):
- s = time.time()
- cprint("PRESET.refresh_exec()")
- refresher_exec.reset() # = Refresher()
-
- self._XX +=1
- self._nr_ok = 0
- for nr in PRESETS.val_presets:
- cfg = get_exec_btn_cfg(nr)
- if not cfg:
- out = {}
- out["bg"] = "lightgrey"
- out["ba"] = "grey"
- out["fg"] = "grey"
- out["text"] = "?"
- cfg = out
- b = self.elem_presets[nr]
- b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"],fx=cfg["fx"])
- time.sleep(0.01)
- def refresh_fix(self):
- refresher_fix.reset() # = Refresher()
- def _refresh_fix(self):
- cprint(self,"_refresh_fix")
- s=time.time(); _XXX=0
- menu_buff = {"DIM":0,"DIM-SUB":0,"FIX":0,"FIX-SUB":0}
- elem_buffer = []
- for fix in FIXTURES.fixtures:
- sdata = FIXTURES.fixtures[fix]
- elem_attr_fix = None
- if fix in self.elem_attr:
- elem_attr_fix = self.elem_attr[fix]
- if "DIM" in sdata["ATTRIBUT"] and "_ACTIVE" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 2:
- KEY = "DIM-SUB"
- else:
- KEY = "FIX-SUB"
- FIX = 0
- DIM = 0
- for attr in sdata["ATTRIBUT"]:
- _buff = {}
- row = sdata["ATTRIBUT"][attr]
- if attr.endswith("-FINE"):
- continue
- b_attr = attr
- if b_attr == "_ACTIVE":
- b_attr = "S"
- elem = None
- if elem_attr_fix:
- if b_attr not in elem_attr_fix:
- continue
- elem = elem_attr_fix[b_attr]
- if not elem:
- continue
-
-
- if "elem" not in _buff:
- _buff["elem"] = elem
- if not attr.startswith("_"):
- v2 = row["VALUE"]
- #_text = "{} {}".format(str(attr).rjust(4,"0"),str(v2).rjust(4,"0")) # ~0.2 sec
- _text = "{} {}".format(attr,v2)
- _buff["text"] = _text
- if row["ACTIVE"]:
- _buff["bg"] = "yellow"
- _buff["abg"] = "yellow"
- menu_buff[KEY] += 1
- if b_attr == "S":
- if KEY == "DIM-SUB":
- DIM =1
- else:
- FIX =1
- else:
- _buff["bg"] = "grey"
- _buff["abg"] = "grey"
- if "FX" not in row: # insert FX2 excetption
- row["FX"] = "" #OrderedDict()
- if "FX2" not in row: # insert FX2 excetption
- row["FX2"] = {} #OrderedDict()
- #print("row",fix,row)
- if row["FX"]:
- _buff["fg"] = "blue"
- elif row["FX2"]:
- _buff["fg"] = "red"
- else:
- _buff["fg"] = "black"
- elem_buffer.append(_buff)
- menu_buff["FIX"] += FIX
- menu_buff["DIM"] += DIM
- cprint(" =+= "*10,"refresh_fix")
- try:
- for row in elem_buffer:
- elem = row["elem"]
- if not elem:
- continue
- #print("<elem>",elem)
- for e in row:
- if e == "elem":
- continue
- v = row[e]
- #print("confg:",["key:",e,"val:",v])
- if e == "abg":
- elem.config(activebackground=v)
- else:
- elem[e] = v
- w = window_manager.get_win("FIXTURES")
- #print(dir(w))
- w.update_idle_task()
- #tkinter.Tk.update_idletasks(w)
- except Exception as e:
- cprint("exc434",e)
- cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
- cprint(gui_menu)
- menu_buff["FIX-SUB"] -= menu_buff["FIX"]
- if menu_buff["FIX-SUB"]:
- gui_menu.config("FIXTURES","bg","yellow")
- gui_menu.config("FIXTURES","activebackground","yellow")
- elif menu_buff["FIX"]:
- gui_menu.config("FIXTURES","bg","orange")
- gui_menu.config("FIXTURES","activebackground","orange")
- else:
- gui_menu.config("FIXTURES","bg","")
- gui_menu.config("FIXTURES","activebackground","")
- gui_menu.update("FIXTURES","{} : {}".format(menu_buff["FIX"],menu_buff["FIX-SUB"]))
- menu_buff["DIM-SUB"] -= menu_buff["DIM"]
- if menu_buff["DIM-SUB"]:
- gui_menu.config("DIMMER","bg","yellow")
- gui_menu.config("DIMMER","activebackground","yellow")
- elif menu_buff["DIM"]:
- gui_menu.config("DIMMER","bg","orange")
- gui_menu.config("DIMMER","activebackground","orange")
- else:
- gui_menu.config("DIMMER","bg","")
- gui_menu.config("DIMMER","activebackground","")
- gui_menu.update("DIMMER","{} : {}".format(menu_buff["DIM"],menu_buff["DIM-SUB"]))
- cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
- def preset_rec(self,nr):
- cprint("------- STORE PRESET")
- data = FIXTURES.get_active()
- if modes.val("REC-FX"):
- PRESETS.rec(nr,data,"REC-FX")
- modes.val("REC-FX",0)
- else:
- PRESETS.rec(nr,data)
-
- sdata=data
- PRESETS.val_presets[nr] = sdata
-
- master._refresh_exec()
- return 1
- def preset_select(self,nr):
- cprint("SELECT PRESET")
- sdata = PRESETS.val_presets[nr]
- cmd = ""
- for fix in sdata:
- if fix == "CFG":
- continue
- for attr in sdata[fix]:
- #v2 = sdata[fix][attr]["VALUE"]
- #v2_fx = sdata[fix][attr]["FX"]
- #print( self.data.elem_attr)
- #if fix in self.elem_attr:
- # if attr in self.elem_attr[fix]:
- # elem = self.elem_attr[fix][attr]
- FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
- FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
- #elem["bg"] = "yellow"
- def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
- s=time.time()
- t_start = time.time()
- if xfade is None and FADE._is():
- xfade = FADE.val()
-
- if ptfade is None and FADE_move._is():
- ptfade = FADE_move.val()
- cprint("GO PRESET FADE",nr,val)
- rdata = PRESETS.get_raw_map(nr)
- if not rdata:
- return 0
- cprint("???????")
- cfg = PRESETS.get_cfg(nr)
- cprint("''''''''")
- #virtcmd = FIXTURES.get_virtual(rdata)
- if not cfg:
- cprint("NO CFG",cfg,nr)
- return 0
- xFLASH = 0
- value=None
- cprint("preset_go",nr,cfg)
- if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
- self.preset_select(nr)
- elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
- xFLASH = 1
- xfade = 0
- if type(val) is not type(None) and val == 0 :
- value = "off"
- xfade=0
- if "OUT-FADE" in cfg:
- xfade=cfg["OUT-FADE"]
- if event:
- if str(event.type) == "ButtonRelease" or event.type == '5' :
- value = "off"
- xfade=0
- if "OUT-FADE" in cfg:
- xfade=cfg["OUT-FADE"]
- cprint("preset_go() FLUSH",value,color="red")
- #print(";",rdata)
- print(";",cfg)
- fcmd = FIXTURES.update_raw(rdata,update=0)
- #print(":",fcmd) # raw dmx
- self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
-
- elif not val:
- cprint("preset_go() STOP",value,color="red")
- elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
- fcmd = FIXTURES.update_raw(rdata)
- self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
- elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
- fcmd = FIXTURES.update_raw(rdata)
- e=time.time()
- print("_GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
- self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
- e=time.time()
- print("GO TIME:","{:0.02f}".format(e-s),int(e*10)/10)
- return
- if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
- self.refresh_exec()
- self.refresh_fix()
-
- #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
- #print(len(self.elem_presets) )
- if len(self.elem_presets) > nr: # RED BUTTON IF PRESSED
- #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
- if val:# or value:
- #self.elem_presets[nr].config(borderwidth=1)
- self.elem_presets[nr].config(bg="red")
- else:
- self._refresh_exec()
- cprint("preset_go",time.time()-t_start)
- def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
- if xfade is None and FADE._is():
- xfade = FADE.val()
- if ptfade is None and FADE_move._is():
- ptfade = FADE_move.val()
- cprint("PRESETS._preset_go() len=",len(rdata),cfg)
- if xfade is None:
- xfade = cfg["FADE"]
- if ptfade is None:
- ptfade = cfg["FADE"]
- #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
- #cprint(rdata,color="red")
- vcmd = execlib.reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
- cmd = []
- delay=0
- for i,v in enumerate(fcmd):
- #print("go",i,v)
- if xFLASH:
- vcmd[i]["FLASH"] = 1
- DMX = fcmd[i]["DMX"]
-
- if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
- vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
- if value is not None:
- vcmd[i]["VALUE"] = value
- if value == "off":
- if "FX2" in vcmd:
- vcmd[i]["FX2"]["TYPE"] = value
- if "FIX" in fcmd:
- vcmd[i]["FIX"] = fcmd["FIX"]
- if DMX and vcmd[i]:
- vcmd[i]["DMX"] = DMX
- if type(nr) is not type(None):
- vcmd[i]["EXEC"] = str(int(nr)+1)
- cmd.append(vcmd[i])
- if cmd and not modes.val("BLIND"):
- jclient_send(cmd)
- def render(self):
- #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
- #self.draw_input()
- pass
-
- ##draw_sub_dim
- import tkgui.dialog as dialoglib
- dialog = dialoglib.Dialog()
- from tkgui.draw import *
- from tkgui.GUI import *
- class LOAD_SHOW_AND_RESTART():
- def __init__(self,fname=""):
- self.fname=fname
- self.base = baselib.Base()
- def cb(self,event=None,force=0):
- cprint("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
- if not self.fname and not force:
- return 0
- if self.base.show_name == self.fname and not force:
- cprint("filename is the same",self.fname)
- return 0
- if not force:
- self.base._set(self.fname)
- cprint("LOAD SHOW:",event,self.fname)
- BASE_PATH = "/opt/LibreLight/Xdesk/"
- cmd="_LibreLightDesk.py"
- arg = ""
- print("fork",[BASE_PATH,cmd,arg])
- if "--easy" in sys.argv:
- arg = "--easy"
-
- movewin.process_kill(BASE_PATH+"tksdl/")
- os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
- sys.exit()
-
- class BaseCallback():
- def __init__(self,cb=None,args={}):
- self._cb=cb
- self.args = args
- def cb(self,**args):
- print("BaseCallback.cb()")
- print(" ",self.args)
- print(" ",self._cb)
- if self._cb:
- if self.args:
- self._cb(args=self.args)
- else:
- self._cb()
- def frame_of_show_list(frame,cb=None):
- c=0
- r=0
- base = baselib.Base()
- for i in ["name","stamp"]: #,"create"]:
- b = tk.Label(frame,bg="grey",text=i)
- b.grid(row=r, column=c, sticky=tk.W+tk.E)
- c+=1
- r+=1
- blist = base._list()
- for i in range(10):
- blist.append(["",""])
- if cb is None:
- cb = DummyCallback #("load_show_list.cb")
- for i in blist:
- #print(i)
- c=0
- for j in i:
- bg="lightgrey"
- dbg="lightgrey"
- if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
- dbg = "lightgreen"
- elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
- dbg = "green"
- if c > 0:
- b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
- b.config(activebackground=dbg)
- b.grid(row=r, column=c, sticky=tk.W+tk.E)
- else:
- if base.show_name == i[0]:
- bg="green"
- _cb = cb(j)
- b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
- if base.show_name == i[0]:
- b.config(activebackground=bg)
- b.grid(row=r, column=c, sticky=tk.W+tk.E)
- c+=1
- r+=1
- def PRESET_CFG_CHECKER(sdata):
- "repair CFG "
- ok = 0
- if "CFG" not in sdata:
- sdata["CFG"] = OrderedDict()
- ok += 1
- if "FADE" not in sdata["CFG"]:
- sdata["CFG"]["FADE"] = 4
- ok += 1
- if "DELAY" not in sdata["CFG"]:
- sdata["CFG"]["DELAY"] = 0
- ok += 1
- if "BUTTON" not in sdata["CFG"]:
- sdata["CFG"]["BUTTON"] = "GO"
- ok += 1
- if "HTP-MASTER" not in sdata["CFG"]:
- sdata["CFG"]["HTP-MASTER"] = 100 #%
- ok += 1
- if "SIZE-MASTER" not in sdata["CFG"]:
- sdata["CFG"]["SIZE-MASTER"] = 100 #%
- ok += 1
- if "SPEED-MASTER" not in sdata["CFG"]:
- sdata["CFG"]["SPEED-MASTER"] = 100 #%
- ok += 1
- if "OFFSET-MASTER" not in sdata["CFG"]:
- sdata["CFG"]["OFFSET-MASTER"] = 100 #%
- ok += 1
- #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
- #except:pass
- return ok
- class Presets():
- def __init__(self):
- #super().__init__()
- self.base = baselib.Base()
- #self.load()
- self._last_copy = None
- self._last_move = None
- self.fx_buffer = {}
- def load_presets(self):
- #self._load()
- filename="presets"
- #self.base._init()
- d,l = self.base._load(filename)
- for i in d:
- sdata = d[i]
- ok = PRESET_CFG_CHECKER(sdata)
- self.val_presets = d
- self.label_presets = l
- def check_cfg(self,nr=None):
- cprint("PRESETS.check_cfg()",nr)#,color="red")
- ok = 0
- if nr is not None:
- if nr in self.val_presets:
- sdata = self.val_presets[nr]
- ok += self._check_cfg(sdata)
- else:
- cprint("nr not in data ",nr,color="red")
- else:
- for nr in self.val_presets:
- sdata = self.val_presets[nr]
- ok += self._check_cfg(sdata)
- return ok
- def _check_cfg(self,sdata):
- cprint("PRESETS._check_cfg()")#,color="red")
- ok = PRESET_CFG_CHECKER(sdata)
- if ok:
- cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
- return ok
-
- def backup_presets(self,save_as="",new=0):
- filename = "presets"
- data = self.val_presets
- labels = self.label_presets
- if new:
- #a = []
- #for i in range(512):
- # e = PRESET_CFG_CHECKER({})
- # e["NAME"] = str(i)
- # a.append(e)
- #data = a
- data = []#*512
- labls = [""]*512
- #self.base._init()
- self.base._backup(filename,data,labels,save_as)
-
- def get_cfg(self,nr):
- cprint("PRESETS.get_cfg()",nr)
- self.check_cfg(nr)
- if nr not in self.val_presets:
- cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
- return {}
- if "CFG" in self.val_presets[nr]:
- return self.val_presets[nr]["CFG"]
- def clean(self,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]
- for fix in sdata:
- #print("exec.clear()",nr,fix,sdata[fix])
- for attr in sdata[fix]:
- row = sdata[fix][attr]
- if fix == "CFG":
- continue
- if "VALUE" not in row:
- row["VALUE"] = None
- if "FX" not in row:
- row["FX"] = ""
- if "FX2" not in row:
- row["FX2"] = OrderedDict()
- elif row["FX2"]:
- for k in ["SIZE","SPEED","START","OFFSET"]:
- row["FX2"][k] = int( row["FX2"][k] )
- row["FX"] = ""
- if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
- #"off:0:0:0:16909:-:"
- x = row["FX"].split(":")
- cprint("-fx",x,len(x))
- #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
- if len(x) >= 6:
- row["FX2"]["TYPE"] = x[0]
- row["FX2"]["SIZE"] = int(x[1])
- row["FX2"]["SPEED"] = int(x[2])
- row["FX2"]["START"] = int(x[3])
- row["FX2"]["OFFSET"] = int(x[4])
- row["FX2"]["BASE"] = x[5]
- row["FXOLD"] = row["FX"]
- row["FX"] = ""
- #cprint("exec.clear()",nr,fix,row)
-
- def get_raw_map(self,nr):
- self.clean(nr)
- cprint("get_raw_map",nr)
- 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["FX2"] = sdata[fix][attr]["FX2"]
- #x["DMX"] = sdata[fix][attr]["NR"]
- out.append(x)
- return out
- def get_btn_txt(self,nr):
- sdata=self.val_presets[nr]
- BTN="go"
- if "CFG" in sdata:
- if "BUTTON" in sdata["CFG"]:
- BTN = sdata["CFG"]["BUTTON"]
- _label = self.label_presets[nr] # = label
- #txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
- #txt=str(nr+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+_label
- txt="{} {} {}\n{}".format(nr+1,BTN,len(sdata)-1,_label)
- cprint("get_btn_txt",nr,[txt])
- return txt
- def _btn_cfg(self,nr,txt=None):
- if nr not in self.val_presets:
- return ""
- if "CFG" not in self.val_presets[nr]:
- self.val_presets[nr]["CFG"] = OrderedDict()
- return self.val_presets[nr]["CFG"]
- def btn_cfg(self,nr,txt=None):
- if nr not in self.val_presets:
- return ""
- if "CFG" not in self.val_presets[nr]:
- self.val_presets[nr]["CFG"] = OrderedDict()
- if "BUTTON" not in self.val_presets[nr]["CFG"]:
- self.val_presets[nr]["CFG"]["BUTTON"] = ""
- if type(txt) is str:
- self.val_presets[nr]["CFG"]["BUTTON"] = txt
- if self.val_presets[nr]["CFG"]["BUTTON"] is None:
- self.val_presets[nr]["CFG"]["BUTTON"] = ""
- master._refresh_exec(nr=nr)
- cprint("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
- return self.val_presets[nr]["CFG"]["BUTTON"]
- def label(self,nr,txt=None):
- if nr not in self.label_presets:
- return ""
- if type(txt) is str:
- self.label_presets[nr] = txt
- cprint("set label",nr,[txt])
- cprint("??? ?? set label",nr,[txt])
- return self.label_presets[nr]
- def clear_move(self):
- cprint("PRESETS.clear_move()",end=" ")
- self.clear_copy()
-
- def clear_copy(self):
- cprint("PRESETS.clear_copy()",end=" ")
- if self._last_copy is not None:
- cprint("=OK=",color="red")
- self._last_copy = None
- else:
- cprint("=NONE=",color="green")
- def copy(self,nr,overwrite=1):
- cprint("PRESETS._copy",nr,"last",self._last_copy)
- if nr >= 0:
- if self._last_copy is not None:
- if modes.val("COPY"):
- modes.val("COPY",3)
- ok = self._copy(self._last_copy,nr,overwrite=overwrite)
- return ok #ok
- else:
- if modes.val("COPY"):
- modes.val("COPY",2)
- self._last_copy = nr
- cprint("PRESETS.copy START ",color="red")
- return 0
- return 1 # on error reset move
- def _copy(self,nr_from,nr_to,overwrite=1):
- cprint("PRESETS._copy",nr_from,"to",nr_to)
- self.check_cfg(nr_from)
- if type(self._last_copy) is None:
- cprint("PRESETS._copy last nr is None",color="red")
- return 0
- cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
- if nr_from in self.val_presets and nr_to in self.val_presets:
- fdata = self.val_presets[nr_from]
- tdata = self.val_presets[nr_to]
- #cprint(fdata)
- flabel = self.label_presets[nr_from]
- tlabel = self.label_presets[nr_to]
- self.val_presets[nr_to] = copy.deepcopy(fdata)
- self.label_presets[nr_to] = flabel
- if not overwrite: #default
- cprint("overwrite",overwrite)
- self.val_presets[nr_from] = copy.deepcopy(tdata)
- self.label_presets[nr_from] = tlabel
- #self.label_presets[nr_from] = "MOVE"
- self.clear_copy()
- cprint("PRESETS.copy OK",color="green")
- return 1
- def move(self,nr):
- cprint("PRESETS.move",self._last_copy,"to",nr)
- if nr >= 0:
- last = self._last_copy
- if modes.val("MOVE"):
- modes.val("MOVE",2)
- ok= self.copy(nr,overwrite=0)
- if ok and last >= 0:
- if modes.val("MOVE"):
- modes.val("MOVE",3)
- cprint("PRESETS.move OK",color="red")
- #self.delete(last)
- return ok,nr,last #ok
-
- return 0,nr,last # on error reset move
- def delete(self,nr):
- cprint("PRESETS.delete",nr)
- ok=0
- if nr in self.val_presets:
- self.val_presets[nr] = OrderedDict()
- self.label_presets[nr] = "-"
- ok = 1
- self.check_cfg(nr)
- return ok
- def rec(self,nr,data,arg=""):
- cprint("rec",self,"rec()",len(data),arg)
- self.check_cfg(nr)
- self._check_cfg(data) #by ref
- odata=self.val_presets[nr]
- #print("odata",odata)
- if "CFG" in odata:
- if "BUTTON" in odata["CFG"]:
- data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
- self.val_presets[nr] = data
- return 1
-
- class FixtureEditor():
- def __init__(self,dmx=1):
- pass
- self.elem=[]
- self.dmx=dmx
- cprint("init FixtureEditor",dmx)
- def event(self,a1="",a2=""):
- cprint([self.dmx,a1,a2])
- j=[]
- jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
- j.append(jdata)
- jclient_send(j)
- class MasterWingX():
- def __init__(self,dmx=1):
- pass
- self.elem=[]
- self.dmx=dmx
- cprint("init MasterWing",dmx)
- def event(self,a1="",a2=""):
- cprint([self.dmx,a1,a2])
- jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
- j=[]
- j.append(jdata)
- jclient_send(j)
- class BufferVar():
- def __init__(self,elem):
- self.elem = elem
- def change_dmx(self,event=""):
- nr=1
- txt=""
- def cb(data):
- txt = data["Value"]
- dialog._cb = _cb
- dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
- cprint("change_dmx",[event,self])
-
- lf_nr = 0
-
- from tkinter import PhotoImage
- _shift_key = 0
- class WindowManager():
- def __init__(self):
- self.windows = {}
- self.obj = {}
- self.nr= 0
- self.first=""
- self.window_init_buffer = {}
- def update(self,w,name="",obj=None):
- name = str(name)
- for k in self.windows:
- if k == name:
- self.windows[str(name)] = w
- self.obj[str(name)] = obj
- def new(self,w,name="",obj=None,wcb=None):
- name = str(name)
- if wcb and name:
- self.window_init_buffer[name] = wcb
- if not self.first:
- if name:
- self.first = name
- else:
- self.first = str(self.nr)
- if w:
- w.tk.state(newstate='normal')
- w.tk.attributes('-topmost',True)
- if name:
- self.windows[str(name)] = w
- self.obj[str(name)] = obj
- else:
- self.windows[str(self.nr)] = w
- self.obj[str(self.nr)] = obj
- self.nr+=1
- def mainloop(self):
- self.windows[self.first].mainloop()
- def get_win(self,name):
- cprint(self,".get_win(name) =",name)
- name = str(name)
- if name in self.windows:
- out = self.windows[name]
- cprint(out)
- return out
- def get(self,name):
- return get_win(name)
- def get_obj(self,name):
- name = str(name)
- if name in self.windows:
- out = self.obj[name]
- return out
- def create(self,name):
- cprint( "create Window",name)
- if name in self.window_init_buffer:
- c = self.window_init_buffer[name]
- print(c)
- print(dir(c))
- w,obj,cb_ok = c.create()
- window_manager.update(w,name,obj)
- if cb_ok:
- cb_ok()
- resize = 1
- if "resize" in c.args:
- if not c.args["resize"]:
- resize = 0
- #if resize:
- libwin.get_window_position(_filter=name,win=w)
- if name in ["ENCODER"]:
- global _ENCODER_WINDOW
- _ENCODER_WINDOW = w
- if name in ["DIMMER","FIXTURES"]:
- refresher_fix.reset() # = Refresher()
- def _check(self,name):
- try:
- self.windows[name].tk.state(newstate='normal')
- return 1
- except Exception as e:
- cprint("exception",e,color="red")
- cprint("info",name,self.windows[name],color="red")
- def top(self,name):
- name = str(name)
- if name not in self.windows:
- cprint(name,"not in self.windows",self.windows.keys())
- return
- if not self._check(name):
- self.create(name)
-
- w = self.windows[name]
- #def get_lineno():
- print(" 2.1- ln",movewin.get_lineno(),w,str(type(w)))
- #if type(w) is type(window_create_buffer):
- if not str(type(w)).startswith("<class 'function'>"):
- w.tk.attributes('-topmost',True)
- w.tk.attributes('-topmost',False)
- w.tk.update_idletasks()
- else:
- print(" 2.2-",w)
- w()
- class Console():
- def __init__(self):
- pass
- def flash_off(self,fix):
- pass#client.send("df0:alloff:::,")
- def fx_off(self,fix):
- cprint("Console.fx_off()",fix)
- if not fix or fix == "all":
- #client.send("fx0:alloff:,fxf:alloff:,")
- #client.send("df0:alloff:::,")
- j = []
- if 0:
- jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
- j.append(jdata)
- jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
- j.append(jdata)
- else:
- jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
- j.append(jdata)
- if not modes.val("BLIND"):
- jclient_send(j)
- return 0
- def test_1():
- #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
- pass
- window_manager = WindowManager()
- CONSOLE = Console()
- PRESETS = Presets()
- FIXTURES = fixlib.Fixtures()
- FIXTURES.gui = GUIHandler()
- def LOAD_SHOW():
- PRESETS.load_presets()
- FIXTURES.load_patch()
- #master._refresh_fix()
- #master._refresh_exec()
- LOAD_SHOW()
- master = MASTER()
- class Refresher():
- def __init__(self):
- self.time = time.time()
- self.time_max = time.time()
- self.time_delta = 15
- self.update = 1
- self.name = "name" # exec
- self.cb = None #self.dummy_cb
- def dummy_cb(self):
- cprint(self,"dummy_cd()",time.time()-self.time)
- def reset(self):
- self.time = time.time()
- self.update = 1
- def refresh(self):
- if self.update:
- if self.time+self.time_delta < time.time():
- self._refresh()
- else:
- self.time = time.time()
- def _refresh(self):
- cprint("_refresh()",self.name,self)
- if not INIT_OK:
- return
- self.time_max = time.time()
- self.time = time.time()
- self.update = 0
- try:
- if self.cb:
- self.cb()
- else:
- self.dummy_cb()
- except Exception as e:
- cprint("_refresh except:",e,"cb:",self.cb)
- traceback.print_exc()
- cprint()
- cprint("t=",self.time_max- time.time())
- def loop(self,args={}):
- while 1:
- try:
- if INIT_OK:
- self.refresh()
- #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
- except Exception as e:
- cprint("loop exc",e)
- traceback.print_exc()
- cprint("== cb EXCEPT",e,color="red")
- cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
- cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
- time.sleep(0.2)
- print("main",__name__)
- __run_main = 0
- if __name__ == "__main__":
- __run_main = 1
- else:
- import __main__
- if "unittest" not in dir(__main__):
- __run_main = 1
- refresher_fix = Refresher()
- refresher_fix.time_delta = 0.50
- refresher_fix.name = "fix"
- refresher_fix.reset()
- refresher_fix.cb = master._refresh_fix
- refresher_exec = Refresher()
- refresher_exec.time_delta = 10 #0
- refresher_exec.name = "exec"
- refresher_exec.reset()
- refresher_exec.cb = master._refresh_exec
- refresher_exec = Refresher()
- refresher_exec.time_delta = 10 #0
- refresher_exec.name = "exec-fader"
- refresher_exec.reset()
- refresher_exec.cb = refresh_exec_fader_cfg
- def loops(**args):
- time.sleep(5) # wait until draw all window's
- cprint("-> run loops")
- thread.start_new_thread(refresher_fix.loop,())
- thread.start_new_thread(refresher_exec.loop,())
- class window_create_sdl_buffer():
- def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
- self.args = args.copy()
- self.cls = cls
- self.cb_ok = cb_ok
- self.data = data
- self.scroll = scroll
- self.gui = gui
- def create(self,hidde=0):
- cprint()
- return [self.cls,self.cls,None] #w,obj,cb_ok
- class window_create_buffer():
- def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
- self.args = args.copy()
- self.cls = cls
- self.cb_ok = cb_ok
- self.data = data
- self.scroll = scroll
- self.gui = gui
- def create(self,hidde=0):
- cprint()
- cprint()
- cprint("window_create_buffer.create()",id(self),self.args["title"],color="green")
- obj = None
- w = libtk.Window(self.args)
- out = []
- f = None
- h = None
- if self.scroll:
- head = None
- foot = None
- if "head" in self.args:
- head = self.args["head"]
- if "foot" in self.args:
- foot = self.args["foot"]
- w1 = ScrollFrame(w.tk,width=self.args["width"],height=self.args["height"],foot=foot,head=head)
- if type(w1) is list:
- try:
- h = w1[0]
- f = w1[2]
- except:pass
- w1 = w1[1]
- else:
- w1 = tk.Frame(w.tk,width=self.args["width"],height=self.args["height"])
- w1.pack()
- try:
- obj=self.cls(self.gui,w1,self.data,foot=f,head=h)
- except:
- obj=self.cls(self.gui,w1,self.data)
- return w,obj,self.cb_ok
- if __run_main:
- cprint("main")
- #thread.start_new_thread(refresher_fix.loop,())
- #thread.start_new_thread(refresher_exec.loop,())
-
- TOP = _POS_TOP + 15
- L0 = _POS_LEFT
- L1 = _POS_LEFT + 95
- L2 = _POS_LEFT + 920
- W1 = 810
- H1 = 550
- HTB = 23 # hight of the titlebar from window manager
- pos_list = libwin.read_window_position()
-
- data = []
- #data.append({"text":"COMMAND"})
- #data.append({"text":"CONFIG"})
- data.append({"text":"PATCH"})
- data.append({"text":"DIMMER"})
- data.append({"text":"FIXTURES"})
- data.append({"text":"FIX-LIST"})
- data.append({"text":"EXEC","name":"EXEC-BTN"})
- data.append({"text":"EXEC-WING"})
- data.append({"text":"---"})
- data.append({"text":"SETUP"})
- data.append({"text":"COMMAND"})
- data.append({"text":"LIVE"})
- data.append({"text":"FX"})
- data.append({"text":"ENCODER"})
- data.append({"text":"COLORPICKER","name":"COLOR"})
- data.append({"text":"---"})
- data.append({"text":"FIXTURE-EDITOR","name":"FIX-EDIT"})
- data.append({"text":"CONFIG"})
- data.append({"text":"SDL-MIDI"})
- data.append({"text":"CLOCK"})
- data.append({"text":"SDL-DMX"})
- #data.append({"text":"MASTER-WING"})
- name="MAIN"
- args = {"title":"MAIN","master":1,"width":80,"height":H1,"left":L0,"top":TOP,"resize":1}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cls = GUI_menu
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- window_manager.top(name)
- gui_menu_gui = window_manager.get_win(name)
- gui_menu = window_manager.get_obj(name)
- master._refresh_fix()
- # --------------------------------
- name="EXEC"
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- data = PRESETS
- cls = draw_exec #GUI_ExecWingLayout
- cb_ok = None #set_exec_fader_all
-
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- #print(dir(cls))
- #print(cls)
- #sys.exit()
- name="SDL-MIDI"
- def sdl_config():
- cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/midi.py &"
- cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/midi.py " #&"
- print(cmd)
- #os.popen(cmd)
- def xyz123(cmd):
- os.system(cmd)
- thread.start_new_thread(xyz123,(cmd,))
- return [None,None,None]
- #class window_create_sdl_buffer():
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- data = []
- cls = sdl_config #: None #GUI_CONF
- cb_ok = None
- c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="SDL-DMX"
- def sdl_config():
- cmd="nohup /usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/config.py &"
- cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/dmx.py " #&"
- print(cmd)
- #os.popen(cmd)
- def xyz123(cmd):
- os.system(cmd)
- thread.start_new_thread(xyz123,(cmd,))
- return [None,None,None]
- #class window_create_sdl_buffer():
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- data = []
- cls = sdl_config #: None #GUI_CONF
- cb_ok = None
- c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="FIX-LIST"
- def sdl_config():
- cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tksdl/fix.py " #&"
- print(cmd)
- #os.popen(cmd)
- def xyz123(cmd):
- os.system(cmd)
- thread.start_new_thread(xyz123,(cmd,))
- return [None,None,None]
- #class window_create_sdl_buffer():
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- data = []
- cls = sdl_config #: None #GUI_CONF
- cb_ok = None
- c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="CONFIG"
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- data = []
- cls = GUI_CONF
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="DIMMER"
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cls = GUI_DIM
- data = FIXTURES
- ok_cb=None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="FIXTURES"
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cls = GUI_FIX
- ok_cb=None
- data = FIXTURES
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- # -------------------------------
- name="FIXTURE-EDITOR"
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- data=[]
- for i in range(12*6):
- data.append({"text"+str(i):"test"})
-
- cls = GUI_FixtureEditor
- #cls = GUI_FaderLayout
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- #window_manager.top(name)
-
- # -------------------------------
- name="MASTER-WING"
- args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220,"resize":0}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- data=[]
- for i in range(2):
- data.append({"MASTER"+str(i):"MASTER"})
- cls = GUI_MasterWingLayout #(w1,data)
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- # -------------------------------
- name="EXEC-WING"
- args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- data=[]
- for i in range(10*3):
- data.append({"EXEC"+str(i):"EXEC"})
- cls = GUI_ExecWingLayout
- cb_ok = set_exec_fader_all
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="ENCODER"
- args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cls = draw_enc #(master,w.tk)#Xroot)
- cb_ok = None
- data = FIXTURES #master
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name = "SETUP"
- args = {"title":name +" SHOW:"+master.base.show_name,
- "master":0,"width":445,"height":42,"left":L1+10+W1,"top":TOP,"resize":10}
- args["title"] = "SETUP SHOW:"+master.base.show_name
- geo = libwin.split_window_position(pos_list,name)
- try:
- geo["width"] = args["width"]
- geo["height"] = args["height"]
- except:pass
- if geo:
- args.update(geo)
- cls = draw_setup #(master,w.tk)
- data = []
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name = "COMMAND"
- args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":10}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cls = draw_command #(master,w.tk)
- data = []
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name = "LIVE"
- args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":10}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cls = draw_live #(master,w.tk)
- data = []
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name = "CLOCK"
- args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cclock = X_CLOCK()
- cls = cclock.draw_clock
- data = []
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="FX"
- args = {"title":name,"master":0,"width":415,"height":297+30,"left":L1+10+W1,"top":TOP+302,"resize":1}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cls = draw_fx #(master,w.tk)
- data = []
- cb_ok = None
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="PATCH"
- args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP,"foot":1,"head":1}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- cls = GUI_PATCH
- data = FIXTURES
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
- window_manager.new(None,name,wcb=c) #,obj)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="COLORPICKER"
- args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
- geo = libwin.split_window_position(pos_list,name)
- if geo:
- args.update(geo)
- #w = libtk.Window(args)
- #draw_colorpicker(master,w.tk,FIXTURES,master)
- cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
- data = [FIXTURES,master]
- cb_ok = None #FIXTURES
- c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
- window_manager.new(None,name,wcb=c)
- if libwin.split_window_show(pos_list,_filter=name):
- window_manager.top(name)
- name="TableA"
- #w = libtk.Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
- #space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
- #x=TableFrame(root=w.tk)#,left=80,top=620)
- #w.show()
- #data =[]
- #for a in range(40):
- # data.append(["E","E{}".format(a+1)])
- #x.draw(data=data,head=["E","C"],config=[12,5,5])
- #w=x.bframe
- #window_manager.new(w,name)
- master.render()
- window_manager.top("Table")
- #w = frame_fix #Window("OLD",master=0,width=W1,height=500,left=130,top=TOP)
- #window_manager.new(w,name)
- #if "--easy" in sys.argv:
- #load_window_position()
- thread.start_new_thread(loops,())
- mc_fix = MC_FIX()
- def mc_fix_loop():
- time.sleep(5)
- while 1:
- try:
- #print(1)
- data = FIXTURES.fixtures
- mc_fix.set(index="fix",data=data)
- except Exception as e:
- print("MC_FIX EXCEPTION",e)
- time.sleep(1/10)
- thread.start_new_thread(mc_fix_loop,())
-
- try:
- window_manager.mainloop()
- finally:
- BASE_PATH = "/opt/LibreLight/Xdesk/"
- movewin.process_kill(BASE_PATH+"tksdl/")
- master.exit()
|