_LibreLightDesk.py 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138
  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@librelight.de
  15. """
  16. import random
  17. rnd_id = str(random.randint(1000,9000))
  18. rnd_id += " beta 23-03 "
  19. import subprocess
  20. import string
  21. _gcmd=['git', 'rev-parse', '--short', 'HEAD']
  22. try:
  23. r = subprocess.check_output(_gcmd)
  24. rnd_id += r.decode('ascii').strip()
  25. except Exception as e:
  26. rnd_id += " no git"
  27. #rnd_id += " ".join(_gcmd) +str(e)
  28. try:
  29. xtitle = __file__
  30. except:
  31. xtitle = "__file__"
  32. if "/" in xtitle:
  33. xtitle = xtitle.split("/")[-1]
  34. import sys
  35. sys.stdout.write("\x1b]2;"+str(xtitle)+" "+str(rnd_id)+"\x07") # terminal title
  36. import json
  37. import time
  38. import sys
  39. import os
  40. import _thread as thread
  41. import traceback
  42. import tkinter
  43. import tkinter as tk
  44. from tkinter import font
  45. space_font = None
  46. import tkinter.simpledialog
  47. from idlelib.tooltip import Hovertip
  48. INIT_OK = 0
  49. _global_short_key = 1
  50. import lib.zchat as chat
  51. import lib.motion as motion
  52. from collections import OrderedDict
  53. _POS_LEFT = 0
  54. _POS_TOP = 15
  55. _config = []
  56. try:
  57. h = os.environ["HOME"]
  58. lines = [{}]
  59. try:
  60. f = open(h +"/LibreLight/config.json")
  61. lines = f.readlines()
  62. except FileNotFoundError as e: #Exception as e:
  63. f = open(h +"/LibreLight/config.json","w")
  64. f.write('{"POS_TOP":0}\n{"POS_LEFT":0}')
  65. f.close()
  66. print("Exception:",e)
  67. for line in lines:
  68. line=line.strip()
  69. print("config read",line)
  70. row = json.loads(line)
  71. _config.append(row)
  72. except Exception as e:
  73. print("Exception:",e)
  74. try:
  75. for row in _config:
  76. print("config:",row)
  77. if "POS_LEFT" in row:
  78. _POS_LEFT = int(row["POS_LEFT"])
  79. if "POS_TOP" in row:
  80. _POS_TOP = int(row["POS_TOP"])
  81. except Exception as e:
  82. print("Exception:",e)
  83. def showwarning(msg="<ERROR>",title="<TITLE>"):
  84. _main = tkinter.Tk()
  85. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  86. print("showwarning",defaultFont)
  87. defaultFont.configure(family="FreeSans",
  88. size=10,
  89. weight="normal")
  90. geo ="{}x{}".format(20,20)
  91. _main.geometry(geo)
  92. def _quit():
  93. time.sleep(.02)
  94. _main.quit()
  95. thread.start_new_thread(_main.mainloop,())
  96. #_main.quit()
  97. #msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  98. #msg += "please check\n"
  99. #msg += "-{}init.txt\n".format(self.show_path0)
  100. #msg += "-{}".format(self.show_path1)
  101. r=tkinter.messagebox.showwarning(message=msg,title=title,parent=None)
  102. CUES = OrderedDict()
  103. groups = OrderedDict()
  104. class Modes():
  105. def __init__(self):
  106. self.modes = {}
  107. self.__cfg = {}
  108. self.__cb = None
  109. def val(self,mode,value=None): #like jquery
  110. if value is not None:
  111. return self.set(mode,value)
  112. elif mode in self.modes:
  113. return self.modes[mode]
  114. def get(self,mode,value=None):
  115. return self.val(mode,value)
  116. def __check(self,mode):
  117. if mode not in self.modes:
  118. self.modes[mode] = 0
  119. self.__cfg[mode] = 0
  120. def cfg(self,mode,data={}):
  121. self.__check(mode)
  122. if type(data) is dict:
  123. for k in data:
  124. v = data[k]
  125. if v not in self.__cfg:
  126. self.__cfg[k] = v
  127. return 1
  128. elif type(data) is str:
  129. if data in self.__cfg:
  130. return self.__cfg[data]
  131. def set(self,mode,value):
  132. protected = ["BLIND","CLEAR","REC-FX"]
  133. self.__check(mode)
  134. if mode == "CLEAR":
  135. return 1
  136. elif mode == "ESC":
  137. for m in self.modes:
  138. print("ESC",m)
  139. if m == "COPY":
  140. PRESETS.clear_copy()
  141. if m == "MOVE":
  142. PRESETS.clear_move()
  143. if m != "BLIND":
  144. self.modes[m] = 0
  145. self.callback(m)
  146. return 1
  147. if value:
  148. for m in self.modes:
  149. if m not in protected and mode not in protected and m != mode:
  150. #cprint("-#-# clear mode",mode,m,value,color="red")
  151. if self.modes[m]:
  152. self.modes[m]= 0
  153. self.callback(m)
  154. if self.modes[mode] and value == 1:
  155. if modes == "MOVE":
  156. PRESETS.clear_move()
  157. if modes == "COPY":
  158. PRESETS.clear_copy()
  159. self.modes[mode] = 0 # value
  160. else:
  161. self.modes[mode] = value #1 #value
  162. else:
  163. self.modes[mode] = 0 #value
  164. if modes == "COPY":
  165. PRESETS.clear_copy()
  166. if modes == "MOVE":
  167. PRESETS.clear_move()
  168. self.callback(mode)
  169. return value
  170. def set_cb(self,cb):
  171. if cb:
  172. self.__cb = cb
  173. def callback(self,mode):
  174. if self.__cb is not None and mode in self.modes:
  175. value = self.modes[mode]
  176. self.__cb(mode=mode,value=value)
  177. modes = Modes()
  178. #modes.val("BLIND", 0)
  179. #modes.modes["BLIND"] = 0
  180. modes.modes["ESC"] = 0
  181. modes.modes["REC"] = 0
  182. modes.modes["EDIT"] = 0
  183. modes.modes["MOVE"] = 0
  184. modes.modes["FLASH"] = 0
  185. modes.modes["GO"] = 0
  186. modes.modes["DEL"] = 0
  187. modes.modes["REC-FX"] = 0
  188. modes.modes["SELECT"] = 0
  189. modes.modes["CFG-BTN"] = 0
  190. modes.modes["LABEL"] = 0
  191. def xcb(mode,value=None):
  192. print("xcb","MODE CALLBACK",mode,value)
  193. if mode == "REC-FX":
  194. print("xcb",modes.val("REC-FX"))
  195. #modes.set_cb(xcb)
  196. POS = ["PAN","TILT","MOTION"]
  197. COLOR = ["RED","GREEN","BLUE","COLOR"]
  198. BEAM = ["GOBO","G-ROT","PRISMA","P-ROT","FOCUS","SPEED"]
  199. INT = ["DIM","SHUTTER","STROBE","FUNC"]
  200. #client = chat.tcp_sender(port=50001)
  201. def set_exec_fader(nr,val,color=""):
  202. exec_wing = window_manager.get_obj(name="EXEC-WING") #= WindowManager()
  203. if not exec_wing:
  204. return
  205. #print(exec_wing)
  206. try:
  207. exec_wing.set_fader(nr,val,color=color)
  208. except Exception as e:
  209. print("exception",e)
  210. #print("remote in:",round(time.time(),0),"x",i,v)
  211. # remote input - start (memcached)
  212. def JCB(x):
  213. for i in x:
  214. jv = x[i]
  215. try:
  216. jv = json.loads(jv)
  217. jv = jv[0]
  218. #print(jv)
  219. v = jv["iVAL"]
  220. #exec_wing.set_fader(0,v)
  221. set_exec_fader(0,v)
  222. set_exec_fader(1,200-v)
  223. set_exec_fader(2,int(v/2+10))
  224. except Exception as e:
  225. print("exception",e)
  226. #print("remote in:",round(time.time(),0),"x",i,v)
  227. #chat.cmd(JCB,port=30002) # SERVER
  228. thread.start_new_thread(chat.cmd,(JCB,30002)) # SERVER
  229. # remote input - end
  230. # read memcachd
  231. memcache = None
  232. try:
  233. import memcache
  234. except Exception as e:
  235. print("Exception IMPORT ERROR",e)
  236. class MC():
  237. def __init__(self,server="127.0.0.1",port=11211):
  238. print("----------- MC")
  239. try:
  240. self.mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  241. #self.init()
  242. except Exception as e:
  243. print("Exception",e)
  244. # def init(self):
  245. data = {}
  246. start = time.time()
  247. delta = start
  248. index = self.mc.get("index")
  249. if index:
  250. for i in index:
  251. print("key",i)
  252. self.fader_map = []
  253. for i in range(30+1):
  254. self.fader_map.append({"UNIV":0,"DMX":0})
  255. try:
  256. f = open("/home/user/LibreLight/fader.json")
  257. lines = f.readlines()
  258. for i,line in enumerate(lines):
  259. jdata = json.loads(line)
  260. print("fader_map ->>",i,jdata)
  261. self.fader_map[i] = jdata
  262. except Exception as e:
  263. print("Except Fader_map",e)
  264. #exit()
  265. def ok(self):
  266. if self.mc:
  267. return 1
  268. return 0
  269. def test(self):
  270. if not self.ok():
  271. return
  272. self.mc.set("some_key", "Some value")
  273. self.value = mc.get("some_key")
  274. self.mc.set("another_key", 3)
  275. self.mc.delete("another_key")
  276. def loop(self):
  277. thread.start_new_thread(self._loop,())
  278. if not self.ok():
  279. return
  280. def _loop(self):
  281. print("++++++++++ start.memcachd read loop",self )
  282. while 1:
  283. send = 0
  284. #print("+")
  285. try:
  286. ip="10.10.10.13:0"
  287. #ip="ltp-out:0"
  288. #print(ip)
  289. x=self.mc.get(ip)
  290. if x:
  291. #print(ip,x)
  292. #val = x[501-1]
  293. #val = x[141-1]
  294. for i, line in enumerate(self.fader_map):
  295. try:
  296. #print(i,line)
  297. dmx = int(line["DMX"])
  298. if dmx > 0:
  299. val = x[dmx-1]
  300. #print("mc val",val)
  301. set_exec_fader(i,val,color="#aaa")
  302. except:pass
  303. time.sleep(0.01)
  304. except Exception as e:
  305. print("exc", e)
  306. time.sleep(1)
  307. _mc=MC()
  308. _mc.loop()
  309. #time.sleep(1)
  310. #exit()
  311. jclient = chat.tcp_sender()#port=50001)
  312. import zlib
  313. def jclient_send(data):
  314. t_start = time.time()
  315. jtxt = data
  316. jdatas = []
  317. for jdata in data:
  318. if "CMD" in jdata:
  319. try:
  320. jdatas.append(jdata)
  321. except Exception as e:
  322. cprint("jclient_send, Exception DMX ",color="red")
  323. cprint("",jdata,color="red")
  324. cprint("-----",color="red")
  325. elif "DMX" in jdata:
  326. #print(jdata)
  327. try:
  328. dmx = int(jdata["DMX"])
  329. if int(dmx) >= 1: # ignore DMX lower one
  330. if "ATTR" not in jdata:
  331. # for fx off
  332. jdatas.append(jdata)
  333. else: # with "ATTR"
  334. if "FIX" in jdata:
  335. fix = jdata["FIX"]
  336. attr = jdata["ATTR"]
  337. # find dmx-fine channel
  338. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  339. if jdata["ATTR"].startswith("_"):
  340. # ignore attr "_"
  341. # bug with "S" attr._ACTIVE breaks preset_go
  342. pass
  343. else:
  344. jdatas.append(jdata)
  345. else:
  346. cprint("jclient_send, ignore DMX ",color="red")
  347. cprint("-- ",jdata,color="red")
  348. except Exception as e:
  349. cprint("jclient_send, Exception DMX ",color="red")
  350. cprint("",jdata,color="red")
  351. cprint(e,color="red")
  352. cprint("-----",color="red")
  353. jtxt = jdatas
  354. jtxt = json.dumps(jtxt)
  355. jtxt = jtxt.encode()
  356. #jtxt = zlib.compress(jtxt)
  357. jclient.send( jtxt ) #b"\00 ")
  358. #print(round((time.time()-t_start)*1000,4),"milis")
  359. cprint("{:0.04} sec.".format(time.time()-t_start),color="yellow")
  360. cprint("{:0.04} tick".format(time.time()),color="yellow")
  361. def _highlight(fix,_attr="DIM"):
  362. " patch test button "
  363. print("highlight",fix,"1")
  364. if fix not in FIXTURES.fixtures:
  365. return None
  366. d = FIXTURES.fixtures[fix]
  367. #for k,v in d.items():
  368. # print("-",k,v)
  369. DMX = d["DMX"] + d["UNIVERS"]*512
  370. if "ATTRIBUT" in d:
  371. ATTR= d["ATTRIBUT"]
  372. data = {"VALUE":200,"DMX":1}
  373. attr = ""
  374. if _attr in ATTR:
  375. attr = _attr
  376. else:
  377. return #stop
  378. print(attr,ATTR[attr])
  379. old_val = ATTR[attr]["VALUE"]
  380. data["DMX"] = DMX + ATTR[attr]["NR"]-1
  381. print(attr,ATTR[attr])
  382. print(data)
  383. for i in range(3):
  384. print("highlight",fix,"0")
  385. data["VALUE"] = 100
  386. jclient_send([data])
  387. time.sleep(0.1)
  388. print("highlight",fix,"1")
  389. data["VALUE"] = 234
  390. jclient_send([data])
  391. time.sleep(0.3)
  392. print("highlight",fix,"0")
  393. data["VALUE"] = old_val
  394. jclient_send([data])
  395. def highlight2(fix,attr="DIM"):
  396. def x():
  397. highlight(fix,attr=attr)
  398. return x
  399. def highlight(fix):
  400. print("highlight",fix)
  401. thread.start_new_thread(_highlight,(fix,"DIM"))
  402. thread.start_new_thread(_highlight,(fix,"RED"))
  403. thread.start_new_thread(_highlight,(fix,"GREEN"))
  404. thread.start_new_thread(_highlight,(fix,"BLUE"))
  405. class ValueBuffer():
  406. def __init__(self,_min=0,_max=255):
  407. self._value = 2
  408. self._on = 1
  409. self._min=_min
  410. self._max=_max
  411. def check(self):
  412. if self._value < self._min:
  413. self._value = self._min
  414. elif self._value > self._max:
  415. self._value = self._max
  416. def inc(self,value=None):
  417. if value is not None:
  418. if type(value) is float:
  419. self._value += round(value,4)
  420. else:
  421. self._value += value
  422. self.check()
  423. return self._value
  424. def val(self,value=None):
  425. if value is not None:
  426. if type(value) is float:
  427. self._value = round(value,4)
  428. else:
  429. self._value = value
  430. self.check()
  431. return self._value
  432. def on(self):
  433. self._on = 1
  434. def off(self):
  435. self._on = 0
  436. def _is(self):
  437. if self._on:
  438. return 1
  439. return 0
  440. FADE = ValueBuffer() #2 #0.1 #1.13
  441. FADE.val(2.0)
  442. FADE_move = ValueBuffer() #2 #0.1 #1.13
  443. FADE_move.val(4.0)
  444. DELAY = ValueBuffer() #2 #0.1 #1.13
  445. DELAY.off()
  446. DELAY.val(0.2)
  447. fx_prm_move = {"SIZE":40,"SPEED":8,"OFFSET":100,"BASE":"0","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":0,"WING":2,"WIDTH":100}
  448. fx_prm = {"SIZE":255,"SPEED":10,"OFFSET":100,"BASE":"-","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":1,"SHUFFLE":0,"WING":2,"WIDTH":25,"FX-X":1,"FX:MODE":0}
  449. fx_x_modes = ["spiral","left","right","up","down","left_right","up_down"]
  450. fx_modes = ["RED","GREEN","BLUE","MAG","YELLOW","CYAN"]
  451. fx_mo = ["fade","on","rnd","ramp","ramp2","cosinus","sinus"]
  452. class FX_handler():
  453. def __init__():
  454. pass
  455. def reshape_preset(data ,value=None,xfade=0,flash=0,ptfade=0):
  456. f=0 #fade
  457. out = []
  458. delay=0
  459. for row in data:
  460. #cprint("reshape_preset in:",row)
  461. line = {}
  462. line["DELAY"]=delay
  463. if type(value) is float:
  464. line["VALUE"] = value #round(value,3)
  465. else:
  466. line["VALUE"] = value
  467. if value is not None:
  468. line["FX"] = row["FX"].split(":",1)[-1]
  469. else:
  470. line["FX"] = row["FX"]
  471. if row["FX2"]:
  472. line["FX2"] = row["FX2"]
  473. if row["FIX"]:
  474. line["FIX"] = row["FIX"]
  475. if row["ATTR"]:
  476. line["ATTR"] = row["ATTR"]
  477. if row["VALUE"] is not None:
  478. if value is None:
  479. v=row["VALUE"]
  480. if type(v) is float:
  481. line["VALUE"] = v #round(v,3)
  482. else:
  483. line["VALUE"] = v
  484. if row["ATTR"] in ["PAN","TILT"]:
  485. f = ptfade
  486. for a in ["DIM","ZOOM","FOCUS","RED","GREEN","BLUE","WHITE","AMBER","IRIS","BLADE"]:
  487. #FADE ATTRIBUTES
  488. if a in row["ATTR"]:
  489. f = xfade
  490. break
  491. if flash:
  492. xfade = 0
  493. if type( f ) is float:
  494. line["FADE"] = round(f,4)
  495. else:
  496. line["FADE"] = f
  497. if 0:
  498. cprint("reshape_preset j",line,color="red")
  499. #cprint("reshape_preset out:",line)
  500. out.append(line)
  501. if DELAY._is():
  502. delay+=DELAY.val()/100 #0.02
  503. return out
  504. class dummy_event():
  505. def __init__(self):
  506. self.num =0
  507. self.type = 4 #press 5 release
  508. self.set_value=-1
  509. gcolor = 1
  510. def cprint(*text,color="blue",space=" ",end="\n"):
  511. #return 0 #disable print dbg
  512. if not gcolor:
  513. print(text)
  514. return 0
  515. if color == "green":
  516. txt = '\033[92m'
  517. elif color == "red":
  518. txt = '\033[0;31m\033[1m'
  519. elif color == "yellow":
  520. txt = '\033[93m\033[1m'
  521. elif color == "cyan":
  522. txt = '\033[96m'
  523. else:
  524. txt = '\033[94m'
  525. for t in text:
  526. txt += str(t ) +" "
  527. #HEADER = '\033[95m'
  528. #OKBLUE = '\033[94m'
  529. #OKCYAN = '\033[96m'
  530. #OKGREEN = '\033[92m'
  531. #WARNING = '\033[93m'
  532. #FAIL = '\033[91m'
  533. #ENDC = '\033[0m'
  534. #BOLD = '\033[1m'
  535. #UNDERLINE = '\033[4m'
  536. txt += '\033[0m'
  537. print(txt,end=end)
  538. #return txt
  539. cprint("________________________________")
  540. def process_wings(xfixtures):
  541. """process the wing's of selected fixtures
  542. input: [1,2,3,4,10,12,13,14]
  543. if WING = 2 return: [[1,2,3,4][14,13,12,10]]
  544. """
  545. wing_buffer = []
  546. fix_count = len(xfixtures)
  547. prm = fx_prm # ToDo: global WING for PAN/TILE !? ATTRIBUT is not availible in this moment
  548. if prm["WING"] > 1 and fix_count > 1:
  549. wing_count = fix_count // prm["WING"]
  550. number_of_fix_in_wing = fix_count // wing_count
  551. if number_of_fix_in_wing < 2:
  552. number_of_fix_in_wing = 2
  553. for i in range(number_of_fix_in_wing):
  554. j = i*wing_count
  555. wing = xfixtures[j:j+wing_count]
  556. if i%2!=0:
  557. wing = wing[::-1]
  558. print("wing",i,"j",j,"wing_count:",wing_count,"wing",wing)
  559. wing_buffer.append(wing)
  560. if fix_count > j+wing_count: # append Fixtures Left over
  561. wing = xfixtures[j+wing_count:]
  562. wing_buffer.append(wing)
  563. else:
  564. wing_buffer.append(xfixtures)
  565. if prm["SHUFFLE"]:
  566. _wing_buffer = []
  567. for wing in wing_buffer:
  568. wing = wing[:]
  569. random.shuffle(wing)
  570. _wing_buffer.append(wing)
  571. wing_buffer = _wing_buffer
  572. return wing_buffer
  573. def process_effect(wing_buffer,fx_name=""):
  574. jdatas = []
  575. offset = 0
  576. offset_move = 0
  577. start = fx_prm["START"]
  578. base = fx_prm["BASE"]
  579. for wing in wing_buffer:
  580. count_of_fix_in_wing = len(wing)
  581. coffset= 0 # 1024/count_of_fix_in_wing * (offset/255)
  582. coffset_move=0
  583. for fix in wing:
  584. if fix not in FIXTURES.fixtures:
  585. continue
  586. data = FIXTURES.fixtures[fix]
  587. for attr in data["ATTRIBUT"]:
  588. if attr.startswith("_"):
  589. continue
  590. jdata = {"MODE":"FX"}
  591. jdata["VALUE"] = None
  592. jdata["FIX"] = fix
  593. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  594. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  595. jdata["ATTR"] =attr
  596. if attr.endswith("-FINE"):
  597. continue
  598. if attr in ["PAN","TILT"]:
  599. csize = fx_prm_move["SIZE"]
  600. cspeed = fx_prm_move["SPEED"]
  601. cstart = fx_prm_move["START"]
  602. cbase = fx_prm_move["BASE"]
  603. width = fx_prm_move["WIDTH"]
  604. invert = fx_prm_move["INVERT"]
  605. coffset_move= round(offset_move,1)
  606. else:
  607. csize = fx_prm["SIZE"]
  608. cspeed = fx_prm["SPEED"]
  609. cstart = fx_prm["START"]
  610. cbase = fx_prm["BASE"]
  611. width = fx_prm["WIDTH"]
  612. invert = fx_prm["INVERT"]
  613. coffset= round(offset,1)
  614. fx=""
  615. if "SIN" in fx_name:
  616. fx = "sinus"
  617. elif "FD" in fx_name:
  618. fx = "fade"
  619. elif "RND" in fx_name:
  620. fx = "rnd"
  621. elif "ON" in fx_name:
  622. fx = "on"
  623. elif "RAMP2" in fx_name:
  624. fx = "bump2"
  625. fx = "ramp2"
  626. elif "RAMP" in fx_name:
  627. fx = "ramp"
  628. elif "COS" in fx_name:
  629. fx = "cosinus"
  630. if fx:
  631. if attr in ["PAN","TILT"]:
  632. cprint("SKIP FX attr:{} fix:{} " .format(attr,fix) )
  633. continue
  634. if fx:
  635. if fx_prm["SPEED"] < 0:
  636. fx = "off"
  637. else:
  638. if ":DIM" in fx_name:
  639. base=""
  640. ffxb=fx_mo[fx_prm["MO"]]
  641. #ffxb= "cosinus"
  642. if attr == "DIM":
  643. if fx_prm["SPEED"] < 0:
  644. fx = "off"
  645. else:
  646. fx = ffxb #"fade"
  647. elif ":TILT" in fx_name:
  648. base=""
  649. if attr == "PAN":
  650. fx = "off"
  651. if attr == "TILT":
  652. if fx_prm["SPEED"] < 0:
  653. fx = "off"
  654. else:
  655. fx = "sinus"
  656. elif ":PAN" in fx_name:
  657. base=""
  658. if attr == "PAN":
  659. if fx_prm_move["SPEED"] < 0:
  660. fx = "off"
  661. else:
  662. fx = "cosinus"
  663. if attr == "TILT":
  664. fx = "off"
  665. elif ":CIR" in fx_name:
  666. base=""
  667. if attr == "PAN":
  668. if fx_prm_move["SPEED"] < 0:
  669. fx = "off"
  670. else:
  671. fx = "cosinus"
  672. if attr == "TILT":
  673. if fx_prm["SPEED"] < 0:
  674. fx = "off"
  675. else:
  676. fx = "sinus"
  677. elif ":RED" in fx_name:
  678. ffxb= fx_mo[fx_prm["MO"]]
  679. ffx= "off" #fx_mo[fx_prm["MO"]]
  680. if "RED" in fx_modes[fx_prm["MODE"]]:#
  681. base="-"
  682. if attr == "RED":
  683. fx=ffx
  684. if attr == "GREEN":
  685. fx = ffxb# "off"
  686. if attr == "BLUE":
  687. fx = ffxb#"off"
  688. elif "GREEN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#in fx_name:
  689. base="-"
  690. if attr == "RED":
  691. fx = ffxb#"off"
  692. elif "GREEN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#in fx_name:
  693. if attr == "GREEN":
  694. fx = ffxb# "off"
  695. fx=ffx
  696. if attr == "BLUE":
  697. fx = ffxb#"off"
  698. elif "BLUE" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  699. base="-"
  700. if attr == "RED":
  701. fx = ffxb# "off"
  702. if attr == "GREEN":
  703. fx = ffxb# "off"
  704. if attr == "BLUE":
  705. fx = ffxb# "off"
  706. fx=ffx
  707. elif "YELLOW" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  708. base="-"
  709. if attr == "RED":
  710. fx = ffxb# "off"
  711. fx=ffx
  712. if attr == "GREEN":
  713. fx = ffxb# "off"
  714. fx=ffx
  715. if attr == "BLUE":
  716. fx = "off"
  717. elif "CYAN" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  718. base="-"
  719. if attr == "RED":
  720. fx = ffxb# "off"
  721. if attr == "GREEN":
  722. fx = ffxb# "off"
  723. fx=ffx
  724. if attr == "BLUE":
  725. fx = ffxb# "off"
  726. fx=ffx
  727. elif "MAG" in fx_modes[fx_prm["MODE"]]:#fx_prm["MODE"]:#fx_name:
  728. base="-"
  729. if attr == "RED":
  730. fx = ffxb# "off"
  731. fx=ffx
  732. if attr == "GREEN":
  733. fx = ffxb# "off"
  734. if attr == "BLUE":
  735. fx = ffxb# "off"
  736. fx=ffx
  737. else:
  738. cprint("FX: unbekant",fx_modes[fx_prm["MODE"]],color="red")
  739. fxtype = fx
  740. fxtype = fx
  741. if "FX" not in data["ATTRIBUT"][attr]:
  742. data["ATTRIBUT"][attr]["FX"] =""
  743. if "FX2" not in data["ATTRIBUT"][attr]:
  744. data["ATTRIBUT"][attr]["FX2"] ={}
  745. if data["ATTRIBUT"][attr]["ACTIVE"] and fxtype:
  746. #print("++ADD FX",fix,attr,fx)
  747. #data["ATTRIBUT"][attr]["FX"] = fx #"sinus:40:100:10"
  748. fjdata = {}
  749. if cspeed < 0.1:
  750. fjdata["TYPE"] = "off"
  751. else:
  752. fjdata["TYPE"] = fxtype
  753. fjdata["SIZE"] = round(csize,2)
  754. fjdata["SPEED"] = round(cspeed,2)
  755. fjdata["WIDTH"] = int(width)
  756. fjdata["START"] = cstart
  757. if attr in ["PAN","TILT"]:
  758. fjdata["OFFSET"]= round(coffset_move,2)
  759. else:
  760. fjdata["OFFSET"]= round(coffset,2)
  761. fjdata["INVERT"]= int(invert)
  762. fjdata["BASE"] = cbase
  763. jdata["FX2"] = fjdata
  764. data["ATTRIBUT"][attr]["FX2"] = fjdata
  765. jdatas.append(jdata)
  766. if fx_prm_move["OFFSET"] > 0.5: # and
  767. aoffset_move = (100/count_of_fix_in_wing) * (fx_prm_move["OFFSET"]/100)
  768. if fx_prm_move["DIR"] <= 0:
  769. offset_move -= aoffset_move
  770. else:
  771. offset_move += aoffset_move
  772. offset_move = round(offset_move,2)
  773. if fx_prm["OFFSET"] > 0.5: # and
  774. aoffset = (100/count_of_fix_in_wing) * (fx_prm["OFFSET"]/100)
  775. if fx_prm["DIR"] <= 0:
  776. offset -= aoffset
  777. else:
  778. offset += aoffset
  779. offset = round(offset,2)
  780. if jdatas and not modes.val("BLIND"):
  781. jclient_send(jdatas)
  782. master.refresh_fix()
  783. return jdatas
  784. def process_matrix(xfixtures):
  785. fix_count = len(xfixtures)
  786. fx_x = fx_prm["FX-X"]
  787. fx_mod = fx_x_modes[fx_prm["FX:MODE"]]
  788. print("----",fx_x,fx_mod)
  789. if fx_x > 1 and fix_count > fx_x:
  790. try:
  791. from lib import matrix
  792. w=fx_x
  793. h=int(fix_count/fx_x)
  794. if fx_mod == "spiral":
  795. _map = matrix.spiral(w,h)
  796. elif fx_mod == "up_down":
  797. _map = matrix.up_down(w,h)
  798. elif fx_mod == "left_right":
  799. _map = matrix.left_right(w,h)
  800. elif fx_mod == "left":
  801. _map = matrix.left(w,h)
  802. elif fx_mod == "right":
  803. _map = matrix.right(w,h)
  804. elif fx_mod == "up":
  805. _map = matrix.up(w,h)
  806. elif fx_mod == "down":
  807. _map = matrix.down(w,h)
  808. else:
  809. return xfixtures # do nothing
  810. matrix.mprint(xfixtures,w,h)
  811. out = ["0"]*(w*h)
  812. for i,f in enumerate(xfixtures):
  813. if i < w*h:
  814. j = int(_map[i])
  815. print([i,f,j])
  816. out[j] = f
  817. matrix.mprint(out,w,h)
  818. xfixtures = out
  819. except Exception as e:
  820. print("matrix exception",e)
  821. return xfixtures
  822. class Xevent_fx():
  823. """ global input event Handeler for short cut's ... etc
  824. """
  825. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  826. self.fix = fix
  827. self.data = data
  828. self.attr = attr
  829. self.elem = elem
  830. self.mode = mode
  831. def fx(self,event):
  832. cprint("Xevent.fx",self.attr,self.fix,event)
  833. fx2 = {}
  834. if event.num == 4:
  835. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  836. txt = "FX:RED"
  837. fx_prm["MODE"] += 1
  838. if fx_prm["MODE"] >= len(fx_modes):
  839. fx_prm["MODE"]=0
  840. txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
  841. master.fx.elem["FX:RED"]["text"] = txt
  842. elif event.num == 5:
  843. cprint("FX:COLOR CHANGE",fx_prm,color="red")
  844. txt = "FX:RED"
  845. fx_prm["MODE"] -= 1
  846. if fx_prm["MODE"] < 0:
  847. fx_prm["MODE"]= len(fx_modes)-1
  848. txt = "FX:\n"+fx_modes[fx_prm["MODE"]]
  849. master.fx.elem["FX:RED"]["text"] = txt
  850. if event.num == 4:
  851. cprint("FX-X: CHANGE",fx_prm,color="red")
  852. txt = "FX-X:"
  853. fx_prm["FX:MODE"] += 1
  854. if fx_prm["FX:MODE"] >= len(fx_x_modes):
  855. fx_prm["FX:MODE"]=0
  856. txt = "FX:MODE\n"+fx_x_modes[fx_prm["FX:MODE"]]
  857. master.fx.elem["FX:MODE"]["text"] = txt
  858. elif event.num == 5:
  859. cprint("FX-X: CHANGE",fx_prm,color="red")
  860. txt = "FX-X:"
  861. fx_prm["FX:MODE"] -= 1
  862. if fx_prm["FX:MODE"] < 0:
  863. fx_prm["FX:MODE"]= len(fx_x_modes)-1
  864. txt = "FX:MODE\n"+fx_x_modes[fx_prm["FX:MODE"]]
  865. master.fx.elem["FX:MODE"]["text"] = txt
  866. elif event.num == 1:
  867. xfixtures = []
  868. fix_active =FIXTURES.get_active()
  869. for fix in fix_active:
  870. if fix == "CFG":
  871. continue
  872. xfixtures.append(fix)
  873. if not xfixtures:
  874. cprint("470 fx() ... init no fixture selected",color="red")
  875. return 0
  876. xfixtures = process_matrix(xfixtures)
  877. wing_buffer = process_wings(xfixtures)
  878. process_effect(wing_buffer,fx_name=self.attr)
  879. def command(self,event,mode=""):
  880. cprint("fx_command",self.mode)
  881. if self.mode == "FX":
  882. prm = fx_prm
  883. ct = self.data.fx
  884. if self.mode == "FX-MOVE":
  885. prm = fx_prm_move
  886. ct = self.data.fx_moves
  887. if 1:
  888. if self.attr.startswith("SIZE:"):#SIN":
  889. #global fx_prm
  890. k = "SIZE"
  891. if event.num == 1:
  892. prm[k] =30
  893. elif event.num == 3:
  894. prm[k] =100
  895. elif event.num == 4:
  896. if prm[k] <= 0:
  897. prm[k] = 1
  898. prm[k] +=5
  899. elif event.num == 5:
  900. prm[k] -=5
  901. #prm[k] =int(prm[k])
  902. if prm[k] > 4000:
  903. prm[k] = 4000
  904. if prm[k] < 0:
  905. prm[k] =0
  906. if prm[k] == 6: #bug
  907. prm[k] =5
  908. ct.elem[self.attr]["text"] = "SIZE:\n{:0.0f}".format(prm[k])
  909. cprint(prm)
  910. elif self.attr.startswith("SPEED:"):#SIN":
  911. #global prm
  912. k = "SPEED"
  913. if event.num == 1:
  914. prm[k] = 6
  915. elif event.num == 3:
  916. prm[k] = 60
  917. elif event.num == 4:
  918. if prm[k] <= 0:
  919. prm[k] = 0.06
  920. elif prm[k] < 5:
  921. prm[k] *=1.2
  922. else:
  923. prm[k] +=5 #1.1
  924. elif event.num == 5:
  925. if prm[k] <= 5:
  926. prm[k] *=0.8
  927. else:
  928. prm[k] -= 5 #1.1
  929. #prm[k] =int(prm[k])
  930. if prm[k] > 4000:
  931. prm[k] = 4000
  932. if prm[k] < 0.05:
  933. prm[k] =0
  934. if prm[k] > 5 and prm[k] < 10: #bug
  935. prm[k] =5
  936. if prm[k] < 0:
  937. ct.elem[self.attr]["text"] = "SPEED:\noff".format(prm[k])
  938. else:
  939. ct.elem[self.attr]["text"] = "SPEED:\n{:0.02f}".format(prm[k])
  940. cprint(prm)
  941. elif self.attr.startswith("START:"):#SIN":
  942. #global prm
  943. k = "START"
  944. if event.num == 1:
  945. pass
  946. elif event.num == 2:
  947. pass
  948. elif event.num == 4:
  949. if prm[k] <= 0:
  950. prm[k] = 1
  951. prm[k] += 5 #1.1
  952. elif event.num == 5:
  953. prm[k] -= 5 #1.1
  954. #prm[k] =int(prm[k])
  955. if prm[k] > 4000:
  956. prm[k] = 4000
  957. if prm[k] < 5:
  958. prm[k] =0
  959. if prm[k] == 6: #bug
  960. prm[k] =5
  961. ct.elem[self.attr]["text"] = "START:\n{:0.0f}".format(prm[k])
  962. cprint(prm)
  963. elif self.attr.startswith("WIDTH:"):#SIN":
  964. #global prm
  965. k = "WIDTH"
  966. if event.num == 1:
  967. prm[k] = 25
  968. elif event.num == 2:
  969. prm[k] = 50
  970. elif event.num == 3:
  971. prm[k] = 100
  972. elif event.num == 4:
  973. if prm[k] <= 0:
  974. prm[k] = 1
  975. elif prm[k] == 50:
  976. prm[k] = 100
  977. elif prm[k] == 5:
  978. prm[k] = 25
  979. elif prm[k] == 25:
  980. prm[k] = 50
  981. else:
  982. prm[k] += 5 #*=1.1
  983. elif event.num == 5:
  984. if prm[k] == 10:
  985. prm[k] = 5
  986. elif prm[k] == 25:
  987. prm[k] = 10
  988. elif prm[k] == 50:
  989. prm[k] = 25
  990. elif prm[k] == 100:
  991. prm[k] = 50
  992. #else:
  993. # prm[k] -=5 #/=1.1
  994. #prm[k] =int(prm[k])
  995. if prm[k] < 0:
  996. prm[k] = 0
  997. if prm[k] > 100:
  998. prm[k] = 100
  999. if prm[k] == 6: #bug
  1000. prm[k] =5
  1001. if prm[k] > 25 and prm[k] < 50: #bug
  1002. prm[k] =50
  1003. if prm[k] > 50 and prm[k] < 100: #bug
  1004. prm[k] =100
  1005. ct.elem[self.attr]["text"] = "WIDTH:\n{:0.0f}".format(prm[k])
  1006. cprint(prm)
  1007. elif self.attr.startswith("DIR:"):#SIN":
  1008. #global prm
  1009. k = "DIR"
  1010. if event.num == 1:
  1011. prm[k] = 1
  1012. elif event.num == 3:
  1013. prm[k] = -1
  1014. elif event.num == 4:
  1015. prm[k] = 1
  1016. elif event.num == 5:
  1017. prm[k] =-1
  1018. txt = prm[k]
  1019. ct.elem[self.attr]["text"] = "DIR:\n{}".format(prm[k])
  1020. cprint(prm)
  1021. elif self.attr.startswith("SHUFFLE:"):#SIN":
  1022. #global prm
  1023. k = "SHUFFLE"
  1024. if event.num == 1:
  1025. prm[k] = 0
  1026. elif event.num == 3:
  1027. prm[k] = 1
  1028. elif event.num == 4:
  1029. prm[k] = 1
  1030. elif event.num == 5:
  1031. prm[k] =0
  1032. if prm[k] == 6: #bug ?
  1033. prm[k] =5
  1034. ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
  1035. cprint(prm)
  1036. elif self.attr.startswith("INVERT:"):#SIN":
  1037. #global prm
  1038. k = "INVERT"
  1039. if event.num == 1:
  1040. prm[k] = 0
  1041. elif event.num == 3:
  1042. prm[k] = 1
  1043. elif event.num == 4:
  1044. prm[k] = 1
  1045. elif event.num == 5:
  1046. prm[k] =0
  1047. if prm[k] == 6: #bug ?
  1048. prm[k] =5
  1049. ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
  1050. cprint(prm)
  1051. elif self.attr.startswith("FX-X:"):#SIN":
  1052. #global prm
  1053. k = "FX-X"
  1054. if event.num == 1:
  1055. prm[k] = 1
  1056. elif event.num == 3:
  1057. prm[k] = 2
  1058. elif event.num == 4:
  1059. prm[k] += 1
  1060. elif event.num == 5:
  1061. prm[k] -=1
  1062. if prm[k] > 100:
  1063. prm[k] = 100
  1064. if prm[k] < 1:
  1065. prm[k] =1
  1066. txt = prm[k]
  1067. ct.elem[self.attr]["text"] = "FX-X:\n{}".format(prm[k])
  1068. cprint(prm)
  1069. elif self.attr.startswith("WING:"):#SIN":
  1070. #global prm
  1071. k = "WING"
  1072. if event.num == 1:
  1073. prm[k] = 1
  1074. elif event.num == 3:
  1075. prm[k] = 2
  1076. elif event.num == 4:
  1077. prm[k] += 1
  1078. elif event.num == 5:
  1079. prm[k] -=1
  1080. if prm[k] > 100:
  1081. prm[k] = 100
  1082. if prm[k] < 1:
  1083. prm[k] =1
  1084. txt = prm[k]
  1085. ct.elem[self.attr]["text"] = "WING:\n{}".format(prm[k])
  1086. cprint(prm)
  1087. elif self.attr.startswith("OFFSET:"):#SIN":
  1088. #global prm
  1089. k = "OFFSET"
  1090. if event.num == 1:
  1091. prm[k] = 50
  1092. elif event.num == 2:
  1093. prm[k] *= 2
  1094. elif event.num == 3:
  1095. prm[k] = 100
  1096. elif event.num == 4:
  1097. if prm[k] <= 0:
  1098. prm[k] = 1
  1099. prm[k] +=5 #*=1.1
  1100. elif event.num == 5:
  1101. prm[k] -=5 #/=1.1
  1102. #prm[k] =int(prm[k])
  1103. #if prm[k] > 512:
  1104. # prm[k] = 512
  1105. if prm[k] < 5:
  1106. prm[k] =0
  1107. if prm[k] == 6: #bug
  1108. prm[k] =5
  1109. ct.elem[self.attr]["text"] = "OFFSET:\n{:0.0f}".format(prm[k])
  1110. cprint(prm)
  1111. elif self.attr.startswith("BASE:"):
  1112. k = "BASE"
  1113. if event.num == 1:
  1114. prm[k] = "-"
  1115. elif event.num == 3:
  1116. prm[k] = "0"
  1117. elif event.num == 4:
  1118. prm[k] = "+"
  1119. elif event.num == 5:
  1120. prm[k] = "0"
  1121. ct.elem[self.attr]["text"] = "BASE:\n{}".format(prm[k])
  1122. elif self.attr.startswith("FX:"):#SIN":
  1123. self.fx(event)
  1124. elif self.attr == "FX OFF":
  1125. if event.num == 1:
  1126. FIXTURES.fx_off("all")
  1127. CONSOLE.fx_off("all")
  1128. CONSOLE.flash_off("all")
  1129. master.refresh_fix()
  1130. return 0
  1131. #if event.num == 1:
  1132. elif self.attr == "REC-FX":
  1133. print("ELSE",self.attr)
  1134. modes.val(self.attr,1)
  1135. return 0
  1136. def cb(self,event):
  1137. cprint("EVENT_fx cb",self.attr,self.mode,event,color='yellow')
  1138. print(["type",event.type,"num",event.num])
  1139. try:
  1140. change = 0
  1141. if self.mode.startswith("FX"):
  1142. self.command(event)
  1143. return 0
  1144. except Exception as e:
  1145. cprint("== cb EXCEPT",e,color="red")
  1146. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1147. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1148. return 1
  1149. def save_window_position(save_as=""):
  1150. try:
  1151. base = Base()
  1152. fname = "/home/user/LibreLight"
  1153. fname = base.show_path1 +base.show_name
  1154. if save_as:
  1155. fname = save_as
  1156. fname += "/gui.txt"
  1157. print("save_window_position",fname)
  1158. f = open(fname,"w")
  1159. for k,win in window_manager.windows.items():
  1160. print("save:win:pos",win,k)
  1161. if not win:
  1162. continue
  1163. #print("d",dir(win))
  1164. #print("winfo",k,win.tk.geometry())
  1165. line="{} {}\n".format(k,win.tk.geometry())
  1166. #print("> ",[line])
  1167. f.write( line )
  1168. f.flush()
  1169. f.close()
  1170. except Exception as e:
  1171. cprint("save_window_position Exception:",e,color="red")
  1172. return
  1173. def save_window_position_loop(): # like autosave
  1174. def loop():
  1175. time.sleep(20)
  1176. try:
  1177. while 1:
  1178. save_window_position()
  1179. time.sleep(60)
  1180. except Exception as e:
  1181. print("save_loop",e)
  1182. thread.start_new_thread(loop,())
  1183. def load_window_position():
  1184. try:
  1185. base = Base()
  1186. fname = "/home/user/LibreLight"
  1187. fname = base.show_path1 +base.show_name
  1188. fname += "/gui.txt"
  1189. print("load_window_position",fname)
  1190. f = open(fname,"r")
  1191. data = {}
  1192. for line in f.readlines():
  1193. line = line.strip()
  1194. if " " in line:
  1195. k,geo = line.split(" ",1)
  1196. data[k] = geo
  1197. for k,win in window_manager.windows.items():
  1198. if not win:
  1199. continue
  1200. if k in data:
  1201. try:
  1202. #print("> ",[k,data[k]])
  1203. win.tk.geometry(data[k])
  1204. except Exception as e:
  1205. cprint("load_window_position Exception:",e,color="red")
  1206. #print("winfo",k,win.tk.geometry())
  1207. f.close()
  1208. except Exception as e:
  1209. cprint("load_window_position Exception:",e,color="red")
  1210. return
  1211. class Xevent():
  1212. """ global input event Handeler for short cut's ... etc
  1213. """
  1214. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  1215. self.fix = fix
  1216. self.data=data
  1217. self.attr = attr
  1218. self.elem = elem
  1219. self.mode = mode
  1220. def setup(self,event):
  1221. cprint("xevent.SETUP",[self.mode,self.attr],color="red")
  1222. if self.mode == "SETUP":
  1223. if self.attr == "SAVE\nSHOW":
  1224. self.elem["bg"] = "orange"
  1225. self.elem["text"] = "SAVING..."
  1226. self.elem["bg"] = "red"
  1227. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  1228. #self.elem["fg"] = "orange"
  1229. self.elem.config(activebackground="orange")
  1230. modes.val(self.attr,1)
  1231. PRESETS.backup_presets()
  1232. FIXTURES.backup_patch()
  1233. save_window_position()
  1234. #time.sleep(1)
  1235. #modes.val(self.attr,0)
  1236. self.elem["bg"] = "lightgrey"
  1237. #self.elem["fg"] = "lightgrey"
  1238. self.elem.config(activebackground="lightgrey")
  1239. elif self.attr == "LOAD\nSHOW":
  1240. name = "LOAD-SHOW"
  1241. base = Base()
  1242. line1 = "PATH: "+base.show_path1 +base.show_name
  1243. line2 = "DATE: "+ time.strftime("%Y-%m-%d %X", time.localtime(time.time()))
  1244. class cb():
  1245. def __init__(self,name=""):
  1246. self.name=name
  1247. print("cb",name)
  1248. def cb(self,event=None,**args):
  1249. print("cdb",self.name,event,args)
  1250. if self.name != "<exit>":
  1251. print("-----------------------:")
  1252. LOAD_SHOW_AND_RESTAT(self.name).cb()
  1253. #self.elem["bg"] = "lightgrey"
  1254. #self.elem.config(activebackground="lightgrey")
  1255. pw = PopupList(name,cb=cb)
  1256. frame = pw.sframe(line1=line1,line2=line2)
  1257. r = _load_show_list(frame,cb=cb)
  1258. #self.elem["bg"] = "red"# "lightgrey"
  1259. #self.elem.config(activebackground="red")
  1260. #self.elem.config(activebackground="lightgrey")
  1261. #w.tk.attributes('-topmost',False)
  1262. elif self.attr == "SAVE\nSHOW AS":
  1263. base = Base()
  1264. #def _cb(fname):
  1265. def _cb(data):
  1266. fname = data["Value"]
  1267. print(self,"save_show._cb()",fname)
  1268. fpath,fname = base.build_path(fname)
  1269. cprint("SAVE AS",fpath,fname)
  1270. if base._create_path(fpath):
  1271. a=PRESETS.backup_presets(save_as=fpath)
  1272. b=FIXTURES.backup_patch(save_as=fpath)
  1273. #base._set(fname)
  1274. save_window_position(save_as=fpath)
  1275. LOAD_SHOW_AND_RESTAT(fname).cb()
  1276. dialog._cb = _cb
  1277. dialog.askstring("SAVE SHOW AS","SAVE SHOW AS:")
  1278. elif self.attr == "SAVE &\nRESTART":
  1279. self.elem["bg"] = "orange"
  1280. self.elem["text"] = "SAVING..."
  1281. self.elem["bg"] = "red"
  1282. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  1283. #self.elem["fg"] = "orange"
  1284. self.elem.config(activebackground="orange")
  1285. modes.val(self.attr,1)
  1286. PRESETS.backup_presets()
  1287. FIXTURES.backup_patch()
  1288. save_window_position()
  1289. self.elem["text"] = "RESTARTING..."
  1290. #time.sleep(1)
  1291. #modes.val(self.attr,0)
  1292. self.elem["bg"] = "lightgrey"
  1293. #self.elem["fg"] = "lightgrey"
  1294. self.elem.config(activebackground="lightgrey")
  1295. LOAD_SHOW_AND_RESTAT("").cb(force=1)
  1296. elif self.attr == "DRAW\nGUI":
  1297. #self.elem["bg"] = "orange"
  1298. old_text = self.elem["text"]
  1299. self.elem["text"] = "DRAWING..."
  1300. #self.elem["bg"] = "red"
  1301. #time.sleep(0.05)
  1302. #print("redraw",name)
  1303. #if name == "PATCH":
  1304. # gui_patch.draw()
  1305. #if name == "DIMMER":
  1306. # gui_fix.draw()
  1307. self.elem["text"] = "PATCH..."
  1308. window_manager.top("PATCH")
  1309. gui_patch.draw(FIXTURES)
  1310. self.elem["text"] = "FIX..."
  1311. gui_fix.draw(FIXTURES)
  1312. window_manager.top("FIXTURES")
  1313. master._refresh_exec()
  1314. self.elem["text"] = old_text
  1315. else:
  1316. r=tkinter.messagebox.showwarning(message="{}\nnot implemented".format(self.attr.replace("\n"," ")),parent=None)
  1317. return 1
  1318. def live(self,event):
  1319. if self.mode == "LIVE":
  1320. if "FADE" in self.attr or "DELAY" in self.attr:
  1321. if self.attr == "FADE":
  1322. ct = FADE
  1323. if self.attr == "DELAY":
  1324. ct = DELAY
  1325. if "PAN/TILT\nFADE" in self.attr:
  1326. ct = FADE_move
  1327. value = ct.val()
  1328. #print("EVENT CHANGE ",[self.attr])
  1329. print("EVENT CHANGE:",self.mode,value,self.attr)
  1330. if value < 0.01:
  1331. ct.val(0.01)
  1332. elif value > 100.0:
  1333. pass #value = 100
  1334. if event.num == 4:
  1335. value *= 1.1
  1336. elif event.num == 5:
  1337. value /= 1.1
  1338. elif event.num == 1:
  1339. if ct._is():
  1340. ct.off()# = 0
  1341. self.data.commands.elem[self.attr]["bg"] = "grey"
  1342. self.elem.config(activebackground="grey")
  1343. else:
  1344. ct.on()# = 1
  1345. self.data.commands.elem[self.attr]["bg"] = "green"
  1346. self.elem.config(activebackground="lightgreen")
  1347. elif event.num == 2:
  1348. if value > 1 and value < 4:
  1349. value = 4
  1350. elif value > 3 and value < 6:
  1351. value = 6
  1352. elif value > 5 and value < 7:
  1353. value = 8
  1354. elif value > 7 and value < 9:
  1355. value = 10
  1356. elif value > 9:
  1357. value = 0.01
  1358. elif value < 1:
  1359. value = 1.1
  1360. value = round(value,3)
  1361. value = ct.val(value)
  1362. if self.attr == "FADE":
  1363. self.data.commands.elem[self.attr]["text"] = "FADE:\n{:0.2f}".format(value)
  1364. if self.attr == "DELAY":
  1365. self.data.commands.elem[self.attr]["text"] = "DELAY:\n{:0.3f}".format(value)
  1366. if "PAN/TILT\nFADE" in self.attr:
  1367. self.data.commands.elem[self.attr]["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
  1368. def command(self,event):
  1369. if self.mode == "COMMAND":
  1370. if self.attr == "CLEAR":
  1371. if event.num == 1:
  1372. ok = FIXTURES.clear()
  1373. if ok:
  1374. master.refresh_fix()
  1375. modes.val(self.attr,0)
  1376. elif self.attr == "SAVE":
  1377. modes.val(self.attr,1)
  1378. PRESETS.backup_presets()
  1379. FIXTURES.backup_patch()
  1380. #time.sleep(1)
  1381. modes.val(self.attr,0)
  1382. elif self.attr == "S-KEY":
  1383. global _global_short_key
  1384. if _global_short_key:
  1385. _global_short_key = 0
  1386. master.commands.elem["S-KEY"]["bg"] = "red"
  1387. master.commands.elem["S-KEY"]["activebackground"] = "red"
  1388. else:
  1389. _global_short_key = 1
  1390. master.commands.elem["S-KEY"]["bg"] = "green"
  1391. master.commands.elem["S-KEY"]["activebackground"] = "green"
  1392. print("s-key",_global_short_key)
  1393. else:
  1394. if event.num == 1:
  1395. print("ELSE",self.attr)
  1396. modes.val(self.attr,1)
  1397. return 0
  1398. def encoder(self,event):
  1399. global _shift_key
  1400. cprint("Xevent","ENC",self.fix,self.attr,self.mode)
  1401. cprint("SHIFT_KEY",_shift_key,"??????????")
  1402. if self.mode == "ENCODER":
  1403. if self._encoder(event):
  1404. #master._refresh_fix() # now
  1405. master.refresh_fix() # delayed
  1406. #master._refresh_fix() # now
  1407. refresher_fix.reset() # = Refresher()
  1408. if self.mode == "ENCODER2":
  1409. if self._encoder(event):
  1410. master.refresh_fix() # delayed
  1411. refresher_fix.reset() # = Refresher()
  1412. if self.mode == "INVERT":
  1413. print("INVERT",event)
  1414. if self._encoder(event):
  1415. master.refresh_fix() # delayed
  1416. refresher_fix.reset() # = Refresher()
  1417. def _encoder(self,event):
  1418. global _shift_key
  1419. if 1: #self.mode == "ENCODER" or self.mode == "ENCODER2":
  1420. cprint("-- Xevent","_ENC",self.fix,self.attr,self.mode)
  1421. cprint("-- SHIFT_KEY",_shift_key,"??????????")
  1422. #cprint(self.data)
  1423. val=""
  1424. if event.num == 1:
  1425. val ="click"
  1426. elif event.num == 4:
  1427. val ="++"
  1428. if _shift_key:
  1429. val = "+"
  1430. elif event.num == 5:
  1431. val ="--"
  1432. if _shift_key:
  1433. val = "-"
  1434. #print("SHIFT",val,_shift_key)
  1435. if val:
  1436. FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
  1437. return 1
  1438. def cb(self,event):
  1439. cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
  1440. print(["type",event.type,"num",event.num])
  1441. global INIT_OK
  1442. INIT_OK = 1
  1443. try:
  1444. change = 0
  1445. if "keysym" in dir(event):
  1446. if "Escape" == event.keysym:
  1447. ok = FIXTURES.clear()
  1448. master.refresh_fix()
  1449. print()
  1450. return 0
  1451. if self.mode == "SETUP":
  1452. self.setup(event)
  1453. elif self.mode == "COMMAND":
  1454. self.command(event)
  1455. elif self.mode == "LIVE":
  1456. self.live(event)
  1457. elif self.mode == "ENCODER":
  1458. self.encoder(event)
  1459. elif self.mode == "ENCODER2":
  1460. self.encoder(event)
  1461. elif self.mode == "INVERT":
  1462. self.encoder(event)
  1463. elif self.mode == "FX":
  1464. cprint("Xevent CALLING FX WRONG EVENT OBJECT !!",color="red")
  1465. elif self.mode == "ROOT":
  1466. if event.keysym=="Escape":
  1467. pass
  1468. elif self.mode == "INPUT":
  1469. print("INP",self.data.entry.get())
  1470. if event.keycode == 36:
  1471. x=self.data.entry.get()
  1472. #client.send(x)
  1473. elif self.mode == "INPUT2":
  1474. print("INP2",self.data.entry2.get())
  1475. if event.keycode == 36:
  1476. x=self.data.entry2.get()
  1477. #client.send(x)
  1478. elif self.mode == "INPUT3":
  1479. print("INP3",self.data.entry3.get())
  1480. if event.keycode == 36:
  1481. x=self.data.entry3.get()
  1482. #client.send(x)
  1483. elif self.mode == "PRESET":
  1484. nr = self.attr #int(self.attr.split(":")[1])-1
  1485. if event.num == 3: # right click for testing
  1486. if str(event.type) == '4': #4 ButtonPress
  1487. if modes.val("CFG-BTN"):
  1488. master.btn_cfg(nr,testing=1)
  1489. if event.num == 1:
  1490. if str(event.type) == '4': #4 ButtonPress
  1491. if modes.val("REC"):
  1492. self.data.preset_rec(nr)
  1493. modes.val("REC",0)
  1494. elif modes.val("DEL"):
  1495. ok=PRESETS.delete(nr)
  1496. if ok:
  1497. modes.val("DEL",0)
  1498. master.refresh_exec()
  1499. elif modes.val("COPY"):
  1500. ok=PRESETS.copy(nr)
  1501. if ok:
  1502. modes.val("COPY",0)
  1503. master.refresh_exec()
  1504. elif modes.val("MOVE"):
  1505. ok=PRESETS.move(nr)
  1506. if ok:
  1507. #modes.val("MOVE",0) # keep MOVE on
  1508. master.refresh_exec()
  1509. elif modes.val("CFG-BTN"):
  1510. master.btn_cfg(nr)
  1511. elif modes.val("LABEL"):#else:
  1512. master.label(nr)
  1513. elif modes.val("EDIT"):
  1514. FIXTURES.clear()
  1515. self.data.preset_select(nr)
  1516. self.data.preset_go(nr,xfade=0,event=event,val=255,button="go")
  1517. modes.val("EDIT", 0)
  1518. master.refresh_fix()
  1519. elif modes.val("SELECT"):
  1520. self.data.preset_select(nr)
  1521. else:
  1522. self.data.preset_go(nr,event=event,val=255)
  1523. else:
  1524. self.data.preset_go(nr,xfade=0,event=event,val=0)
  1525. if event.num == 3:
  1526. if not modes.val("REC"):
  1527. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=255)
  1528. print()
  1529. return 0
  1530. elif self.mode == "INPUT":
  1531. print()
  1532. return 0
  1533. except Exception as e:
  1534. cprint("== cb EXCEPT",e,color="red")
  1535. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1536. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1537. print()
  1538. return 1
  1539. def wheel(event,d=None):
  1540. print("wheel",event,d)
  1541. import copy
  1542. class Element():
  1543. def __init__(self):
  1544. self.__data = {}
  1545. def set(self,key,val):
  1546. self.__data[key] = val
  1547. class Base():
  1548. def __init__(self):
  1549. cprint("Base.init()",color="red")
  1550. self._init()
  1551. def _init(self):
  1552. show_name = "DemoShow"
  1553. self.home = os.environ['HOME']
  1554. self.show_path0 = self.home +"/LibreLight/"
  1555. self.show_path = self.show_path0
  1556. self.show_path1 = self.show_path0 + "show/"
  1557. try:
  1558. f = open(self.show_path+"init.txt","r")
  1559. for line in f.readlines():
  1560. #cprint(line)
  1561. if not line.startswith("#"):
  1562. show_name = line.strip()
  1563. show_name = show_name.replace(".","")
  1564. show_name = show_name.replace("\\","")
  1565. show_name = show_name.replace("/","")
  1566. self.show_name = show_name
  1567. except Exception as e:
  1568. cprint("show name exception",color="red")
  1569. msg="Error Exception:{}".format(e)
  1570. r=tkinter.messagebox.showwarning(message=msg,parent=None)
  1571. finally:
  1572. f.close()
  1573. fpath = self.show_path1 +show_name
  1574. if not os.path.isdir(fpath):
  1575. cprint(fpath)
  1576. print( os.path.isdir(fpath))
  1577. msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  1578. msg += "please check\n"
  1579. msg += "-{}init.txt\n".format(self.show_path0)
  1580. msg += "-{}".format(self.show_path1)
  1581. showwarning(msg=msg,title="Show Error")
  1582. exit()
  1583. self._check()
  1584. def _set(self,fname):
  1585. ok= os.path.isdir(self.show_path1+"/"+fname)
  1586. ini = self.show_path0+"init.txt"
  1587. print("SET SHOW NAME",fname,ok,ini)
  1588. try:
  1589. f = open( ini ,"r")
  1590. lines = f.readlines()
  1591. f.close()
  1592. if len(lines) >= 10: # cut show history
  1593. print("_set",ini,len(lines))
  1594. lines = lines[-10:]
  1595. f = open( ini ,"w")
  1596. f.writelines(lines)
  1597. f.close()
  1598. exit()
  1599. except:pass
  1600. if ok:
  1601. #self.show_name = fname
  1602. f = open( ini ,"a")
  1603. f.write(fname+"\n")
  1604. f.close()
  1605. return 1
  1606. def _check(self):
  1607. if not os.path.isdir(self.show_path):
  1608. os.mkdir(self.show_path)
  1609. self.show_path += "/show/"
  1610. if not os.path.isdir(self.show_path):
  1611. os.mkdir(self.show_path)
  1612. self.show_path += "/" +self.show_name +"/"
  1613. if not os.path.isdir(self.show_path):
  1614. os.mkdir(self.show_path)
  1615. pass
  1616. def _list(self):
  1617. #self._check()
  1618. show_list = list(os.listdir( self.show_path1 ))
  1619. out = []
  1620. for fname in show_list:
  1621. #print(fname)
  1622. ctime = os.path.getmtime(self.show_path1+fname)
  1623. ctime = time.strftime("%Y-%m-%d %X", time.localtime(ctime)) #1650748726.6604707))
  1624. try:
  1625. mtime = os.path.getmtime(self.show_path1+fname+"/patch.sav")
  1626. mtime = time.strftime("%Y-%m-%d %X", time.localtime(mtime)) #1650748726.6604707))
  1627. except:
  1628. mtime = 0
  1629. if mtime:
  1630. out.append([fname,mtime])#,ctime])
  1631. from operator import itemgetter
  1632. out=sorted(out, key=itemgetter(1))
  1633. out.reverse()
  1634. return out
  1635. def _load(self,filename):
  1636. xfname = self.show_path+"/"+str(filename)+".sav"
  1637. print("load",xfname)
  1638. try:
  1639. f = open(xfname,"r")
  1640. lines = f.readlines()
  1641. f.close()
  1642. except Exception as e:
  1643. msg = "Exception: {}".format(e)
  1644. msg += "\n\ncheck\n-init.txt"
  1645. cprint(msg,color="red")
  1646. showwarning(msg=msg,title="load Error")
  1647. data = OrderedDict()
  1648. labels = OrderedDict()
  1649. i=0
  1650. for line in lines:
  1651. if line.count("\t") < 2:
  1652. cprint("Error line.count('\\t') < 2 (is:{})".format(line.count("\t")),color="red",end=" ")
  1653. cprint("file:{}".format(xfname),color="red")
  1654. continue
  1655. key,label,rdata = line.split("\t",2)
  1656. key = int(key)
  1657. jdata = json.loads(rdata,object_pairs_hook=OrderedDict)
  1658. nrnull = 0
  1659. if "ATTRIBUT" in jdata: # translate old FIXTURES.fixtures start with 0 to 1
  1660. if nrnull:
  1661. print("DMX NR IS NULL",attr,"CHANGE +1")
  1662. for attr in jdata["ATTRIBUT"]:
  1663. if "NR" in jdata["ATTRIBUT"][attr]:
  1664. nr = jdata["ATTRIBUT"][attr]["NR"]
  1665. if nr >= 0:
  1666. jdata["ATTRIBUT"][attr]["NR"] +=1
  1667. data[key] = jdata
  1668. labels[key] = label
  1669. return data,labels
  1670. def _clean_path(self,fpath):
  1671. _path=[]
  1672. for i in fpath:
  1673. fpath = fpath.replace(" ","_")
  1674. if i in string.ascii_letters+string.digits+"äöüßÖÄÜ_-":
  1675. _path.append(i)
  1676. path = "".join(_path)
  1677. return path
  1678. def build_path(self,save_as):
  1679. save_as = self._clean_path(save_as)
  1680. path = self.show_path.split("/")
  1681. path = "/".join(path[:-2])
  1682. fpath = path+"/"+save_as
  1683. return fpath,save_as
  1684. def _create_path(self,fpath):
  1685. if os.path.isdir(fpath):
  1686. cprint("STOP SHOW EXIST !",color="red")
  1687. return 0
  1688. else:
  1689. cprint("CREATE DIR ",fpath,color="green")
  1690. os.mkdir(fpath)
  1691. #self._set(save_as)
  1692. return fpath
  1693. def _backup(self,filename,data,labels,save_as):
  1694. if save_as:
  1695. xfname = save_as +"/"+str(filename)+".sav"
  1696. else:
  1697. xfname = self.show_path+"/"+str(filename)+".sav"
  1698. print("backup",xfname)
  1699. f = open(xfname,"w")
  1700. for key in data:
  1701. line = data[key]
  1702. #print(line)
  1703. label = "label"
  1704. if key in labels:
  1705. label = labels[key]
  1706. if label == "Name-"+str(key):
  1707. label = ""
  1708. #print(xfname,"load",key,label,len(line))
  1709. f.write( "{}\t{}\t{}\n".format( key,label,json.dumps(line) ) )
  1710. f.close()
  1711. return 1
  1712. def hex_to_rgb(hex):
  1713. return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
  1714. class cb():
  1715. def __init__(self,win):
  1716. self.win = win
  1717. def _callback(self,event):
  1718. clobj=event.widget
  1719. ## undermouse=find_withtag(master.CURRENT)
  1720. undermouse=self.win.find_closest(self.win.CURRENT)
  1721. print( repr(undermouse))
  1722. def callback(self,event):
  1723. print(__file__,self,"callback",event)
  1724. cnv = self.win
  1725. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  1726. tags = cnv.gettags(item)
  1727. #cnv.itemconfigure(self.tag, text=tags[0])
  1728. print(tags,item)
  1729. color = cnv.itemcget(item, "fill")
  1730. cnv.itemconfig("all", width=1)#filla="green")
  1731. cnv.itemconfig(item, width=3)#filla="green")
  1732. print(color)
  1733. print( hex_to_rgb(color[1:]))
  1734. class Elem_Container():
  1735. def __init__(self):
  1736. self.commands = []
  1737. self.val = {}
  1738. self.elem = {}
  1739. class MASTER():
  1740. def __init__(self):
  1741. #super().__init__()
  1742. self.base = Base ()
  1743. self.load()
  1744. self._XX = 0
  1745. self.all_attr =["DIM","PAN","TILT"]
  1746. self.elem_attr = {}
  1747. self.fx_moves = Elem_Container()
  1748. self.fx_moves.commands =["REC-FX","FX OFF","\n"
  1749. ,"FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  1750. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  1751. ]
  1752. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  1753. self.fx = Elem_Container()
  1754. self.fx.commands =[
  1755. "FX:DIM","FX:RED", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  1756. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","FX-X:\n-","FX:MODE"
  1757. ]
  1758. self.fx_generic = Elem_Container()
  1759. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON"]
  1760. self.commands = Elem_Container()
  1761. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  1762. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  1763. ,"BLIND","CLEAR","REC","EDIT","COPY","-","\n"
  1764. ]
  1765. self.elem_presets = {}
  1766. for i in range(8*8*8):
  1767. if i not in PRESETS.val_presets:
  1768. name = "Preset:"+str(i+1)+":\nXYZ"
  1769. #self.presets[i] = [i]
  1770. PRESETS.val_presets[i] = OrderedDict() # FIX
  1771. PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
  1772. PRESETS.label_presets[i] = "-"
  1773. modes.set_cb(self.xcb)
  1774. def button_refresh(self,name,color,color2=None,text="",fg=None):
  1775. cprint("button_refresh",name,color)
  1776. #if color == "gold":
  1777. # color2 = "yellow"
  1778. if color2 is None:
  1779. color2 = color
  1780. if text:
  1781. text = "\n"+str(text)
  1782. if name in self.commands.elem:
  1783. self.commands.elem[name]["bg"] = color
  1784. self.commands.elem[name]["text"] = name+ text
  1785. self.commands.elem[name].config(activebackground=color2)
  1786. if fg:
  1787. self.commands.elem[name]["fg"] = fg
  1788. elif name in self.fx.elem:
  1789. #todo
  1790. self.fx.elem[name]["bg"] = color
  1791. self.fx.elem[name].config(activebackground=color2)
  1792. if fg:
  1793. self.fx.elem[name]["fg"] = fg
  1794. # new version
  1795. for elems in [self.fx_moves]:
  1796. if name in elems.elem:
  1797. elem = elems.elem[name]
  1798. cprint("elem",elem)
  1799. elem.config(bg = color)
  1800. elem.config(text = name+text)
  1801. elem.config(activebackground=color2)
  1802. if fg and "fg" in elem:
  1803. elem["fg"] = fg
  1804. def btn_cfg(self,nr,testing=0):
  1805. cfg = PRESETS._btn_cfg(nr)
  1806. button = PRESETS.btn_cfg(nr)
  1807. label = PRESETS.label(nr)
  1808. def _cb(data):
  1809. print(self,"btn_cfg._cb()",data)
  1810. if data:
  1811. if "Button" in data and type(data["Button"]) is str:
  1812. txt = data["Button"]
  1813. PRESETS.btn_cfg(nr,txt)
  1814. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1815. if "Label" in data and type(data["Label"]) is str:
  1816. txt = data["Label"]
  1817. PRESETS.label(nr,txt)
  1818. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1819. modes.val("CFG-BTN",0)
  1820. master._refresh_exec()
  1821. dialog._cb = _cb
  1822. if 1: # testing:
  1823. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  1824. else:
  1825. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  1826. def label(self,nr):
  1827. txt = PRESETS.label(nr)
  1828. def _cb(data):
  1829. txt = data["Value"]
  1830. print(self,"label._cb()",nr,txt)
  1831. if txt:
  1832. PRESETS.label(nr,txt)
  1833. self.elem_presets[nr].configure(text = PRESETS.get_btn_txt(nr))
  1834. modes.val("LABEL", 0)
  1835. master._refresh_exec()
  1836. dialog._cb= _cb #_x(nr)
  1837. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  1838. def xcb(self,mode,value=None):
  1839. cprint("MODE CALLBACK",mode,value,color="green",end="")
  1840. #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
  1841. if value:
  1842. cprint("===== ON ======",color="red")
  1843. txt = ""
  1844. if mode == "REC-FX":
  1845. modes.val("REC",0)
  1846. modes.val("REC",1)
  1847. if value == 2:
  1848. if mode in ["MOVE","COPY"]:
  1849. txt="to"
  1850. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  1851. else:
  1852. if mode in ["MOVE","COPY"]:
  1853. txt="from"
  1854. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  1855. else:
  1856. cprint("===== OFF ======",color="red")
  1857. if mode == "REC-FX":
  1858. modes.val("REC",0)
  1859. self.button_refresh(mode,color="lightgrey")#,fg="black")
  1860. def load(self,fname=""):
  1861. pass
  1862. def exit(self):
  1863. print("__del__",self)
  1864. PRESETS.backup_presets()
  1865. #print("********************************************************")
  1866. FIXTURES.backup_patch()
  1867. #print("*********del",self,"***********************************************")
  1868. def refresh_exec(self):
  1869. refresher_exec.reset() # = Refresher()
  1870. def _refresh_exec(self):
  1871. cprint("PRESET.refresh_exec()")
  1872. self._XX +=1
  1873. for k in PRESETS.val_presets:
  1874. label = ""
  1875. if k not in self.elem_presets:
  1876. cprint("ERROR",k ,"not in elem_presets continue")
  1877. continue
  1878. if k in PRESETS.label_presets:
  1879. label = PRESETS.label_presets[k]
  1880. #print([label])
  1881. b = self.elem_presets[k]
  1882. ifval = 0
  1883. fx_only = 0
  1884. if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
  1885. sdata = PRESETS.val_presets[k]
  1886. #print("sdata7654",sdata)
  1887. BTN="go"
  1888. if "CFG" in sdata:#["BUTTON"] = "GO"
  1889. if "BUTTON" in sdata["CFG"]:
  1890. BTN = sdata["CFG"]["BUTTON"]
  1891. #txt=str(k+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+label
  1892. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  1893. #txt+=str(self._XX)
  1894. b.configure(text= txt)
  1895. b.configure(bg="yellow")
  1896. b.config(activebackground="yellow")
  1897. if len(sdata) > 1:
  1898. ifval = 1
  1899. fx_color = 0
  1900. val_color = 0
  1901. for fix in sdata:
  1902. if fix == "CFG":
  1903. continue
  1904. #print( "$$$$",fix,sdata[fix])
  1905. for attr in sdata[fix]:
  1906. if "FX2" in sdata[fix][attr]:
  1907. if sdata[fix][attr]["FX2"]:
  1908. fx_color = 1
  1909. if "FX" in sdata[fix][attr]:
  1910. if sdata[fix][attr]["FX"]:
  1911. fx_color = 1
  1912. if "VALUE" in sdata[fix][attr]:
  1913. if sdata[fix][attr]["VALUE"] is not None:
  1914. val_color = 1
  1915. b.configure(fg= "black")
  1916. if val_color:
  1917. b.configure(bg="gold")
  1918. b.config(activebackground="#ffaa55")
  1919. if fx_color:
  1920. b.configure(fg = "blue")
  1921. else:
  1922. if fx_color:
  1923. fx_only = 1
  1924. else:
  1925. b.configure(bg="grey")
  1926. b.config(activebackground="#aaa")
  1927. if "\n" in txt:
  1928. txt1 = txt.split("\n")[0]
  1929. b.configure(fg="black")
  1930. if ifval:
  1931. if fx_only:
  1932. b.configure(bg = "cyan")
  1933. b.config(activebackground="#55d4ff")
  1934. if "SEL" in txt1:
  1935. b.configure(bg="#77f")
  1936. else:
  1937. b.configure(bg="grey")
  1938. b.configure(fg="darkgrey") #black")
  1939. if "SEL" in txt1:
  1940. b.configure(fg="blue")
  1941. elif "ON" in txt1:
  1942. b.configure(fg="#040")
  1943. elif "GO" in txt1:
  1944. b.configure(fg="#555")
  1945. if "FL" in txt1:
  1946. b.configure(fg="#00e")
  1947. def refresh_fix(self):
  1948. refresher_fix.reset() # = Refresher()
  1949. def _refresh_fix(self):
  1950. c_d =0
  1951. c_f =0
  1952. c_a =0
  1953. for fix in FIXTURES.fixtures:
  1954. sdata = FIXTURES.fixtures[fix]
  1955. _c_a = 0
  1956. for attr in sdata["ATTRIBUT"]:
  1957. #if attr.startswith("_"):
  1958. # continue
  1959. if attr.endswith("-FINE"):
  1960. continue
  1961. v2 = sdata["ATTRIBUT"][attr]["VALUE"]
  1962. if fix in self.elem_attr:
  1963. b_attr = attr
  1964. if b_attr == "_ACTIVE":
  1965. b_attr = "S"
  1966. if b_attr in self.elem_attr[fix]:
  1967. elem = self.elem_attr[fix][b_attr]
  1968. #print( "::::",attr,v2,elem)
  1969. if elem:
  1970. if not attr.startswith("_"):
  1971. elem["text"] = "{} {:0.2f}".format(attr,v2)
  1972. if sdata["ATTRIBUT"][attr]["ACTIVE"]:
  1973. elem["bg"] = "yellow"
  1974. elem.config(activebackground="yellow")
  1975. if "DIM" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 1:
  1976. c_d+=1
  1977. else:
  1978. _c_a += 1
  1979. else:
  1980. elem["bg"] = "grey"
  1981. elem.config(activebackground="grey")
  1982. if "FX2" not in sdata["ATTRIBUT"][attr]: # insert FX2 excetption
  1983. sdata["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  1984. if sdata["ATTRIBUT"][attr]["FX"]:
  1985. elem["fg"] = "blue"
  1986. elif sdata["ATTRIBUT"][attr]["FX2"]:
  1987. elem["fg"] = "red"
  1988. else:
  1989. elem["fg"] = "black"
  1990. else:
  1991. print( ":::;",attr,v2,elem)
  1992. c_a += _c_a
  1993. if _c_a>0:
  1994. c_f +=1
  1995. c_a2=0
  1996. if c_f > 0:
  1997. c_a2 = round(c_a/c_f,2)
  1998. if c_a2 % 1 > 0:
  1999. gui_menu.config("FIXTURES","bg","orange")
  2000. gui_menu.config("FIXTURES","activebackground","orange")
  2001. else:
  2002. gui_menu.config("FIXTURES","bg","yellow")
  2003. gui_menu.config("FIXTURES","activebackground","yellow")
  2004. else:
  2005. gui_menu.config("FIXTURES","bg","")
  2006. gui_menu.config("FIXTURES","activebackground","")
  2007. gui_menu.update("FIXTURES","{} : {}".format(c_f,c_a2))
  2008. if c_d > 0:
  2009. gui_menu.config("DIMMER","bg","yellow")
  2010. gui_menu.config("DIMMER","activebackground","yellow")
  2011. else:
  2012. gui_menu.config("DIMMER","bg","")
  2013. gui_menu.config("DIMMER","activebackground","")
  2014. gui_menu.update("DIMMER","{}".format(c_d))
  2015. def preset_rec(self,nr):
  2016. print("------- STORE PRESET")
  2017. data = FIXTURES.get_active()
  2018. if modes.val("REC-FX"):
  2019. PRESETS.rec(nr,data,"REC-FX")
  2020. modes.val("REC-FX",0)
  2021. else:
  2022. PRESETS.rec(nr,data)
  2023. sdata=data
  2024. PRESETS.val_presets[nr] = sdata
  2025. master._refresh_exec()
  2026. return 1
  2027. def preset_select(self,nr):
  2028. print("SELECT PRESET")
  2029. sdata = PRESETS.val_presets[nr]
  2030. cmd = ""
  2031. for fix in sdata:
  2032. if fix == "CFG":
  2033. continue
  2034. for attr in sdata[fix]:
  2035. v2 = sdata[fix][attr]["VALUE"]
  2036. v2_fx = sdata[fix][attr]["FX"]
  2037. #print( self.data.elem_attr)
  2038. if fix in self.elem_attr:
  2039. if attr in self.elem_attr[fix]:
  2040. elem = self.elem_attr[fix][attr]
  2041. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  2042. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2043. #elem["bg"] = "yellow"
  2044. def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  2045. t_start = time.time()
  2046. if xfade is None and FADE._is():
  2047. xfade = FADE.val()
  2048. if ptfade is None and FADE_move._is():
  2049. ptfade = FADE_move.val()
  2050. print("GO PRESET FADE",nr,val)
  2051. rdata = PRESETS.get_raw_map(nr)
  2052. if not rdata:
  2053. return 0
  2054. print("???????")
  2055. cfg = PRESETS.get_cfg(nr)
  2056. print("''''''''")
  2057. #virtcmd = FIXTURES.get_virtual(rdata)
  2058. if not cfg:
  2059. cprint("NO CFG",cfg,nr)
  2060. return 0
  2061. xFLASH = 0
  2062. value=None
  2063. cprint("preset_go",nr,cfg)
  2064. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  2065. self.preset_select(nr)
  2066. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  2067. xFLASH = 1
  2068. xfade = 0
  2069. if type(val) is not type(None) and val == 0 :
  2070. value = "off"
  2071. if event:
  2072. if str(event.type) == "ButtonRelease" or event.type == '5' :
  2073. value = "off"
  2074. cprint("preset_go() FLUSH",value,color="red")
  2075. fcmd = FIXTURES.update_raw(rdata,update=0)
  2076. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  2077. elif not val:
  2078. cprint("preset_go() STOP",value,color="red")
  2079. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  2080. fcmd = FIXTURES.update_raw(rdata)
  2081. self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  2082. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  2083. fcmd = FIXTURES.update_raw(rdata)
  2084. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  2085. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  2086. self.refresh_exec()
  2087. self.refresh_fix()
  2088. cprint("preset_go",time.time()-t_start)
  2089. def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  2090. if xfade is None and FADE._is():
  2091. xfade = FADE.val()
  2092. if ptfade is None and FADE_move._is():
  2093. ptfade = FADE_move.val()
  2094. cprint("PRESETS._preset_go() len=",len(rdata),cfg)
  2095. if xfade is None:
  2096. xfade = cfg["FADE"]
  2097. if ptfade is None:
  2098. ptfade = cfg["FADE"]
  2099. #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
  2100. #cprint(rdata,color="red")
  2101. vcmd = reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
  2102. cmd = []
  2103. delay=0
  2104. for i,v in enumerate(fcmd):
  2105. #print("go",i,v)
  2106. if xFLASH:
  2107. vcmd[i]["FLASH"] = 1
  2108. DMX = fcmd[i]["DMX"]
  2109. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  2110. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  2111. if value is not None:
  2112. vcmd[i]["VALUE"] = value
  2113. if value == "off":
  2114. if "FX2" in vcmd:
  2115. vcmd[i]["FX2"]["TYPE"] = value
  2116. if "FIX" in fcmd:
  2117. vcmd[i]["FIX"] = fcmd["FIX"]
  2118. if DMX and vcmd[i]:
  2119. vcmd[i]["DMX"] = DMX
  2120. if "VIRTUAL" in fcmd[i]:
  2121. for a in fcmd[i]["VIRTUAL"]:
  2122. DMX = fcmd[i]["VIRTUAL"][a]
  2123. if DMX and vcmd[i]:
  2124. vcmd[i]["DMX"] = DMX
  2125. if type(nr) is not type(None):
  2126. vcmd[i]["EXEC"] = str(int(nr)+1)
  2127. #cprint(vcmd[i],color="red")
  2128. cmd.append(vcmd[i])
  2129. if cmd and not modes.val("BLIND"):
  2130. jclient_send(cmd)
  2131. def render(self):
  2132. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  2133. #self.draw_input()
  2134. pass
  2135. ##draw_sub_dim
  2136. class InputEventBlocker():
  2137. def __init__(self):
  2138. self.__init = 0
  2139. self.cursor = "88888"
  2140. def set(self,el,txt):
  2141. self.e = el
  2142. self.e_txt = txt
  2143. self.cursor = "88888"
  2144. def init(self):
  2145. if self.__init == 0:
  2146. try:
  2147. self.el = tk.Button()
  2148. self.e_txt = tk.StringVar()
  2149. self.__init = 1
  2150. except Exception as e:
  2151. pirnt("init() exception",e)
  2152. def _lock(self):
  2153. global _global_short_key
  2154. _global_short_key = 0
  2155. master.commands.elem["S-KEY"]["bg"] = "red"
  2156. def _unlock(self):
  2157. global _global_short_key
  2158. _global_short_key = 1
  2159. master.commands.elem["S-KEY"]["bg"] = "green"
  2160. def lock(self):
  2161. self._lock()
  2162. #self.e["bg"] = "red"
  2163. #self.el.config({"background": "grey"})
  2164. #self.e.focus()
  2165. def unlock(self):
  2166. self._unlock()
  2167. #self.e["bg"] = "blue"
  2168. #self.el.config({"background": "yellow"})
  2169. #self.el.focus_set()
  2170. def event(self,event,**args):
  2171. self.init()
  2172. #print()
  2173. print(self,event,args)
  2174. #print("###-",self.e_txt,dir(self.e_txt))
  2175. if "S-KEY" not in master.commands.elem:
  2176. return
  2177. if "num" in dir(event):
  2178. self.lock()
  2179. if "keysym" in dir(event):
  2180. t=self.e_txt.get()
  2181. if t and t[-1] == "<":
  2182. t = t[:-1]
  2183. if event.keysym == "Return" or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  2184. self.unlock()
  2185. #self.e_txt.set(t)
  2186. print("filter: get()",_global_short_key,t)
  2187. t2 = t
  2188. if _global_short_key == 0:
  2189. if event.keysym == "BackSpace":
  2190. if len(t) > 1:
  2191. t2 = t[:-1]
  2192. else:
  2193. t2=""
  2194. elif event.keysym == "Escape":
  2195. t2=""
  2196. elif event.keysym == "space":
  2197. t2=t+" "
  2198. elif event.char in "äöüÄÖÜ-_,.;:#'*+~":
  2199. t2=t+event.char
  2200. elif len(event.keysym) == 1:
  2201. t2=t+event.keysym
  2202. #self.e_txt.set(t2+"<")
  2203. #time.sleep(0.2)
  2204. #_global_short_key = 1
  2205. input_event_blocker = InputEventBlocker()
  2206. from tkgui.dialog import *
  2207. dialog = Dialog()
  2208. from tkgui.draw import *
  2209. from tkgui.GUI import *
  2210. #draw_enc
  2211. class LOAD_FIXTURE():
  2212. def __init__(self,name="",master=None):
  2213. self.name=name
  2214. self.master=master
  2215. def cb(self,event=None):
  2216. print("LOAD_FIXTURE",self.name,event)
  2217. if self.master is not None:
  2218. #for i in dir(self.master): #.load_MH2()
  2219. # print(i)
  2220. if "SPARX" in self.name:
  2221. self.master.load_MH2()
  2222. else:
  2223. self.master.load_DIM()
  2224. print(dir(self.master))
  2225. class LOAD_SHOW_AND_RESTAT():
  2226. def __init__(self,fname=""):
  2227. self.fname=fname
  2228. self.base = Base()
  2229. def cb(self,event=None,force=0):
  2230. print("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
  2231. if not self.fname and not force:
  2232. return 0
  2233. if self.base.show_name == self.fname and not force:
  2234. cprint("filename is the same",self.fname)
  2235. return 0
  2236. if not force:
  2237. self.base._set(self.fname)
  2238. print("LOAD SHOW:",event,self.fname)
  2239. print(sys.executable, os.path.abspath(__file__), *sys.argv)
  2240. os.execl("/usr/bin/python3", "/opt/LibreLight/Xdesk/_LibreLightDesk.py", "_LibreLightDesk.py")
  2241. sys.exit()
  2242. class PopupList():
  2243. def __init__(self,name="<NAME>",master=0,width=400,height=450,exit=1,left=_POS_LEFT+400,top=_POS_TOP+100,cb=None,bg="black"):
  2244. self.name = name
  2245. self.frame = None
  2246. self.bg=bg
  2247. self.cb = cb
  2248. if cb is None:
  2249. cb = DummyCallback #("load_show_list.cb")
  2250. w = Window(self.name,master=master,width=width,height=height,exit=exit,left=left,top=top,cb=cb)
  2251. self.w = w
  2252. w.show()
  2253. def sframe(self,line1="<line1>",line2="<line2>",data=[]):
  2254. xframe=self.w.tk
  2255. if self.bg:
  2256. xframe.configure(bg=self.bg)
  2257. self.w.tk.configure(bg=self.bg)
  2258. c=0
  2259. r=0
  2260. b = tk.Label(xframe,bg="grey",text=line1,anchor="w")
  2261. b.pack(side="top",expand=0,fill="x" )
  2262. b = tk.Label(xframe,bg="grey",text=line2,anchor="w")
  2263. b.pack(side="top",expand=0,fill="x" )
  2264. b = tk.Label(xframe,bg="black",fg="black",text="")
  2265. if self.bg:
  2266. b.configure(fg=self.bg)
  2267. b.configure(bg=self.bg)
  2268. b.pack(side="top")
  2269. b = tk.Entry(xframe,width=10,text="")#,anchor="w")
  2270. b.pack(side="top",expand=0,fill="x")
  2271. b.focus()
  2272. #frame = tk.Frame(xframe,heigh=2800)
  2273. #frame.pack(fill=tk.BOTH,expand=1, side=tk.TOP)
  2274. frame = ScrollFrame(xframe,width=300,height=500,bd=1,bg=self.bg)
  2275. #frame.pack(side="left") #fill=tk.BOTH,expand=1, side=tk.TOP)
  2276. #self.frame = frame
  2277. self.w.tk.state(newstate='normal')
  2278. self.w.tk.attributes('-topmost',True)
  2279. return frame
  2280. class DummyCallback():
  2281. def __init__(self,name="name"):
  2282. self.name = name
  2283. def cb(self,event=None):
  2284. print("DummyCallback.cb",[self.name,event])
  2285. def _load_show_list(frame,cb=None):
  2286. c=0
  2287. r=0
  2288. base = Base()
  2289. for i in ["name","stamp"]: #,"create"]:
  2290. b = tk.Label(frame,bg="grey",text=i)
  2291. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2292. c+=1
  2293. r+=1
  2294. blist = base._list()
  2295. for i in range(10):
  2296. blist.append(["",""])
  2297. if cb is None:
  2298. cb = DummyCallback #("load_show_list.cb")
  2299. for i in blist:
  2300. #print(i)
  2301. c=0
  2302. for j in i:
  2303. bg="lightgrey"
  2304. dbg="lightgrey"
  2305. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2306. dbg = "lightgreen"
  2307. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2308. dbg = "green"
  2309. if c > 0:
  2310. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2311. b.config(activebackground=dbg)
  2312. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2313. else:
  2314. if base.show_name == i[0]:
  2315. bg="green"
  2316. _cb = cb(j)
  2317. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2318. if base.show_name == i[0]:
  2319. b.config(activebackground=bg)
  2320. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2321. c+=1
  2322. r+=1
  2323. def _load_fixture_list(frame,cb=None,master=None,bg="black"):
  2324. frame.configure(bg=bg)
  2325. c=0
  2326. r=0
  2327. base = Base()
  2328. for i in ["name","stamp"]: #,"create"]:
  2329. b = tk.Label(frame,bg="grey",text=i)
  2330. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2331. c+=1
  2332. r+=1
  2333. blist = [] #base._list()
  2334. blist.append(["MAC-500","martin","z"])
  2335. blist.append(["MAC-2000","martin","z"])
  2336. blist.append(["MAC-VIPER","martin","z"])
  2337. blist.append(["SPARX-7","JB","z"])
  2338. blist.append(["SPARX-11","JB","z"])
  2339. blist.append(["JB-P6","JB","z"])
  2340. blist.append(["JB-P7","JB","z"])
  2341. blist.append(["JB-A7","JB","z"])
  2342. blist.append(["TMH-12","Eurolight","z"])
  2343. for i in range(10):
  2344. blist.append(["",""])
  2345. if cb is None:
  2346. cb = DummyCallback #("load_show_list.cb")
  2347. for i in blist:
  2348. #print(i)
  2349. c=0
  2350. for j in i:
  2351. bg="lightgrey"
  2352. dbg="lightgrey"
  2353. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2354. dbg = "lightgreen"
  2355. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2356. dbg = "green"
  2357. if c > 0:
  2358. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2359. b.config(activebackground=dbg)
  2360. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2361. else:
  2362. if base.show_name == i[0]:
  2363. bg="green"
  2364. _cb=cb(j)
  2365. _cb.master=master
  2366. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2367. if base.show_name == i[0]:
  2368. b.config(activebackground=bg)
  2369. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2370. c+=1
  2371. r+=1
  2372. class Fixtures():
  2373. def __init__(self):
  2374. #super().__init__()
  2375. self.base=Base()
  2376. #self.load()
  2377. self.fixtures = OrderedDict()
  2378. self.gui = GUIHandler()
  2379. def load_patch(self):
  2380. filename="patch"
  2381. #self.base._init()
  2382. d,l = self.base._load(filename)
  2383. self.fixtures = OrderedDict()
  2384. for i in l:
  2385. sdata = d[i]
  2386. new_f = OrderedDict()
  2387. #print("++++")
  2388. for k,j in sdata.items():
  2389. overide=0 # only for repair
  2390. if overide:
  2391. if k in ["TYPE","VENDOR"]: #ignor
  2392. continue
  2393. new_f[k] = j
  2394. if k =="NAME":
  2395. #print("AAAADDDDDD")
  2396. if "TYPE" not in sdata and not overide:
  2397. if len( sdata["ATTRIBUT"]) == 1:
  2398. new_f["TYPE"] = "DIMMER"
  2399. elif "PAN" in sdata["ATTRIBUT"]:
  2400. new_f["TYPE"] = "MOVER"
  2401. elif "RED" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 3:
  2402. new_f["TYPE"] = "RGB"
  2403. elif "RED" in sdata["ATTRIBUT"]:
  2404. new_f["TYPE"] = "LED"
  2405. elif "CYAN" in sdata["ATTRIBUT"]:
  2406. new_f["TYPE"] = "COLOR"
  2407. else:
  2408. new_f["TYPE"] = ""
  2409. if "VENDOR" not in sdata and not overide:
  2410. new_f["VENDOR"] = ""
  2411. #print(k,j)#,sdata)
  2412. sdata = new_f
  2413. if "ACTIVE" not in sdata:
  2414. sdata["ACTIVE"] = 0
  2415. sdata["ATTRIBUT"]["_ACTIVE"] = OrderedDict()
  2416. sdata["ATTRIBUT"]["_ACTIVE"]["NR"] = 0
  2417. sdata["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2418. sdata["ATTRIBUT"]["_ACTIVE"]["VALUE"] = 0
  2419. for attr in sdata["ATTRIBUT"]:
  2420. sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
  2421. #print("load",filename,sdata)
  2422. #if "CFG" not in sdata:
  2423. # sdata["CFG"] = OrderedDict()
  2424. self.fixtures[str(i)] = sdata
  2425. #PRESETS.label_presets = l
  2426. self.fx_off("all")
  2427. def backup_patch(self,save_as=""):
  2428. filename = "patch"
  2429. #self.fx_off("all")
  2430. data = self.fixtures
  2431. labels = {}
  2432. for k in data:
  2433. labels[k] = k
  2434. #self.base._init()
  2435. self.base._backup(filename,data,labels,save_as)
  2436. def fx_get(self,fix=None):
  2437. out={}
  2438. if not fix or fix == "all":
  2439. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2440. for fix in self.fixtures:
  2441. data = self.fixtures[fix]
  2442. for attr in data["ATTRIBUT"]:
  2443. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX"]
  2444. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX2"]
  2445. return out
  2446. def fx_off(self,fix=None):
  2447. if not fix or fix == "all":
  2448. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2449. for fix in self.fixtures:
  2450. data = self.fixtures[fix]
  2451. for attr in data["ATTRIBUT"]:
  2452. data["ATTRIBUT"][attr]["FX"] = ""
  2453. data["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  2454. def get_attr(self,fix,attr):
  2455. if fix in self.fixtures:
  2456. data = self.fixtures[fix]
  2457. if "ATTRIBUT" in data:
  2458. if attr in data["ATTRIBUT"]:
  2459. return data["ATTRIBUT"][attr]
  2460. def get_max_dmx_nr(self,fix):
  2461. max_dmx = 0
  2462. used_dmx = 0
  2463. if fix not in self.fixtures:
  2464. return (used_dmx,max_dmx)
  2465. data = self.fixtures[fix]
  2466. used_dmx = len(data["ATTRIBUT"])
  2467. for a in data["ATTRIBUT"]:
  2468. attr = data["ATTRIBUT"][a]
  2469. if "NR" in attr:
  2470. try:
  2471. _n = int(attr["NR"])
  2472. if _n > max_dmx:
  2473. max_dmx=_n
  2474. except ValueError:pass
  2475. return (used_dmx,max_dmx)
  2476. def get_dmx(self,fix,attr):
  2477. #cprint("get_dmx",[fix,attr])
  2478. if fix in self.fixtures:
  2479. data = self.fixtures[fix]
  2480. DMX = -99
  2481. if "DMX" in data:
  2482. DMX = int(data["DMX"])
  2483. if DMX < 1: # ignore attribute with DMX lower 1
  2484. return -22
  2485. else:
  2486. return -1
  2487. if "UNIVERS" in data:
  2488. if int(data["UNIVERS"]) >= 0:
  2489. DMX += (int(data["UNIVERS"])*512)
  2490. else:
  2491. return -33
  2492. adata = self.get_attr(fix,attr)
  2493. #-hier ende 8.2.22
  2494. #cprint("adata",adata,DMX)
  2495. if adata:
  2496. if "NR" in adata:
  2497. NR = adata["NR"]
  2498. if NR >= 1:
  2499. DMX+=NR-1
  2500. else:
  2501. return -44
  2502. return DMX
  2503. return -4
  2504. return -3
  2505. def update_raw(self,rdata,update=1):
  2506. cprint("update_raw",len(rdata))
  2507. cmd = []
  2508. for i,d in enumerate(rdata):
  2509. xcmd = {"DMX":""}
  2510. #print("fix:",i,d)
  2511. fix = d["FIX"]
  2512. attr = d["ATTR"]
  2513. v2 = d["VALUE"]
  2514. v2_fx = d["FX"]
  2515. if fix not in self.fixtures:
  2516. continue
  2517. sdata = self.fixtures[fix] #shortcat
  2518. ATTR = sdata["ATTRIBUT"]
  2519. sDMX = 0
  2520. if sdata["DMX"] > 0:
  2521. #print( sdata)
  2522. sDMX = (sdata["UNIVERS"]*512)+sdata["DMX"]
  2523. #sDMX =sdata["DMX"]
  2524. #else:
  2525. # continue
  2526. if attr not in ATTR:
  2527. continue
  2528. #DMX = FIXTURES.get_dmx(fix)
  2529. if ATTR[attr]["NR"] >= 0:
  2530. DMX = sDMX+ATTR[attr]["NR"]-1
  2531. xcmd["DMX"] = str(DMX)
  2532. else:
  2533. if attr == "DIM" and ATTR[attr]["NR"] < 0:
  2534. xcmd["VIRTUAL"] = {}
  2535. for a in ATTR:
  2536. if ATTR[a]["MASTER"]:
  2537. xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
  2538. #print( "VIRTUAL",xcmd)
  2539. cmd.append(xcmd)
  2540. v=ATTR[attr]["VALUE"]
  2541. if v2 is not None and update:
  2542. ATTR[attr]["VALUE"] = v2
  2543. if d["FX2"] and update:
  2544. ATTR[attr]["FX2"] = d["FX2"]
  2545. #self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
  2546. text = str(attr)+' '+str(round(v,2))
  2547. #self.gui.update(fix,attr,args={"text":text})
  2548. #print("END 5454 _=_=_=_=_==_")
  2549. #cprint("update_raw",cmd,color="red")
  2550. return cmd
  2551. def encoder(self,fix,attr,xval="",xfade=0,xdelay=0,blind=0):
  2552. _blind = 0
  2553. if modes.val("BLIND"):
  2554. _blind = 1
  2555. if blind:
  2556. _blind = 1
  2557. if not _blind:
  2558. cprint("FIXTURES.encoder",fix,attr,xval,xfade,color="yellow")
  2559. if attr == "CLEAR":
  2560. self.clear()
  2561. return 0
  2562. if attr == "ALL":
  2563. x=self.select(fix,attr,mode="toggle")
  2564. return x
  2565. if attr == "INV-ATTR":
  2566. print("-x-x-x-x-x-x-x-X-")
  2567. x=self.select(fix,attr,mode="swap")
  2568. #x=self.select(fix,"ALL",mode="swap")
  2569. master.refresh_fix()
  2570. return x
  2571. if attr == "INV-FIX":
  2572. print("-x-x-x-x-x-x-x-x-")
  2573. x=self.select(fix,attr,mode="swap")
  2574. #x=self.select(fix,"ALL",mode="swap")
  2575. return x
  2576. out = []
  2577. if fix not in self.fixtures:
  2578. print(" activate Fixture in fixture list on encoder click ")
  2579. #jdata=[{"MODE":"---"}]
  2580. ii =0
  2581. #jclient_send(jdata)
  2582. delay=0
  2583. print("-->A HIER <--")
  2584. sub_data = []
  2585. for fix in self.fixtures:
  2586. ii+=1
  2587. #cprint(fix,attr,xval)
  2588. data = self.fixtures[fix]
  2589. if "-FINE" in attr.upper():
  2590. continue
  2591. elif (attr in data["ATTRIBUT"] ) and "-FINE" not in attr.upper() :
  2592. if xval == "click":
  2593. self.select(fix,attr,mode="on")
  2594. elif data["ATTRIBUT"][attr]["ACTIVE"]:
  2595. if fix: # prevent endless recursion
  2596. #print("------",end="")
  2597. #self.encoder(fix,attr,xval,xfade,delay)
  2598. sub_data.append([fix,attr,xval,xfade,delay])
  2599. if DELAY._is():
  2600. delay += DELAY.val()/100
  2601. sub_jdata = []
  2602. for dd in sub_data:
  2603. #print("---",len(sub_data),end="")
  2604. #self.encoder(fix,attr,xval,xfade,delay)
  2605. _x123 = self.encoder(dd[0],dd[1],dd[2],dd[3],dd[4],blind=1)
  2606. sub_jdata.append(_x123)
  2607. if sub_jdata:
  2608. print("--- SEND MASTER ENCODER:",len(sub_data),sub_data[0],"... _blind:",_blind)#,end="")
  2609. jclient_send(sub_jdata)
  2610. jdata=[{"MODE":ii}]
  2611. print("-->B HIER <--")
  2612. jclient_send(jdata)
  2613. return 0
  2614. data = self.fixtures[fix]
  2615. if xval == "click":
  2616. #cprint(data)
  2617. return self.select(fix,attr,mode="toggle")
  2618. v2=data["ATTRIBUT"][attr]["VALUE"]
  2619. change=0
  2620. increment = 4.11
  2621. jdata = {"MODE":"ENC"}
  2622. if xval == "++":
  2623. v2+= increment
  2624. jdata["INC"] = increment
  2625. change=1
  2626. elif xval == "--":
  2627. jdata["INC"] = increment*-1
  2628. v2-= increment
  2629. change=1
  2630. elif xval == "+":
  2631. increment = 0.5
  2632. v2+= increment
  2633. jdata["INC"] = increment
  2634. change=1
  2635. elif xval == "-":
  2636. increment = 0.5
  2637. jdata["INC"] = increment*-1
  2638. v2-= increment
  2639. change=1
  2640. elif type(xval) is int or type(xval) is float:
  2641. v2 = xval
  2642. change=1
  2643. if v2 < 0:
  2644. v2=0
  2645. elif v2 > 256:
  2646. v2=256
  2647. jdata["VALUE"] = round(v2,4)
  2648. jdata["FIX"] = fix
  2649. jdata["ATTR"] = attr
  2650. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  2651. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  2652. out = {}
  2653. if change:
  2654. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2655. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2656. data["ATTRIBUT"][attr]["VALUE"] = round(v2,4)
  2657. jdata["FADE"] = 0
  2658. if xfade:
  2659. jdata["FADE"] = xfade
  2660. if xdelay:
  2661. #if attr not in ["PAN","TILT"] and 1:
  2662. jdata["DELAY"] = xdelay
  2663. if not _blind:
  2664. jdata = [jdata]
  2665. #print("ENC",jdata)
  2666. jclient_send(jdata)
  2667. time.sleep(0.001)
  2668. return jdata
  2669. return v2
  2670. def get_active(self):
  2671. cprint("get_active",self)
  2672. CFG = OrderedDict()
  2673. sdata = OrderedDict()
  2674. sdata["CFG"] = CFG # OrderedDict()
  2675. sdata["CFG"]["FADE"] = FADE.val()
  2676. sdata["CFG"]["DEALY"] = 0
  2677. #sdata["CFG"]["BUTTON"] = "GO"
  2678. for fix in self.fixtures:
  2679. data = self.fixtures[fix]
  2680. for attr in data["ATTRIBUT"]:
  2681. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2682. if fix not in sdata:
  2683. sdata[fix] = {}
  2684. if attr not in sdata[fix]:
  2685. sdata[fix][attr] = OrderedDict()
  2686. if not modes.val("REC-FX"):
  2687. sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
  2688. #sdata[fix][attr]["FADE"] = FADE.val() #fade
  2689. else:
  2690. sdata[fix][attr]["VALUE"] = None #data["ATTRIBUT"][attr]["VALUE"]
  2691. if "FX" not in data["ATTRIBUT"][attr]:
  2692. data["ATTRIBUT"][attr]["FX"] =""
  2693. if "FX2" not in data["ATTRIBUT"][attr]:
  2694. data["ATTRIBUT"][attr]["FX2"] ={}
  2695. sdata[fix][attr]["FX"] = data["ATTRIBUT"][attr]["FX"]
  2696. sdata[fix][attr]["FX2"] = data["ATTRIBUT"][attr]["FX2"]
  2697. return sdata
  2698. def get_active2(self):
  2699. pass
  2700. def _deselect_all(self,fix=None):
  2701. cprint("FIXTURES._deselect_all()",fix,"ALL",color="yellow")
  2702. c=0
  2703. if fix in self.fixtures:
  2704. data = self.fixtures[fix]
  2705. for attr in data["ATTRIBUT"]:
  2706. #print("SELECT ALL",fix,attr)
  2707. if "-FINE" in attr.upper():
  2708. pass
  2709. else:
  2710. c+=self.select(fix,attr,mode="off",mute=1)
  2711. return c
  2712. def _select_all(self,fix=None,mode="toggle",mute=0):
  2713. if not mute:
  2714. cprint("FIXTURES._select_all()",fix,"ALL",mode,color="yellow")
  2715. c=0
  2716. if fix in self.fixtures:
  2717. data = self.fixtures[fix]
  2718. for attr in data["ATTRIBUT"]:
  2719. #print("SELECT ALL",fix,attr)
  2720. if "-FINE" in attr.upper():
  2721. continue
  2722. if mode == "toggle":
  2723. c+=self.select(fix,attr,mode="on",mute=mute)
  2724. elif mode == "swap":
  2725. if not attr.startswith("_"):
  2726. c+=self.select(fix,attr,mode="toggle",mute=mute)
  2727. if not c and mode == "toggle": # unselect all
  2728. c= self._deselect_all(fix=fix)
  2729. return c
  2730. def select(self,fix=None,attr=None,mode="on",mute=0):
  2731. if not mute:
  2732. cprint("FIXTURES.select() >>",fix,attr,mode,color="yellow")
  2733. out = 0
  2734. if fix == "SEL":
  2735. if attr.upper() == "INV-ATTR":
  2736. fixs = self.get_active()
  2737. print("selected:",len(fixs))
  2738. for fix in fixs:
  2739. x=self._select_all(fix=fix,mode=mode,mute=1)
  2740. return None
  2741. if fix in self.fixtures:
  2742. if attr.upper() == "ALL":
  2743. x=self._select_all(fix=fix,mode=mode)
  2744. return x
  2745. data = self.fixtures[fix]
  2746. if attr in data["ATTRIBUT"]:
  2747. if mode == "on":
  2748. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  2749. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2750. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2751. out = 1
  2752. elif mode == "off":
  2753. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2754. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2755. out = 1
  2756. elif mode == "toggle":
  2757. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2758. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2759. else:
  2760. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2761. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2762. out = 1
  2763. return out
  2764. def clear(self):
  2765. out = 0
  2766. for fix in self.fixtures:
  2767. data = self.fixtures[fix]
  2768. for attr in data["ATTRIBUT"]:
  2769. #if attr.endswith("-FINE"):
  2770. # continue
  2771. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2772. out +=1
  2773. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2774. return out
  2775. def CFG_CHECKER(sdata):
  2776. "repair CFG "
  2777. ok = 0
  2778. if "CFG" not in sdata:
  2779. sdata["CFG"] = OrderedDict()
  2780. ok += 1
  2781. if "FADE" not in sdata["CFG"]:
  2782. sdata["CFG"]["FADE"] = 4
  2783. ok += 1
  2784. if "DELAY" not in sdata["CFG"]:
  2785. sdata["CFG"]["DELAY"] = 0
  2786. ok += 1
  2787. if "BUTTON" not in sdata["CFG"]:
  2788. sdata["CFG"]["BUTTON"] = "GO"
  2789. ok += 1
  2790. if "HTP-MASTER" not in sdata["CFG"]:
  2791. sdata["CFG"]["HTP-MASTER"] = 100 #%
  2792. ok += 1
  2793. if "SIZE-MASTER" not in sdata["CFG"]:
  2794. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  2795. ok += 1
  2796. if "SPEED-MASTER" not in sdata["CFG"]:
  2797. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  2798. ok += 1
  2799. if "OFFSET-MASTER" not in sdata["CFG"]:
  2800. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  2801. ok += 1
  2802. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  2803. #except:pass
  2804. return ok
  2805. class Presets():
  2806. def __init__(self):
  2807. #super().__init__()
  2808. self.base = Base()
  2809. #self.load()
  2810. self._last_copy = None
  2811. self._last_move = None
  2812. self.fx_buffer = {}
  2813. def load_presets(self):
  2814. #self._load()
  2815. filename="presets"
  2816. #self.base._init()
  2817. d,l = self.base._load(filename)
  2818. for i in d:
  2819. sdata = d[i]
  2820. ok = CFG_CHECKER(sdata)
  2821. self.val_presets = d
  2822. self.label_presets = l
  2823. def check_cfg(self,nr=None):
  2824. cprint("PRESETS.check_cfg()",nr)#,color="red")
  2825. ok = 0
  2826. if nr is not None:
  2827. if nr in self.val_presets:
  2828. sdata = self.val_presets[nr]
  2829. ok += self._check_cfg(sdata)
  2830. else:
  2831. cprint("nr not in data ",nr,color="red")
  2832. else:
  2833. for nr in self.val_presets:
  2834. sdata = self.val_presets[nr]
  2835. ok += self._check_cfg(sdata)
  2836. return ok
  2837. def _check_cfg(self,sdata):
  2838. cprint("PRESETS._check_cfg()")#,color="red")
  2839. ok = CFG_CHECKER(sdata)
  2840. if ok:
  2841. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  2842. return ok
  2843. def backup_presets(self,save_as=""):
  2844. filename = "presets"
  2845. data = self.val_presets
  2846. labels = self.label_presets
  2847. #self.base._init()
  2848. self.base._backup(filename,data,labels,save_as)
  2849. def get_cfg(self,nr):
  2850. cprint("PRESETS.get_cfg()",nr)
  2851. self.check_cfg(nr)
  2852. if nr not in self.val_presets:
  2853. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  2854. return {}
  2855. if "CFG" in self.val_presets[nr]:
  2856. return self.val_presets[nr]["CFG"]
  2857. def clean(self,nr):
  2858. if nr not in self.val_presets:
  2859. self.val_presets[nr] = OrderedDict()
  2860. #self.val_presets[nr]["VALUE"] = 0
  2861. #self.val_presets[nr]["FX"] = ""
  2862. sdata = self.val_presets[nr]
  2863. for fix in sdata:
  2864. #print("exec.clear()",nr,fix,sdata[fix])
  2865. for attr in sdata[fix]:
  2866. row = sdata[fix][attr]
  2867. if fix == "CFG":
  2868. continue
  2869. if "VALUE" not in row:
  2870. row["VALUE"] = None
  2871. if "FX" not in row:
  2872. row["FX"] = ""
  2873. if "FX2" not in row:
  2874. row["FX2"] = OrderedDict()
  2875. elif row["FX2"]:
  2876. for k in ["SIZE","SPEED","START","OFFSET"]:
  2877. row["FX2"][k] = int( row["FX2"][k] )
  2878. row["FX"] = ""
  2879. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  2880. #"off:0:0:0:16909:-:"
  2881. x = row["FX"].split(":")
  2882. print("-fx",x,len(x))
  2883. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  2884. if len(x) >= 6:
  2885. row["FX2"]["TYPE"] = x[0]
  2886. row["FX2"]["SIZE"] = int(x[1])
  2887. row["FX2"]["SPEED"] = int(x[2])
  2888. row["FX2"]["START"] = int(x[3])
  2889. row["FX2"]["OFFSET"] = int(x[4])
  2890. row["FX2"]["BASE"] = x[5]
  2891. row["FXOLD"] = row["FX"]
  2892. row["FX"] = ""
  2893. #cprint("exec.clear()",nr,fix,row)
  2894. def get_raw_map(self,nr):
  2895. self.clean(nr)
  2896. print("get_raw_map",nr)
  2897. sdata = self.val_presets[nr]
  2898. cmd = ""
  2899. out = []
  2900. dmx=-1
  2901. for fix in sdata:
  2902. if fix == "CFG":
  2903. #print("CFG",nr,sdata[fix])
  2904. continue
  2905. for attr in sdata[fix]:
  2906. x = {}
  2907. #print("RAW",attr)
  2908. x["FIX"] = fix
  2909. x["ATTR"] = attr
  2910. x["VALUE"] = sdata[fix][attr]["VALUE"]
  2911. x["FX"] = sdata[fix][attr]["FX"]
  2912. x["FX2"] = sdata[fix][attr]["FX2"]
  2913. #x["DMX"] = sdata[fix][attr]["NR"]
  2914. out.append(x)
  2915. return out
  2916. def get_btn_txt(self,nr):
  2917. sdata=self.val_presets[nr]
  2918. BTN="go"
  2919. if "CFG" in sdata:
  2920. if "BUTTON" in sdata["CFG"]:
  2921. BTN = sdata["CFG"]["BUTTON"]
  2922. _label = self.label_presets[nr] # = label
  2923. txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  2924. print("get_btn_txt",nr,[txt])
  2925. return txt
  2926. def _btn_cfg(self,nr,txt=None):
  2927. if nr not in self.val_presets:
  2928. return ""
  2929. if "CFG" not in self.val_presets[nr]:
  2930. self.val_presets[nr]["CFG"] = OrderedDict()
  2931. return self.val_presets[nr]["CFG"]
  2932. def btn_cfg(self,nr,txt=None):
  2933. if nr not in self.val_presets:
  2934. return ""
  2935. if "CFG" not in self.val_presets[nr]:
  2936. self.val_presets[nr]["CFG"] = OrderedDict()
  2937. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  2938. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  2939. if type(txt) is str:
  2940. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  2941. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  2942. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  2943. print("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  2944. return self.val_presets[nr]["CFG"]["BUTTON"]
  2945. def label(self,nr,txt=None):
  2946. if nr not in self.label_presets:
  2947. return ""
  2948. if type(txt) is str:
  2949. self.label_presets[nr] = txt
  2950. print("set label",nr,[txt])
  2951. print("??? ?? set label",nr,[txt])
  2952. return self.label_presets[nr]
  2953. def clear_move(self):
  2954. cprint("PRESETS.clear_move()",end=" ")
  2955. self.clear_copy()
  2956. def clear_copy(self):
  2957. cprint("PRESETS.clear_copy()",end=" ")
  2958. if self._last_copy is not None:
  2959. cprint("=OK=",color="red")
  2960. self._last_copy = None
  2961. else:
  2962. cprint("=NONE=",color="green")
  2963. def copy(self,nr,overwrite=1):
  2964. cprint("PRESETS._copy",nr,"last",self._last_copy)
  2965. if nr >= 0:
  2966. if self._last_copy is not None:
  2967. if modes.val("COPY"):
  2968. modes.val("COPY",3)
  2969. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  2970. return ok #ok
  2971. else:
  2972. if modes.val("COPY"):
  2973. modes.val("COPY",2)
  2974. self._last_copy = nr
  2975. cprint("PRESETS.copy START ",color="red")
  2976. return 0
  2977. return 1 # on error reset move
  2978. def _copy(self,nr_from,nr_to,overwrite=1):
  2979. cprint("PRESETS._copy",nr_from,"to",nr_to)
  2980. self.check_cfg(nr_from)
  2981. if type(self._last_copy) is None:
  2982. cprint("PRESETS._copy last nr is None",color="red")
  2983. return 0
  2984. cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
  2985. if nr_from in self.val_presets and nr_to in self.val_presets:
  2986. fdata = self.val_presets[nr_from]
  2987. tdata = self.val_presets[nr_to]
  2988. #cprint(fdata)
  2989. flabel = self.label_presets[nr_from]
  2990. tlabel = self.label_presets[nr_to]
  2991. self.val_presets[nr_to] = copy.deepcopy(fdata)
  2992. self.label_presets[nr_to] = flabel
  2993. if not overwrite: #default
  2994. cprint("overwrite",overwrite)
  2995. self.val_presets[nr_from] = copy.deepcopy(tdata)
  2996. self.label_presets[nr_from] = tlabel
  2997. #self.label_presets[nr_from] = "MOVE"
  2998. self.clear_copy()
  2999. cprint("PRESETS.copy OK",color="green")
  3000. return 1
  3001. def move(self,nr):
  3002. cprint("PRESETS.move",self._last_copy,"to",nr)
  3003. if nr >= 0:
  3004. last = self._last_copy
  3005. if modes.val("MOVE"):
  3006. modes.val("MOVE",2)
  3007. ok= self.copy(nr,overwrite=0)
  3008. if ok and last:
  3009. if modes.val("MOVE"):
  3010. modes.val("MOVE",3)
  3011. cprint("PRESETS.move OK",color="red")
  3012. #self.delete(last)
  3013. return ok #ok
  3014. return 0 # on error reset move
  3015. def delete(self,nr):
  3016. cprint("PRESETS.delete",nr)
  3017. ok=0
  3018. if nr in self.val_presets:
  3019. self.val_presets[nr] = OrderedDict()
  3020. self.label_presets[nr] = ""
  3021. ok = 1
  3022. self.check_cfg(nr)
  3023. return ok
  3024. def rec(self,nr,data,arg=""):
  3025. cprint("rec",self,"rec()",len(data),arg)
  3026. self.check_cfg(nr)
  3027. self._check_cfg(data) #by ref
  3028. odata=self.val_presets[nr]
  3029. #print("odata",odata)
  3030. if "CFG" in odata:
  3031. if "BUTTON" in odata["CFG"]:
  3032. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  3033. self.val_presets[nr] = data
  3034. return 1
  3035. class FixtureEditor():
  3036. def __init__(self,dmx=1):
  3037. pass
  3038. self.elem=[]
  3039. self.dmx=dmx
  3040. print("init FixtureEditor",dmx)
  3041. def event(self,a1="",a2=""):
  3042. print([self.dmx,a1,a2])
  3043. j=[]
  3044. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
  3045. j.append(jdata)
  3046. jclient_send(j)
  3047. class MasterWing():
  3048. def __init__(self,dmx=1):
  3049. pass
  3050. self.elem=[]
  3051. self.dmx=dmx
  3052. print("init MasterWing",dmx)
  3053. def event(self,a1="",a2=""):
  3054. print([self.dmx,a1,a2])
  3055. jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
  3056. j=[]
  3057. j.append(jdata)
  3058. jclient_send(j)
  3059. class BufferVar():
  3060. def __init__(self,elem):
  3061. self.elem = elem
  3062. def change_dmx(self,event=""):
  3063. nr=1
  3064. txt=""
  3065. def cb(data):
  3066. txt = data["Value"]
  3067. dialog._cb = _cb
  3068. dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
  3069. print("change_dmx",[event,self])
  3070. # GUI_FaderLayout():
  3071. lf_nr = 0
  3072. from tkinter import PhotoImage
  3073. _shift_key = 0
  3074. class Window():
  3075. def __init__(self,title="tilte",master=0,width=100,height=100,left=None,top=None,exit=0,cb=None,resize=1):
  3076. global lf_nr
  3077. #ico_path="/opt/LibreLight/Xdesk/icon/"
  3078. ico_path="./icon/"
  3079. self.cb = cb
  3080. if master:
  3081. self.tk = tkinter.Tk()
  3082. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3083. self.tk.withdraw() # do not draw
  3084. self.tk.resizable(resize,resize)
  3085. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  3086. print(defaultFont)
  3087. defaultFont.configure(family="FreeSans",
  3088. size=10,
  3089. weight="bold")
  3090. #self.tk.option_add("*Font", FontBold)
  3091. # MAIN MENUE
  3092. try:
  3093. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"main.png"))
  3094. except Exception as e:
  3095. print("Exception GUIWindow.__init__",e)
  3096. else:
  3097. # addtional WINDOW
  3098. self.tk = tkinter.Toplevel()
  3099. self.tk.iconify()
  3100. #self.tk.withdraw() # do not draw
  3101. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3102. self.tk.resizable(resize,resize)
  3103. try:
  3104. if "COLORPICKER" in title:
  3105. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"picker.png"))
  3106. elif "ENCODER" in title:
  3107. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"enc.png"))
  3108. elif "EXEC" in title:
  3109. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  3110. elif "FX" in title:
  3111. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"fx.png"))
  3112. else:
  3113. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png"))
  3114. except Exception as e:
  3115. print("Exception on load window icon",title)
  3116. print("Exception:",e)
  3117. #time.sleep(3)
  3118. self.tk.deiconify()
  3119. self.tk["bg"] = "black"
  3120. self.tk.bind("<Button>",self.callback)
  3121. self.tk.bind("<Key>",self.callback)
  3122. self.tk.bind("<KeyRelease>",self.callback)
  3123. self.tk.title(""+str(title)+" "+str(lf_nr)+":"+str(rnd_id))
  3124. lf_nr+=1
  3125. #self.tk.geometry("270x600+0+65")
  3126. geo ="{}x{}".format(width,height)
  3127. if left is not None:
  3128. geo += "+{}".format(left)
  3129. if top is not None:
  3130. geo += "+{}".format(top)
  3131. #self._event_clear = Xevent(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
  3132. self.tk.geometry(geo)
  3133. self.show()
  3134. def update_idle_task(self):
  3135. if INIT_OK:
  3136. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3137. pass
  3138. def close_app_win(self,event=None):
  3139. print("close_app_win",self,event)
  3140. if exit:
  3141. save_window_position()
  3142. self.tk.destroy()
  3143. try:
  3144. self.cb("<exit>").cb()
  3145. except Exception as e:
  3146. print("EXCETPION close_app",e)
  3147. def title(self,title=None):
  3148. if title is None:
  3149. return self.tk.title()
  3150. else:
  3151. #return self.tk.title(title)
  3152. return self.tk.title(""+str(title)+" "+str(lf_nr)+":"+str(rnd_id))
  3153. def show(self):
  3154. self.tk.deiconify()
  3155. pass
  3156. def mainloop(self):
  3157. #save_window_position_loop() #like autosave
  3158. try:
  3159. self.tk.mainloop()
  3160. finally:
  3161. self.tk.quit()
  3162. def callback(self,event,data={}):#value=255):
  3163. global _global_short_key
  3164. #time.sleep(0.1)
  3165. if not _global_short_key:
  3166. #cprint("<GLOBAL-GUI-EVENT-DISABLED>",event,color="red")
  3167. return 1
  3168. global _shift_key
  3169. #cprint("<GUI>",event,color="yellow")
  3170. #cprint("<GUI>",event.state,data,[event.type,event.keysym],color="yellow")
  3171. value = 255
  3172. if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
  3173. value = 0
  3174. if "keysym" in dir(event):
  3175. if "Escape" == event.keysym:
  3176. FIXTURES.clear()
  3177. modes.val("ESC",1)
  3178. master.refresh_fix()
  3179. elif event.keysym in ["Shift_L","Shift_R"]:
  3180. #cprint(event.type)
  3181. if "KeyRelease" in str(event.type) or str(event.type) in ["3"]:
  3182. _shift_key = 0
  3183. else:
  3184. _shift_key = 1
  3185. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3186. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3187. global _ENCODER_WINDOW
  3188. if _shift_key:
  3189. _ENCODER_WINDOW.title("SHIFT/FINE ")
  3190. else:
  3191. _ENCODER_WINDOW.title("ENCODER")
  3192. elif event.keysym in "ebfclrms" and value:
  3193. if "e" == event.keysym:
  3194. modes.val("EDIT",1)
  3195. elif "b" == event.keysym:
  3196. modes.val("BLIND",1)
  3197. elif "f" == event.keysym:
  3198. modes.val("FLASH",1)
  3199. elif "c" == event.keysym:
  3200. modes.val("CFG-BTN",1)
  3201. elif "l" == event.keysym:
  3202. modes.val("LABEL",1)
  3203. elif "r" == event.keysym:
  3204. modes.val("REC",1)
  3205. elif "m" == event.keysym:
  3206. x=modes.val("MOVE",1)
  3207. if not x:
  3208. PRESETS.clear_move()
  3209. elif "s" == event.keysym:
  3210. modes.val("SELECT",1)
  3211. elif event.keysym in ["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]:
  3212. nr = int( event.keysym[1:]) # F:1-12
  3213. nr = nr-1+81
  3214. cprint("F-KEY",value,nr,event.keysym)
  3215. #print(event)
  3216. master.preset_go(nr-1,xfade=None,val=value)
  3217. elif event.keysym in ["1","2","3","4","5","6","7","8","9","0"]:
  3218. nr = int( event.keysym)
  3219. if nr == 0:
  3220. nr = 10
  3221. nr = nr-1+161
  3222. cprint("NUM-KEY",value,nr)
  3223. master.preset_go(nr-1,xfade=None,val=value)
  3224. elif "numbersign" == event.keysym and value: # is char "#"
  3225. PRESETS.backup_presets()
  3226. FIXTURES.backup_patch()
  3227. #save_window_position()
  3228. #e = Xevent(fix=0,elem=None,attr="SAVE\nSHOW",mode="SETUP")
  3229. #e.cb(event=event)
  3230. elif "End" == event.keysym:
  3231. FIXTURES.fx_off("all")
  3232. CONSOLE.fx_off("all")
  3233. CONSOLE.flash_off("all")
  3234. elif "Delete" == event.keysym:
  3235. #PRESETS.delete(nr)
  3236. if value:
  3237. modes.val("DEL",1)
  3238. class WindowManager():
  3239. def __init__(self):
  3240. self.windows = {}
  3241. self.obj = {}
  3242. self.nr= 0
  3243. self.first=""
  3244. def new(self,w,name="",obj=None):
  3245. if not self.first:
  3246. if name:
  3247. self.first = name
  3248. else:
  3249. self.first = str(self.nr)
  3250. w.tk.state(newstate='normal')
  3251. w.tk.attributes('-topmost',True)
  3252. if name:
  3253. self.windows[str(name)] = w
  3254. self.obj[str(name)] = obj
  3255. else:
  3256. self.windows[str(self.nr)] = w
  3257. self.obj[str(self.nr)] = obj
  3258. self.nr+=1
  3259. #w.show()
  3260. def mainloop(self):
  3261. self.windows[self.first].mainloop()
  3262. def get(self,name):
  3263. print(self,".get(name) =",name)
  3264. name = str(name)
  3265. if name in self.windows:
  3266. out = self.windows[name]
  3267. print(out)
  3268. return out
  3269. def get_obj(self,name):
  3270. #print(self,".get(name) =",name)
  3271. name = str(name)
  3272. if name in self.windows:
  3273. out = self.obj[name]
  3274. #print(out)
  3275. return out
  3276. def top(self,name):
  3277. name = str(name)
  3278. if name in self.windows:
  3279. self.windows[name].tk.state(newstate='normal')
  3280. self.windows[name].tk.attributes('-topmost',True)
  3281. self.windows[name].tk.attributes('-topmost',False)
  3282. self.windows[name].tk.update_idletasks()# gui_menu_gui.tk)
  3283. #print("redraw",name)
  3284. #if name == "PATCH":
  3285. # gui_patch.draw()
  3286. #if name == "DIMMER":
  3287. # gui_fix.draw()
  3288. if name == "EXEC":
  3289. master._refresh_exec()
  3290. #self.windows[name].tk.update_idletasks()# gui_menu_gui.tk)
  3291. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3292. else:
  3293. print(name,"not in self.windows",self.windows.keys())
  3294. class Console():
  3295. def __init__(self):
  3296. pass
  3297. def flash_off(self,fix):
  3298. pass#client.send("df0:alloff:::,")
  3299. def fx_off(self,fix):
  3300. cprint("Console.fx_off()",fix)
  3301. if not fix or fix == "all":
  3302. #client.send("fx0:alloff:,fxf:alloff:,")
  3303. #client.send("df0:alloff:::,")
  3304. j = []
  3305. if 0:
  3306. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  3307. j.append(jdata)
  3308. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  3309. j.append(jdata)
  3310. else:
  3311. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  3312. j.append(jdata)
  3313. jclient_send(j)
  3314. return 0
  3315. def test_1():
  3316. #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
  3317. pass
  3318. window_manager = WindowManager()
  3319. CONSOLE = Console()
  3320. PRESETS = Presets()
  3321. FIXTURES = Fixtures()
  3322. def LOAD_SHOW():
  3323. PRESETS.load_presets()
  3324. FIXTURES.load_patch()
  3325. #draw_enc(gui,root2)
  3326. #master._refresh_fix()
  3327. #master._refresh_exec()
  3328. LOAD_SHOW()
  3329. master = MASTER()
  3330. class Refresher():
  3331. def __init__(self):
  3332. self.time = time.time()
  3333. self.time_max = time.time()
  3334. self.update = 1
  3335. self.name = "fix" # exec
  3336. def reset(self):
  3337. self.time = time.time() #+.1
  3338. self.update = 1
  3339. def refresh(self):
  3340. #print("refresh",self.update,int((self.time-time.time())*1000))
  3341. if self.time_max+15 < time.time():
  3342. #print("----- MAX REFRES TIMEOUT -----")
  3343. self._refresh()
  3344. if self.update:
  3345. if self.time+0.2 < time.time():
  3346. self._refresh()
  3347. else:
  3348. self.time = time.time() #+.1
  3349. def _refresh(self):
  3350. print(self,"_refresh()")
  3351. if not INIT_OK:
  3352. return
  3353. self.time_max = time.time()
  3354. self.time = time.time()
  3355. self.update = 0
  3356. if self.name == "fix": # exec
  3357. master._refresh_fix()
  3358. else:
  3359. master._refresh_exec()
  3360. print("t=",self.time_max- time.time())
  3361. def loop(self,args={}):
  3362. while 1:
  3363. try:
  3364. if INIT_OK:
  3365. self.refresh()
  3366. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3367. except Exception as e:
  3368. print("loop exc",e)
  3369. traceback.print_exc()
  3370. cprint("== cb EXCEPT",e,color="red")
  3371. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  3372. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  3373. time.sleep(0.2)
  3374. print("main",__name__)
  3375. __run_main = 0
  3376. if __name__ == "__main__":
  3377. __run_main = 1
  3378. else:
  3379. import __main__
  3380. if "unittest" not in dir(__main__):
  3381. __run_main = 1
  3382. refresher_fix = Refresher()
  3383. refresher_fix.name = "fix"
  3384. refresher_exec = Refresher()
  3385. refresher_exec.name = "exec"
  3386. def loops(**args):
  3387. time.sleep(15) # wait until draw all window's
  3388. thread.start_new_thread(refresher_fix.loop,())
  3389. thread.start_new_thread(refresher_exec.loop,())
  3390. if __run_main:
  3391. print("main")
  3392. #thread.start_new_thread(refresher_fix.loop,())
  3393. #thread.start_new_thread(refresher_exec.loop,())
  3394. TOP = _POS_TOP + 15
  3395. L0 = _POS_LEFT
  3396. L1 = _POS_LEFT + 95
  3397. L2 = _POS_LEFT + 920
  3398. W1 = 810
  3399. H1 = 550
  3400. HTB = 23 # hight of the titlebar from window manager
  3401. #w = Window("MAIN",master=1,width=95,height=H1//2,left=L0,top=TOP,resize=0)
  3402. w = Window("MAIN",master=1,width=100,height=H1,left=L0,top=TOP,resize=1)
  3403. gui_menu_gui = w
  3404. data = []
  3405. #data.append({"text":"COMMAND"})
  3406. #data.append({"text":"CONFIG"})
  3407. data.append({"text":"PATCH"})
  3408. data.append({"text":"DIMMER"})
  3409. data.append({"text":"FIXTURES"})
  3410. data.append({"text":"EXEC","name":"EXEC-BTN"})
  3411. data.append({"text":"EXEC-WING"})
  3412. data.append({"text":"---"})
  3413. data.append({"text":"ENCODER"})
  3414. data.append({"text":"COMMAND"})
  3415. data.append({"text":"COLORPICKER","name":"COLOR"})
  3416. data.append({"text":"FX"})
  3417. gui_menu = GUI_menu(w.tk,data)
  3418. window_manager = gui_menu.window_manager #= window_manager
  3419. window_manager.new(w)
  3420. name="EXEC"
  3421. w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3422. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3423. #frame_exe = w.tk
  3424. #draw_preset(master,w1)#w.tk)
  3425. draw_exec(master,w1,PRESETS)#w.tk)
  3426. window_manager.new(w,name)
  3427. name="CONFIG"
  3428. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3429. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3430. #frame_exe = w.tk
  3431. #draw_preset(master,w1)#w.tk)
  3432. #window_manager.new(w,name)
  3433. name="DIMMER"
  3434. w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3435. w2 = ScrollFrame(w.tk,width=W1,height=H1)
  3436. #frame_dim = w1 # w.tk
  3437. #master.draw_dim(w1.tk)
  3438. window_manager.new(w,name)
  3439. name="FIXTURES"
  3440. w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3441. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3442. #frame_fix = w1 #w.tk
  3443. #draw_fix(master,w1,w2)#.tk)
  3444. gui_fix = GUI_FIX(master,w1,w2)
  3445. gui_fix.draw(FIXTURES)
  3446. window_manager.new(w,name)
  3447. name="FIXTURE-EDITOR"
  3448. w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3449. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3450. data=[]
  3451. for i in range((24+12)*15):
  3452. data.append({"text"+str(i):"test"})
  3453. GUI_FaderLayout(w1,data)
  3454. window_manager.new(w,name)
  3455. name="MASTER-WING"
  3456. #w = Window(name,master=0,width=730,height=205,left=L1-80,top=TOP+H1-200)
  3457. w = Window(name,master=0,width=75,height=405,left=L0,top=TOP+H1-220)
  3458. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3459. w1 = tk.Frame(w.tk,width=W1,height=H1)
  3460. w1.pack()
  3461. data=[]
  3462. for i in range(2):
  3463. data.append({"MASTER"+str(i):"MASTER"})
  3464. GUI_MasterWingLayout(w1,data)
  3465. window_manager.new(w,name)
  3466. name="EXEC-WING"
  3467. #w = Window(name,master=0,width=730,height=205,left=L1-80,top=TOP+H1-200)
  3468. w = Window(name,master=0,width=600,height=415,left=L1,top=TOP+H1+HTB*2)
  3469. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3470. w1 = tk.Frame(w.tk,width=W1,height=H1)
  3471. w1.pack()
  3472. data=[]
  3473. for i in range(10*3):
  3474. data.append({"EXEC"+str(i):"EXEC"})
  3475. obj=GUI_ExecWingLayout(w1,data)
  3476. window_manager.new(w,name,obj)
  3477. name="ENCODER"
  3478. w = Window(name,master=0,width=620,height=113,left=L0+710,top=TOP+H1+15+HTB*2)
  3479. _ENCODER_WINDOW = w
  3480. draw_enc(master,w.tk)#Xroot)
  3481. window_manager.new(w,name)
  3482. #name="REMOTE-CONTROL"
  3483. #w = Window(name,master=0,width=220,height=113,left=L0+710,top=TOP+H1+HTB*2+123)
  3484. #_ENCODER_WINDOW = w
  3485. #draw_enc(master,w.tk)#Xroot)
  3486. name = "SETUP"
  3487. w = Window(name,master=0,width=415,height=42,left=L1+10+W1,top=TOP,resize=0)
  3488. w.tk.title("SETUP SHOW:"+master.base.show_name)
  3489. draw_setup(master,w.tk)
  3490. window_manager.new(w,name)
  3491. name = "COMMAND"
  3492. w = Window(name,master=0,width=415,height=130,left=L1+10+W1,top=TOP+81,resize=0)#+96)
  3493. draw_command(master,w.tk)
  3494. window_manager.new(w,name)
  3495. name = "LIVE"
  3496. w = Window(name,master=0,width=415,height=42,left=L1+10+W1,top=TOP+235,resize=0)#250)
  3497. draw_live(master,w.tk)
  3498. window_manager.new(w,name)
  3499. name = "CLOCK"
  3500. w = Window(name,master=0,width=335,height=102,left=L1+10+W1+80,top=TOP+H1+HTB+160,resize=0)#250)
  3501. draw_clock(master,w.tk)
  3502. window_manager.new(w,name)
  3503. name="FX"
  3504. w = Window(name,master=0,width=415,height=297,left=L1+10+W1,top=TOP+302,resize=0)#317)
  3505. #frame_fx = w.tk
  3506. draw_fx(master,w.tk)
  3507. window_manager.new(w,name)
  3508. name="PATCH"
  3509. w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3510. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3511. main_preset_frame = w1
  3512. gui_patch = GUI_PATCH(master,main_preset_frame)
  3513. gui_patch.draw(FIXTURES)
  3514. window_manager.new(w,name)
  3515. #LibreLightDesk
  3516. name="COLORPICKER"
  3517. w = Window(name,master=0,width=600,height=113,left=L1+5,top=TOP+5+HTB*2+H1)
  3518. draw_colorpicker(master,w.tk,FIXTURES,master)
  3519. window_manager.new(w,name)
  3520. name="TableA"
  3521. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3522. #space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
  3523. #x=TableFrame(root=w.tk)#,left=80,top=620)
  3524. #w.show()
  3525. #data =[]
  3526. #for a in range(40):
  3527. # data.append(["E","E{}".format(a+1)])
  3528. #x.draw(data=data,head=["E","C"],config=[12,5,5])
  3529. #w=x.bframe
  3530. #window_manager.new(w,name)
  3531. #Xroot = tk.Tk()
  3532. #Xroot["bg"] = "black" #white
  3533. #Xroot.title( xtitle+" "+str(rnd_id) )
  3534. #Xroot.geometry("1024x800+130+65")
  3535. master.render()
  3536. window_manager.top("Table")
  3537. #w = frame_fix #Window("OLD",master=0,width=W1,height=500,left=130,top=TOP)
  3538. window_manager.new(w,name)
  3539. #Set EXEC-FADER SIZE TO 0 on Startup
  3540. for nr in range(10):
  3541. set_exec_fader(nr,0) #,color="#fff")
  3542. load_window_position()
  3543. #thread.start_new_thread(refresher_fix.loop,())
  3544. #thread.start_new_thread(refresher_exec.loop,())
  3545. thread.start_new_thread(loops,())
  3546. try:
  3547. #root.mainloop()
  3548. #tk.mainloop()
  3549. window_manager.mainloop()
  3550. finally:
  3551. master.exit()