_LibreLightDesk.py 89 KB

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