_LibreLightDesk.py 170 KB

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