_LibreLightDesk.py 180 KB

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