_LibreLightDesk.py 141 KB

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