_LibreLightDesk.py 159 KB

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