_LibreLightDesk.py 171 KB

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