_LibreLightDesk.py 162 KB

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