_LibreLightDesk.py 158 KB

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