_LibreLightDesk.py 73 KB

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