_LibreLightDesk.py 133 KB

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