_LibreLightDesk.py 190 KB

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