_LibreLightDesk.py 172 KB

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