_LibreLightDesk.py 186 KB

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