_LibreLightDesk.py 163 KB

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