_LibreLightDesk.py 150 KB

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