_LibreLightDesk.py 157 KB

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