_LibreLightDesk.py 157 KB

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