_LibreLightDesk.py 89 KB

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