_LibreLightDesk.py 138 KB

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