_LibreLightDesk.py 158 KB

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