_LibreLightDesk.py 159 KB

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