_LibreLightDesk.py 162 KB

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