_LibreLightDesk.py 167 KB

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