_LibreLightDesk.py 180 KB

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