_LibreLightDesk.py 167 KB

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