_LibreLightDesk.py 157 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949
  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. def _read_sav_file(xfname):
  1820. cprint("load",xfname)
  1821. lines = []
  1822. if not os.path.isfile(xfname):
  1823. return []
  1824. f = open(xfname,"r")
  1825. lines = f.readlines()
  1826. f.close()
  1827. data = OrderedDict()
  1828. labels = OrderedDict()
  1829. i=0
  1830. for line in lines:
  1831. r = _fixture_decode_sav_line(line)
  1832. #print(" r",r)
  1833. if not r:
  1834. continue
  1835. key,label,jdata = r
  1836. _fixture_repair_nr0(jdata)
  1837. data[key] = jdata
  1838. labels[key] = label
  1839. return data,labels
  1840. class Base():
  1841. def __init__(self):
  1842. cprint("Base.init()",color="red")
  1843. self._init()
  1844. def _init(self):
  1845. show_name = "DemoShow"
  1846. self.show_path0 = HOME +"/LibreLight/"
  1847. self.show_path = self.show_path0
  1848. self.show_path1 = self.show_path0 + "show/"
  1849. msg = " X "
  1850. self.show_name,msg = _read_init_txt(self.show_path)
  1851. if not self.show_name:
  1852. r=tkinter.messagebox.showwarning(message=msg,parent=None)
  1853. sys.exit()
  1854. fpath = self.show_path1 +show_name
  1855. if not os.path.isdir(fpath):
  1856. cprint(fpath)
  1857. cprint( os.path.isdir(fpath))
  1858. msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  1859. msg += "please check\n"
  1860. msg += "-{}init.txt\n".format(self.show_path0)
  1861. msg += "-{}".format(self.show_path1)
  1862. showwarning(msg=msg,title="Show Error")
  1863. exit()
  1864. self._check()
  1865. def _set(self,fname):
  1866. ok= os.path.isdir(self.show_path1+"/"+fname)
  1867. ini = self.show_path0+"init.txt"
  1868. cprint("SET SHOW NAME",fname,ok,ini)
  1869. try:
  1870. f = open( ini ,"r")
  1871. lines = f.readlines()
  1872. f.close()
  1873. if len(lines) >= 10: # cut show history
  1874. cprint("_set",ini,len(lines))
  1875. lines = lines[-10:]
  1876. f = open( ini ,"w")
  1877. f.writelines(lines)
  1878. f.close()
  1879. exit()
  1880. except:pass
  1881. if ok:
  1882. #self.show_name = fname
  1883. f = open( ini ,"a")
  1884. f.write(fname+"\n")
  1885. f.close()
  1886. return 1
  1887. def _check(self):
  1888. if not os.path.isdir(self.show_path):
  1889. os.mkdir(self.show_path)
  1890. self.show_path += "/show/"
  1891. if not os.path.isdir(self.show_path):
  1892. os.mkdir(self.show_path)
  1893. self.show_path += "/" +self.show_name +"/"
  1894. if not os.path.isdir(self.show_path):
  1895. os.mkdir(self.show_path)
  1896. pass
  1897. def _list(self):
  1898. cprint("BASE._list()")
  1899. out = _listdir(self.show_path1)
  1900. return out
  1901. def _load(self,filename):
  1902. xpath = self.show_path+"/"+str(filename)+".sav"
  1903. if not os.path.isfile(xpath):
  1904. msg = "Exception: {}".format(e)
  1905. msg += "\n\ncheck\n-init.txt"
  1906. cprint(msg,color="red")
  1907. showwarning(msg=msg,title="load Error")
  1908. return _read_sav_file(xpath)
  1909. def build_path(self,save_as):
  1910. save_as = _clean_path(save_as)
  1911. path = self.show_path.split("/")
  1912. path = "/".join(path[:-2])
  1913. fpath = path+"/"+save_as
  1914. return fpath,save_as
  1915. def _create_path(self,fpath):
  1916. if os.path.isdir(fpath):
  1917. cprint("STOP SHOW EXIST !",color="red")
  1918. return 0
  1919. else:
  1920. cprint("CREATE DIR ",fpath,color="green")
  1921. os.mkdir(fpath)
  1922. #self._set(save_as)
  1923. return fpath
  1924. def _backup(self,filename,data,labels,save_as):
  1925. if save_as:
  1926. xfname = save_as +"/"+str(filename)+".sav"
  1927. else:
  1928. xfname = self.show_path+"/"+str(filename)+".sav"
  1929. cprint("backup",xfname)
  1930. f = open(xfname,"w")
  1931. for key in data:
  1932. line = data[key]
  1933. #print(line)
  1934. label = "label"
  1935. if key in labels:
  1936. label = labels[key]
  1937. if label == "Name-"+str(key):
  1938. label = ""
  1939. #print(xfname,"load",key,label,len(line))
  1940. f.write( "{}\t{}\t{}\n".format( key,label,json.dumps(line) ) )
  1941. f.close()
  1942. return 1
  1943. def hex_to_rgb(hex):
  1944. return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
  1945. class cb():
  1946. def __init__(self,win):
  1947. self.win = win
  1948. def _callback(self,event):
  1949. clobj=event.widget
  1950. ## undermouse=find_withtag(master.CURRENT)
  1951. undermouse=self.win.find_closest(self.win.CURRENT)
  1952. cprint( repr(undermouse))
  1953. def callback(self,event):
  1954. cprint(__file__,self,"callback",event)
  1955. cnv = self.win
  1956. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  1957. tags = cnv.gettags(item)
  1958. #cnv.itemconfigure(self.tag, text=tags[0])
  1959. cprint(tags,item)
  1960. color = cnv.itemcget(item, "fill")
  1961. cnv.itemconfig("all", width=1)#filla="green")
  1962. cnv.itemconfig(item, width=3)#filla="green")
  1963. cprint(color)
  1964. cprint( hex_to_rgb(color[1:]))
  1965. def get_exec_btn_cfg(nr):
  1966. #b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
  1967. #for k in PRESETS.val_presets:
  1968. k = nr
  1969. if 1:
  1970. _bg = "grey"
  1971. _ba = "grey"
  1972. _fg = "lightgrey"
  1973. _text = "N/V"
  1974. if nr >= 0:
  1975. #if self._nr_ok:
  1976. # return #pass#abreak
  1977. if nr != k:
  1978. return #continue
  1979. #else:
  1980. # self._nr_ok = 1
  1981. label = ""
  1982. #if k not in self.elem_presets:
  1983. # cprint("ERROR",k ,"not in elem_presets continue")
  1984. # return #continue
  1985. if k in PRESETS.label_presets:
  1986. label = PRESETS.label_presets[k]
  1987. #print([label])
  1988. #b = self.elem_presets[k]
  1989. ifval = 0
  1990. fx_only = 0
  1991. if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
  1992. sdata = PRESETS.val_presets[k]
  1993. #print("sdata7654",sdata)
  1994. BTN="go"
  1995. if "CFG" in sdata:#["BUTTON"] = "GO"
  1996. if "BUTTON" in sdata["CFG"]:
  1997. BTN = sdata["CFG"]["BUTTON"]
  1998. #txt=str(k+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+label
  1999. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  2000. _text = txt
  2001. #if b.text != txt: # TODO
  2002. # #txt+=str(self._XX)
  2003. # #b.configure(text= txt)
  2004. # _text = txt
  2005. # _bg="yellow"
  2006. # _ba="yellow"
  2007. if len(sdata) > 1:
  2008. ifval = 1
  2009. fx_color = 0
  2010. val_color = 0
  2011. for fix in sdata:
  2012. if fix == "CFG":
  2013. continue
  2014. #print( "$$$$",fix,sdata[fix])
  2015. for attr in sdata[fix]:
  2016. if "FX2" in sdata[fix][attr]:
  2017. if sdata[fix][attr]["FX2"]:
  2018. fx_color = 1
  2019. if "FX" in sdata[fix][attr]:
  2020. if sdata[fix][attr]["FX"]:
  2021. fx_color = 1
  2022. if "VALUE" in sdata[fix][attr]:
  2023. if sdata[fix][attr]["VALUE"] is not None:
  2024. val_color = 1
  2025. #try:b.configure(fg= "black")
  2026. #except:pass
  2027. if val_color:
  2028. _bg = "gold"
  2029. _ba = "#ffaa55"
  2030. if fx_color:
  2031. _fg = "blue"
  2032. else:
  2033. if fx_color:
  2034. fx_only = 1
  2035. else:
  2036. _bg = "grey"
  2037. _ba = "#aaa"
  2038. if "\n" in txt:
  2039. txt1 = txt.split("\n")[0]
  2040. _fg = "black"
  2041. if ifval:
  2042. if fx_only:
  2043. _bg = "cyan"
  2044. _ba = "#55d4ff"
  2045. if "SEL" in txt1:
  2046. #b.configure(bg="#77f")
  2047. _bg = "#77f"
  2048. else:
  2049. _bg = "grey"
  2050. _fg = "darkgrey"
  2051. if "SEL" in txt1:
  2052. _fg = "blue"
  2053. elif "ON" in txt1:
  2054. _fg = "#040"
  2055. elif "GO" in txt1:
  2056. _fg = "#555"
  2057. if "FL" in txt1:
  2058. _fg = "#00e"
  2059. out = {}
  2060. out["bg"] = _bg
  2061. out["ba"] = _ba
  2062. out["fg"] = _fg
  2063. out["text"] = _text
  2064. return out
  2065. #b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
  2066. class Elem_Container():
  2067. def __init__(self):
  2068. self.commands = []
  2069. self.val = {}
  2070. self.elem = {}
  2071. class MASTER():
  2072. def __init__(self):
  2073. #super().__init__()
  2074. self.base = Base ()
  2075. self.load()
  2076. self._XX = 0
  2077. self.all_attr =["DIM","PAN","TILT"]
  2078. self.elem_attr = {}
  2079. self.setup_elem = {} # Elem_Container()
  2080. self.setup_cmd = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI"]
  2081. self.fx_moves = Elem_Container()
  2082. self.fx_moves.commands =["REC-FX","FX OFF","\n"
  2083. ,"FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  2084. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  2085. ]
  2086. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  2087. self.fx = Elem_Container()
  2088. self.fx.commands =[
  2089. "FX:DIM","FX:RED", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  2090. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","FX-X:\n-","FX:MODE"
  2091. ]
  2092. self.fx_generic = Elem_Container()
  2093. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON"]
  2094. self.commands = Elem_Container()
  2095. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  2096. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  2097. ,"BLIND","CLEAR","REC","EDIT","COPY",".","\n"
  2098. ]
  2099. self.elem_presets = {}
  2100. for i in range(8*8*8):
  2101. if i not in PRESETS.val_presets:
  2102. name = "Preset:"+str(i+1)+":\nXYZ"
  2103. #self.presets[i] = [i]
  2104. PRESETS.val_presets[i] = OrderedDict() # FIX
  2105. PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
  2106. PRESETS.label_presets[i] = "-"
  2107. modes.set_cb(self.xcb)
  2108. def button_refresh(self,name,color,color2=None,text="",fg=None):
  2109. cprint("button_refresh",name,color)
  2110. #if color == "gold":
  2111. # color2 = "yellow"
  2112. try:
  2113. if color2 is None:
  2114. color2 = color
  2115. if text:
  2116. text = "\n"+str(text)
  2117. if name in self.commands.elem:
  2118. self.commands.elem[name]["bg"] = color
  2119. self.commands.elem[name]["text"] = name+ text
  2120. self.commands.elem[name].config(activebackground=color2)
  2121. if fg:
  2122. self.commands.elem[name]["fg"] = fg
  2123. elif name in self.fx.elem:
  2124. #todo
  2125. self.fx.elem[name]["bg"] = color
  2126. self.fx.elem[name].config(activebackground=color2)
  2127. if fg:
  2128. self.fx.elem[name]["fg"] = fg
  2129. # new version
  2130. for elems in [self.fx_moves]:
  2131. if name in elems.elem:
  2132. elem = elems.elem[name]
  2133. cprint("elem",elem)
  2134. elem.config(bg = color)
  2135. elem.config(text = name+text)
  2136. elem.config(activebackground=color2)
  2137. if fg and "fg" in elem:
  2138. elem["fg"] = fg
  2139. except Exception as e:cprint("exc",self,e)
  2140. def btn_cfg(self,nr,testing=0):
  2141. cfg = PRESETS._btn_cfg(nr)
  2142. button = PRESETS.btn_cfg(nr)
  2143. label = PRESETS.label(nr)
  2144. def _cb(data):
  2145. if not data:
  2146. cprint("err443",self,"_cb",data)
  2147. return None
  2148. cprint(self,"btn_cfg._cb()",data)
  2149. if data:
  2150. if "Button" in data and type(data["Button"]) is str:
  2151. txt = data["Button"]
  2152. PRESETS.btn_cfg(nr,txt)
  2153. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  2154. if "Label" in data and type(data["Label"]) is str:
  2155. txt = data["Label"]
  2156. PRESETS.label(nr,txt)
  2157. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  2158. modes.val("CFG-BTN",0)
  2159. master._refresh_exec(nr=nr)
  2160. dialog._cb = _cb
  2161. if 1: # testing:
  2162. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  2163. else:
  2164. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  2165. def label(self,nr):
  2166. txt = PRESETS.label(nr)
  2167. def _cb(data):
  2168. if not data:
  2169. cprint("err443",self,"_cb",data)
  2170. return None
  2171. txt = data["Value"]
  2172. cprint(self,"label._cb()",nr,txt)
  2173. if txt:
  2174. PRESETS.label(nr,txt)
  2175. self.elem_presets[nr].configure(text = PRESETS.get_btn_txt(nr))
  2176. modes.val("LABEL", 0)
  2177. master._refresh_exec(nr=nr)
  2178. dialog._cb= _cb #_x(nr)
  2179. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  2180. def xcb(self,mode,value=None):
  2181. cprint("MODE CALLBACK",mode,value,color="green",end="")
  2182. #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
  2183. if value:
  2184. cprint("===== ON ======",color="red")
  2185. txt = ""
  2186. if mode == "REC-FX":
  2187. modes.val("REC",0)
  2188. modes.val("REC",1)
  2189. if value == 2:
  2190. if mode in ["MOVE","COPY"]:
  2191. txt="to"
  2192. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  2193. else:
  2194. if mode in ["MOVE","COPY"]:
  2195. txt="from"
  2196. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  2197. else:
  2198. cprint("===== OFF ======",color="red")
  2199. if mode == "REC-FX":
  2200. modes.val("REC",0)
  2201. self.button_refresh(mode,color="lightgrey")#,fg="black")
  2202. def load(self,fname=""):
  2203. pass
  2204. def exit(self):
  2205. cprint("__del__",self)
  2206. PRESETS.backup_presets()
  2207. #print("********************************************************")
  2208. FIXTURES.backup_patch()
  2209. #print("*********del",self,"***********************************************")
  2210. def refresh_exec(self):
  2211. refresher_exec.reset() # = Refresher()
  2212. def _refresh_exec(self,nr=-1):
  2213. s = time.time()
  2214. cprint("PRESET.refresh_exec()")
  2215. refresher_exec.reset() # = Refresher()
  2216. self._XX +=1
  2217. self._nr_ok = 0
  2218. for nr in PRESETS.val_presets:
  2219. cfg = get_exec_btn_cfg(nr)
  2220. if not cfg:
  2221. out = {}
  2222. out["bg"] = "lightgrey"
  2223. out["ba"] = "grey"
  2224. out["fg"] = "grey"
  2225. out["text"] = "?"
  2226. cfg = out
  2227. b = self.elem_presets[nr]
  2228. b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"])
  2229. time.sleep(0.01)
  2230. def refresh_fix(self):
  2231. refresher_fix.reset() # = Refresher()
  2232. def _refresh_fix(self):
  2233. cprint(self,"_refresh_fix")
  2234. s=time.time(); _XXX=0
  2235. menu_buff = {"DIM":0,"DIM-SUB":0,"FIX":0,"FIX-SUB":0}
  2236. elem_buffer = []
  2237. for fix in FIXTURES.fixtures:
  2238. sdata = FIXTURES.fixtures[fix]
  2239. elem_attr_fix = None
  2240. if fix in self.elem_attr:
  2241. elem_attr_fix = self.elem_attr[fix]
  2242. if "DIM" in sdata["ATTRIBUT"] and "_ACTIVE" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 2:
  2243. KEY = "DIM-SUB"
  2244. else:
  2245. KEY = "FIX-SUB"
  2246. FIX = 0
  2247. DIM = 0
  2248. for attr in sdata["ATTRIBUT"]:
  2249. _buff = {}
  2250. row = sdata["ATTRIBUT"][attr]
  2251. if attr.endswith("-FINE"):
  2252. continue
  2253. b_attr = attr
  2254. if b_attr == "_ACTIVE":
  2255. b_attr = "S"
  2256. elem = None
  2257. if elem_attr_fix:
  2258. if b_attr not in elem_attr_fix:
  2259. continue
  2260. elem = elem_attr_fix[b_attr]
  2261. if not elem:
  2262. continue
  2263. if "elem" not in _buff:
  2264. _buff["elem"] = elem
  2265. if not attr.startswith("_"):
  2266. v2 = row["VALUE"]
  2267. #_text = "{} {}".format(str(attr).rjust(4,"0"),str(v2).rjust(4,"0")) # ~0.2 sec
  2268. _text = "{} {}".format(attr,v2)
  2269. _buff["text"] = _text
  2270. if row["ACTIVE"]:
  2271. _buff["bg"] = "yellow"
  2272. _buff["abg"] = "yellow"
  2273. menu_buff[KEY] += 1
  2274. if b_attr == "S":
  2275. if KEY == "DIM-SUB":
  2276. DIM =1
  2277. else:
  2278. FIX =1
  2279. else:
  2280. _buff["bg"] = "grey"
  2281. _buff["abg"] = "grey"
  2282. if "FX2" not in row: # insert FX2 excetption
  2283. row["FX2"] = OrderedDict()
  2284. if row["FX"]:
  2285. _buff["fg"] = "blue"
  2286. elif row["FX2"]:
  2287. _buff["fg"] = "red"
  2288. else:
  2289. _buff["fg"] = "black"
  2290. elem_buffer.append(_buff)
  2291. menu_buff["FIX"] += FIX
  2292. menu_buff["DIM"] += DIM
  2293. cprint(" =+= "*10,"refresh_fix")
  2294. try:
  2295. for row in elem_buffer:
  2296. elem = row["elem"]
  2297. if not elem:
  2298. continue
  2299. #print("<elem>",elem)
  2300. for e in row:
  2301. if e == "elem":
  2302. continue
  2303. v = row[e]
  2304. #print("confg:",["key:",e,"val:",v])
  2305. if e == "abg":
  2306. elem.config(activebackground=v)
  2307. else:
  2308. elem[e] = v
  2309. w = window_manager.get_win("FIXTURES")
  2310. #print(dir(w))
  2311. w.update_idle_task()
  2312. #tkinter.Tk.update_idletasks(w)
  2313. except Exception as e:
  2314. cprint("exc434",e)
  2315. cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
  2316. cprint(gui_menu)
  2317. menu_buff["FIX-SUB"] -= menu_buff["FIX"]
  2318. if menu_buff["FIX-SUB"]:
  2319. gui_menu.config("FIXTURES","bg","yellow")
  2320. gui_menu.config("FIXTURES","activebackground","yellow")
  2321. elif menu_buff["FIX"]:
  2322. gui_menu.config("FIXTURES","bg","orange")
  2323. gui_menu.config("FIXTURES","activebackground","orange")
  2324. else:
  2325. gui_menu.config("FIXTURES","bg","")
  2326. gui_menu.config("FIXTURES","activebackground","")
  2327. gui_menu.update("FIXTURES","{} : {}".format(menu_buff["FIX"],menu_buff["FIX-SUB"]))
  2328. menu_buff["DIM-SUB"] -= menu_buff["DIM"]
  2329. if menu_buff["DIM-SUB"]:
  2330. gui_menu.config("DIMMER","bg","yellow")
  2331. gui_menu.config("DIMMER","activebackground","yellow")
  2332. elif menu_buff["DIM"]:
  2333. gui_menu.config("DIMMER","bg","orange")
  2334. gui_menu.config("DIMMER","activebackground","orange")
  2335. else:
  2336. gui_menu.config("DIMMER","bg","")
  2337. gui_menu.config("DIMMER","activebackground","")
  2338. gui_menu.update("DIMMER","{} : {}".format(menu_buff["DIM"],menu_buff["DIM-SUB"]))
  2339. cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
  2340. def preset_rec(self,nr):
  2341. cprint("------- STORE PRESET")
  2342. data = FIXTURES.get_active()
  2343. if modes.val("REC-FX"):
  2344. PRESETS.rec(nr,data,"REC-FX")
  2345. modes.val("REC-FX",0)
  2346. else:
  2347. PRESETS.rec(nr,data)
  2348. sdata=data
  2349. PRESETS.val_presets[nr] = sdata
  2350. master._refresh_exec()
  2351. return 1
  2352. def preset_select(self,nr):
  2353. cprint("SELECT PRESET")
  2354. sdata = PRESETS.val_presets[nr]
  2355. cmd = ""
  2356. for fix in sdata:
  2357. if fix == "CFG":
  2358. continue
  2359. for attr in sdata[fix]:
  2360. #v2 = sdata[fix][attr]["VALUE"]
  2361. #v2_fx = sdata[fix][attr]["FX"]
  2362. #print( self.data.elem_attr)
  2363. #if fix in self.elem_attr:
  2364. # if attr in self.elem_attr[fix]:
  2365. # elem = self.elem_attr[fix][attr]
  2366. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  2367. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2368. #elem["bg"] = "yellow"
  2369. def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  2370. t_start = time.time()
  2371. if xfade is None and FADE._is():
  2372. xfade = FADE.val()
  2373. if ptfade is None and FADE_move._is():
  2374. ptfade = FADE_move.val()
  2375. cprint("GO PRESET FADE",nr,val)
  2376. rdata = PRESETS.get_raw_map(nr)
  2377. if not rdata:
  2378. return 0
  2379. cprint("???????")
  2380. cfg = PRESETS.get_cfg(nr)
  2381. cprint("''''''''")
  2382. #virtcmd = FIXTURES.get_virtual(rdata)
  2383. if not cfg:
  2384. cprint("NO CFG",cfg,nr)
  2385. return 0
  2386. xFLASH = 0
  2387. value=None
  2388. cprint("preset_go",nr,cfg)
  2389. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  2390. self.preset_select(nr)
  2391. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  2392. xFLASH = 1
  2393. xfade = 0
  2394. if type(val) is not type(None) and val == 0 :
  2395. value = "off"
  2396. if event:
  2397. if str(event.type) == "ButtonRelease" or event.type == '5' :
  2398. value = "off"
  2399. cprint("preset_go() FLUSH",value,color="red")
  2400. fcmd = FIXTURES.update_raw(rdata,update=0)
  2401. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  2402. elif not val:
  2403. cprint("preset_go() STOP",value,color="red")
  2404. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  2405. fcmd = FIXTURES.update_raw(rdata)
  2406. self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  2407. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  2408. fcmd = FIXTURES.update_raw(rdata)
  2409. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  2410. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  2411. self.refresh_exec()
  2412. self.refresh_fix()
  2413. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  2414. #print(len(self.elem_presets) )
  2415. if len(self.elem_presets) > nr: # RED BUTTON IF PRESSED
  2416. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  2417. if val:# or value:
  2418. #self.elem_presets[nr].config(borderwidth=1)
  2419. self.elem_presets[nr].config(bg="red")
  2420. else:
  2421. self._refresh_exec()
  2422. cprint("preset_go",time.time()-t_start)
  2423. def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  2424. if xfade is None and FADE._is():
  2425. xfade = FADE.val()
  2426. if ptfade is None and FADE_move._is():
  2427. ptfade = FADE_move.val()
  2428. cprint("PRESETS._preset_go() len=",len(rdata),cfg)
  2429. if xfade is None:
  2430. xfade = cfg["FADE"]
  2431. if ptfade is None:
  2432. ptfade = cfg["FADE"]
  2433. #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
  2434. #cprint(rdata,color="red")
  2435. vcmd = reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
  2436. cmd = []
  2437. delay=0
  2438. for i,v in enumerate(fcmd):
  2439. #print("go",i,v)
  2440. if xFLASH:
  2441. vcmd[i]["FLASH"] = 1
  2442. DMX = fcmd[i]["DMX"]
  2443. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  2444. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  2445. if value is not None:
  2446. vcmd[i]["VALUE"] = value
  2447. if value == "off":
  2448. if "FX2" in vcmd:
  2449. vcmd[i]["FX2"]["TYPE"] = value
  2450. if "FIX" in fcmd:
  2451. vcmd[i]["FIX"] = fcmd["FIX"]
  2452. if DMX and vcmd[i]:
  2453. vcmd[i]["DMX"] = DMX
  2454. if "VIRTUAL" in fcmd[i]:
  2455. for a in fcmd[i]["VIRTUAL"]:
  2456. DMX = fcmd[i]["VIRTUAL"][a]
  2457. if DMX and vcmd[i]:
  2458. vcmd[i]["DMX"] = DMX
  2459. if type(nr) is not type(None):
  2460. vcmd[i]["EXEC"] = str(int(nr)+1)
  2461. #cprint(vcmd[i],color="red")
  2462. cmd.append(vcmd[i])
  2463. if cmd and not modes.val("BLIND"):
  2464. jclient_send(cmd)
  2465. def render(self):
  2466. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  2467. #self.draw_input()
  2468. pass
  2469. ##draw_sub_dim
  2470. class InputEventBlocker():
  2471. def __init__(self):
  2472. self.__init = 0
  2473. self.cursor = "88888"
  2474. def set(self,el,txt):
  2475. self.e = el
  2476. self.e_txt = txt
  2477. self.cursor = "88888"
  2478. def init(self):
  2479. if self.__init == 0:
  2480. try:
  2481. self.el = tk.Button()
  2482. self.e_txt = tk.StringVar()
  2483. self.__init = 1
  2484. except Exception as e:
  2485. pirnt("init() exception",e)
  2486. def _lock(self):
  2487. global _global_short_key
  2488. _global_short_key = 0
  2489. try:master.commands.elem["S-KEY"]["bg"] = "red"
  2490. except Exception as e:cprint("exc",self,e)
  2491. cmd="xset -display :0.0 r rate 240 15"
  2492. print(cmd)
  2493. os.system(cmd)
  2494. def _unlock(self):
  2495. global _global_short_key
  2496. _global_short_key = 1
  2497. try:master.commands.elem["S-KEY"]["bg"] = "green"
  2498. except Exception as e:cprint("exc",self,e)
  2499. cmd = "xset -display :0.0 r off"
  2500. print(cmd)
  2501. os.system(cmd)
  2502. def lock(self):
  2503. self._lock()
  2504. #self.e["bg"] = "red"
  2505. #self.el.config({"background": "grey"})
  2506. #self.e.focus()
  2507. def unlock(self):
  2508. self._unlock()
  2509. #self.e["bg"] = "blue"
  2510. #self.el.config({"background": "yellow"})
  2511. #self.el.focus_set()
  2512. def event(self,event,**args):
  2513. self.init()
  2514. #print()
  2515. cprint(self,event,args)
  2516. #print("###-",self.e_txt,dir(self.e_txt))
  2517. if "S-KEY" not in master.commands.elem:
  2518. #cprint("<GLOBAL-GUI-EVENT-DISABLED>",event,color="red")
  2519. return
  2520. if "num" in dir(event):
  2521. self.lock()
  2522. if "keysym" in dir(event):
  2523. t=self.e_txt.get()
  2524. if t and t[-1] == "<":
  2525. t = t[:-1]
  2526. if event.keysym == "Return" or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  2527. self.unlock()
  2528. #self.e_txt.set(t)
  2529. cprint("filter: get()",_global_short_key,t)
  2530. t2 = t
  2531. if _global_short_key == 0:
  2532. if event.keysym == "BackSpace":
  2533. if len(t) > 1:
  2534. t2 = t[:-1]
  2535. else:
  2536. t2=""
  2537. elif event.keysym == "Escape":
  2538. t2=""
  2539. elif event.keysym == "space":
  2540. t2=t+" "
  2541. elif event.char in "äöüÄÖÜ-_,.;:#'*+~":
  2542. t2=t+event.char
  2543. elif len(event.keysym) == 1:
  2544. t2=t+event.keysym
  2545. #self.e_txt.set(t2+"<")
  2546. #time.sleep(0.2)
  2547. #_global_short_key = 1
  2548. input_event_blocker = InputEventBlocker()
  2549. from tkgui.dialog import *
  2550. dialog = Dialog()
  2551. from tkgui.draw import *
  2552. from tkgui.GUI import *
  2553. class LOAD_SHOW_AND_RESTAT():
  2554. def __init__(self,fname=""):
  2555. self.fname=fname
  2556. self.base = Base()
  2557. def cb(self,event=None,force=0):
  2558. cprint("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
  2559. if not self.fname and not force:
  2560. return 0
  2561. if self.base.show_name == self.fname and not force:
  2562. cprint("filename is the same",self.fname)
  2563. return 0
  2564. if not force:
  2565. self.base._set(self.fname)
  2566. cprint("LOAD SHOW:",event,self.fname)
  2567. cprint(sys.executable, os.path.abspath(__file__), *sys.argv)
  2568. os.execl("/usr/bin/python3", "/opt/LibreLight/Xdesk/_LibreLightDesk.py", "_LibreLightDesk.py")
  2569. sys.exit()
  2570. class PopupList():
  2571. 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"):
  2572. self.name = name
  2573. self.frame = None
  2574. self.bg=bg
  2575. self.cb = cb
  2576. if cb is None:
  2577. cb = DummyCallback #("load_show_list.cb")
  2578. #w = Window(self.name,master=master,width=width,height=height,exit=exit,left=left,top=top,cb=cb)
  2579. args = {"title":self.name,"master":master,"width":width,"height":height,"exit":exit,"left":left,"top":top,"cb":cb}
  2580. w = Window(args)
  2581. self.w = w
  2582. w.show()
  2583. def sframe(self,line1="<line1>",line2="<line2>",data=[]):
  2584. xframe=self.w.tk
  2585. if self.bg:
  2586. xframe.configure(bg=self.bg)
  2587. self.w.tk.configure(bg=self.bg)
  2588. c=0
  2589. r=0
  2590. b = tk.Label(xframe,bg="grey",text=line1,anchor="w")
  2591. b.pack(side="top",expand=0,fill="x" )
  2592. b = tk.Label(xframe,bg="grey",text=line2,anchor="w")
  2593. b.pack(side="top",expand=0,fill="x" )
  2594. b = tk.Label(xframe,bg="black",fg="black",text="")
  2595. if self.bg:
  2596. b.configure(fg=self.bg)
  2597. b.configure(bg=self.bg)
  2598. b.pack(side="top")
  2599. b = tk.Entry(xframe,width=10,text="")#,anchor="w")
  2600. b.pack(side="top",expand=0,fill="x")
  2601. b.focus()
  2602. #frame = tk.Frame(xframe,heigh=2800)
  2603. #frame.pack(fill=tk.BOTH,expand=1, side=tk.TOP)
  2604. frame = ScrollFrame(xframe,width=300,height=500,bd=1,bg=self.bg)
  2605. #frame.pack(side="left") #fill=tk.BOTH,expand=1, side=tk.TOP)
  2606. #self.frame = frame
  2607. self.w.tk.state(newstate='normal')
  2608. self.w.tk.attributes('-topmost',True)
  2609. return frame
  2610. class DummyCallback():
  2611. def __init__(self,name="name"):
  2612. self.name = name
  2613. def cb(self,event=None):
  2614. cprint("DummyCallback.cb",[self.name,event])
  2615. class BaseCallback():
  2616. def __init__(self,cb=None,args={}):
  2617. self._cb=cb
  2618. self.args = args
  2619. def cb(self,**args):
  2620. print("BaseCallback.cb()")
  2621. print(" ",self.args)
  2622. print(" ",self._cb)
  2623. if self._cb:
  2624. if self.args:
  2625. self._cb(args=self.args)
  2626. else:
  2627. self._cb()
  2628. def frame_of_show_list(frame,cb=None):
  2629. c=0
  2630. r=0
  2631. base = Base()
  2632. for i in ["name","stamp"]: #,"create"]:
  2633. b = tk.Label(frame,bg="grey",text=i)
  2634. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2635. c+=1
  2636. r+=1
  2637. blist = base._list()
  2638. for i in range(10):
  2639. blist.append(["",""])
  2640. if cb is None:
  2641. cb = DummyCallback #("load_show_list.cb")
  2642. for i in blist:
  2643. #print(i)
  2644. c=0
  2645. for j in i:
  2646. bg="lightgrey"
  2647. dbg="lightgrey"
  2648. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2649. dbg = "lightgreen"
  2650. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2651. dbg = "green"
  2652. if c > 0:
  2653. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2654. b.config(activebackground=dbg)
  2655. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2656. else:
  2657. if base.show_name == i[0]:
  2658. bg="green"
  2659. _cb = cb(j)
  2660. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2661. if base.show_name == i[0]:
  2662. b.config(activebackground=bg)
  2663. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2664. c+=1
  2665. r+=1
  2666. def _parse_fixture_name(name):
  2667. out = []
  2668. #{"FIX","MAN","CH","PATH":""}
  2669. if name.count(".") == 2:
  2670. m,n,e = name.split(".")
  2671. #out = [n,m,"0",name]
  2672. out = {"name":n,"manufactor":m,"fname":name}
  2673. elif name.count("_") == 2:
  2674. name,e = name.split(".")
  2675. m,n,c = name.split("_")
  2676. out = {"name":n,"ch":c,"manufactor":m,"name":name}
  2677. #out = [n,m,c,name]
  2678. else:
  2679. out = {"name":name}
  2680. return out
  2681. def online_help(page):
  2682. print("INIT:online_help",page)
  2683. try:
  2684. page = page.replace("&","")
  2685. page = page.replace("=","")
  2686. page = page.replace("/","")
  2687. import webbrowser
  2688. def _cb():
  2689. print("online_help",page)
  2690. webbrowser.open("http://librelight.de/wiki/doku.php?id="+page )
  2691. return _cb
  2692. except Exception as e:
  2693. print("online_help Exception",e)
  2694. raise e
  2695. def _cb():
  2696. print("error online_help",page)
  2697. return _cb
  2698. def index_fixtures():
  2699. p="/opt/LibreLight/Xdesk/fixtures/"
  2700. ls = os.listdir(p )
  2701. ls.sort()
  2702. for l in ls:
  2703. b = _parse_fixture_name(l)
  2704. b.append(p)
  2705. b.insert(0,"base")
  2706. blist.append(b)
  2707. def _fixture_load_list(path):
  2708. blist = []
  2709. try:
  2710. ls = os.listdir(path)
  2711. ls.sort()
  2712. print(path)
  2713. for fn in ls:
  2714. b = _parse_fixture_name(fn)
  2715. b["xpath"] = path
  2716. b["xfname"] = fn.replace(path,"")
  2717. print(" ",b)
  2718. blist.append(b)
  2719. except Exception as e:
  2720. cprint("Exce 877 ",e)
  2721. return blist
  2722. def _fixture_create_import_list():
  2723. path = "/home/user/LibreLight/show"
  2724. blist = []
  2725. for sname in os.listdir(path):
  2726. #print(" ",sname)
  2727. try:
  2728. fname = path+"/"+sname+"/patch.sav"
  2729. if os.path.isfile(fname):
  2730. f = open(fname)
  2731. lines = f.readlines()
  2732. f.close()
  2733. for line in lines:
  2734. line = line.split("\t")
  2735. line = json.loads(line[2])
  2736. name = line["NAME"]
  2737. #row = [name,fname+":"+name,path])
  2738. xfname = fname.replace(path,"")
  2739. row = {"name":name,"xfname":xfname , "xpath":path}
  2740. blist.append(row)
  2741. except Exception as e:
  2742. print("exception",e)
  2743. return blist
  2744. def _fixture_load_import_list():
  2745. return _fixture_create_import_list()
  2746. pass
  2747. path = HOME+"/LibreLight/fixture.index.json"
  2748. if not os.path.isfile(path):
  2749. blist = _fixture_create_import_list()
  2750. f = open(path,"w")
  2751. for line in blist:
  2752. line = json.dumps(line)
  2753. f.writelines(line)
  2754. f.close()
  2755. blist = []
  2756. if os.path.isfile(path):
  2757. f = open(path,"r")
  2758. lines = f.readlines()
  2759. f.close()
  2760. for line in lines:
  2761. print("_fixture_load__import",line)
  2762. line = line.strip()
  2763. blist.append(json.loads(line))
  2764. return blist
  2765. def _fixture_load_data(path,number):
  2766. 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}
  2767. """
  2768. return data
  2769. def _load_fixture_list(mode="None"):
  2770. blist = []
  2771. if mode == "USER":
  2772. path = HOME+"/LibreLight/fixtures/"
  2773. _r = _fixture_load_list(path=path)
  2774. blist.extend( _r )
  2775. elif mode == "GLOBAL":
  2776. path="/opt/LibreLight/Xdesk/fixtures/"
  2777. _r = _fixture_load_list(path=path)
  2778. blist.extend( _r )
  2779. elif mode == "IMPORT":
  2780. _r=_fixture_load_import_list()
  2781. blist.extend( _r )
  2782. for i in blist:
  2783. print(" -",i)
  2784. return blist
  2785. class Fixtures():
  2786. def __init__(self):
  2787. #super().__init__()
  2788. self.base=Base()
  2789. #self.load()
  2790. self.fixtures = OrderedDict()
  2791. self.gui = GUIHandler()
  2792. def load_patch(self):
  2793. filename="patch"
  2794. #self.base._init()
  2795. d,l = self.base._load(filename)
  2796. self.fixtures = OrderedDict()
  2797. for i in l:
  2798. sdata = d[i]
  2799. new_f = OrderedDict()
  2800. #print("++++")
  2801. for k,j in sdata.items():
  2802. overide=0 # only for repair
  2803. if overide:
  2804. if k in ["TYPE","VENDOR"]: #ignor
  2805. continue
  2806. new_f[k] = j
  2807. if k =="NAME":
  2808. #print("AAAADDDDDD")
  2809. if "TYPE" not in sdata and not overide:
  2810. if len( sdata["ATTRIBUT"]) == 1:
  2811. new_f["TYPE"] = "DIMMER"
  2812. elif "PAN" in sdata["ATTRIBUT"]:
  2813. new_f["TYPE"] = "MOVER"
  2814. elif "RED" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 3:
  2815. new_f["TYPE"] = "RGB"
  2816. elif "RED" in sdata["ATTRIBUT"]:
  2817. new_f["TYPE"] = "LED"
  2818. elif "CYAN" in sdata["ATTRIBUT"]:
  2819. new_f["TYPE"] = "COLOR"
  2820. else:
  2821. new_f["TYPE"] = ""
  2822. if "VENDOR" not in sdata and not overide:
  2823. new_f["VENDOR"] = ""
  2824. #print(k,j)#,sdata)
  2825. sdata = new_f
  2826. if "ACTIVE" not in sdata:
  2827. sdata["ACTIVE"] = 0
  2828. sdata["ATTRIBUT"]["_ACTIVE"] = OrderedDict()
  2829. sdata["ATTRIBUT"]["_ACTIVE"]["NR"] = 0
  2830. sdata["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2831. sdata["ATTRIBUT"]["_ACTIVE"]["VALUE"] = 0
  2832. for attr in sdata["ATTRIBUT"]:
  2833. sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
  2834. #print("load",filename,sdata)
  2835. #if "CFG" not in sdata:
  2836. # sdata["CFG"] = OrderedDict()
  2837. self.fixtures[str(i)] = sdata
  2838. #PRESETS.label_presets = l
  2839. self.fx_off("all")
  2840. def backup_patch(self,save_as=""):
  2841. filename = "patch"
  2842. #self.fx_off("all")
  2843. data = self.fixtures
  2844. labels = {}
  2845. for k in data:
  2846. labels[k] = k
  2847. #self.base._init()
  2848. self.base._backup(filename,data,labels,save_as)
  2849. def fx_get(self,fix=None):
  2850. out={}
  2851. if not fix or fix == "all":
  2852. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2853. for fix in self.fixtures:
  2854. data = self.fixtures[fix]
  2855. for attr in data["ATTRIBUT"]:
  2856. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX"]
  2857. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX2"]
  2858. return out
  2859. def fx_off(self,fix=None):
  2860. if not fix or fix == "all":
  2861. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2862. for fix in self.fixtures:
  2863. data = self.fixtures[fix]
  2864. for attr in data["ATTRIBUT"]:
  2865. data["ATTRIBUT"][attr]["FX"] = ""
  2866. data["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  2867. def get_attr(self,fix,attr):
  2868. if fix in self.fixtures:
  2869. data = self.fixtures[fix]
  2870. if "ATTRIBUT" in data:
  2871. if attr in data["ATTRIBUT"]:
  2872. return data["ATTRIBUT"][attr]
  2873. def get_max_dmx_nr(self,fix):
  2874. max_dmx = 0
  2875. used_dmx = 0
  2876. if fix not in self.fixtures:
  2877. return (used_dmx,max_dmx)
  2878. data = self.fixtures[fix]
  2879. used_dmx = len(data["ATTRIBUT"])
  2880. for a in data["ATTRIBUT"]:
  2881. attr = data["ATTRIBUT"][a]
  2882. if "NR" in attr:
  2883. try:
  2884. _n = int(attr["NR"])
  2885. if _n > max_dmx:
  2886. max_dmx=_n
  2887. except ValueError:pass
  2888. return (used_dmx,max_dmx)
  2889. def get_dmx(self,fix,attr):
  2890. #cprint("get_dmx",[fix,attr])
  2891. if fix in self.fixtures:
  2892. data = self.fixtures[fix]
  2893. DMX = -99
  2894. if "DMX" in data:
  2895. DMX = int(data["DMX"])
  2896. if DMX < 1: # ignore attribute with DMX lower 1
  2897. return -22
  2898. else:
  2899. return -1
  2900. if "UNIVERS" in data:
  2901. if int(data["UNIVERS"]) >= 0:
  2902. DMX += (int(data["UNIVERS"])*512)
  2903. else:
  2904. return -33
  2905. adata = self.get_attr(fix,attr)
  2906. #-hier ende 8.2.22
  2907. #cprint("adata",adata,DMX)
  2908. if adata:
  2909. if "NR" in adata:
  2910. NR = adata["NR"]
  2911. if NR >= 1:
  2912. DMX+=NR-1
  2913. else:
  2914. return -44
  2915. return DMX
  2916. return -4
  2917. return -3
  2918. def update_raw(self,rdata,update=1):
  2919. cprint("update_raw",len(rdata))
  2920. cmd = []
  2921. for i,d in enumerate(rdata):
  2922. xcmd = {"DMX":""}
  2923. #print("fix:",i,d)
  2924. fix = d["FIX"]
  2925. attr = d["ATTR"]
  2926. v2 = d["VALUE"]
  2927. v2_fx = d["FX"]
  2928. if fix not in self.fixtures:
  2929. continue
  2930. sdata = self.fixtures[fix] #shortcat
  2931. ATTR = sdata["ATTRIBUT"]
  2932. sDMX = 0
  2933. if sdata["DMX"] > 0:
  2934. #print( sdata)
  2935. sDMX = (sdata["UNIVERS"]*512)+sdata["DMX"]
  2936. #sDMX =sdata["DMX"]
  2937. #else:
  2938. # continue
  2939. if attr not in ATTR:
  2940. continue
  2941. #DMX = FIXTURES.get_dmx(fix)
  2942. if ATTR[attr]["NR"] >= 0:
  2943. DMX = sDMX+ATTR[attr]["NR"]-1
  2944. xcmd["DMX"] = str(DMX)
  2945. else:
  2946. if attr == "DIM" and ATTR[attr]["NR"] < 0:
  2947. xcmd["VIRTUAL"] = {}
  2948. for a in ATTR:
  2949. if ATTR[a]["MASTER"]:
  2950. xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
  2951. #print( "VIRTUAL",xcmd)
  2952. cmd.append(xcmd)
  2953. v=ATTR[attr]["VALUE"]
  2954. if v2 is not None and update:
  2955. ATTR[attr]["VALUE"] = v2
  2956. if d["FX2"] and update:
  2957. ATTR[attr]["FX2"] = d["FX2"]
  2958. #self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
  2959. text = str(attr)+' '+str(round(v,2))
  2960. #self.gui.update(fix,attr,args={"text":text})
  2961. #print("END 5454 _=_=_=_=_==_")
  2962. #cprint("update_raw",cmd,color="red")
  2963. return cmd
  2964. def encoder(self,fix,attr,xval="",xfade=0,xdelay=0,blind=0):
  2965. _blind = 0
  2966. if modes.val("BLIND"):
  2967. _blind = 1
  2968. if blind:
  2969. _blind = 1
  2970. if not _blind:
  2971. cprint("FIXTURES.encoder",fix,attr,xval,xfade,color="yellow")
  2972. if attr == "CLEAR":
  2973. self.clear()
  2974. return 0
  2975. if attr == "ALL":
  2976. x=self.select(fix,attr,mode="toggle")
  2977. return x
  2978. if attr == "INV-ATTR":
  2979. cprint("-x-x-x-x-x-x-x-X-")
  2980. x=self.select(fix,attr,mode="swap")
  2981. #x=self.select(fix,"ALL",mode="swap")
  2982. master.refresh_fix()
  2983. return x
  2984. if attr == "INV-FIX":
  2985. cprint("-x-x-x-x-x-x-x-x-")
  2986. x=self.select(fix,attr,mode="swap")
  2987. #x=self.select(fix,"ALL",mode="swap")
  2988. return x
  2989. out = []
  2990. if fix not in self.fixtures:
  2991. cprint(" activate Fixture in fixture list on encoder click ")
  2992. ii =0
  2993. delay=0
  2994. sstart = time.time()
  2995. cprint("-->A HIER <--")
  2996. sub_data = []
  2997. for _fix in self.fixtures:
  2998. ii+=1
  2999. data = self.fixtures[_fix]
  3000. if "-FINE" in attr.upper():
  3001. continue
  3002. elif (attr in data["ATTRIBUT"] ) and "-FINE" not in attr.upper() :
  3003. if xval == "click":
  3004. self.select(_fix,attr,mode="on")
  3005. elif data["ATTRIBUT"][attr]["ACTIVE"]:
  3006. if _fix:
  3007. sub_data.append([_fix,attr,xval,xfade,delay])
  3008. if DELAY._is():
  3009. delay += DELAY.val()/100
  3010. sub_jdata = []
  3011. for dd in sub_data:
  3012. #print("---",len(sub_data),end="")
  3013. #self.encoder(fix,attr,xval,xfade,delay)
  3014. _x123 = self.encoder(dd[0],dd[1],dd[2],dd[3],dd[4],blind=1)
  3015. sub_jdata.append(_x123)
  3016. if sub_jdata:
  3017. cprint("--- SEND MASTER ENCODER:",len(sub_data),sub_data[0],"... _blind:",_blind)#,end="")
  3018. jclient_send(sub_jdata)
  3019. jdata=[{"MODE":ii}]
  3020. cprint("-->B HIER <--")
  3021. jclient_send(jdata)
  3022. return 0
  3023. data = self.fixtures[fix]
  3024. if xval == "click":
  3025. #cprint(data)
  3026. return self.select(fix,attr,mode="toggle")
  3027. v2=data["ATTRIBUT"][attr]["VALUE"]
  3028. change=0
  3029. increment = 5 #4.11
  3030. jdata = {"MODE":"ENC"}
  3031. if xval == "++":
  3032. v2+= increment
  3033. jdata["INC"] = increment
  3034. change=1
  3035. elif xval == "--":
  3036. jdata["INC"] = increment*-1
  3037. v2-= increment
  3038. change=1
  3039. elif xval == "+":
  3040. increment = 0.25 #.5
  3041. v2+= increment
  3042. jdata["INC"] = increment
  3043. change=1
  3044. elif xval == "-":
  3045. increment = 0.25 #.5
  3046. jdata["INC"] = increment*-1
  3047. v2-= increment
  3048. change=1
  3049. elif type(xval) is int or type(xval) is float:
  3050. v2 = xval
  3051. change=1
  3052. if v2 < 0:
  3053. v2=0
  3054. elif v2 > 256:
  3055. v2=256
  3056. jdata["VALUE"] = round(v2,4)
  3057. jdata["FIX"] = fix
  3058. jdata["ATTR"] = attr
  3059. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  3060. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  3061. out = {}
  3062. if change:
  3063. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  3064. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  3065. data["ATTRIBUT"][attr]["VALUE"] = round(v2,4)
  3066. jdata["FADE"] = 0
  3067. if xfade:
  3068. jdata["FADE"] = xfade
  3069. if xdelay:
  3070. #if attr not in ["PAN","TILT"] and 1:
  3071. jdata["DELAY"] = xdelay
  3072. if not _blind:
  3073. jdata = [jdata]
  3074. #print("ENC",jdata)
  3075. jclient_send(jdata)
  3076. time.sleep(0.001)
  3077. return jdata
  3078. return v2
  3079. def get_active(self):
  3080. cprint("get_active",self)
  3081. CFG = OrderedDict()
  3082. sdata = OrderedDict()
  3083. sdata["CFG"] = CFG # OrderedDict()
  3084. sdata["CFG"]["FADE"] = FADE.val()
  3085. sdata["CFG"]["DEALY"] = 0
  3086. for fix in self.fixtures:
  3087. data = self.fixtures[fix]
  3088. for attr in data["ATTRIBUT"]:
  3089. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  3090. continue
  3091. if fix not in sdata:
  3092. sdata[fix] = {}
  3093. if attr not in sdata[fix]:
  3094. sdata[fix][attr] = OrderedDict()
  3095. if not modes.val("REC-FX"):
  3096. sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
  3097. else:
  3098. sdata[fix][attr]["VALUE"] = None
  3099. if "FX" not in data["ATTRIBUT"][attr]:
  3100. data["ATTRIBUT"][attr]["FX"] = ""
  3101. if "FX2" not in data["ATTRIBUT"][attr]:
  3102. data["ATTRIBUT"][attr]["FX2"] = {}
  3103. sdata[fix][attr]["FX"] = data["ATTRIBUT"][attr]["FX"]
  3104. sdata[fix][attr]["FX2"] = data["ATTRIBUT"][attr]["FX2"]
  3105. return sdata
  3106. def _deselect_all(self,fix=None):
  3107. cprint("FIXTURES._deselect_all()",fix,"ALL",color="yellow")
  3108. c=0
  3109. if fix in self.fixtures:
  3110. data = self.fixtures[fix]
  3111. for attr in data["ATTRIBUT"]:
  3112. #print("SELECT ALL",fix,attr)
  3113. if "-FINE" in attr.upper():
  3114. pass
  3115. else:
  3116. c+=self.select(fix,attr,mode="off",mute=1)
  3117. return c
  3118. def _select_all(self,fix=None,mode="toggle",mute=0):
  3119. if not mute:
  3120. cprint("FIXTURES._select_all()",fix,"ALL",mode,color="yellow")
  3121. c=0
  3122. if fix in self.fixtures:
  3123. data = self.fixtures[fix]
  3124. for attr in data["ATTRIBUT"]:
  3125. #print("SELECT ALL",fix,attr)
  3126. if "-FINE" in attr.upper():
  3127. continue
  3128. if mode == "toggle":
  3129. c+=self.select(fix,attr,mode="on",mute=mute)
  3130. elif mode == "swap":
  3131. if not attr.startswith("_"):
  3132. c+=self.select(fix,attr,mode="toggle",mute=mute)
  3133. if not c and mode == "toggle": # unselect all
  3134. c= self._deselect_all(fix=fix)
  3135. return c
  3136. def select(self,fix=None,attr=None,mode="on",mute=0):
  3137. if not mute:
  3138. cprint("FIXTURES.select() >>",fix,attr,mode,color="yellow")
  3139. out = 0
  3140. if fix == "SEL":
  3141. if attr.upper() == "INV-ATTR":
  3142. fixs = self.get_active()
  3143. cprint("selected:",len(fixs))
  3144. for fix in fixs:
  3145. x=self._select_all(fix=fix,mode=mode,mute=1)
  3146. return None
  3147. if fix in self.fixtures:
  3148. if attr.upper() == "ALL":
  3149. x=self._select_all(fix=fix,mode=mode)
  3150. return x
  3151. data = self.fixtures[fix]
  3152. if attr in data["ATTRIBUT"]:
  3153. if mode == "on":
  3154. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  3155. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  3156. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  3157. out = 1
  3158. elif mode == "off":
  3159. if data["ATTRIBUT"][attr]["ACTIVE"]:
  3160. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  3161. out = 1
  3162. elif mode == "toggle":
  3163. if data["ATTRIBUT"][attr]["ACTIVE"]:
  3164. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  3165. else:
  3166. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  3167. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  3168. out = 1
  3169. return out
  3170. def clear(self):
  3171. out = 0
  3172. for fix in self.fixtures:
  3173. data = self.fixtures[fix]
  3174. for attr in data["ATTRIBUT"]:
  3175. #if attr.endswith("-FINE"):
  3176. # continue
  3177. if data["ATTRIBUT"][attr]["ACTIVE"]:
  3178. out +=1
  3179. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  3180. return out
  3181. def CFG_CHECKER(sdata):
  3182. "repair CFG "
  3183. ok = 0
  3184. if "CFG" not in sdata:
  3185. sdata["CFG"] = OrderedDict()
  3186. ok += 1
  3187. if "FADE" not in sdata["CFG"]:
  3188. sdata["CFG"]["FADE"] = 4
  3189. ok += 1
  3190. if "DELAY" not in sdata["CFG"]:
  3191. sdata["CFG"]["DELAY"] = 0
  3192. ok += 1
  3193. if "BUTTON" not in sdata["CFG"]:
  3194. sdata["CFG"]["BUTTON"] = "GO"
  3195. ok += 1
  3196. if "HTP-MASTER" not in sdata["CFG"]:
  3197. sdata["CFG"]["HTP-MASTER"] = 100 #%
  3198. ok += 1
  3199. if "SIZE-MASTER" not in sdata["CFG"]:
  3200. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  3201. ok += 1
  3202. if "SPEED-MASTER" not in sdata["CFG"]:
  3203. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  3204. ok += 1
  3205. if "OFFSET-MASTER" not in sdata["CFG"]:
  3206. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  3207. ok += 1
  3208. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  3209. #except:pass
  3210. return ok
  3211. class Presets():
  3212. def __init__(self):
  3213. #super().__init__()
  3214. self.base = Base()
  3215. #self.load()
  3216. self._last_copy = None
  3217. self._last_move = None
  3218. self.fx_buffer = {}
  3219. def load_presets(self):
  3220. #self._load()
  3221. filename="presets"
  3222. #self.base._init()
  3223. d,l = self.base._load(filename)
  3224. for i in d:
  3225. sdata = d[i]
  3226. ok = CFG_CHECKER(sdata)
  3227. self.val_presets = d
  3228. self.label_presets = l
  3229. def check_cfg(self,nr=None):
  3230. cprint("PRESETS.check_cfg()",nr)#,color="red")
  3231. ok = 0
  3232. if nr is not None:
  3233. if nr in self.val_presets:
  3234. sdata = self.val_presets[nr]
  3235. ok += self._check_cfg(sdata)
  3236. else:
  3237. cprint("nr not in data ",nr,color="red")
  3238. else:
  3239. for nr in self.val_presets:
  3240. sdata = self.val_presets[nr]
  3241. ok += self._check_cfg(sdata)
  3242. return ok
  3243. def _check_cfg(self,sdata):
  3244. cprint("PRESETS._check_cfg()")#,color="red")
  3245. ok = CFG_CHECKER(sdata)
  3246. if ok:
  3247. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  3248. return ok
  3249. def backup_presets(self,save_as=""):
  3250. filename = "presets"
  3251. data = self.val_presets
  3252. labels = self.label_presets
  3253. #self.base._init()
  3254. self.base._backup(filename,data,labels,save_as)
  3255. def get_cfg(self,nr):
  3256. cprint("PRESETS.get_cfg()",nr)
  3257. self.check_cfg(nr)
  3258. if nr not in self.val_presets:
  3259. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  3260. return {}
  3261. if "CFG" in self.val_presets[nr]:
  3262. return self.val_presets[nr]["CFG"]
  3263. def clean(self,nr):
  3264. if nr not in self.val_presets:
  3265. self.val_presets[nr] = OrderedDict()
  3266. #self.val_presets[nr]["VALUE"] = 0
  3267. #self.val_presets[nr]["FX"] = ""
  3268. sdata = self.val_presets[nr]
  3269. for fix in sdata:
  3270. #print("exec.clear()",nr,fix,sdata[fix])
  3271. for attr in sdata[fix]:
  3272. row = sdata[fix][attr]
  3273. if fix == "CFG":
  3274. continue
  3275. if "VALUE" not in row:
  3276. row["VALUE"] = None
  3277. if "FX" not in row:
  3278. row["FX"] = ""
  3279. if "FX2" not in row:
  3280. row["FX2"] = OrderedDict()
  3281. elif row["FX2"]:
  3282. for k in ["SIZE","SPEED","START","OFFSET"]:
  3283. row["FX2"][k] = int( row["FX2"][k] )
  3284. row["FX"] = ""
  3285. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  3286. #"off:0:0:0:16909:-:"
  3287. x = row["FX"].split(":")
  3288. cprint("-fx",x,len(x))
  3289. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  3290. if len(x) >= 6:
  3291. row["FX2"]["TYPE"] = x[0]
  3292. row["FX2"]["SIZE"] = int(x[1])
  3293. row["FX2"]["SPEED"] = int(x[2])
  3294. row["FX2"]["START"] = int(x[3])
  3295. row["FX2"]["OFFSET"] = int(x[4])
  3296. row["FX2"]["BASE"] = x[5]
  3297. row["FXOLD"] = row["FX"]
  3298. row["FX"] = ""
  3299. #cprint("exec.clear()",nr,fix,row)
  3300. def get_raw_map(self,nr):
  3301. self.clean(nr)
  3302. cprint("get_raw_map",nr)
  3303. sdata = self.val_presets[nr]
  3304. cmd = ""
  3305. out = []
  3306. dmx=-1
  3307. for fix in sdata:
  3308. if fix == "CFG":
  3309. #print("CFG",nr,sdata[fix])
  3310. continue
  3311. for attr in sdata[fix]:
  3312. x = {}
  3313. #print("RAW",attr)
  3314. x["FIX"] = fix
  3315. x["ATTR"] = attr
  3316. x["VALUE"] = sdata[fix][attr]["VALUE"]
  3317. x["FX"] = sdata[fix][attr]["FX"]
  3318. x["FX2"] = sdata[fix][attr]["FX2"]
  3319. #x["DMX"] = sdata[fix][attr]["NR"]
  3320. out.append(x)
  3321. return out
  3322. def get_btn_txt(self,nr):
  3323. sdata=self.val_presets[nr]
  3324. BTN="go"
  3325. if "CFG" in sdata:
  3326. if "BUTTON" in sdata["CFG"]:
  3327. BTN = sdata["CFG"]["BUTTON"]
  3328. _label = self.label_presets[nr] # = label
  3329. #txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  3330. #txt=str(nr+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+_label
  3331. txt="{} {} {}\n{}".format(nr+1,BTN,len(sdata)-1,_label)
  3332. cprint("get_btn_txt",nr,[txt])
  3333. return txt
  3334. def _btn_cfg(self,nr,txt=None):
  3335. if nr not in self.val_presets:
  3336. return ""
  3337. if "CFG" not in self.val_presets[nr]:
  3338. self.val_presets[nr]["CFG"] = OrderedDict()
  3339. return self.val_presets[nr]["CFG"]
  3340. def btn_cfg(self,nr,txt=None):
  3341. if nr not in self.val_presets:
  3342. return ""
  3343. if "CFG" not in self.val_presets[nr]:
  3344. self.val_presets[nr]["CFG"] = OrderedDict()
  3345. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  3346. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3347. if type(txt) is str:
  3348. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  3349. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  3350. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3351. master._refresh_exec(nr=nr)
  3352. cprint("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  3353. return self.val_presets[nr]["CFG"]["BUTTON"]
  3354. def label(self,nr,txt=None):
  3355. if nr not in self.label_presets:
  3356. return ""
  3357. if type(txt) is str:
  3358. self.label_presets[nr] = txt
  3359. cprint("set label",nr,[txt])
  3360. cprint("??? ?? set label",nr,[txt])
  3361. return self.label_presets[nr]
  3362. def clear_move(self):
  3363. cprint("PRESETS.clear_move()",end=" ")
  3364. self.clear_copy()
  3365. def clear_copy(self):
  3366. cprint("PRESETS.clear_copy()",end=" ")
  3367. if self._last_copy is not None:
  3368. cprint("=OK=",color="red")
  3369. self._last_copy = None
  3370. else:
  3371. cprint("=NONE=",color="green")
  3372. def copy(self,nr,overwrite=1):
  3373. cprint("PRESETS._copy",nr,"last",self._last_copy)
  3374. if nr >= 0:
  3375. if self._last_copy is not None:
  3376. if modes.val("COPY"):
  3377. modes.val("COPY",3)
  3378. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  3379. return ok #ok
  3380. else:
  3381. if modes.val("COPY"):
  3382. modes.val("COPY",2)
  3383. self._last_copy = nr
  3384. cprint("PRESETS.copy START ",color="red")
  3385. return 0
  3386. return 1 # on error reset move
  3387. def _copy(self,nr_from,nr_to,overwrite=1):
  3388. cprint("PRESETS._copy",nr_from,"to",nr_to)
  3389. self.check_cfg(nr_from)
  3390. if type(self._last_copy) is None:
  3391. cprint("PRESETS._copy last nr is None",color="red")
  3392. return 0
  3393. cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
  3394. if nr_from in self.val_presets and nr_to in self.val_presets:
  3395. fdata = self.val_presets[nr_from]
  3396. tdata = self.val_presets[nr_to]
  3397. #cprint(fdata)
  3398. flabel = self.label_presets[nr_from]
  3399. tlabel = self.label_presets[nr_to]
  3400. self.val_presets[nr_to] = copy.deepcopy(fdata)
  3401. self.label_presets[nr_to] = flabel
  3402. if not overwrite: #default
  3403. cprint("overwrite",overwrite)
  3404. self.val_presets[nr_from] = copy.deepcopy(tdata)
  3405. self.label_presets[nr_from] = tlabel
  3406. #self.label_presets[nr_from] = "MOVE"
  3407. self.clear_copy()
  3408. cprint("PRESETS.copy OK",color="green")
  3409. return 1
  3410. def move(self,nr):
  3411. cprint("PRESETS.move",self._last_copy,"to",nr)
  3412. if nr >= 0:
  3413. last = self._last_copy
  3414. if modes.val("MOVE"):
  3415. modes.val("MOVE",2)
  3416. ok= self.copy(nr,overwrite=0)
  3417. if ok and last >= 0:
  3418. if modes.val("MOVE"):
  3419. modes.val("MOVE",3)
  3420. cprint("PRESETS.move OK",color="red")
  3421. #self.delete(last)
  3422. return ok,nr,last #ok
  3423. return 0,nr,last # on error reset move
  3424. def delete(self,nr):
  3425. cprint("PRESETS.delete",nr)
  3426. ok=0
  3427. if nr in self.val_presets:
  3428. self.val_presets[nr] = OrderedDict()
  3429. self.label_presets[nr] = "-"
  3430. ok = 1
  3431. self.check_cfg(nr)
  3432. return ok
  3433. def rec(self,nr,data,arg=""):
  3434. cprint("rec",self,"rec()",len(data),arg)
  3435. self.check_cfg(nr)
  3436. self._check_cfg(data) #by ref
  3437. odata=self.val_presets[nr]
  3438. #print("odata",odata)
  3439. if "CFG" in odata:
  3440. if "BUTTON" in odata["CFG"]:
  3441. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  3442. self.val_presets[nr] = data
  3443. return 1
  3444. class FixtureEditor():
  3445. def __init__(self,dmx=1):
  3446. pass
  3447. self.elem=[]
  3448. self.dmx=dmx
  3449. cprint("init FixtureEditor",dmx)
  3450. def event(self,a1="",a2=""):
  3451. cprint([self.dmx,a1,a2])
  3452. j=[]
  3453. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
  3454. j.append(jdata)
  3455. jclient_send(j)
  3456. class MasterWing():
  3457. def __init__(self,dmx=1):
  3458. pass
  3459. self.elem=[]
  3460. self.dmx=dmx
  3461. cprint("init MasterWing",dmx)
  3462. def event(self,a1="",a2=""):
  3463. cprint([self.dmx,a1,a2])
  3464. jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
  3465. j=[]
  3466. j.append(jdata)
  3467. jclient_send(j)
  3468. class BufferVar():
  3469. def __init__(self,elem):
  3470. self.elem = elem
  3471. def change_dmx(self,event=""):
  3472. nr=1
  3473. txt=""
  3474. def cb(data):
  3475. txt = data["Value"]
  3476. dialog._cb = _cb
  3477. dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
  3478. cprint("change_dmx",[event,self])
  3479. lf_nr = 0
  3480. from tkinter import PhotoImage
  3481. _shift_key = 0
  3482. class on_focus():
  3483. def __init__(self,name,mode):
  3484. self.name = name
  3485. self.mode = mode
  3486. def cb(self,event=None):
  3487. print("on_focus",event,self.name,self.mode)
  3488. e = master.commands.elem["."]
  3489. if self.mode == "Out":
  3490. cmd="xset -display :0.0 r rate 240 20"
  3491. print(cmd)
  3492. os.system(cmd)
  3493. e["bg"] = "#aaa"
  3494. e["activebackground"] = "#aaa"
  3495. if self.mode == "In":
  3496. cmd = "xset -display :0.0 r off"
  3497. print(cmd)
  3498. os.system(cmd)
  3499. e["bg"] = "#fff"
  3500. e["activebackground"] = "#fff"
  3501. class Window():
  3502. def __init__(self,args): #title="title",master=0,width=100,height=100,left=None,top=None,exit=0,cb=None,resize=1):
  3503. global lf_nr
  3504. self.args = {"title":"title","master":0,"width":100,"height":100,"left":None,"top":None,"exit":0,"cb":None,"resize":1}
  3505. self.args.update(args)
  3506. cprint("Window.init()",id(self.args),color="yellow")
  3507. cprint(" ",self.args,color="yellow")
  3508. ico_path="./icon/"
  3509. self.cb = cb
  3510. if self.args["master"]:
  3511. self.tk = tkinter.Tk()
  3512. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3513. self.tk.withdraw() # do not draw
  3514. self.tk.resizable(self.args["resize"],self.args["resize"])
  3515. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  3516. cprint(defaultFont)
  3517. defaultFont.configure(family="FreeSans",
  3518. size=10,
  3519. weight="bold")
  3520. # MAIN MENUE
  3521. try:
  3522. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"main.png"))
  3523. except Exception as e:
  3524. cprint("Exception GUIWindow.__init__",e)
  3525. else:
  3526. # addtional WINDOW
  3527. self.tk = tkinter.Toplevel()
  3528. self.tk.iconify()
  3529. #self.tk.withdraw() # do not draw
  3530. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3531. self.tk.resizable(self.args["resize"],self.args["resize"])
  3532. try:
  3533. if "COLORPICKER" in self.args["title"]:
  3534. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"picker.png"))
  3535. elif "ENCODER" in self.args["title"]:
  3536. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"enc.png"))
  3537. elif "EXEC" in self.args["title"]:
  3538. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  3539. elif "FX" in self.args["title"]:
  3540. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"fx.png"))
  3541. else:
  3542. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png"))
  3543. except Exception as e:
  3544. cprint("Exception on load window icon",self.args["title"])
  3545. cprint("Exception:",e)
  3546. #time.sleep(3)
  3547. self.tk.deiconify()
  3548. self.tk["bg"] = "black"
  3549. self.tk.bind("<Button>",self.callback)
  3550. self.tk.bind("<Key>",self.callback)
  3551. self.tk.bind("<KeyRelease>",self.callback)
  3552. self.tk.bind("<FocusIn>", on_focus(self.args["title"],"In").cb)
  3553. self.tk.bind("<FocusOut>", on_focus(self.args["title"],"Out").cb)
  3554. self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3555. lf_nr+=1
  3556. #self.tk.geometry("270x600+0+65")
  3557. geo ="{}x{}".format(self.args["width"],self.args["height"])
  3558. if self.args["left"] is not None:
  3559. geo += "+{}".format(self.args["left"])
  3560. if self.args["top"] is not None:
  3561. geo += "+{}".format(self.args["top"])
  3562. #self._event_clear = Xevent(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
  3563. self.tk.geometry(geo)
  3564. self.show()
  3565. def update_idle_task(self):
  3566. if INIT_OK:
  3567. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3568. pass
  3569. def close_app_win(self,event=None):
  3570. cprint("close_app_win",self,event,self.args["title"],color="red")
  3571. if exit:
  3572. if self.title == "MAIN":
  3573. save_window_position()
  3574. save_window_position()
  3575. self.tk.destroy()
  3576. try:
  3577. self.cb("<exit>").cb()
  3578. except Exception as e:
  3579. cprint("EXCETPION: close_app_win",e,self,color="red")
  3580. def title(self,title=None):
  3581. if title is None:
  3582. return self.tk.title()
  3583. else:
  3584. #return self.tk.title(title)
  3585. self.args["title"] = title
  3586. return self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3587. def show(self):
  3588. self.tk.deiconify()
  3589. pass
  3590. def mainloop(self):
  3591. #save_window_position_loop() #like autosave
  3592. try:
  3593. self.tk.mainloop()
  3594. finally:
  3595. self.tk.quit()
  3596. def callback(self,event,data={}):#value=255):
  3597. global _global_short_key
  3598. sstart = time.time()
  3599. #time.sleep(0.1)
  3600. if not _global_short_key:
  3601. return 1
  3602. global _shift_key
  3603. #cprint("<GUI>",event,color="yellow")
  3604. value = 255
  3605. if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
  3606. value = 0
  3607. cprint("<GUI>",event.state,data,value,[event.type,event.keysym],color="yellow")
  3608. #print(event)
  3609. if "state" in dir(event) and "keysym" in dir(event):
  3610. #print([event.state,event.keysym,event.type])
  3611. if event.state == 4 and str(2) == str(event.type): # strg + s
  3612. if str(event.keysym) == "s":
  3613. cprint("tTtT ReW "*20)
  3614. #print("numbersign !!")
  3615. PRESETS.backup_presets()
  3616. FIXTURES.backup_patch()
  3617. save_window_position()
  3618. e = master.setup_elem["SAVE\nSHOW"]
  3619. #print(e)
  3620. b = BLINKI(e)
  3621. b.blink()
  3622. if str(event.keysym) == "c":
  3623. PRESETS.backup_presets()
  3624. FIXTURES.backup_patch()
  3625. save_window_position()
  3626. #self.elem.config(activebackground="lightgrey")
  3627. LOAD_SHOW_AND_RESTAT("").cb(force=1)
  3628. #cprint("oipo "*10,round(int(time.time()-sstart)*1000,2))
  3629. return
  3630. if "keysym" in dir(event):
  3631. if "Escape" == event.keysym:
  3632. FIXTURES.clear()
  3633. modes.val("ESC",1)
  3634. master.refresh_fix()
  3635. elif event.keysym in ["Shift_L","Shift_R"]:
  3636. #cprint(event.type)
  3637. if "KeyRelease" in str(event.type) or str(event.type) in ["3"]:
  3638. _shift_key = 0
  3639. else:
  3640. _shift_key = 1
  3641. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3642. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3643. global _ENCODER_WINDOW
  3644. try:
  3645. if _shift_key:
  3646. _ENCODER_WINDOW.title("SHIFT/FINE ")
  3647. else:
  3648. _ENCODER_WINDOW.title("ENCODER")
  3649. except Exception as e:
  3650. cprint("exc9800",e)
  3651. elif event.keysym in "ebfclrmsRx" and value:
  3652. if "e" == event.keysym:
  3653. modes.val("EDIT",1)
  3654. elif "b" == event.keysym:
  3655. modes.val("BLIND",1)
  3656. elif "f" == event.keysym:
  3657. modes.val("FLASH",1)
  3658. elif "c" == event.keysym:
  3659. modes.val("CFG-BTN",1)
  3660. elif "l" == event.keysym:
  3661. modes.val("LABEL",1)
  3662. elif "r" == event.keysym:
  3663. modes.val("REC",1)
  3664. elif "R" == event.keysym:
  3665. modes.val("REC-FX",1)
  3666. elif "x" == event.keysym:
  3667. modes.val("REC-FX",1)
  3668. elif "m" == event.keysym:
  3669. x=modes.val("MOVE",1)
  3670. if not x:
  3671. PRESETS.clear_move()
  3672. elif "s" == event.keysym:
  3673. modes.val("SELECT",1)
  3674. elif event.keysym in ["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]:
  3675. nr = int( event.keysym[1:]) # F:1-12
  3676. nr = nr-1+81
  3677. cprint("F-KEY",value,nr,event.keysym)
  3678. #print(event)
  3679. master.preset_go(nr-1,xfade=None,val=value)
  3680. elif event.keysym in ["1","2","3","4","5","6","7","8","9","0"]:
  3681. nr = int( event.keysym)
  3682. if nr == 0:
  3683. nr = 10
  3684. nr = nr-1+161
  3685. cprint("NUM-KEY",value,nr)
  3686. master.preset_go(nr-1,xfade=None,val=value)
  3687. elif "numbersign" == event.keysym and value: # is char "#"
  3688. cprint("numbersign !!")
  3689. PRESETS.backup_presets()
  3690. FIXTURES.backup_patch()
  3691. save_window_position()
  3692. for e in master.setup_cmd:
  3693. cprint(e)
  3694. e = master.setup_elem["SAVE\nSHOW"]
  3695. cprint(e)
  3696. b = BLINKI(e)
  3697. b.blink()
  3698. #e = Xevent(fix=0,elem=None,attr="SAVE\nSHOW",mode="SETUP")
  3699. #e.cb(event=event)
  3700. elif "End" == event.keysym:
  3701. FIXTURES.fx_off("all")
  3702. CONSOLE.fx_off("all")
  3703. CONSOLE.flash_off("all")
  3704. elif "Delete" == event.keysym:
  3705. #PRESETS.delete(nr)
  3706. if value:
  3707. modes.val("DEL",1)
  3708. cprint("oipo "*10,round(int(time.time()-sstart)*1000,2))
  3709. class WindowManager():
  3710. def __init__(self):
  3711. self.windows = {}
  3712. self.obj = {}
  3713. self.nr= 0
  3714. self.first=""
  3715. self.window_init_buffer = {}
  3716. def update(self,w,name="",obj=None):
  3717. name = str(name)
  3718. for k in self.windows:
  3719. if k == name:
  3720. self.windows[str(name)] = w
  3721. self.obj[str(name)] = obj
  3722. def new(self,w,name="",obj=None,wcb=None):
  3723. name = str(name)
  3724. if wcb and name:
  3725. self.window_init_buffer[name] = wcb
  3726. if not self.first:
  3727. if name:
  3728. self.first = name
  3729. else:
  3730. self.first = str(self.nr)
  3731. if w:
  3732. w.tk.state(newstate='normal')
  3733. w.tk.attributes('-topmost',True)
  3734. if name:
  3735. self.windows[str(name)] = w
  3736. self.obj[str(name)] = obj
  3737. else:
  3738. self.windows[str(self.nr)] = w
  3739. self.obj[str(self.nr)] = obj
  3740. self.nr+=1
  3741. def mainloop(self):
  3742. self.windows[self.first].mainloop()
  3743. def get_win(self,name):
  3744. cprint(self,".get_win(name) =",name)
  3745. name = str(name)
  3746. if name in self.windows:
  3747. out = self.windows[name]
  3748. cprint(out)
  3749. return out
  3750. def get(self,name):
  3751. return get_win(name)
  3752. def get_obj(self,name):
  3753. name = str(name)
  3754. if name in self.windows:
  3755. out = self.obj[name]
  3756. return out
  3757. def create(self,name):
  3758. cprint( "create Window",name)
  3759. if name in self.window_init_buffer:
  3760. c = self.window_init_buffer[name]
  3761. w,obj,cb_ok = c.create()
  3762. window_manager.update(w,name,obj)
  3763. if cb_ok:
  3764. cb_ok()
  3765. resize = 1
  3766. if "resize" in c.args:
  3767. if not c.args["resize"]:
  3768. resize = 0
  3769. #if resize:
  3770. get_window_position(_filter=name,win=w)
  3771. if name in ["ENCODER"]:
  3772. global _ENCODER_WINDOW
  3773. _ENCODER_WINDOW = w
  3774. if name in ["DIMMER","FIXTURES"]:
  3775. refresher_fix.reset() # = Refresher()
  3776. def _check(self,name):
  3777. try:
  3778. self.windows[name].tk.state(newstate='normal')
  3779. return 1
  3780. except Exception as e:
  3781. cprint("exception",e,color="red")
  3782. cprint("info",name,self.windows[name],color="red")
  3783. def top(self,name):
  3784. name = str(name)
  3785. if name not in self.windows:
  3786. cprint(name,"not in self.windows",self.windows.keys())
  3787. return
  3788. if not self._check(name):
  3789. self.create(name)
  3790. self.windows[name].tk.attributes('-topmost',True)
  3791. self.windows[name].tk.attributes('-topmost',False)
  3792. self.windows[name].tk.update_idletasks()
  3793. class Console():
  3794. def __init__(self):
  3795. pass
  3796. def flash_off(self,fix):
  3797. pass#client.send("df0:alloff:::,")
  3798. def fx_off(self,fix):
  3799. cprint("Console.fx_off()",fix)
  3800. if not fix or fix == "all":
  3801. #client.send("fx0:alloff:,fxf:alloff:,")
  3802. #client.send("df0:alloff:::,")
  3803. j = []
  3804. if 0:
  3805. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  3806. j.append(jdata)
  3807. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  3808. j.append(jdata)
  3809. else:
  3810. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  3811. j.append(jdata)
  3812. jclient_send(j)
  3813. return 0
  3814. def test_1():
  3815. #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
  3816. pass
  3817. window_manager = WindowManager()
  3818. CONSOLE = Console()
  3819. PRESETS = Presets()
  3820. FIXTURES = Fixtures()
  3821. def LOAD_SHOW():
  3822. PRESETS.load_presets()
  3823. FIXTURES.load_patch()
  3824. #master._refresh_fix()
  3825. #master._refresh_exec()
  3826. LOAD_SHOW()
  3827. master = MASTER()
  3828. class Refresher():
  3829. def __init__(self):
  3830. self.time = time.time()
  3831. self.time_max = time.time()
  3832. self.time_delta = 15
  3833. self.update = 1
  3834. self.name = "name" # exec
  3835. self.cb = None #self.dummy_cb
  3836. def dummy_cb(self):
  3837. cprint(self,"dummy_cd()",time.time()-self.time)
  3838. def reset(self):
  3839. self.time = time.time()
  3840. self.update = 1
  3841. def refresh(self):
  3842. if self.update:
  3843. if self.time+self.time_delta < time.time():
  3844. self._refresh()
  3845. else:
  3846. self.time = time.time()
  3847. def _refresh(self):
  3848. cprint("_refresh()",self.name,self)
  3849. if not INIT_OK:
  3850. return
  3851. self.time_max = time.time()
  3852. self.time = time.time()
  3853. self.update = 0
  3854. try:
  3855. if self.cb:
  3856. self.cb()
  3857. else:
  3858. self.dummy_cb()
  3859. except Exception as e:
  3860. cprint("_refresh except:",e,"cb:",self.cb)
  3861. traceback.print_exc()
  3862. cprint()
  3863. cprint("t=",self.time_max- time.time())
  3864. def loop(self,args={}):
  3865. while 1:
  3866. try:
  3867. if INIT_OK:
  3868. self.refresh()
  3869. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3870. except Exception as e:
  3871. cprint("loop exc",e)
  3872. traceback.print_exc()
  3873. cprint("== cb EXCEPT",e,color="red")
  3874. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  3875. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  3876. time.sleep(0.2)
  3877. print("main",__name__)
  3878. __run_main = 0
  3879. if __name__ == "__main__":
  3880. __run_main = 1
  3881. else:
  3882. import __main__
  3883. if "unittest" not in dir(__main__):
  3884. __run_main = 1
  3885. refresher_fix = Refresher()
  3886. refresher_fix.time_delta = 0.50
  3887. refresher_fix.name = "fix"
  3888. refresher_fix.reset()
  3889. refresher_fix.cb = master._refresh_fix
  3890. refresher_exec = Refresher()
  3891. refresher_exec.time_delta = 10 #0
  3892. refresher_exec.name = "exec"
  3893. refresher_exec.reset()
  3894. refresher_exec.cb = master._refresh_exec
  3895. refresher_exec = Refresher()
  3896. refresher_exec.time_delta = 10 #0
  3897. refresher_exec.name = "exec-fader"
  3898. refresher_exec.reset()
  3899. refresher_exec.cb = refresh_exec_fader_cfg
  3900. def loops(**args):
  3901. time.sleep(5) # wait until draw all window's
  3902. cprint("-> run loops")
  3903. thread.start_new_thread(refresher_fix.loop,())
  3904. thread.start_new_thread(refresher_exec.loop,())
  3905. class window_create_buffer():
  3906. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  3907. self.args = args.copy()
  3908. self.cls = cls
  3909. self.cb_ok = cb_ok
  3910. self.data = data
  3911. self.scroll = scroll
  3912. self.gui = gui
  3913. def create(self,hidde=0):
  3914. cprint()
  3915. cprint()
  3916. cprint("window_create_buffer.create()",id(self),self.args["title"],color="green")
  3917. obj = None
  3918. w = Window(self.args)
  3919. out = []
  3920. f = None
  3921. h = None
  3922. if self.scroll:
  3923. head = None
  3924. foot = None
  3925. if "head" in self.args:
  3926. head = self.args["head"]
  3927. if "foot" in self.args:
  3928. foot = self.args["foot"]
  3929. w1 = ScrollFrame(w.tk,width=self.args["width"],height=self.args["height"],foot=foot,head=head)
  3930. if type(w1) is list:
  3931. try:
  3932. h = w1[0]
  3933. f = w1[2]
  3934. except:pass
  3935. w1 = w1[1]
  3936. else:
  3937. w1 = tk.Frame(w.tk,width=self.args["width"],height=self.args["height"])
  3938. w1.pack()
  3939. try:
  3940. obj=self.cls(self.gui,w1,self.data,foot=f,head=h)
  3941. except:
  3942. obj=self.cls(self.gui,w1,self.data)
  3943. return w,obj,self.cb_ok
  3944. if __run_main:
  3945. cprint("main")
  3946. #thread.start_new_thread(refresher_fix.loop,())
  3947. #thread.start_new_thread(refresher_exec.loop,())
  3948. TOP = _POS_TOP + 15
  3949. L0 = _POS_LEFT
  3950. L1 = _POS_LEFT + 95
  3951. L2 = _POS_LEFT + 920
  3952. W1 = 810
  3953. H1 = 550
  3954. HTB = 23 # hight of the titlebar from window manager
  3955. pos_list = read_window_position()
  3956. data = []
  3957. #data.append({"text":"COMMAND"})
  3958. #data.append({"text":"CONFIG"})
  3959. data.append({"text":"PATCH"})
  3960. data.append({"text":"DIMMER"})
  3961. data.append({"text":"FIXTURES"})
  3962. data.append({"text":"EXEC","name":"EXEC-BTN"})
  3963. data.append({"text":"EXEC-WING"})
  3964. data.append({"text":"---"})
  3965. data.append({"text":"SETUP"})
  3966. data.append({"text":"COMMAND"})
  3967. data.append({"text":"LIVE"})
  3968. data.append({"text":"FX"})
  3969. data.append({"text":"ENCODER"})
  3970. data.append({"text":"COLORPICKER","name":"COLOR"})
  3971. data.append({"text":"---"})
  3972. data.append({"text":"FIXTURE-EDITOR","name":"FIX-EDIT"})
  3973. data.append({"text":"CONFIG"})
  3974. data.append({"text":"CLOCK"})
  3975. data.append({"text":"---"})
  3976. name="MAIN"
  3977. args = {"title":"MAIN","master":1,"width":80,"height":H1,"left":L0,"top":TOP,"resize":1}
  3978. geo = split_window_position(pos_list,name)
  3979. if geo:
  3980. args.update(geo)
  3981. cls = GUI_menu
  3982. cb_ok = None
  3983. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  3984. window_manager.new(None,name,wcb=c)
  3985. window_manager.top(name)
  3986. gui_menu_gui = window_manager.get_win(name)
  3987. gui_menu = window_manager.get_obj(name)
  3988. master._refresh_fix()
  3989. # --------------------------------
  3990. name="EXEC"
  3991. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3992. geo = split_window_position(pos_list,name)
  3993. if geo:
  3994. args.update(geo)
  3995. data = PRESETS
  3996. cls = draw_exec #GUI_ExecWingLayout
  3997. cb_ok = None #set_exec_fader_all
  3998. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3999. window_manager.new(None,name,wcb=c)
  4000. if split_window_show(pos_list,_filter=name):
  4001. window_manager.top(name)
  4002. name="CONFIG"
  4003. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  4004. geo = split_window_position(pos_list,name)
  4005. if geo:
  4006. args.update(geo)
  4007. data = []
  4008. cls = GUI_CONF
  4009. cb_ok = None
  4010. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  4011. window_manager.new(None,name,wcb=c)
  4012. if split_window_show(pos_list,_filter=name):
  4013. window_manager.top(name)
  4014. name="DIMMER"
  4015. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  4016. geo = split_window_position(pos_list,name)
  4017. if geo:
  4018. args.update(geo)
  4019. cls = GUI_DIM
  4020. data = FIXTURES
  4021. ok_cb=None
  4022. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  4023. window_manager.new(None,name,wcb=c)
  4024. if split_window_show(pos_list,_filter=name):
  4025. window_manager.top(name)
  4026. name="FIXTURES"
  4027. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  4028. geo = split_window_position(pos_list,name)
  4029. if geo:
  4030. args.update(geo)
  4031. cls = GUI_FIX
  4032. ok_cb=None
  4033. data = FIXTURES
  4034. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  4035. window_manager.new(None,name,wcb=c)
  4036. if split_window_show(pos_list,_filter=name):
  4037. window_manager.top(name)
  4038. # -------------------------------
  4039. name="FIXTURE-EDITOR"
  4040. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  4041. geo = split_window_position(pos_list,name)
  4042. if geo:
  4043. args.update(geo)
  4044. data=[]
  4045. for i in range(12*6):
  4046. data.append({"text"+str(i):"test"})
  4047. cls = GUI_FixtureEditor
  4048. #cls = GUI_FaderLayout
  4049. cb_ok = None
  4050. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4051. window_manager.new(None,name,wcb=c)
  4052. #window_manager.top(name)
  4053. # -------------------------------
  4054. name="MASTER-WING"
  4055. args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220,"resize":0}
  4056. geo = split_window_position(pos_list,name)
  4057. if geo:
  4058. args.update(geo)
  4059. data=[]
  4060. for i in range(2):
  4061. data.append({"MASTER"+str(i):"MASTER"})
  4062. cls = GUI_MasterWingLayout #(w1,data)
  4063. cb_ok = None
  4064. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4065. window_manager.new(None,name,wcb=c)
  4066. if split_window_show(pos_list,_filter=name):
  4067. window_manager.top(name)
  4068. # -------------------------------
  4069. name="EXEC-WING"
  4070. args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
  4071. geo = split_window_position(pos_list,name)
  4072. if geo:
  4073. args.update(geo)
  4074. data=[]
  4075. for i in range(10*3):
  4076. data.append({"EXEC"+str(i):"EXEC"})
  4077. cls = GUI_ExecWingLayout
  4078. cb_ok = set_exec_fader_all
  4079. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  4080. window_manager.new(None,name,wcb=c)
  4081. if split_window_show(pos_list,_filter=name):
  4082. window_manager.top(name)
  4083. name="ENCODER"
  4084. args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
  4085. geo = split_window_position(pos_list,name)
  4086. if geo:
  4087. args.update(geo)
  4088. cls = draw_enc #(master,w.tk)#Xroot)
  4089. cb_ok = None
  4090. data = FIXTURES #master
  4091. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4092. window_manager.new(None,name,wcb=c)
  4093. if split_window_show(pos_list,_filter=name):
  4094. window_manager.top(name)
  4095. name = "SETUP"
  4096. args = {"title":name +" SHOW:"+master.base.show_name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP,"resize":0}
  4097. args["title"] = "SETUP SHOW:"+master.base.show_name
  4098. cls = draw_setup #(master,w.tk)
  4099. data = []
  4100. cb_ok = None
  4101. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4102. window_manager.new(None,name,wcb=c)
  4103. if split_window_show(pos_list,_filter=name):
  4104. window_manager.top(name)
  4105. name = "COMMAND"
  4106. args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":0}
  4107. cls = draw_command #(master,w.tk)
  4108. data = []
  4109. cb_ok = None
  4110. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4111. window_manager.new(None,name,wcb=c)
  4112. if split_window_show(pos_list,_filter=name):
  4113. window_manager.top(name)
  4114. name = "LIVE"
  4115. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":0}
  4116. cls = draw_live #(master,w.tk)
  4117. 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. name = "CLOCK"
  4124. args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
  4125. cclock = X_CLOCK()
  4126. cls = cclock.draw_clock
  4127. data = []
  4128. cb_ok = None
  4129. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4130. window_manager.new(None,name,wcb=c)
  4131. if split_window_show(pos_list,_filter=name):
  4132. window_manager.top(name)
  4133. name="FX"
  4134. args = {"title":name,"master":0,"width":415,"height":297,"left":L1+10+W1,"top":TOP+302,"resize":0}
  4135. geo = split_window_position(pos_list,name)
  4136. if geo:
  4137. args.update(geo)
  4138. cls = draw_fx #(master,w.tk)
  4139. data = []
  4140. cb_ok = None
  4141. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4142. window_manager.new(None,name,wcb=c)
  4143. if split_window_show(pos_list,_filter=name):
  4144. window_manager.top(name)
  4145. name="PATCH"
  4146. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP,"foot":1,"head":1}
  4147. geo = split_window_position(pos_list,name)
  4148. if geo:
  4149. args.update(geo)
  4150. cls = GUI_PATCH
  4151. data = FIXTURES
  4152. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  4153. window_manager.new(None,name,wcb=c) #,obj)
  4154. if split_window_show(pos_list,_filter=name):
  4155. window_manager.top(name)
  4156. name="COLORPICKER"
  4157. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  4158. geo = split_window_position(pos_list,name)
  4159. if geo:
  4160. args.update(geo)
  4161. #w = Window(args)
  4162. #draw_colorpicker(master,w.tk,FIXTURES,master)
  4163. cls = draw_colorpicker #(master,w.tk,FIXTURES,master)
  4164. data = [FIXTURES,master]
  4165. cb_ok = None #FIXTURES
  4166. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  4167. window_manager.new(None,name,wcb=c)
  4168. if split_window_show(pos_list,_filter=name):
  4169. window_manager.top(name)
  4170. name="TableA"
  4171. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  4172. #space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
  4173. #x=TableFrame(root=w.tk)#,left=80,top=620)
  4174. #w.show()
  4175. #data =[]
  4176. #for a in range(40):
  4177. # data.append(["E","E{}".format(a+1)])
  4178. #x.draw(data=data,head=["E","C"],config=[12,5,5])
  4179. #w=x.bframe
  4180. #window_manager.new(w,name)
  4181. master.render()
  4182. window_manager.top("Table")
  4183. #w = frame_fix #Window("OLD",master=0,width=W1,height=500,left=130,top=TOP)
  4184. #window_manager.new(w,name)
  4185. load_window_position()
  4186. thread.start_new_thread(loops,())
  4187. try:
  4188. window_manager.mainloop()
  4189. finally:
  4190. master.exit()