_LibreLightDesk.py 166 KB

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