_LibreLightDesk.py 168 KB

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