_LibreLightDesk.py 165 KB

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