_LibreLightDesk.py 180 KB

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