_LibreLightDesk.py 168 KB

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