_LibreLightDesk.py 156 KB

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