_LibreLightDesk.py 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. This file is part of LibreLight.
  5. LibreLight is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. LibreLight is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with LibreLight. If not, see <http://www.gnu.org/licenses/>.
  15. (c) 2012 micha@uxsrv.de
  16. """
  17. import random
  18. rnd_id = str(random.randint(1000,9000))
  19. rnd_id += " Beta 22.01"
  20. try:
  21. xtitle = __file__
  22. except:
  23. xtitle = "__file__"
  24. if "/" in xtitle:
  25. xtitle = xtitle.split("/")[-1]
  26. import sys
  27. sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title
  28. import json
  29. import time
  30. import sys
  31. import os
  32. import _thread as thread
  33. import traceback
  34. import tkinter
  35. import tkinter as tk
  36. from tkinter import font
  37. import tkinter.simpledialog
  38. import lib.chat as chat
  39. import lib.motion as motion
  40. from collections import OrderedDict
  41. CUES = OrderedDict()
  42. groups = OrderedDict()
  43. class Modes():
  44. def __init__(self):
  45. self.modes = {}
  46. self.__cfg = {}
  47. self.__cb = None
  48. def val(self,mode,value=None):
  49. if value is not None:
  50. return self.set(mode,value)
  51. elif mode in self.modes:
  52. return self.modes[mode]
  53. def get(self,mode,value=None):
  54. return slef.val(mode,value)
  55. def __check(self,mode):
  56. if mode not in self.modes:
  57. self.modes[mode] = 0
  58. self.__cfg[mode] = 0
  59. def cfg(self,mode,data={}):
  60. self.__check(mode)
  61. if type(data) is dict:
  62. for k in data:
  63. v = data[k]
  64. if v not in self.__cfg:
  65. self.__cfg[k] = v
  66. return 1
  67. elif type(data) is str:
  68. if data in self.__cfg:
  69. return self.__cfg[data]
  70. def set(self,mode,value):
  71. protected = ["BLIND","CLEAR"]
  72. self.__check(mode)
  73. out = 0
  74. if mode == "CLEAR":
  75. return 1
  76. elif mode == "ESC":
  77. for m in self.modes:
  78. print("ESC",m)
  79. if m == "COPY":
  80. PRESETS.clear_copy()
  81. if m == "MOVE":
  82. PRESETS.clear_move()
  83. if m != "BLIND":
  84. self.modes[m] = 0
  85. self.callback(m)
  86. out = 1
  87. return 1
  88. elif value:
  89. for m in self.modes:
  90. if m not in protected and mode not in protected and m != mode:
  91. if self.modes[m]:
  92. self.modes[m]= 0
  93. self.callback(m)
  94. if self.modes[mode]:
  95. if modes == "MOVE":
  96. PRESETS.clear_move()
  97. if modes == "COPY":
  98. PRESETS.clear_copy()
  99. self.modes[mode] = 0 # value
  100. else:
  101. self.modes[mode] = 1 #value
  102. out = 1
  103. else:
  104. self.modes[mode] = 0 #value
  105. if modes == "COPY":
  106. PRESETS.clear_copy()
  107. if modes == "MOVE":
  108. PRESETS.clear_move()
  109. self.callback(mode)
  110. return value
  111. def set_cb(self,cb):
  112. if cb:
  113. self.__cb = cb
  114. def callback(self,mode):
  115. if self.__cb is not None and mode in self.modes:
  116. value = self.modes[mode]
  117. self.__cb(mode=mode,value=value)
  118. modes = Modes()
  119. #modes.val("BLIND", 0)
  120. #modes.modes["BLIND"] = 0
  121. modes.modes["ESC"] = 0
  122. modes.modes["REC"] = 0
  123. modes.modes["EDIT"] = 0
  124. modes.modes["MOVE"] = 0
  125. modes.modes["FLASH"] = 0
  126. modes.modes["GO"] = 0
  127. modes.modes["DEL"] = 0
  128. modes.modes["STONY_FX"] = 0
  129. modes.modes["SELECT"] = 0
  130. modes.modes["CFG-BTN"] = 0
  131. modes.modes["LABEL"] = 0
  132. def xcb(mode,value=None):
  133. print("xcb","MODE CALLBACK",mode,value)
  134. #modes.set_cb(xcb)
  135. POS = ["PAN","TILT","MOTION"]
  136. COLOR = ["RED","GREEN","BLUE","COLOR"]
  137. BEAM = ["GOBO","G-ROT","PRISMA","P-ROT","FOCUS","SPEED"]
  138. INT = ["DIM","SHUTTER","STROBE","FUNC"]
  139. client = chat.tcp_sender()
  140. fade = 2 #2 #0.1 #1.13
  141. fade_on = 1
  142. fx_move_prm = {"SIZE":20,"SPEED":100,"OFFSET":50,"BASE":"-","START":0}
  143. fx_prm = {"SIZE":200,"SPEED":30,"OFFSET":255,"BASE":"-","START":0,"MODE":0,"MO":0,"DIR":1,"WING":2}
  144. fx_modes = [":RED",":GREEN",":BLUE",":MAG",":YELLOW",":CYAN"]
  145. fx_mo = ["sinus","on","on2","bump","bump2","fade","cosinus"]
  146. def build_cmd(dmx,val,args=[fade],flash=0,xpfx="",attr=""):
  147. cmd=""
  148. if xpfx:
  149. pfx=xpfx
  150. elif flash:
  151. pfx ="df"
  152. else:
  153. pfx ="d"
  154. if type(val) is float or type(val) is int:
  155. cmd += ",{}{}:{:0.4f}".format(pfx,dmx,val)
  156. else:
  157. cmd += ",{}{}:{}".format(pfx,dmx,val)
  158. if flash:
  159. cmd += ":0:0"#.format(val)
  160. else:
  161. for val in args:
  162. if type(val) is float or type(val) is int:
  163. cmd += ":{:0.4f}".format(val)
  164. else:
  165. cmd += ":{}".format(val)
  166. if attr:
  167. cmd += ":"+str(attr)
  168. return cmd
  169. def update_raw_dmx(data ,value=None,args=[fade],flash=0,pfx="d",fx=0):
  170. cmd = []
  171. if flash:
  172. pfx += "f"
  173. for row in data:
  174. if fx:
  175. if value is not None:
  176. # z.b. flush off
  177. xcmd = str(value)+":"+row["FX"].split(":",1)[-1]
  178. else:
  179. xcmd = row["FX"]
  180. else:
  181. if row["VALUE"] is None:
  182. xcmd = ""
  183. else:
  184. if value is not None:
  185. if type(value) is float:
  186. xcmd = "{:0.4f}".format(value)
  187. else:
  188. xcmd = "{}".format(value)
  189. else:
  190. xcmd = "{:0.4f}".format(row["VALUE"])
  191. for arg in args:
  192. if type(arg) is float:
  193. xcmd += ":{}".format(arg)
  194. else:
  195. xcmd += ":{:0.4f}".format(arg)
  196. #print( "pack: FIX",row["FIX"],row["ATTR"], xcmd)
  197. #xcmd += ":{}".format(row["ATTR"])
  198. cmd.append( xcmd)
  199. return cmd
  200. def update_dmx(attr,data,value=None,args=[fade],flash=0,pfx=""):
  201. #global modes #BLIND
  202. #print("update_dmx",data)
  203. dmx = data["DMX"]
  204. dmx = (data["UNIVERS"]*512)+data["DMX"]
  205. val = None
  206. cmd=""
  207. try:
  208. if attr == "DIM" and data["ATTRIBUT"][attr]["NR"] < 0: #VDIM
  209. #print( "VDIM")
  210. for attr in data["ATTRIBUT"]:
  211. dmx = (data["UNIVERS"]*512) + data["DMX"]
  212. dmx = data["DMX"]
  213. if data["ATTRIBUT"][attr]["NR"] < 0: #virtual channels
  214. continue
  215. dmx += data["ATTRIBUT"][attr]["NR"]-1
  216. mode = ""
  217. if "MODE" in data["ATTRIBUT"][attr]:
  218. mode = data["ATTRIBUT"][attr]["MODE"]
  219. #print(attr)
  220. val = data["ATTRIBUT"][attr]["VALUE"]
  221. if data["ATTRIBUT"][attr]["MASTER"]:
  222. val = val * (data["ATTRIBUT"]["DIM"]["VALUE"] / 255.)
  223. if val is not None:
  224. #cmd += ",d{}:{:0.4f}".format(dmx,int(val))
  225. if value is not None:
  226. val = value
  227. if mode == "F": #FADE
  228. cmd += build_cmd(dmx,val,args=args,flash=flash,xpfx=pfx,attr=attr)
  229. else:
  230. cmd += build_cmd(dmx,val,args=[0],flash=flash,xpfx=pfx,attr=attr)
  231. #print("cmd",cmd)
  232. elif data["ATTRIBUT"][attr]["NR"] > 0:
  233. dmx += data["ATTRIBUT"][attr]["NR"]-1
  234. val = data["ATTRIBUT"][attr]["VALUE"]
  235. mode = ""
  236. if "MODE" in data["ATTRIBUT"][attr]:
  237. mode = data["ATTRIBUT"][attr]["MODE"]
  238. if data["ATTRIBUT"][attr]["MASTER"]:
  239. #if "VDIM" in data["ATTRIBUT"]:
  240. if "DIM" in data["ATTRIBUT"] and data["ATTRIBUT"]["DIM"]["NR"] < 0: #VDIM
  241. val = val * (data["ATTRIBUT"]["DIM"]["VALUE"] / 255.)
  242. if val is not None:
  243. #cmd += ",d{}:{}".format(dmx,int(val))
  244. if value is not None:
  245. val = value
  246. if mode == "F": #FADE
  247. cmd += build_cmd(dmx,val,args=args,flash=flash,xpfx=pfx,attr=attr)
  248. else:
  249. cmd += build_cmd(dmx,val,args=[0],flash=flash,xpfx=pfx,attr=attr)
  250. #print("cmd",cmd)
  251. if modes.val("BLIND"):
  252. cmd=""
  253. return cmd
  254. except Exception as e:
  255. cprint("== cb EXCEPT",e,color="red")
  256. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  257. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  258. raise e
  259. class dummy_event():
  260. def __init__(self):
  261. self.num =0
  262. self.type = 4 #press 5 release
  263. self.set_value=-1
  264. gcolor = 1
  265. def cprint(*text,color="blue",space=" ",end="\n"):
  266. if not gcolor:
  267. print(text)
  268. return 0
  269. if color == "green":
  270. txt = '\033[92m'
  271. elif color == "red":
  272. txt = '\033[0;31m\033[1m'
  273. elif color == "yellow":
  274. txt = '\033[93m\033[1m'
  275. elif color == "cyan":
  276. txt = '\033[96m'
  277. else:
  278. txt = '\033[94m'
  279. for t in text:
  280. txt += str(t ) +" "
  281. #HEADER = '\033[95m'
  282. #OKBLUE = '\033[94m'
  283. #OKCYAN = '\033[96m'
  284. #OKGREEN = '\033[92m'
  285. #WARNING = '\033[93m'
  286. #FAIL = '\033[91m'
  287. #ENDC = '\033[0m'
  288. #BOLD = '\033[1m'
  289. #UNDERLINE = '\033[4m'
  290. txt += '\033[0m'
  291. print(txt,end=end)
  292. #return txt
  293. cprint("________________________________")
  294. class Xevent():
  295. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  296. self.fix = fix
  297. self.data=data
  298. self.attr = attr
  299. self.elem = elem
  300. self.mode = mode
  301. def fx(self,event):
  302. cprint("Xevent.fx",self.attr,self.fix,event)
  303. if event.num == 4:
  304. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  305. txt = "FX:RED"
  306. fx_prm["MODE"] += 1
  307. if fx_prm["MODE"] > len(fx_modes):
  308. fx_prm["MODE"]=0
  309. txt = "FX:"+fx_modes[fx_prm["MODE"]]
  310. master.elem_fx_commands["FX:RED"]["text"] = txt
  311. elif event.num == 5:
  312. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  313. txt = "FX:RED"
  314. fx_prm["MODE"] -= 1
  315. if fx_prm["MODE"] < 0:
  316. fx_prm["MODE"]= len(fx_modes)-1
  317. txt = "FX:"+fx_modes[fx_prm["MODE"]]
  318. master.elem_fx_commands["FX:RED"]["text"] = txt
  319. elif event.num == 1:
  320. cmd = ""
  321. offset = 0
  322. offset_flag=0
  323. start = fx_prm["START"]
  324. base = fx_prm["BASE"]
  325. #FIXTURES.start_fx(attr)
  326. xfixtures = []
  327. # WING's and BLOCK's
  328. for fix in FIXTURES.fixtures:
  329. xfixtures.append(fix)
  330. x=0
  331. if fx_prm["DIR"] < 0:
  332. xfixtures = xfixtures[::-1]
  333. x=-1
  334. wings = []
  335. if fx_prm["WING"]:
  336. l = len(xfixtures)
  337. w = l // fx_prm["WING"]
  338. teiler = l//w
  339. if teiler < 2:
  340. teiler = 2
  341. for i in range(teiler):
  342. j = i*w
  343. wing = xfixtures[j:j+w]
  344. if i%2==0:
  345. wing = wing[::-1]
  346. print("wing",i,"j",j,"w",w,"wing",wing)
  347. wings.append(wing)
  348. if l > j+w:
  349. wing = xfixtures[j+w:]
  350. wings.append(wing)
  351. else:
  352. wings.append(xfixtures)
  353. print("FX442 ",xfixtures)
  354. print("FX442 ",fx_prm,x)
  355. for wing in wings:
  356. coffset= offset
  357. for fix in wing:
  358. data = FIXTURES.fixtures[fix]
  359. #print( "ADD FX",fix)
  360. for attr in data["ATTRIBUT"]:
  361. if attr.endswith("-FINE"):
  362. continue
  363. csize = fx_prm["SIZE"]
  364. cspeed = fx_prm["SPEED"]
  365. cstart = fx_prm["START"]
  366. cbase = fx_prm["BASE"]
  367. #cstart = start
  368. coffset= offset
  369. #cbase = base
  370. fx=""
  371. if "SIN" in self.attr:
  372. fx = "sinus"
  373. elif "FD" in self.attr:
  374. fx = "fade"
  375. elif "ON2" in self.attr:
  376. fx = "on2"
  377. elif "ON" in self.attr:
  378. fx = "on"
  379. elif "BUM2" in self.attr:
  380. fx = "bump2"
  381. elif "BUM" in self.attr:
  382. fx = "bump"
  383. elif "COS" in self.attr:
  384. fx = "cosinus"
  385. if fx:
  386. if fx_prm["SPEED"] < 0.1:
  387. fx = "off"
  388. else:
  389. if ":DIM" in self.attr:
  390. base=""
  391. ffxb= fx_mo[fx_prm["MO"]]
  392. if attr == "DIM":
  393. if fx_prm["SPEED"] < 0.1:
  394. fx = "off"
  395. else:
  396. fx = ffxb #"fade"
  397. elif ":TILT" in self.attr:
  398. base=""
  399. if attr == "PAN":
  400. fx = "off"
  401. if attr == "TILT":
  402. if fx_prm["SPEED"] < 0.1:
  403. fx = "off"
  404. else:
  405. fx = "sinus"
  406. elif ":PAN" in self.attr:
  407. base=""
  408. if attr == "PAN":
  409. if fx_prm["SPEED"] < 0.1:
  410. fx = "off"
  411. else:
  412. fx = "cosinus"
  413. if attr == "TILT":
  414. fx = "off"
  415. elif ":CIR" in self.attr:
  416. base=""
  417. if attr == "PAN":
  418. if fx_prm["SPEED"] < 0.1:
  419. fx = "off"
  420. else:
  421. fx = "cosinus"
  422. if attr == "TILT":
  423. if fx_prm["SPEED"] < 0.1:
  424. fx = "off"
  425. else:
  426. fx = "sinus"
  427. elif ":RED" in self.attr:
  428. ffxb= fx_mo[fx_prm["MO"]]
  429. ffx= "off" #fx_mo[fx_prm["MO"]]
  430. if ":RED" in fx_modes[fx_prm["MODE"]]:#
  431. base="-"
  432. if attr == "RED":
  433. #coffset=0
  434. #cspeed=0
  435. fx=ffx
  436. if attr == "GREEN":
  437. fx = ffxb# "off"
  438. if attr == "BLUE":
  439. fx = ffxb#"off"
  440. elif ":GREEN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#in self.attr:
  441. base="-"
  442. if attr == "RED":
  443. fx = ffxb#"off"
  444. elif ":GREEN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#in self.attr:
  445. if attr == "GREEN":
  446. fx = ffxb# "off"
  447. #cspeed=0
  448. #coffset=0
  449. fx=ffx
  450. if attr == "BLUE":
  451. fx = ffxb#"off"
  452. elif ":BLUE" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#self.attr:
  453. base="-"
  454. if attr == "RED":
  455. fx = ffxb# "off"
  456. if attr == "GREEN":
  457. fx = ffxb# "off"
  458. if attr == "BLUE":
  459. fx = ffxb# "off"
  460. #cspeed=0
  461. #coffset=0
  462. fx=ffx
  463. elif ":YELLOW" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#self.attr:
  464. base="-"
  465. if attr == "RED":
  466. fx = ffxb# "off"
  467. #cspeed=0
  468. #coffset=0
  469. fx=ffx
  470. if attr == "GREEN":
  471. fx = ffxb# "off"
  472. #cspeed=0
  473. #coffset=0
  474. fx=ffx
  475. if attr == "BLUE":
  476. fx = "off"
  477. elif ":CYAN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#self.attr:
  478. base="-"
  479. if attr == "RED":
  480. fx = ffxb# "off"
  481. if attr == "GREEN":
  482. fx = ffxb# "off"
  483. #cspeed=0
  484. #coffset=0
  485. fx=ffx
  486. if attr == "BLUE":
  487. fx = ffxb# "off"
  488. #cspeed=0
  489. #coffset=0
  490. fx=ffx
  491. elif ":MAG" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#self.attr:
  492. base="-"
  493. if attr == "RED":
  494. fx = ffxb# "off"
  495. fx=ffx
  496. #cspeed=0
  497. #coffset=0
  498. if attr == "GREEN":
  499. fx = ffxb# "off"
  500. if attr == "BLUE":
  501. fx = ffxb# "off"
  502. fx=ffx
  503. #cspeed=0
  504. #coffset=0
  505. else:
  506. cprint("FX: unbekant",fx_modes[fx_prm["MODE"]],color="red")
  507. if fx:
  508. #fx += ":{:0.0f}:{:0.0f}:{:0.0f}:{:0.0f}:{}:".format(fx_prm["SIZE"],fx_prm["SPEED"],start,offset,base)
  509. fx += ":{:0.0f}:{:0.0f}:{:0.0f}:{:0.0f}:{}:".format(csize,cspeed,cstart,coffset,cbase)
  510. offset_flag=1
  511. #print("ADD FX",fix,attr,fx,data["ATTRIBUT"][attr]["ACTIVE"])
  512. if "FX" not in data["ATTRIBUT"][attr]:
  513. data["ATTRIBUT"][attr]["FX"] =""
  514. if data["ATTRIBUT"][attr]["ACTIVE"] and fx:
  515. print("++ADD FX",fix,attr,fx)
  516. data["ATTRIBUT"][attr]["FX"] = fx #"sinus:40:100:10"
  517. cmd+=update_dmx(attr,data,pfx="fx",value=fx)#,flash=FLASH)
  518. if fx_prm["OFFSET"] > 0.5 and offset_flag:
  519. offset_flag=0
  520. offset += fx_prm["OFFSET"] # add offset on next fixture
  521. #print("offset",offset)
  522. if cmd and not modes.val("BLIND"):
  523. client.send(cmd)
  524. master.refresh_fix()
  525. def command(self,event):
  526. if self.mode == "COMMAND":
  527. if self.attr == "CLEAR":
  528. if event.num == 1:
  529. ok = FIXTURES.clear()
  530. if ok:
  531. master.refresh_fix()
  532. modes.val(self.attr,0)
  533. elif self.attr.startswith("SZ:"):#SIN":
  534. #global fx_prm
  535. k = "SIZE"
  536. if event.num == 1:
  537. pass
  538. elif event.num == 2:
  539. pass
  540. elif event.num == 4:
  541. if fx_prm[k] <= 0:
  542. fx_prm[k] = 1
  543. fx_prm[k] *=1.2
  544. elif event.num == 5:
  545. fx_prm[k] /=1.2
  546. #fx_prm[k] =int(fx_prm[k])
  547. if fx_prm[k] > 4000:
  548. fx_prm[k] = 4000
  549. if fx_prm[k] < 0:
  550. fx_prm[k] =0
  551. self.data.elem_fx_commands[self.attr]["text"] = "SZ:{:0.0f}".format(fx_prm[k])
  552. elif self.attr.startswith("SP:"):#SIN":
  553. #global fx_prm
  554. k = "SPEED"
  555. if event.num == 1:
  556. pass
  557. elif event.num == 2:
  558. pass
  559. elif event.num == 4:
  560. if fx_prm[k] <= 0:
  561. fx_prm[k] = 1
  562. fx_prm[k] *=1.2
  563. elif event.num == 5:
  564. fx_prm[k] /=1.2
  565. #fx_prm[k] =int(fx_prm[k])
  566. if fx_prm[k] > 4000:
  567. fx_prm[k] = 4000
  568. if fx_prm[k] < 0:
  569. fx_prm[k] =0
  570. if fx_prm[k] < 0.1:
  571. self.data.elem_fx_commands[self.attr]["text"] = "SP:off".format(fx_prm[k])
  572. else:
  573. self.data.elem_fx_commands[self.attr]["text"] = "SP:{:0.0f}".format(fx_prm[k])
  574. elif self.attr.startswith("ST:"):#SIN":
  575. #global fx_prm
  576. k = "START"
  577. if event.num == 1:
  578. pass
  579. elif event.num == 2:
  580. pass
  581. elif event.num == 4:
  582. if fx_prm[k] <= 0:
  583. fx_prm[k] = 1
  584. fx_prm[k] *=1.2
  585. elif event.num == 5:
  586. fx_prm[k] /=1.2
  587. #fx_prm[k] =int(fx_prm[k])
  588. if fx_prm[k] > 4000:
  589. fx_prm[k] = 4000
  590. if fx_prm[k] < 0:
  591. fx_prm[k] =0
  592. self.data.elem_fx_commands[self.attr]["text"] = "ST:{:0.0f}".format(fx_prm[k])
  593. elif self.attr.startswith("MO:"):# on,sinus,bump
  594. #global fx_prm
  595. k = "MO"
  596. if event.num == 1:
  597. pass
  598. elif event.num == 2:
  599. pass
  600. elif event.num == 4:
  601. fx_prm[k] -=1
  602. if fx_prm[k] < 0:
  603. fx_prm[k] = len(fx_mo)-1
  604. elif event.num == 5:
  605. fx_prm[k] +=1
  606. if fx_prm[k] >= len(fx_mo):
  607. fx_prm[k] = 0
  608. txt = fx_mo[fx_prm[k]]
  609. self.data.elem_fx_commands[self.attr]["text"] = "MO:{}".format(txt)
  610. elif self.attr.startswith("DIR:"):#SIN":
  611. #global fx_prm
  612. k = "DIR"
  613. if event.num == 1:
  614. pass
  615. elif event.num == 2:
  616. pass
  617. elif event.num == 4:
  618. fx_prm[k] = 1
  619. elif event.num == 5:
  620. fx_prm[k] =-1
  621. txt = fx_prm[k]
  622. self.data.elem_fx_commands[self.attr]["text"] = "DIR:{}".format(fx_prm[k])
  623. elif self.attr.startswith("WING:"):#SIN":
  624. #global fx_prm
  625. k = "WING"
  626. if event.num == 1:
  627. pass
  628. elif event.num == 2:
  629. pass
  630. elif event.num == 4:
  631. fx_prm[k] += 1
  632. elif event.num == 5:
  633. fx_prm[k] -=1
  634. if fx_prm[k] > 10:
  635. fx_prm[k] = 10
  636. if fx_prm[k] < 0:
  637. fx_prm[k] =0
  638. txt = fx_prm[k]
  639. self.data.elem_fx_commands[self.attr]["text"] = "WING:{}".format(fx_prm[k])
  640. elif self.attr.startswith("OF:"):#SIN":
  641. #global fx_prm
  642. k = "OFFSET"
  643. if event.num == 1:
  644. pass
  645. elif event.num == 2:
  646. pass
  647. elif event.num == 4:
  648. if fx_prm[k] <= 0:
  649. fx_prm[k] = 1
  650. fx_prm[k] *=1.2
  651. elif event.num == 5:
  652. fx_prm[k] /=1.2
  653. #fx_prm[k] =int(fx_prm[k])
  654. if fx_prm[k] > 1024:
  655. fx_prm[k] = 1024
  656. if fx_prm[k] < 0:
  657. fx_prm[k] =0
  658. self.data.elem_fx_commands[self.attr]["text"] = "OF:{:0.0f}".format(fx_prm[k])
  659. elif self.attr.startswith("BS:"):
  660. k = "BASE"
  661. if event.num == 1:
  662. fx_prm[k] = "0"
  663. elif event.num == 2:
  664. pass
  665. elif event.num == 4:
  666. fx_prm[k] = "+"
  667. elif event.num == 5:
  668. fx_prm[k] = "-"
  669. self.data.elem_fx_commands[self.attr]["text"] = "BS:{}".format(fx_prm[k])
  670. elif self.attr.startswith("FX:"):#SIN":
  671. self.fx(event)
  672. elif self.attr == "FX OFF":
  673. if event.num == 1:
  674. FIXTURES.fx_off("all")
  675. CONSOLE.fx_off("all")
  676. CONSOLE.flash_off("all")
  677. master.refresh_fix()
  678. return 0
  679. elif self.attr == "FADE":
  680. global fade
  681. global fade_on
  682. if fade < 0.01:
  683. fade = 0.01
  684. elif fade > 100.0:
  685. fade = 100
  686. if event.num == 4:
  687. fade *= 1.1
  688. elif event.num == 5:
  689. fade /= 1.1
  690. elif event.num == 1:
  691. if fade_on:
  692. fade_on = 0
  693. self.data.elem_commands[self.attr]["bg"] = "grey"
  694. else:
  695. fade_on = 1
  696. self.data.elem_commands[self.attr]["bg"] = "green"
  697. elif event.num == 2:
  698. if fade > 1 and fade < 4:
  699. fade = 4
  700. elif fade > 3 and fade < 6:
  701. fade = 6
  702. elif fade > 5 and fade < 7:
  703. fade = 8
  704. elif fade > 7 and fade < 9:
  705. fade = 10
  706. elif fade > 9:
  707. fade = 0.01
  708. elif fade < 1:
  709. fade = 1.1
  710. self.data.elem_commands[self.attr]["text"] = "Fade{:0.2f}".format(fade)
  711. elif self.attr == "BACKUP":
  712. modes.val(self.attr,1)
  713. PRESETS.backup_presets()
  714. FIXTURES.backup_patch()
  715. #time.sleep(1)
  716. modes.val(self.attr,0)
  717. else:
  718. if event.num == 1:
  719. print("ELSE",self.attr)
  720. modes.val(self.attr,1)
  721. return 0
  722. def cb(self,event):
  723. cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
  724. print(["type",event.type,"num",event.num])
  725. try:
  726. change = 0
  727. if "keysym" in dir(event):
  728. if "Escape" == event.keysym:
  729. ok = FIXTURES.clear()
  730. master.refresh_fix()
  731. return 0
  732. if self.mode == "COMMAND":
  733. self.command(event)
  734. elif self.mode == "ROOT":
  735. if event.keysym=="Escape":
  736. pass
  737. elif self.mode == "INPUT":
  738. print("INP",self.data.entry.get())
  739. if event.keycode == 36:
  740. x=self.data.entry.get()
  741. client.send(x)
  742. elif self.mode == "INPUT2":
  743. print("INP2",self.data.entry2.get())
  744. if event.keycode == 36:
  745. x=self.data.entry2.get()
  746. client.send(x)
  747. elif self.mode == "INPUT3":
  748. print("INP3",self.data.entry3.get())
  749. if event.keycode == 36:
  750. x=self.data.entry3.get()
  751. client.send(x)
  752. elif self.mode == "PRESET":
  753. nr = self.attr #int(self.attr.split(":")[1])-1
  754. if event.num == 1:
  755. if str(event.type) == '4': #4 ButtonPress
  756. if modes.val("REC"):
  757. self.data.preset_rec(nr)
  758. modes.val("REC",0)
  759. elif modes.val("DEL"):
  760. ok=PRESETS.delete(nr)
  761. if ok:
  762. modes.val("DEL",0)
  763. elif modes.val("COPY"):
  764. ok=PRESETS.copy(nr)
  765. if ok:
  766. modes.val("COPY",0)
  767. master.refresh_exec()
  768. elif modes.val("MOVE"):
  769. ok=PRESETS.move(nr)
  770. if ok:
  771. modes.val("MOVE",0)
  772. master.refresh_exec()
  773. elif modes.val("CFG-BTN"):
  774. master.btn_cfg(nr)
  775. elif modes.val("LABEL"):#else:
  776. master.label(nr)
  777. elif modes.val("EDIT"):
  778. self.data.preset_select(nr)
  779. self.data.preset_go(nr,xfade=0,event=event,val=255)
  780. modes.val("EDIT", 0)
  781. elif modes.val("SELECT"):
  782. self.data.preset_select(nr)
  783. else:
  784. self.data.preset_go(nr,event=event,val=255)
  785. else:
  786. self.data.preset_go(nr,xfade=0,event=event,val=0)
  787. if event.num == 3:
  788. if not modes.val("REC"):
  789. self.data.preset_go(nr,xfade=0,event=event,val=255)
  790. return 0
  791. elif self.mode == "INPUT":
  792. return 0
  793. if self.mode == "ENCODER":
  794. cprint("ENC",self.fix,self.attr,self.mode)
  795. cprint(self.data)
  796. val=""
  797. if event.num == 1:
  798. val ="click"
  799. elif event.num == 4:
  800. val ="+"
  801. elif event.num == 5:
  802. val ="-"
  803. if val:
  804. FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
  805. master.refresh_fix()
  806. except Exception as e:
  807. cprint("== cb EXCEPT",e,color="red")
  808. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  809. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  810. def wheel(event,d=None):
  811. print("wheel",event,d)
  812. import copy
  813. class Element():
  814. def __init__(self):
  815. self.__data = {}
  816. def set(self,key,val):
  817. self.__data[key] = val
  818. class Base():
  819. def __init__(self):
  820. show_name = "GloryCamp2021"
  821. #show_name = "JMS"
  822. #show_name = "Dimmer"
  823. self.home = os.environ['HOME']
  824. self.show_path = self.home +"/LibreLight/"
  825. if not os.path.isdir(self.show_path):
  826. os.mkdir(self.show_path)
  827. self.show_path += "/show/"
  828. if not os.path.isdir(self.show_path):
  829. os.mkdir(self.show_path)
  830. self.show_path += "/" +show_name +"/"
  831. if not os.path.isdir(self.show_path):
  832. os.mkdir(self.show_path)
  833. pass
  834. def _load(self,filename):
  835. xfname = self.show_path+"/"+str(filename)+".sav"
  836. print("load",xfname)
  837. f = open(xfname,"r")
  838. lines = f.readlines()
  839. f.close()
  840. data = OrderedDict()
  841. labels = OrderedDict()
  842. for line in lines:
  843. key,label,rdata = line.split("\t",2)
  844. key = int(key)
  845. #print(xfname,"load",key,label)
  846. #print(line)
  847. jdata = json.loads(rdata,object_pairs_hook=OrderedDict)
  848. nrnull = 0
  849. if "ATTRIBUT" in jdata: # translate old FIXTURES.fixtures start with 0 to 1
  850. for attr in jdata["ATTRIBUT"]:
  851. if "NR" in jdata["ATTRIBUT"][attr]:
  852. nr = jdata["ATTRIBUT"][attr]["NR"]
  853. if nr == 0:
  854. nrnull = 1
  855. break
  856. if nrnull:
  857. print("DMX NR IS NULL",attr,"CHANGE +1")
  858. for attr in jdata["ATTRIBUT"]:
  859. if "NR" in jdata["ATTRIBUT"][attr]:
  860. nr = jdata["ATTRIBUT"][attr]["NR"]
  861. if nr >= 0:
  862. jdata["ATTRIBUT"][attr]["NR"] +=1
  863. data[key] = jdata
  864. labels[key] = label
  865. return data,labels
  866. def _backup(self,filename,data,labels):
  867. #fixture
  868. #xfname = "show/"+show_name+"/"+str(filename)+".sav"
  869. xfname = self.show_path+"/"+str(filename)+".sav"
  870. print("backup",xfname)
  871. f = open(xfname,"w")
  872. for key in data:
  873. line = data[key]
  874. #print(line)
  875. label = "label"
  876. if key in labels:
  877. label = labels[key]
  878. if label == "Name-"+str(key):
  879. label = ""
  880. #print(xfname,"load",key,label,len(line))
  881. f.write( "{}\t{}\t{}\n".format( key,label,json.dumps(line) ) )
  882. f.close()
  883. class Event():
  884. def __init__(self,name):
  885. self.name=name
  886. #print("init",self)
  887. def event(self,event):
  888. print(self.name,event)
  889. class scroll():
  890. def __init__(self,canvas):
  891. self.canvas=canvas
  892. def config(self,event):
  893. canvas = self.canvas
  894. canvas.configure(scrollregion=canvas.bbox("all"))#,width=400,height=200)
  895. def hex_to_rgb(hex):
  896. return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
  897. class cb():
  898. def __init__(self,win):
  899. self.win = win
  900. def _callback(self,event):
  901. clobj=event.widget
  902. ## undermouse=find_withtag(master.CURRENT)
  903. undermouse=self.win.find_closest(self.win.CURRENT)
  904. print( repr(undermouse))
  905. def callback(self,event):
  906. print(__file__,self,"callback",event)
  907. cnv = self.win
  908. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  909. tags = cnv.gettags(item)
  910. #cnv.itemconfigure(self.tag, text=tags[0])
  911. print(tags,item)
  912. color = cnv.itemcget(item, "fill")
  913. cnv.itemconfig("all", width=1)#filla="green")
  914. cnv.itemconfig(item, width=3)#filla="green")
  915. print(color)
  916. print( hex_to_rgb(color[1:]))
  917. class GUI(Base):
  918. def __init__(self):
  919. super().__init__()
  920. self.load()
  921. self._XX = 0
  922. self.all_attr =["DIM","PAN","TILT"]
  923. self.elem_attr = {}
  924. self.fx_commands =["STONY_FX","FX OFF","\n"
  925. ,"FX:CIR","FX:PAN","FX:TILT","\n"
  926. ,"MSZ:","MSP:","MST:","MOF:","MBS:-","\n"
  927. ,"FX:DIM","FX:RED", "MO:on","DIR:1","WING:0","\n"
  928. ,"SZ:","SP:","ST:","OF:","BS:-","\n"
  929. , "FX:SIN","FX:COS","FX:BUM","FX:BUM2","FX:FD","FX:ON","FX:ON2" ]
  930. self.commands =["\n","ESC","CFG-BTN","LABEL","BACKUP","DEL","\n"
  931. ,"SELECT","FLASH","GO","FADE","MOVE","\n"
  932. ,"BLIND","CLEAR","REC","EDIT","COPY","\n"
  933. ]
  934. self.elem_fx_commands = {}
  935. self.val_fx_commands = {}
  936. self.elem_commands = {}
  937. self.val_commands = {}
  938. self.elem_presets = {}
  939. for i in range(8*8*8):
  940. if i not in PRESETS.val_presets:
  941. name = "Preset:"+str(i+1)+":\nXYZ"
  942. #self.presets[i] = [i]
  943. PRESETS.val_presets[i] = OrderedDict() # FIX
  944. PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
  945. PRESETS.label_presets[i] = "-"
  946. modes.set_cb(self.xcb)
  947. def button_refresh(self,name,color,fg=None):
  948. cprint("button_refresh",name,color)
  949. if name in self.elem_commands:
  950. self.elem_commands[name]["bg"] = color
  951. self.elem_commands[name].config(activebackground=color)
  952. if fg:
  953. self.elem_commands[name]["fg"] = fg
  954. print(dir(self.elem_commands[name]))
  955. def btn_cfg(self,nr):
  956. txt = PRESETS.btn_cfg(nr)
  957. txt = tkinter.simpledialog.askstring("CFG-BTN","GO,FLASH,TOGGLE,SWOP\n EXE:"+str(nr+1),initialvalue=txt)
  958. if txt:
  959. PRESETS.btn_cfg(nr,txt)
  960. self.elem_presets[nr]["text"] = PRESETS.get_btn_txt(nr)
  961. modes.val("CFG-BTN",0)
  962. def label(self,nr):
  963. txt = PRESETS.label(nr)
  964. txt = tkinter.simpledialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  965. if txt:
  966. PRESETS.label(nr,txt)
  967. self.elem_presets[nr]["text"] = PRESETS.get_btn_txt(nr)
  968. modes.val("LABEL", 0)
  969. def xcb(self,mode,value=None):
  970. cprint("MODE CALLBACK",mode,value,color="green",end="")
  971. #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
  972. if value:
  973. cprint("===== ON ======",color="red")
  974. self.button_refresh(mode,color="red")#,fg="blue")
  975. else:
  976. cprint("===== OFF ======",color="red")
  977. self.button_refresh(mode,color="lightgrey")#,fg="black")
  978. def load(self,fname=""):
  979. pass
  980. def exit(self):
  981. print("__del__",self)
  982. PRESETS.backup_presets()
  983. #print("********************************************************")
  984. FIXTURES.backup_patch()
  985. #print("*********del",self,"***********************************************")
  986. def refresh_exec(self):
  987. cprint("PRESET.refresh_exec()")
  988. self._XX +=1
  989. for k in PRESETS.val_presets:
  990. label = ""
  991. if k not in self.elem_presets:
  992. cprint("ERROR",k ,"not in elem_presets continue")
  993. continue
  994. if k in PRESETS.label_presets:
  995. label = PRESETS.label_presets[k]
  996. #print([label])
  997. b = self.elem_presets[k]
  998. if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
  999. sdata = PRESETS.val_presets[k]
  1000. BTN="go"
  1001. if "CFG" in sdata:#["BUTTON"] = "GO"
  1002. if "BUTTON" in sdata["CFG"]:
  1003. BTN = sdata["CFG"]["BUTTON"]
  1004. txt=str(k)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+label
  1005. #txt+=str(self._XX)
  1006. b["text"] = txt
  1007. b["bg"] = "yellow"
  1008. if len(sdata) > 1:
  1009. fx_color = 0
  1010. val_color = 0
  1011. for fix in sdata:
  1012. if fix == "CFG":
  1013. continue
  1014. #print( "$$$$",fix,sdata[fix])
  1015. for attr in sdata[fix]:
  1016. if "FX" in sdata[fix][attr]:
  1017. if sdata[fix][attr]["FX"]:
  1018. fx_color = 1
  1019. if "VALUE" in sdata[fix][attr]:
  1020. if sdata[fix][attr]["VALUE"] is not None:
  1021. val_color = 1
  1022. b["fg"] = "black"
  1023. if val_color:
  1024. b["bg"] = "gold"
  1025. if fx_color:
  1026. b["fg"] = "blue"
  1027. else:
  1028. if fx_color:
  1029. b["bg"] = "cyan"
  1030. else:
  1031. b["bg"] = "grey"
  1032. if "SEL" in txt:
  1033. b["fg"] = "black"
  1034. b["bg"] = "#5555ff"
  1035. elif "GO" in txt:
  1036. b["fg"] = "black"
  1037. elif "FL" in txt:
  1038. b["fg"] = "#7f00ff"
  1039. def refresh_fix(self):
  1040. for fix in FIXTURES.fixtures:
  1041. sdata = FIXTURES.fixtures[fix]
  1042. for attr in sdata["ATTRIBUT"]:
  1043. if "FINE" in attr:
  1044. continue
  1045. v2 = sdata["ATTRIBUT"][attr]["VALUE"]
  1046. if fix in self.elem_attr:
  1047. elem = self.elem_attr[fix][attr]
  1048. #print( attr,v2)
  1049. elem["text"] = "{} {:0.2f}".format(attr,v2)
  1050. if sdata["ATTRIBUT"][attr]["ACTIVE"]:
  1051. elem["bg"] = "yellow"
  1052. elem.config(activebackground="yellow")
  1053. else:
  1054. elem["bg"] = "grey"
  1055. elem.config(activebackground="grey")
  1056. if sdata["ATTRIBUT"][attr]["FX"]:
  1057. elem["fg"] = "blue"
  1058. else:
  1059. elem["fg"] = "black"
  1060. def preset_rec(self,nr):
  1061. print("------- STORE PRESET")
  1062. data = FIXTURES.get_active()
  1063. if modes.val("STONY_FX"):
  1064. PRESETS.rec(nr,data,"STONY_FX")
  1065. else:
  1066. PRESETS.rec(nr,data)
  1067. sdata=data
  1068. PRESETS.val_presets[nr] = sdata
  1069. master.refresh_exec()
  1070. return 1
  1071. def preset_select(self,nr):
  1072. print("SELECT PRESET")
  1073. sdata = PRESETS.val_presets[nr]
  1074. cmd = ""
  1075. for fix in sdata:
  1076. if fix == "CFG":
  1077. continue
  1078. for attr in sdata[fix]:
  1079. v2 = sdata[fix][attr]["VALUE"]
  1080. v2_fx = sdata[fix][attr]["FX"]
  1081. #print( self.data.elem_attr)
  1082. if fix in self.elem_attr:
  1083. elem = self.elem_attr[fix][attr]
  1084. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  1085. elem["bg"] = "yellow"
  1086. def preset_go(self,nr,val=None,xfade=fade,event=None):
  1087. print("GO PRESET FADE",nr,val)
  1088. rdata = PRESETS.get_raw_map(nr)
  1089. print("???????")
  1090. cfg = PRESETS.get_cfg(nr)
  1091. print("''''''''")
  1092. fcmd = FIXTURES.update_raw(rdata)
  1093. print("========")
  1094. #virtcmd = FIXTURES.get_virtual(rdata)
  1095. if not cfg:
  1096. cprint("NO CFG",cfg,nr)
  1097. return 0
  1098. xFLASH = 0
  1099. value=None
  1100. cprint("preset_go",nr,cfg)
  1101. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val: #FLASH
  1102. self.preset_select(nr)
  1103. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL"): #FLASH
  1104. xFLASH = 1
  1105. xfade = 0
  1106. if type(val) is not None and val == 0 :
  1107. value = "off"
  1108. if event:
  1109. if str(event.type) == "ButtonRelease" or event.type == '5' :
  1110. # 4 fix vor ThinkPad / Debian 11
  1111. if xFLASH:
  1112. value = "off"
  1113. cprint("preset_go() FLUSH",value,color="red")
  1114. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH)
  1115. elif not val:
  1116. cprint("preset_go() STOP",value,color="red")
  1117. elif modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"]):
  1118. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH)
  1119. self.refresh_exec()
  1120. def _preset_go(self,rdata,cfg,fcmd,value,xfade=fade,event=None,xFLASH=0):
  1121. cprint("PRESETS._preset_go()",len(rdata))
  1122. vvcmd = update_raw_dmx( rdata ,value,[xfade] )
  1123. fxcmd = update_raw_dmx( rdata ,value,[xfade],fx=1)
  1124. cmd = []
  1125. for vcmd,d in [[vvcmd,"d"],[fxcmd,"fx"]]:
  1126. if xFLASH:
  1127. d+="f"
  1128. for i,v in enumerate(fcmd):
  1129. DMX = fcmd[i]["DMX"]
  1130. if DMX and vcmd[i]:
  1131. xcmd = ",{}{}:{}".format(d,DMX,vcmd[i])
  1132. cmd.append( xcmd )
  1133. if "VIRTUAL" in fcmd[i]:
  1134. for a in fcmd[i]["VIRTUAL"]:
  1135. DMX = fcmd[i]["VIRTUAL"][a]
  1136. if DMX and vcmd[i]:
  1137. xcmd = ",{}{}:{}".format(d,DMX,vcmd[i])
  1138. cmd.append( xcmd )
  1139. cmd = "".join(cmd)
  1140. print("cmd",cmd)
  1141. if cmd and not modes.val("BLIND"):
  1142. client.send(cmd )
  1143. def draw_sub_dim(self,fix,data,c=0,r=0,frame=None):
  1144. Font = font.Font(family='Helvetica', size=9, weight='normal')
  1145. FontBold = font.Font(family='Helvetica', size=10, weight='bold')
  1146. i=0
  1147. if frame is None:
  1148. frame = tk.Frame(root,bg="black")
  1149. frame.pack(fill=tk.X, side=tk.TOP)
  1150. if fix not in self.elem_attr:
  1151. self.elem_attr[fix] = {}
  1152. for attr in data["ATTRIBUT"]:
  1153. if attr not in self.all_attr:
  1154. self.all_attr.append(attr)
  1155. if attr not in self.elem_attr[fix]:
  1156. self.elem_attr[fix][attr] = []
  1157. if attr.endswith("-FINE"):
  1158. continue
  1159. v= data["ATTRIBUT"][attr]["VALUE"]
  1160. b = tk.Button(frame,bg="lightblue",font=FontBold, text=""+str(fix)+" "+data["NAME"],width=4)
  1161. b.bind("<Button>",Xevent(fix=fix,mode="D-SELECT",elem=b).cb)
  1162. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1163. c+=1
  1164. b = tk.Button(frame,bg="grey",font=FontBold, text=str(attr)+' '+str(round(v,2)),width=6)
  1165. self.elem_attr[fix][attr] = b
  1166. b.bind("<Button>",Xevent(fix=fix,elem=b,attr=attr,mode="ENCODER",data=data).cb)
  1167. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1168. c+=1
  1169. if c >=12:
  1170. c=0
  1171. r+=1
  1172. return c,r
  1173. def draw_patch(self,xframe):
  1174. r=0
  1175. c=0
  1176. frame_dim = xframe
  1177. root = frame_dim
  1178. dim_frame = tk.Frame(root,bg="black")
  1179. dim_frame.pack(fill=tk.X, side=tk.TOP)
  1180. root = frame_patch
  1181. fix_frame = tk.Frame(root,bg="black")
  1182. canvas = tk.Canvas(root)
  1183. def yview(event):
  1184. print("yevent",event)
  1185. #print(dir(canvas))
  1186. yyy=20.1
  1187. fix_frame.yview_moveto(yyy)
  1188. fix_frame = tk.Frame(root,bg="black")
  1189. fix_frame.pack(fill=tk.X, side=tk.TOP)
  1190. i=0
  1191. c=0
  1192. r=0
  1193. for fix in FIXTURES.fixtures:
  1194. i+=1
  1195. data = FIXTURES.fixtures[fix]
  1196. #print("draw_patch", fix ,data )
  1197. if 1:
  1198. frame = fix_frame
  1199. b = tk.Button(frame,bg="lightblue", text="FIX:"+str(fix)+" "+data["NAME"],width=20)
  1200. b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  1201. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1202. c+=1
  1203. #r+=1
  1204. if fix not in self.elem_attr:
  1205. self.elem_attr[fix] = {}
  1206. patch = ["DMX","UNIVERS"]
  1207. for k in patch:
  1208. v=data[k]
  1209. b = tk.Button(frame,bg="grey", text=str(k)+' '+str(v),width=8)
  1210. #self.elem_attr[fix][attr] = b
  1211. #b.bind("<Button>",Xevent(fix=fix,elem=b,attr=attr,data=data).cb)
  1212. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1213. c+=1
  1214. if c >=8:
  1215. c=1
  1216. r+=1
  1217. for attr in data["ATTRIBUT"]:
  1218. if attr not in self.all_attr:
  1219. self.all_attr.append(attr)
  1220. if attr not in self.elem_attr[fix]:
  1221. self.elem_attr[fix][attr] = []
  1222. if attr.endswith("-FINE"):
  1223. continue
  1224. v= data["ATTRIBUT"][attr]["VALUE"]
  1225. b = tk.Button(frame,bg="grey", text=str(attr)+' '+str(round(v,2)),width=8)
  1226. self.elem_attr[fix][attr] = b
  1227. #b.bind("<Button>",Xevent(fix=fix,elem=b,attr=attr,data=data).cb)
  1228. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1229. c+=1
  1230. if c >=8:
  1231. c=1
  1232. r+=1
  1233. c=0
  1234. r+=1
  1235. def draw_fix(self,xframe,yframe=None):
  1236. r=0
  1237. c=0
  1238. frame_dim=xframe
  1239. if yframe:
  1240. frame_dim=yframe
  1241. frame_fix=xframe
  1242. root = frame_dim
  1243. dim_frame = tk.Frame(root,bg="black")
  1244. dim_frame.pack(fill=tk.X, side=tk.TOP)
  1245. root = frame_fix
  1246. fix_frame = tk.Frame(root,bg="black")
  1247. fix_frame.pack(fill=tk.X, side=tk.TOP)
  1248. Font = font.Font(family='Helvetica', size=9, weight='normal')
  1249. FontBold = font.Font(family='Helvetica', size=10, weight='bold')
  1250. i=0
  1251. c=0
  1252. r=0
  1253. dim_end=0
  1254. for fix in FIXTURES.fixtures:
  1255. i+=1
  1256. data = FIXTURES.fixtures[fix]
  1257. #print("draw_fix", fix ,data )
  1258. if(len(data["ATTRIBUT"].keys()) <= 1):
  1259. c,r=self.draw_sub_dim(fix,data,c=c,r=r,frame=dim_frame)
  1260. else:
  1261. if not dim_end:
  1262. dim_end=1
  1263. c=0
  1264. r=0
  1265. #self._draw_fix(fix,data,root=fix_frame)
  1266. frame = fix_frame
  1267. b = tk.Button(frame,bg="lightblue",font=FontBold, text="FIX:"+str(fix)+" "+data["NAME"],width=20)
  1268. b.bind("<Button>",Xevent(fix=fix,mode="SELECT",elem=b).cb)
  1269. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1270. c+=1
  1271. #r+=1
  1272. if fix not in self.elem_attr:
  1273. self.elem_attr[fix] = {}
  1274. for attr in data["ATTRIBUT"]:
  1275. if attr.endswith("-FINE"):
  1276. continue
  1277. if attr not in self.all_attr:
  1278. self.all_attr.append(attr)
  1279. if attr not in self.elem_attr[fix]:
  1280. self.elem_attr[fix][attr] = ["line1348",fix,attr]
  1281. v= data["ATTRIBUT"][attr]["VALUE"]
  1282. b = tk.Button(frame,bg="grey",font=FontBold, text=str(attr)+' '+str(round(v,2)),width=8)
  1283. self.elem_attr[fix][attr] = b
  1284. b.bind("<Button>",Xevent(fix=fix,elem=b,attr=attr,mode="ENCODER",data=data).cb)
  1285. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1286. c+=1
  1287. if c >=8:
  1288. c=1
  1289. r+=1
  1290. c=0
  1291. r+=1
  1292. def draw_enc(self,xframe):
  1293. root2 = xframe
  1294. i=0
  1295. c=0
  1296. r=0
  1297. frame = tk.Frame(root2,bg="black")
  1298. frame.pack( side=tk.TOP,expand=1,fill="both")
  1299. b = tk.Button(frame,bg="lightblue", text="ENCODER",width=6)
  1300. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1301. c+=1
  1302. for attr in self.all_attr:
  1303. if attr.endswith("-FINE"):
  1304. continue
  1305. v=0
  1306. b = tk.Button(frame,bg="orange", text=str(attr)+'',width=6)
  1307. b.bind("<Button>",Xevent(fix=0,elem=b,attr=attr,data=self,mode="ENCODER").cb)
  1308. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1309. c+=1
  1310. if c >=8:
  1311. c=0
  1312. r+=1
  1313. def draw_fx(self,xframe):
  1314. frame_fx=xframe
  1315. i=0
  1316. c=0
  1317. r=0
  1318. frame = tk.Frame(frame_fx,bg="black")
  1319. frame.pack(fill=tk.X, side=tk.TOP)
  1320. b = tk.Button(frame,bg="lightblue", text="FX.",width=6)
  1321. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  1322. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1323. c+=1
  1324. for comm in self.fx_commands:
  1325. if comm == "\n":
  1326. c=0
  1327. r+=1
  1328. continue
  1329. v=0
  1330. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  1331. if comm not in self.elem_fx_commands:
  1332. self.elem_fx_commands[comm] = b
  1333. self.val_fx_commands[comm] = 0
  1334. b.bind("<Button>",Xevent(fix=0,elem=b,attr=comm,data=self,mode="COMMAND").cb)
  1335. if comm == "BLIND":
  1336. b["bg"] = "grey"
  1337. elif comm == "CLEAR":
  1338. b["bg"] = "grey"
  1339. elif comm == "STONY_FX":
  1340. b["bg"] = "grey"
  1341. elif comm == "FADE":
  1342. b["bg"] = "green"
  1343. elif comm == "FX OFF":
  1344. b["bg"] = "magenta"
  1345. elif comm[:3] == "FX:":
  1346. b["text"] = comm #"BS:{}".format(fx_prm["BASE"])
  1347. b["bg"] = "#ffbf00"
  1348. elif comm == "MO:on":
  1349. b["text"] = comm #"BS:{}".format(fx_prm["BASE"])
  1350. b["bg"] = "lightgreen"
  1351. elif comm == "MO:on":
  1352. b["text"] = comm #"BS:{}".format(fx_prm["BASE"])
  1353. b["bg"] = "lightgreen"
  1354. elif comm == "SZ:":
  1355. b["text"] = "SZ:{:0.0f}".format(fx_prm["SIZE"])
  1356. b["bg"] = "lightgreen"
  1357. elif comm == "SP:":
  1358. b["text"] = "SP:{:0.0f}".format(fx_prm["SPEED"])
  1359. b["bg"] = "lightgreen"
  1360. elif comm == "ST:":
  1361. b["bg"] = "lightgreen"
  1362. elif comm == "OF:":
  1363. b["bg"] = "lightgreen"
  1364. elif comm == "BS:-":
  1365. b["text"] = "BS:{}".format(fx_prm["BASE"])
  1366. b["bg"] = "lightgreen"
  1367. elif comm[0] == "M":
  1368. b["text"] = comm #"BS:{}".format(fx_prm["BASE"])
  1369. b["bg"] = "lightgrey"
  1370. if comm:
  1371. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1372. c+=1
  1373. if c >=5:
  1374. c=0
  1375. r+=1
  1376. def draw_command(self,xframe):
  1377. frame_cmd=xframe
  1378. i=0
  1379. c=0
  1380. r=0
  1381. frame = tk.Frame(frame_cmd,bg="black")
  1382. frame.pack(fill=tk.X, side=tk.TOP)
  1383. b = tk.Button(frame,bg="lightblue", text="COMM.",width=6)
  1384. #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  1385. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1386. #r+=1
  1387. c+=1
  1388. for comm in self.commands:
  1389. if comm == "\n":
  1390. c=0
  1391. r+=1
  1392. continue
  1393. v=0
  1394. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  1395. if comm not in self.elem_commands:
  1396. self.elem_commands[comm] = b
  1397. self.val_commands[comm] = 0
  1398. b.bind("<Button>",Xevent(fix=0,elem=b,attr=comm,data=self,mode="COMMAND").cb)
  1399. if comm == "BLIND":
  1400. b["bg"] = "grey"
  1401. if comm == "CLEAR":
  1402. b["bg"] = "grey"
  1403. if comm == "STONY_FX":
  1404. b["bg"] = "grey"
  1405. if comm == "FADE":
  1406. b["bg"] = "green"
  1407. if comm == "FX OFF":
  1408. b["bg"] = "magenta"
  1409. if comm == "SZ:":
  1410. b["text"] = "SZ:{:0.0f}".format(fx_prm["SIZE"])
  1411. if comm == "SP:":
  1412. b["text"] = "SP:{:0.0f}".format(fx_prm["SPEED"])
  1413. if comm == "FADE":
  1414. b["text"] = "FADE:{:0.02f}".format(fade)
  1415. if comm == "ST:":
  1416. b["text"] = "ST:{:0.0f}".format(fx_prm["START"])
  1417. if comm == "OF:":
  1418. b["text"] = "OF:{:0.0f}".format(fx_prm["OFFSET"])
  1419. if comm == "BS:":
  1420. b["text"] = "BS:{}".format(fx_prm["BASE"])
  1421. if comm:
  1422. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1423. c+=1
  1424. if c >=5:
  1425. c=0
  1426. r+=1
  1427. def draw_preset(self,xframe):
  1428. i=0
  1429. c=0
  1430. r=0
  1431. root = xframe
  1432. frame = tk.Frame(root,bg="black")
  1433. frame.pack(fill=tk.X, side=tk.TOP)
  1434. i=0
  1435. for k in PRESETS.val_presets:
  1436. if i%(8*8)==0 or i ==0:
  1437. c=0
  1438. b = tk.Label(frame,bg="black", text="X" )
  1439. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1440. r+=1
  1441. c=0
  1442. b = tk.Button(frame,bg="lightblue", text="EXEC " )
  1443. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1444. c+=1
  1445. b = tk.Button(frame,bg="lightblue", text="PAGE " + str(int(i/(8*8))+1) )
  1446. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1447. c+=1
  1448. b = tk.Button(frame,bg="lightblue", text="<NAME>" )
  1449. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1450. r+=1
  1451. c=0
  1452. i+=1
  1453. v=0
  1454. label = ""
  1455. #if k in PRESETS.label_presets:
  1456. # label = PRESETS.label_presets[k]
  1457. # #print([label])
  1458. sdata=PRESETS.val_presets[k]
  1459. BTN="go"
  1460. if "CFG" in sdata:#["BUTTON"] = "GO"
  1461. if "BUTTON" in sdata["CFG"]:
  1462. BTN = sdata["CFG"]["BUTTON"]
  1463. txt=str(k+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+label
  1464. b = tk.Button(frame,bg="grey", text=txt,width=8,height=2)
  1465. b.bind("<Button>",Xevent(fix=0,elem=b,attr=k,data=self,mode="PRESET").cb)
  1466. b.bind("<ButtonRelease>",Xevent(fix=0,elem=b,attr=k,data=self,mode="PRESET").cb)
  1467. if k not in self.elem_presets:
  1468. self.elem_presets[k] = b
  1469. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1470. c+=1
  1471. if c >=8:
  1472. c=0
  1473. r+=1
  1474. self.refresh_exec()
  1475. def draw_input(self):
  1476. i=0
  1477. c=0
  1478. r=0
  1479. frame = tk.Frame(root2,bg="black")
  1480. frame.pack(fill=tk.X, side=tk.TOP)
  1481. b = tk.Label(frame,bg="black", text="------------------------ ---------------------------------------")
  1482. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1483. r=0
  1484. frame = tk.Frame(root2,bg="black")
  1485. frame.pack(fill=tk.X, side=tk.TOP)
  1486. b = tk.Label(frame, text="send:")
  1487. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1488. c+=1
  1489. b = tk.Entry(frame,bg="grey", text="",width=50)
  1490. self.entry = b
  1491. b.bind("<Button>",Xevent(fix=0,elem=b,attr="INPUT",data=self,mode="INPUT").cb)
  1492. b.bind("<Key>",Xevent(fix=0,elem=b,attr="INPUT",data=self,mode="INPUT").cb)
  1493. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1494. b.insert("end","d0:127,fx241:sinus:50:50:10,fx243:cosinus:50:50:10,d201:127,fx201:sinus:50:300:10")
  1495. r+=1
  1496. b = tk.Entry(frame,bg="grey", text="",width=20)
  1497. self.entry2 = b
  1498. b.bind("<Button>",Xevent(fix=0,elem=b,attr="INPUT",data=self,mode="INPUT2").cb)
  1499. b.bind("<Key>",Xevent(fix=0,elem=b,attr="INPUT",data=self,mode="INPUT2").cb)
  1500. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1501. b.insert("end","d1:0:4")
  1502. r+=1
  1503. b = tk.Entry(frame,bg="grey", text="",width=20)
  1504. self.entry3 = b
  1505. b.bind("<Button>",Xevent(fix=0,elem=b,attr="INPUT",data=self,mode="INPUT3").cb)
  1506. #b.bind("<B1-Motion>",Xevent(fix=0,elem=b,attr="INPUT",data=self,mode="INPUT3").cb)
  1507. b.bind("<Key>",Xevent(fix=0,elem=b,attr="INPUT",data=self,mode="INPUT3").cb)
  1508. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  1509. b.insert("end","fx:alloff:::")
  1510. def draw_colorpicker(self,xframe):
  1511. import lib.colorpicker as colp
  1512. class _CB():
  1513. def __init__(self):
  1514. self.old_color = (0,0,0)
  1515. def cb(self,event,data):
  1516. cprint("colorpicker CB")
  1517. if "color" in data and self.old_color != data["color"] or event.num==2:
  1518. self.old_color = data["color"]
  1519. else:
  1520. return 0
  1521. color = data["color"]
  1522. print("e",event,data)
  1523. print("e",dir(event))#.keys())
  1524. try:
  1525. print("e.state",event.state)
  1526. except:pass
  1527. set_fade = fade
  1528. if "color" in data and (event.num == 1 or event.num == 3 or event.num==2 or event.state in [256,1024]):
  1529. cr=None
  1530. cg=None
  1531. cb=None
  1532. if event.num == 1:
  1533. set_fade=fade
  1534. cr = color[0]
  1535. cg = color[1]
  1536. cb = color[2]
  1537. elif event.num == 3:
  1538. cr = color[0]
  1539. cg = color[1]
  1540. cb = color[2]
  1541. set_fade=0
  1542. elif event.num == 2:
  1543. cr= "click"
  1544. cg= "click"
  1545. cb= "click"
  1546. elif event.state == 256:
  1547. cr = color[0]
  1548. cg = color[1]
  1549. cb = color[2]
  1550. set_fade=0
  1551. else:
  1552. set_fade=0
  1553. if cr is not None:
  1554. FIXTURES.encoder(fix=0,attr="RED",xval=cr,xfade=set_fade)
  1555. if cg is not None:
  1556. FIXTURES.encoder(fix=0,attr="GREEN",xval=cg,xfade=set_fade)
  1557. if cb is not None:
  1558. FIXTURES.encoder(fix=0,attr="BLUE",xval=cb,xfade=set_fade)
  1559. master.refresh_fix()
  1560. print("PICK COLOR:",data["color"])
  1561. _cb=_CB()
  1562. colp.colorpicker(xframe,width=600,height=100, xcb=_cb.cb)
  1563. return 0
  1564. canvas=tk.Canvas(xframe,width=600,height=100)
  1565. canvas["bg"] = "yellow" #"green"
  1566. canvas.pack()
  1567. # RGB
  1568. x=0
  1569. y=0
  1570. j=0
  1571. d = 20
  1572. for i in range(0,d+1):
  1573. fi = int(i*255/d)
  1574. f = 255-fi
  1575. if i > d/2:
  1576. pass#break
  1577. color = '#%02x%02x%02x' % (f, fi, fi)
  1578. print( "farbe", i*10, j, f,fi,fi,color)
  1579. r = canvas.create_rectangle(x, y, x+20, y+20, fill=color)
  1580. x+=20
  1581. def render(self):
  1582. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  1583. self.draw_input()
  1584. def ScrollFrame(root,width=50,height=100,bd=1):
  1585. #print("ScrollFrame init",width,height)
  1586. aframe=tk.Frame(root,relief=tk.GROOVE)#,width=width,height=height,bd=bd)
  1587. #aframe.place(x=0,y=0)
  1588. aframe.pack(side="left",fill="both",expand=1) #x=0,y=0)
  1589. canvas=tk.Canvas(aframe,width=width-24,height=height)
  1590. canvas["bg"] = "black" #"green"
  1591. bframe=tk.Frame(canvas)#,width=width,height=height)
  1592. bframe["bg"] = "blue"
  1593. scrollbar=tk.Scrollbar(aframe,orient="vertical",command=canvas.yview,width=20)
  1594. canvas.configure(yscrollcommand=scrollbar.set)
  1595. scrollbar.pack(side="right",fill="y")
  1596. canvas.pack(side="left",expand=1,fill="both")
  1597. canvas.create_window((0,0),window=bframe,anchor='nw')
  1598. bframe.bind("<Configure>",scroll(canvas).config)
  1599. canvas.bind("<Button>",Event("XXX").event)
  1600. canvas.bind("<Key>",Event("XXX").event)
  1601. canvas.bind("<KeyRelease>",Event("XXX").event)
  1602. return bframe
  1603. #frame = ScrollFrame(root)
  1604. class GUIHandler():
  1605. def __init__(self):
  1606. pass
  1607. def update(self,fix,attr,args={}):
  1608. #print("GUIHandler",fix,attr,args)
  1609. for i,k in enumerate(args):
  1610. v = args[k]
  1611. #print("GUI-H", i,k,v)
  1612. class Fixtures(Base):
  1613. def __init__(self):
  1614. super().__init__()
  1615. #self.load()
  1616. self.fixtures = OrderedDict()
  1617. self.gui = GUIHandler()
  1618. def load_patch(self):
  1619. filename="patch"
  1620. d,l = self._load(filename)
  1621. self.fixtures = OrderedDict()
  1622. for i in l:
  1623. sdata = d[i]
  1624. for attr in sdata["ATTRIBUT"]:
  1625. sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
  1626. #print("load",filename,sdata)
  1627. #if "CFG" not in sdata:
  1628. # sdata["CFG"] = OrderedDict()
  1629. self.fixtures[str(i)] = sdata
  1630. #PRESETS.label_presets = l
  1631. def backup_patch(self):
  1632. filename = "patch"
  1633. data = self.fixtures
  1634. labels = {}
  1635. for k in data:
  1636. labels[k] = k
  1637. self._backup(filename,data,labels)
  1638. def fx_off(self,fix=None):
  1639. if not fix or fix == "all":
  1640. #self.data.elem_fx_commands[self.attr]["bg"] = "magenta"
  1641. for fix in self.fixtures:
  1642. data = self.fixtures[fix]
  1643. for attr in data["ATTRIBUT"]:
  1644. data["ATTRIBUT"][attr]["FX"] = ""
  1645. def update_raw(self,rdata):
  1646. cprint("update_raw",len(rdata))
  1647. cmd = []
  1648. for i,d in enumerate(rdata):
  1649. xcmd = {"DMX":""}
  1650. #print("fix:",i,d)
  1651. fix = d["FIX"]
  1652. attr = d["ATTR"]
  1653. v2 = d["VALUE"]
  1654. v2_fx = d["FX"]
  1655. if fix not in self.fixtures:
  1656. continue
  1657. sdata = self.fixtures[fix] #shortcat
  1658. ATTR = sdata["ATTRIBUT"]
  1659. sDMX = 0
  1660. if sdata["DMX"] > 0:
  1661. #print( sdata)
  1662. sDMX = (sdata["UNIVERS"]*512)+sdata["DMX"]
  1663. #sDMX =sdata["DMX"]
  1664. if attr not in ATTR:
  1665. continue
  1666. if ATTR[attr]["NR"] >= 0:
  1667. DMX = sDMX+ATTR[attr]["NR"]-1
  1668. xcmd["DMX"] = str(DMX)
  1669. else:
  1670. if attr == "DIM" and ATTR[attr]["NR"] < 0:
  1671. xcmd["VIRTUAL"] = {}
  1672. for a in ATTR:
  1673. if ATTR[a]["MASTER"]:
  1674. xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
  1675. #print( "VIRTUAL",xcmd)
  1676. cmd.append(xcmd)
  1677. v=ATTR[attr]["VALUE"]
  1678. if v2 is not None:
  1679. ATTR[attr]["VALUE"] = v2
  1680. #self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
  1681. text = str(attr)+' '+str(round(v,2))
  1682. self.gui.update(fix,attr,args={"text":text})
  1683. #print("END 5454 _=_=_=_=_==_")
  1684. return cmd
  1685. def encoder(self,fix,attr,xval="",xfade=0):
  1686. cprint("FIXTURES.encoder",fix,attr,xval,xfade,color="yellow")
  1687. if attr == "CLEAR":
  1688. self.clear()
  1689. return 0
  1690. if fix not in self.fixtures:
  1691. for fix in self.fixtures:
  1692. #cprint(fix,attr,xval)
  1693. data = self.fixtures[fix]
  1694. if attr in data["ATTRIBUT"]:
  1695. if xval == "click":
  1696. self.select(fix,attr,mode="on")
  1697. elif data["ATTRIBUT"][attr]["ACTIVE"]:
  1698. if fix: # prevent endless recursion
  1699. self.encoder(fix,attr,xval,xfade)
  1700. return 0
  1701. data = self.fixtures[fix]
  1702. if xval == "click":
  1703. #cprint(data)
  1704. return self.select(fix,attr,mode="toggle")
  1705. v2=data["ATTRIBUT"][attr]["VALUE"]
  1706. change=0
  1707. increment = 4.11
  1708. if xval == "+":
  1709. v2+= increment
  1710. v = "+{:0.4f}".format( increment ) #) #4.11"
  1711. change=1
  1712. elif xval == "-":
  1713. v2-= increment
  1714. v = "-{:0.4f}".format( increment ) #) #4.11"
  1715. change=1
  1716. elif type(xval) is int or type(xval) is float:
  1717. v2 = xval
  1718. change=1
  1719. if v2 < 0:
  1720. v2=0
  1721. elif v2 > 256:
  1722. v2=256
  1723. out = {}
  1724. if change:
  1725. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  1726. data["ATTRIBUT"][attr]["VALUE"] = v2
  1727. if xfade:
  1728. cmd=update_dmx(attr=attr,data=data)
  1729. else:
  1730. cmd=update_dmx(attr=attr,data=data,args=[0])
  1731. if cmd and not modes.val("BLIND"):
  1732. client.send(cmd)
  1733. return v2
  1734. def get_active(self):
  1735. cprint("get_active",self,"get_active")
  1736. CFG = OrderedDict()
  1737. sdata = OrderedDict()
  1738. sdata["CFG"] = CFG # OrderedDict()
  1739. sdata["CFG"]["FADE"] = fade
  1740. sdata["CFG"]["DEALY"] = 0
  1741. #sdata["CFG"]["BUTTON"] = "GO"
  1742. for fix in self.fixtures:
  1743. data = self.fixtures[fix]
  1744. for attr in data["ATTRIBUT"]:
  1745. if data["ATTRIBUT"][attr]["ACTIVE"]:
  1746. if fix not in sdata:
  1747. sdata[fix] = {}
  1748. if attr not in sdata[fix]:
  1749. sdata[fix][attr] = OrderedDict()
  1750. if not modes.val("STONY_FX"):
  1751. sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
  1752. #sdata[fix][attr]["FADE"] = fade
  1753. else:
  1754. sdata[fix][attr]["VALUE"] = None #data["ATTRIBUT"][attr]["VALUE"]
  1755. if "FX" not in data["ATTRIBUT"][attr]:
  1756. data["ATTRIBUT"][attr]["FX"] =""
  1757. sdata[fix][attr]["FX"] = data["ATTRIBUT"][attr]["FX"]
  1758. return sdata
  1759. def select(self,fix=None,attr=None,mode="on"):
  1760. cprint("FIXTURES.select()",fix,attr,mode,color="yellow")
  1761. out = 0
  1762. if fix in self.fixtures:
  1763. data = self.fixtures[fix]
  1764. if attr in data["ATTRIBUT"]:
  1765. if mode == "on":
  1766. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  1767. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  1768. out = 1
  1769. elif mode == "off":
  1770. if data["ATTRIBUT"][attr]["ACTIVE"]:
  1771. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  1772. out = 1
  1773. elif mode == "toggle":
  1774. if data["ATTRIBUT"][attr]["ACTIVE"]:
  1775. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  1776. else:
  1777. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  1778. out = 1
  1779. return out
  1780. def clear(self):
  1781. out = 0
  1782. for fix in self.fixtures:
  1783. data = self.fixtures[fix]
  1784. for attr in data["ATTRIBUT"]:
  1785. if attr.endswith("-FINE"):
  1786. continue
  1787. if data["ATTRIBUT"][attr]["ACTIVE"]:
  1788. out +=1
  1789. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  1790. return out
  1791. class Presets(Base):
  1792. def __init__(self):
  1793. super().__init__()
  1794. #self.load()
  1795. self._last_copy = None
  1796. self._last_move = None
  1797. def load_presets(self):
  1798. filename="presets"
  1799. d,l = self._load(filename)
  1800. for i in d:
  1801. sdata = d[i]
  1802. if "CFG" not in sdata:
  1803. sdata["CFG"] = OrderedDict()
  1804. if "FADE" not in sdata["CFG"]:
  1805. sdata["CFG"]["FADE"] = 4
  1806. if "DELAY" not in sdata["CFG"]:
  1807. sdata["CFG"]["DELAY"] = 0
  1808. if "BUTTON" not in sdata["CFG"]:
  1809. sdata["CFG"]["BUTTON"] = "GO"
  1810. self.val_presets = d
  1811. self.label_presets = l
  1812. def check_cfg(self,nr=None):
  1813. cprint("PRESETS.check_cfg()",nr)
  1814. ok = 0
  1815. if nr is not None:
  1816. ok += self._check_cfg(nr)
  1817. else:
  1818. for nr in self.val_presets:
  1819. ok += self._check_cfg(nr)
  1820. return ok
  1821. def _check_cfg(self,nr):
  1822. #cprint("PRESETS._check_cfg()",nr)
  1823. ok=0
  1824. if nr in self.val_presets:
  1825. sdata = self.val_presets[nr]
  1826. if "CFG" not in sdata:
  1827. sdata["CFG"] = OrderedDict()
  1828. ok += 1
  1829. if "FADE" not in sdata["CFG"]:
  1830. sdata["CFG"]["FADE"] = 4
  1831. ok += 1
  1832. if "DELAY" not in sdata["CFG"]:
  1833. sdata["CFG"]["DELAY"] = 0
  1834. ok += 1
  1835. if "BUTTON" not in sdata["CFG"]:
  1836. sdata["CFG"]["BUTTON"] = "GO"
  1837. ok += 1
  1838. if ok:
  1839. cprint("REPAIR CFG's",nr,sdata["CFG"],color="red")
  1840. else:
  1841. cprint("nr not in data ",nr,color="red")
  1842. return ok
  1843. def backup_presets(self):
  1844. filename = "presets"
  1845. data = self.val_presets
  1846. labels = self.label_presets
  1847. self._backup(filename,data,labels)
  1848. def get_cfg(self,nr):
  1849. cprint("PRESETS.get_cfg()",nr)
  1850. self.check_cfg(nr)
  1851. if nr not in self.val_presets:
  1852. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  1853. return {}
  1854. if "CFG" in self.val_presets[nr]:
  1855. return self.val_presets[nr]["CFG"]
  1856. def get_raw_map(self,nr):
  1857. print("get_raw_map",nr)
  1858. if nr not in self.val_presets:
  1859. self.val_presets[nr] = OrderedDict()
  1860. self.val_presets[nr]["VALUE"] = 0
  1861. self.val_presets[nr]["FX"] = ""
  1862. sdata = self.val_presets[nr]
  1863. cmd = ""
  1864. out = []
  1865. dmx=-1
  1866. for fix in sdata:
  1867. if fix == "CFG":
  1868. #print("CFG",nr,sdata[fix])
  1869. continue
  1870. for attr in sdata[fix]:
  1871. x = {}
  1872. #print("RAW",attr)
  1873. x["FIX"] = fix
  1874. x["ATTR"] = attr
  1875. x["VALUE"] = sdata[fix][attr]["VALUE"]
  1876. x["FX"] = sdata[fix][attr]["FX"]
  1877. #x["DMX"] = sdata[fix][attr]["NR"]
  1878. out.append(x)
  1879. return out
  1880. def get_btn_txt(self,nr):
  1881. sdata=self.val_presets[nr]
  1882. BTN="go"
  1883. if "CFG" in sdata:
  1884. if "BUTTON" in sdata["CFG"]:
  1885. BTN = sdata["CFG"]["BUTTON"]
  1886. _label = self.label_presets[nr] # = label
  1887. txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  1888. print("get_btn_txt",nr,[txt])
  1889. return txt
  1890. def btn_cfg(self,nr,txt=None):
  1891. if nr not in self.val_presets:
  1892. return ""
  1893. if "CFG" not in self.val_presets[nr]:
  1894. self.val_presets[nr]["CFG"] = OrderedDict()
  1895. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  1896. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  1897. if type(txt) is str:
  1898. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  1899. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  1900. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  1901. print("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  1902. return self.val_presets[nr]["CFG"]["BUTTON"]
  1903. def label(self,nr,txt=None):
  1904. if nr not in self.label_presets:
  1905. return ""
  1906. if type(txt) is str:
  1907. self.label_presets[nr] = txt
  1908. print("set label",nr,[txt])
  1909. print("??? ?? set label",nr,[txt])
  1910. return self.label_presets[nr]
  1911. def clear_move(self):
  1912. cprint("PRESETS.clear_move()",end=" ")
  1913. self.clear_copy()
  1914. def clear_copy(self):
  1915. cprint("PRESETS.clear_copy()",end=" ")
  1916. if self._last_copy is not None:
  1917. cprint("=OK=",color="red")
  1918. self._last_copy = None
  1919. else:
  1920. cprint("=NONE=",color="green")
  1921. def copy(self,nr,overwrite=1):
  1922. cprint("PRESETS._copy",nr,"last",self._last_copy)
  1923. if nr:
  1924. if self._last_copy is not None:
  1925. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  1926. return ok #ok
  1927. else:
  1928. self._last_copy = nr
  1929. cprint("PRESETS.copy START ",color="red")
  1930. return 0
  1931. return 1 # on error reset move
  1932. def _copy(self,nr_from,nr_to,overwrite=1):
  1933. cprint("PRESETS._copy",nr_from,"to",nr_to)
  1934. self.check_cfg(nr_from)
  1935. if self._last_copy is None:
  1936. cprint("PRESETS._copy last nr is None")
  1937. return 0
  1938. if nr_from in self.val_presets and nr_to in self.val_presets:
  1939. fdata = self.val_presets[nr_from]
  1940. tdata = self.val_presets[nr_to]
  1941. #cprint(fdata)
  1942. flabel = self.label_presets[nr_from]
  1943. tlabel = self.label_presets[nr_to]
  1944. self.val_presets[nr_to] = fdata
  1945. self.label_presets[nr_to] = flabel
  1946. if not overwrite: #default
  1947. cprint("overwrite",overwrite)
  1948. self.val_presets[nr_from] = tdata
  1949. self.label_presets[nr_from] = tlabel
  1950. #self.label_presets[nr_from] = "MOVE"
  1951. self.clear_copy()
  1952. cprint("PRESETS.copy OK",color="red")
  1953. return 1
  1954. def move(self,nr):
  1955. cprint("PRESETS.move",self._last_copy,"to",nr)
  1956. if nr:
  1957. last = self._last_copy
  1958. ok= self.copy(nr,overwrite=0)
  1959. if ok and last:
  1960. cprint("PRESETS.move OK",color="red")
  1961. #self.delete(last)
  1962. return ok #ok
  1963. return 0 # on error reset move
  1964. def delete(self,nr):
  1965. cprint("PRESETS.delete",nr)
  1966. ok=0
  1967. if nr in self.val_presets:
  1968. self.val_presets[nr] = OrderedDict()
  1969. self.label_presets[nr] = ""
  1970. ok = 1
  1971. self.check_cfg(nr)
  1972. return ok
  1973. def rec(self,nr,data,arg=""):
  1974. print("rec",self,"rec()",data,arg)
  1975. self.check_cfg(nr)
  1976. self.val_presets[nr] = data
  1977. return 1
  1978. class GUI_grid():
  1979. def __init__(self,root,data,title="tilte",width=800):
  1980. self.data = data
  1981. self.frame = tk.Frame(root,bg="black",width=width)
  1982. self.frame.pack(fill=tk.BOTH, side=tk.LEFT)
  1983. r=0
  1984. c=0
  1985. i=1
  1986. for row in data:
  1987. self.b = tk.Button(self.frame,bg="lightblue", text=row["text"],width=11,height=4)
  1988. #self.b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
  1989. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  1990. c+=1
  1991. if c % 8 == 0:
  1992. r+=1
  1993. c=0
  1994. i+=1
  1995. self.frame.pack()
  1996. class BEvent():
  1997. def __init__(self,data,cb):
  1998. self._data = data
  1999. self._cb = cb
  2000. def cb(self,event):
  2001. #print(self,event)
  2002. self._cb(event,self._data)
  2003. class GUI_menu():
  2004. def __init__(self,root,data,title="tilte",width=800):
  2005. global tk
  2006. self.data = data
  2007. self.frame = tk.Frame(root,bg="black",width=width)
  2008. self.frame.pack(fill=tk.BOTH, side=tk.LEFT)
  2009. r=0
  2010. c=0
  2011. i=1
  2012. self.b = tk.Label(self.frame,bg="blue", text="MAIN:MENU",width=13,height=1)
  2013. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  2014. r+=1
  2015. for row in data:
  2016. #print(i)
  2017. #row = data[i]
  2018. self.b = tk.Button(self.frame,bg="lightblue", text=row["text"],width=13,height=3)
  2019. self.b.bind("<Button>",BEvent({"NR":i,"text":row["text"]},self.callback).cb)
  2020. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  2021. r+=1
  2022. i+=1
  2023. self.frame.pack()
  2024. def callback(self,event,data={}):
  2025. print("callback543",self,event,data)
  2026. window_manager.top(data["text"])# = WindowManager()
  2027. lf_nr = 0
  2028. class GUIWindow():
  2029. def __init__(self,title="tilte",master=0,width=100,height=100,left=None,top=None):
  2030. global lf_nr
  2031. if master:
  2032. #Font = font.Font(family='Helvetica', size=9, weight='normal')
  2033. self.tk = tkinter.Tk()#font=Font) #Toplevel()
  2034. #Font = font.Font(family='Helvetica', size=9, weight='normal')
  2035. #FontBold = font.Font(family='Helvetica', size=10, weight='bold')
  2036. #self.tk.default_font.configure(size=9)
  2037. #self.tk.option_add("*Font", FontBold)
  2038. #self.tk.configure(font=Font)
  2039. else:
  2040. self.tk = tkinter.Toplevel()
  2041. self.tk["bg"] = "black"
  2042. self.tk.bind("<Button>",self.callback)
  2043. self.tk.bind("<Key>",self.callback)
  2044. self.tk.bind("<KeyRelease>",self.callback)
  2045. self.tk.title(""+str(title)+" "+str(lf_nr)+":"+str(rnd_id))
  2046. lf_nr+=1
  2047. #self.tk.geometry("270x600+0+65")
  2048. geo ="{}x{}".format(width,height)
  2049. if left is not None:
  2050. geo += "+{}".format(left)
  2051. if top is not None:
  2052. geo += "+{}".format(top)
  2053. #self._event_clear = Xevent(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
  2054. self.tk.geometry(geo)
  2055. def title(self,title=None):
  2056. if title is None:
  2057. return self.tk.title()
  2058. else:
  2059. return self.tk.title(title)
  2060. def show(self):
  2061. pass
  2062. #self.frame.pack()
  2063. def mainloop(self):
  2064. self.tk.mainloop()
  2065. def callback(self,event,data={}):#value=255):
  2066. print()
  2067. print()
  2068. cprint("<GUI>",self,event,event.state,data,[event.type],color="yellow")
  2069. value = 255
  2070. if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
  2071. value = 0
  2072. if "keysym" in dir(event):
  2073. if "Escape" == event.keysym:
  2074. FIXTURES.clear()
  2075. modes.val("ESC",1)
  2076. master.refresh_fix()
  2077. elif event.keysym in "ebfclrms" and value:
  2078. if "e" == event.keysym:
  2079. modes.val("EDIT",1)
  2080. elif "b" == event.keysym:
  2081. modes.val("BLIND",1)
  2082. elif "f" == event.keysym:
  2083. modes.val("FLASH",1)
  2084. elif "c" == event.keysym:
  2085. modes.val("CFG-BTN",1)
  2086. elif "l" == event.keysym:
  2087. modes.val("LABEL",1)
  2088. elif "r" == event.keysym:
  2089. modes.val("REC",1)
  2090. elif "m" == event.keysym:
  2091. x=modes.val("MOVE",1)
  2092. if not x:
  2093. PRESETS.clear_move()
  2094. elif "s" == event.keysym:
  2095. modes.val("SELECT",1)
  2096. elif event.keysym in ["1","2","3","4","5","6","7","8","9","0"]:
  2097. nr = int( event.keysym[1])-1
  2098. cprint("F-KEY",value,nr)
  2099. master.preset_go(129-1+nr,xfade=fade,val=value)
  2100. elif event.keysym in ["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]:
  2101. nr = int( event.keysym[1])-1
  2102. cprint("F-KEY",value,nr)
  2103. master.preset_go(65-1+nr,xfade=fade,val=value)
  2104. elif "End" == event.keysym:
  2105. FIXTURES.fx_off("all")
  2106. CONSOLE.fx_off("all")
  2107. CONSOLE.flash_off("all")
  2108. elif "Delete" == event.keysym:
  2109. #PRESETS.delete(nr)
  2110. if value:
  2111. modes.val("DEL",1)
  2112. class WindowManager():
  2113. def __init__(self):
  2114. self.windows = {}
  2115. self.nr= 0
  2116. self.first=""
  2117. def new(self,w,name=""):
  2118. if not self.first:
  2119. if name:
  2120. self.first = name
  2121. else:
  2122. self.first = str(self.nr)
  2123. w.tk.attributes('-topmost',True)
  2124. if name:
  2125. self.windows[str(name)] = w
  2126. else:
  2127. self.windows[str(self.nr)] = w
  2128. self.nr+=1
  2129. #w.show()
  2130. def mainloop(self):
  2131. self.windows[self.first].mainloop()
  2132. def top(self,name):
  2133. name = str(name)
  2134. if name in self.windows:
  2135. self.windows[name].tk.attributes('-topmost',True)
  2136. self.windows[name].tk.attributes('-topmost',False)
  2137. else:
  2138. print(name,"not in self.windows",self.windows.keys())
  2139. class Console():
  2140. def __init__(self):
  2141. pass
  2142. def flash_off(self,fix):
  2143. client.send("df0:alloff:::,")
  2144. def fx_off(self,fix):
  2145. cprint("Console.fx_off()",fix)
  2146. if not fix or fix == "all":
  2147. client.send("fx0:alloff:,fxf:alloff:,")
  2148. client.send("df0:alloff:::,")
  2149. return 0
  2150. window_manager = WindowManager()
  2151. CONSOLE = Console()
  2152. PRESETS = Presets()
  2153. PRESETS.load_presets()
  2154. FIXTURES = Fixtures()
  2155. FIXTURES.load_patch()
  2156. master = GUI()
  2157. w = GUIWindow("MAIN",master=1,width=130,height=450,left=0,top=65)
  2158. data = []
  2159. #data.append({"text":"COMMAND"})
  2160. data.append({"text":"EXEC"})
  2161. data.append({"text":"DIMMER"})
  2162. data.append({"text":"FIXTURES"})
  2163. f = GUI_menu(w.tk,data)
  2164. window_manager.new(w)
  2165. name="DIMMER"
  2166. w = GUIWindow(name,master=0,width=800,height=400,left=140,top=65)
  2167. w2 = ScrollFrame(w.tk,width=800,height=400)
  2168. #frame_dim = w1 # w.tk
  2169. #master.draw_dim(w1.tk)
  2170. window_manager.new(w,name)
  2171. name="FIXTURES"
  2172. w = GUIWindow(name,master=0,width=800,height=400,left=140,top=65)
  2173. w1 = ScrollFrame(w.tk,width=800,height=400)
  2174. #frame_fix = w1 #w.tk
  2175. master.draw_fix(w1,w2)#.tk)
  2176. window_manager.new(w,name)
  2177. name="ENCODER"
  2178. ww = GUIWindow(name,master=0,width=800,height=50,left=140,top=500)
  2179. Xroot = ww.tk
  2180. #default_font = font.Font(family='Helvetica', size=12, weight='bold')
  2181. Font = font.Font(family='Helvetica', size=9, weight='normal')
  2182. FontBold = font.Font(family='Helvetica', size=10, weight='bold')
  2183. #default_font.configure(size=9)
  2184. Xroot.option_add("*Font", FontBold)
  2185. w = None
  2186. root = tk.Frame(Xroot,bg="black",width="10px")
  2187. root.pack(fill=tk.BOTH,expand=0, side=tk.LEFT)
  2188. root3 = tk.Frame(Xroot,bg="black",width="20px")
  2189. root3.pack(fill=tk.BOTH,expand=0, side=tk.LEFT)
  2190. root2 = tk.Frame(Xroot,bg="black",width="1px")
  2191. master.draw_enc(root2)
  2192. root2.pack(fill=tk.BOTH,expand=0, side=tk.LEFT)
  2193. #w = GUIWindow("GRID",master=0,width=1000,height=200,left=232,top=65)
  2194. #data = []
  2195. #for i in range(10):
  2196. # data.append({"text":"P {:02}".format(i+1)})
  2197. #w = GUI_grid(w.tk,data)
  2198. #window_manager.new(w)
  2199. name = "COMMAND"
  2200. w = GUIWindow(name,master=0,width=350,height=200,left=950,top=65)
  2201. master.draw_command(w.tk)
  2202. window_manager.new(w,name)
  2203. name="EXEC"
  2204. w = GUIWindow(name,master=0,width=800,height=400,left=140,top=65)
  2205. w1 = ScrollFrame(w.tk,width=800,height=400)
  2206. #frame_exe = w.tk
  2207. master.draw_preset(w1)#w.tk)
  2208. window_manager.new(w,name)
  2209. name="PATCH"
  2210. w = GUIWindow(name,master=0,width=800,height=400,left=140,top=65)
  2211. w1 = ScrollFrame(w.tk,width=800,height=400)
  2212. frame_patch = w1 #w.tk
  2213. window_manager.new(w,name)
  2214. name="FX"
  2215. w = GUIWindow(name,master=0,width=350,height=250,left=950,top=305)
  2216. #frame_fx = w.tk
  2217. master.draw_fx(w.tk)
  2218. window_manager.new(w,name)
  2219. #LibreLightDesk
  2220. name="COLERPICKER"
  2221. w = GUIWindow(name,master=0,width=580,height=100,left=80,top=620)
  2222. master.draw_colorpicker(w.tk)
  2223. window_manager.new(w,name)
  2224. #Xroot = tk.Tk()
  2225. #Xroot["bg"] = "black" #white
  2226. #Xroot.title( xtitle+" "+str(rnd_id) )
  2227. #Xroot.geometry("1024x800+130+65")
  2228. master.render()
  2229. #w = frame_fix #GUIWindow("OLD",master=0,width=800,height=500,left=130,top=65)
  2230. window_manager.new(w,name)
  2231. try:
  2232. #root.mainloop()
  2233. #tk.mainloop()
  2234. window_manager.mainloop()
  2235. finally:
  2236. master.exit()