_LibreLightDesk.py 133 KB

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