_LibreLightDesk.py 183 KB

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