_LibreLightDesk.py 160 KB

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