_LibreLightDesk.py 158 KB

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