_LibreLightDesk.py 170 KB

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