_LibreLightDesk.py 128 KB

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