_LibreLightDesk.py 161 KB

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