_LibreLightDesk.py 163 KB

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