_LibreLightDesk.py 186 KB

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