_LibreLightDesk.py 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326
  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 Xevent():
  1244. """ global input event Handeler for short cut's ... etc
  1245. """
  1246. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  1247. self.fix = fix
  1248. self.data=data
  1249. self.attr = attr
  1250. self.elem = elem
  1251. self.mode = mode
  1252. def setup(self,event):
  1253. cprint("xevent.SETUP",[self.mode,self.attr],color="red")
  1254. if self.mode == "SETUP":
  1255. if self.attr == "SAVE\nSHOW":
  1256. self.elem["bg"] = "orange"
  1257. self.elem["text"] = "SAVING..."
  1258. self.elem["bg"] = "red"
  1259. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  1260. #self.elem["fg"] = "orange"
  1261. self.elem.config(activebackground="orange")
  1262. modes.val(self.attr,1)
  1263. PRESETS.backup_presets()
  1264. FIXTURES.backup_patch()
  1265. save_window_position()
  1266. #time.sleep(1)
  1267. #modes.val(self.attr,0)
  1268. self.elem["bg"] = "lightgrey"
  1269. #self.elem["fg"] = "lightgrey"
  1270. self.elem.config(activebackground="lightgrey")
  1271. elif self.attr == "LOAD\nSHOW":
  1272. name = "LOAD-SHOW"
  1273. base = Base()
  1274. line1 = "PATH: "+base.show_path1 +base.show_name
  1275. line2 = "DATE: "+ time.strftime("%Y-%m-%d %X", time.localtime(time.time()))
  1276. class cb():
  1277. def __init__(self,name=""):
  1278. self.name=name
  1279. print("cb",name)
  1280. def cb(self,event=None,**args):
  1281. print("cdb",self.name,event,args)
  1282. if self.name != "<exit>":
  1283. print("-----------------------:")
  1284. LOAD_SHOW_AND_RESTAT(self.name).cb()
  1285. #self.elem["bg"] = "lightgrey"
  1286. #self.elem.config(activebackground="lightgrey")
  1287. pw = PopupList(name,cb=cb)
  1288. frame = pw.sframe(line1=line1,line2=line2)
  1289. r = _load_show_list(frame,cb=cb)
  1290. #self.elem["bg"] = "red"# "lightgrey"
  1291. #self.elem.config(activebackground="red")
  1292. #self.elem.config(activebackground="lightgrey")
  1293. #w.tk.attributes('-topmost',False)
  1294. elif self.attr == "SAVE\nSHOW AS":
  1295. base = Base()
  1296. #def _cb(fname):
  1297. def _cb(data):
  1298. fname = data["Value"]
  1299. print(self,"save_show._cb()",fname)
  1300. fpath,fname = base.build_path(fname)
  1301. cprint("SAVE AS",fpath,fname)
  1302. if base._create_path(fpath):
  1303. a=PRESETS.backup_presets(save_as=fpath)
  1304. b=FIXTURES.backup_patch(save_as=fpath)
  1305. #base._set(fname)
  1306. save_window_position(save_as=fpath)
  1307. LOAD_SHOW_AND_RESTAT(fname).cb()
  1308. dialog._cb = _cb
  1309. dialog.askstring("SAVE SHOW AS","SAVE SHOW AS:")
  1310. elif self.attr == "SAVE &\nRESTART":
  1311. self.elem["bg"] = "orange"
  1312. self.elem["text"] = "SAVING..."
  1313. self.elem["bg"] = "red"
  1314. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  1315. #self.elem["fg"] = "orange"
  1316. self.elem.config(activebackground="orange")
  1317. modes.val(self.attr,1)
  1318. PRESETS.backup_presets()
  1319. FIXTURES.backup_patch()
  1320. save_window_position()
  1321. self.elem["text"] = "RESTARTING..."
  1322. #time.sleep(1)
  1323. #modes.val(self.attr,0)
  1324. self.elem["bg"] = "lightgrey"
  1325. #self.elem["fg"] = "lightgrey"
  1326. self.elem.config(activebackground="lightgrey")
  1327. LOAD_SHOW_AND_RESTAT("").cb(force=1)
  1328. elif self.attr == "DRAW\nGUI":
  1329. #self.elem["bg"] = "orange"
  1330. old_text = self.elem["text"]
  1331. self.elem["text"] = "DRAWING..."
  1332. #self.elem["bg"] = "red"
  1333. #time.sleep(0.05)
  1334. #print("redraw",name)
  1335. #if name == "PATCH":
  1336. # gui_patch.draw()
  1337. #if name == "DIMMER":
  1338. # gui_fix.draw()
  1339. self.elem["text"] = "PATCH..."
  1340. window_manager.top("PATCH")
  1341. gui_patch.draw(FIXTURES)
  1342. self.elem["text"] = "FIX..."
  1343. gui_fix.draw(FIXTURES)
  1344. window_manager.top("FIXTURES")
  1345. master._refresh_exec()
  1346. self.elem["text"] = old_text
  1347. else:
  1348. r=tkinter.messagebox.showwarning(message="{}\nnot implemented".format(self.attr.replace("\n"," ")),parent=None)
  1349. return 1
  1350. def live(self,event):
  1351. if self.mode == "LIVE":
  1352. if "FADE" in self.attr or "DELAY" in self.attr:
  1353. if self.attr == "FADE":
  1354. ct = FADE
  1355. if self.attr == "DELAY":
  1356. ct = DELAY
  1357. if "PAN/TILT\nFADE" in self.attr:
  1358. ct = FADE_move
  1359. value = ct.val()
  1360. #print("EVENT CHANGE ",[self.attr])
  1361. print("EVENT CHANGE:",self.mode,value,self.attr)
  1362. if value < 0.01:
  1363. ct.val(0.01)
  1364. elif value > 100.0:
  1365. pass #value = 100
  1366. if event.num == 4:
  1367. value *= 1.1
  1368. elif event.num == 5:
  1369. value /= 1.1
  1370. elif event.num == 1:
  1371. if ct._is():
  1372. ct.off()# = 0
  1373. self.data.commands.elem[self.attr]["bg"] = "grey"
  1374. self.elem.config(activebackground="grey")
  1375. else:
  1376. ct.on()# = 1
  1377. self.data.commands.elem[self.attr]["bg"] = "green"
  1378. self.elem.config(activebackground="lightgreen")
  1379. elif event.num == 2:
  1380. if value > 1 and value < 4:
  1381. value = 4
  1382. elif value > 3 and value < 6:
  1383. value = 6
  1384. elif value > 5 and value < 7:
  1385. value = 8
  1386. elif value > 7 and value < 9:
  1387. value = 10
  1388. elif value > 9:
  1389. value = 0.01
  1390. elif value < 1:
  1391. value = 1.1
  1392. value = round(value,3)
  1393. value = ct.val(value)
  1394. if self.attr == "FADE":
  1395. self.data.commands.elem[self.attr]["text"] = "FADE:\n{:0.2f}".format(value)
  1396. if self.attr == "DELAY":
  1397. self.data.commands.elem[self.attr]["text"] = "DELAY:\n{:0.3f}".format(value)
  1398. if "PAN/TILT\nFADE" in self.attr:
  1399. self.data.commands.elem[self.attr]["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
  1400. def command(self,event):
  1401. if self.mode == "COMMAND":
  1402. if self.attr == "CLEAR":
  1403. if event.num == 1:
  1404. ok = FIXTURES.clear()
  1405. if ok:
  1406. master._refresh_fix()
  1407. modes.val(self.attr,0)
  1408. elif self.attr == "SAVE":
  1409. modes.val(self.attr,1)
  1410. PRESETS.backup_presets()
  1411. FIXTURES.backup_patch()
  1412. #time.sleep(1)
  1413. modes.val(self.attr,0)
  1414. elif self.attr == "S-KEY":
  1415. global _global_short_key
  1416. if _global_short_key:
  1417. _global_short_key = 0
  1418. master.commands.elem["S-KEY"]["bg"] = "red"
  1419. master.commands.elem["S-KEY"]["activebackground"] = "red"
  1420. else:
  1421. _global_short_key = 1
  1422. master.commands.elem["S-KEY"]["bg"] = "green"
  1423. master.commands.elem["S-KEY"]["activebackground"] = "green"
  1424. print("s-key",_global_short_key)
  1425. else:
  1426. if event.num == 1:
  1427. print("ELSE",self.attr)
  1428. modes.val(self.attr,1)
  1429. return 0
  1430. def encoder(self,event):
  1431. global _shift_key
  1432. cprint("Xevent","ENC",self.fix,self.attr,self.mode)
  1433. cprint("SHIFT_KEY",_shift_key,"??????????")
  1434. if self.mode == "ENCODER":
  1435. if self._encoder(event):
  1436. master.refresh_fix() # delayed
  1437. refresher_fix.reset() # = Refresher()
  1438. if self.mode == "ENCODER2":
  1439. if self._encoder(event):
  1440. master.refresh_fix() # delayed
  1441. refresher_fix.reset() # = Refresher()
  1442. if self.mode == "INVERT":
  1443. print("INVERT",event)
  1444. if self._encoder(event):
  1445. master.refresh_fix() # delayed
  1446. refresher_fix.reset() # = Refresher()
  1447. def _encoder(self,event):
  1448. global _shift_key
  1449. if 1: #self.mode == "ENCODER" or self.mode == "ENCODER2":
  1450. cprint("-- Xevent","_ENC",self.fix,self.attr,self.mode)
  1451. cprint("-- SHIFT_KEY",_shift_key,"??????????")
  1452. #cprint(self.data)
  1453. val=""
  1454. if event.num == 1:
  1455. val ="click"
  1456. elif event.num == 4:
  1457. val ="++"
  1458. if _shift_key:
  1459. val = "+"
  1460. elif event.num == 5:
  1461. val ="--"
  1462. if _shift_key:
  1463. val = "-"
  1464. #print("SHIFT",val,_shift_key)
  1465. if val:
  1466. FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
  1467. return 1
  1468. def cb(self,event):
  1469. cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
  1470. print(["type",event.type,"num",event.num])
  1471. global INIT_OK
  1472. INIT_OK = 1
  1473. try:
  1474. change = 0
  1475. if "keysym" in dir(event):
  1476. if "Escape" == event.keysym:
  1477. ok = FIXTURES.clear()
  1478. master._refresh_fix()
  1479. print()
  1480. return 0
  1481. if self.mode == "SETUP":
  1482. self.setup(event)
  1483. elif self.mode == "COMMAND":
  1484. self.command(event)
  1485. elif self.mode == "LIVE":
  1486. self.live(event)
  1487. elif self.mode == "ENCODER":
  1488. self.encoder(event)
  1489. master._refresh_fix()
  1490. elif self.mode == "ENCODER2":
  1491. self.encoder(event)
  1492. elif self.mode == "INVERT":
  1493. self.encoder(event)
  1494. elif self.mode == "FX":
  1495. cprint("Xevent CALLING FX WRONG EVENT OBJECT !!",color="red")
  1496. elif self.mode == "ROOT":
  1497. if event.keysym=="Escape":
  1498. pass
  1499. elif self.mode == "INPUT":
  1500. print("INP",self.data.entry.get())
  1501. if event.keycode == 36:
  1502. x=self.data.entry.get()
  1503. #client.send(x)
  1504. elif self.mode == "INPUT2":
  1505. print("INP2",self.data.entry2.get())
  1506. if event.keycode == 36:
  1507. x=self.data.entry2.get()
  1508. #client.send(x)
  1509. elif self.mode == "INPUT3":
  1510. print("INP3",self.data.entry3.get())
  1511. if event.keycode == 36:
  1512. x=self.data.entry3.get()
  1513. #client.send(x)
  1514. elif self.mode == "PRESET":
  1515. nr = self.attr #int(self.attr.split(":")[1])-1
  1516. if event.num == 3: # right click for testing
  1517. if str(event.type) == '4': #4 ButtonPress
  1518. if modes.val("CFG-BTN"):
  1519. master.btn_cfg(nr,testing=1)
  1520. if event.num == 1:
  1521. if str(event.type) == '4': #4 ButtonPress
  1522. if modes.val("REC"):
  1523. self.data.preset_rec(nr)
  1524. modes.val("REC",0)
  1525. time.sleep(0.05)
  1526. master._refresh_exec(nr=nr)
  1527. elif modes.val("DEL"):
  1528. ok=PRESETS.delete(nr)
  1529. if ok:
  1530. modes.val("DEL",0)
  1531. #master.refresh_exec()
  1532. master._refresh_exec(nr=nr)
  1533. elif modes.val("COPY"):
  1534. ok=PRESETS.copy(nr)
  1535. if ok:
  1536. modes.val("COPY",0)
  1537. master._refresh_exec(nr=nr)
  1538. elif modes.val("MOVE"):
  1539. ok,cnr,bnr=PRESETS.move(nr)
  1540. if ok:
  1541. #modes.val("MOVE",0) # keep MOVE on
  1542. master._refresh_exec(nr=nr)
  1543. master._refresh_exec(nr=bnr)
  1544. elif modes.val("CFG-BTN"):
  1545. master.btn_cfg(nr)
  1546. #master._refresh_exec(nr=nr)
  1547. elif modes.val("LABEL"):#else:
  1548. master.label(nr)
  1549. #master._refresh_exec(nr=nr)
  1550. elif modes.val("EDIT"):
  1551. FIXTURES.clear()
  1552. self.data.preset_select(nr)
  1553. self.data.preset_go(nr,xfade=0,event=event,val=255,button="go")
  1554. modes.val("EDIT", 0)
  1555. master.refresh_fix()
  1556. elif modes.val("SELECT"):
  1557. self.data.preset_select(nr)
  1558. else:
  1559. self.data.preset_go(nr,event=event,val=255)
  1560. else:
  1561. self.data.preset_go(nr,xfade=0,event=event,val=0)
  1562. if event.num == 3:
  1563. if not modes.val("REC"):
  1564. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=255)
  1565. print()
  1566. return 0
  1567. elif self.mode == "INPUT":
  1568. print()
  1569. return 0
  1570. except Exception as e:
  1571. cprint("== cb EXCEPT",e,color="red")
  1572. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1573. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1574. print()
  1575. return 1
  1576. def wheel(event,d=None):
  1577. print("wheel",event,d)
  1578. class Element():
  1579. def __init__(self):
  1580. self.__data = {}
  1581. def set(self,key,val):
  1582. self.__data[key] = val
  1583. class Base():
  1584. def __init__(self):
  1585. cprint("Base.init()",color="red")
  1586. self._init()
  1587. def _init(self):
  1588. show_name = "DemoShow"
  1589. self.home = os.environ['HOME']
  1590. self.show_path0 = self.home +"/LibreLight/"
  1591. self.show_path = self.show_path0
  1592. self.show_path1 = self.show_path0 + "show/"
  1593. try:
  1594. f = open(self.show_path+"init.txt","r")
  1595. for line in f.readlines():
  1596. #cprint(line)
  1597. if not line.startswith("#"):
  1598. show_name = line.strip()
  1599. show_name = show_name.replace(".","")
  1600. show_name = show_name.replace("\\","")
  1601. show_name = show_name.replace("/","")
  1602. self.show_name = show_name
  1603. except Exception as e:
  1604. cprint("show name exception",color="red")
  1605. msg="Error Exception:{}".format(e)
  1606. r=tkinter.messagebox.showwarning(message=msg,parent=None)
  1607. finally:
  1608. f.close()
  1609. fpath = self.show_path1 +show_name
  1610. if not os.path.isdir(fpath):
  1611. cprint(fpath)
  1612. print( os.path.isdir(fpath))
  1613. msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  1614. msg += "please check\n"
  1615. msg += "-{}init.txt\n".format(self.show_path0)
  1616. msg += "-{}".format(self.show_path1)
  1617. showwarning(msg=msg,title="Show Error")
  1618. exit()
  1619. self._check()
  1620. def _set(self,fname):
  1621. ok= os.path.isdir(self.show_path1+"/"+fname)
  1622. ini = self.show_path0+"init.txt"
  1623. print("SET SHOW NAME",fname,ok,ini)
  1624. try:
  1625. f = open( ini ,"r")
  1626. lines = f.readlines()
  1627. f.close()
  1628. if len(lines) >= 10: # cut show history
  1629. print("_set",ini,len(lines))
  1630. lines = lines[-10:]
  1631. f = open( ini ,"w")
  1632. f.writelines(lines)
  1633. f.close()
  1634. exit()
  1635. except:pass
  1636. if ok:
  1637. #self.show_name = fname
  1638. f = open( ini ,"a")
  1639. f.write(fname+"\n")
  1640. f.close()
  1641. return 1
  1642. def _check(self):
  1643. if not os.path.isdir(self.show_path):
  1644. os.mkdir(self.show_path)
  1645. self.show_path += "/show/"
  1646. if not os.path.isdir(self.show_path):
  1647. os.mkdir(self.show_path)
  1648. self.show_path += "/" +self.show_name +"/"
  1649. if not os.path.isdir(self.show_path):
  1650. os.mkdir(self.show_path)
  1651. pass
  1652. def _list(self):
  1653. #self._check()
  1654. show_list = list(os.listdir( self.show_path1 ))
  1655. out = []
  1656. for fname in show_list:
  1657. #print(fname)
  1658. ctime = os.path.getmtime(self.show_path1+fname)
  1659. ctime = time.strftime("%Y-%m-%d %X", time.localtime(ctime)) #1650748726.6604707))
  1660. try:
  1661. mtime = os.path.getmtime(self.show_path1+fname+"/patch.sav")
  1662. mtime = time.strftime("%Y-%m-%d %X", time.localtime(mtime)) #1650748726.6604707))
  1663. except:
  1664. mtime = 0
  1665. if mtime:
  1666. out.append([fname,mtime])#,ctime])
  1667. from operator import itemgetter
  1668. out=sorted(out, key=itemgetter(1))
  1669. out.reverse()
  1670. return out
  1671. def _load(self,filename):
  1672. xfname = self.show_path+"/"+str(filename)+".sav"
  1673. print("load",xfname)
  1674. try:
  1675. f = open(xfname,"r")
  1676. lines = f.readlines()
  1677. f.close()
  1678. except Exception as e:
  1679. msg = "Exception: {}".format(e)
  1680. msg += "\n\ncheck\n-init.txt"
  1681. cprint(msg,color="red")
  1682. showwarning(msg=msg,title="load Error")
  1683. data = OrderedDict()
  1684. labels = OrderedDict()
  1685. i=0
  1686. for line in lines:
  1687. if line.count("\t") < 2:
  1688. cprint("Error line.count('\\t') < 2 (is:{})".format(line.count("\t")),color="red",end=" ")
  1689. cprint("file:{}".format(xfname),color="red")
  1690. continue
  1691. key,label,rdata = line.split("\t",2)
  1692. key = int(key)
  1693. jdata = json.loads(rdata,object_pairs_hook=OrderedDict)
  1694. nrnull = 0
  1695. if "ATTRIBUT" in jdata: # translate old FIXTURES.fixtures start with 0 to 1
  1696. if nrnull:
  1697. print("DMX NR IS NULL",attr,"CHANGE +1")
  1698. for attr in jdata["ATTRIBUT"]:
  1699. if "NR" in jdata["ATTRIBUT"][attr]:
  1700. nr = jdata["ATTRIBUT"][attr]["NR"]
  1701. if nr >= 0:
  1702. jdata["ATTRIBUT"][attr]["NR"] +=1
  1703. data[key] = jdata
  1704. labels[key] = label
  1705. return data,labels
  1706. def _clean_path(self,fpath):
  1707. _path=[]
  1708. for i in fpath:
  1709. fpath = fpath.replace(" ","_")
  1710. if i in string.ascii_letters+string.digits+"äöüßÖÄÜ_-":
  1711. _path.append(i)
  1712. path = "".join(_path)
  1713. return path
  1714. def build_path(self,save_as):
  1715. save_as = self._clean_path(save_as)
  1716. path = self.show_path.split("/")
  1717. path = "/".join(path[:-2])
  1718. fpath = path+"/"+save_as
  1719. return fpath,save_as
  1720. def _create_path(self,fpath):
  1721. if os.path.isdir(fpath):
  1722. cprint("STOP SHOW EXIST !",color="red")
  1723. return 0
  1724. else:
  1725. cprint("CREATE DIR ",fpath,color="green")
  1726. os.mkdir(fpath)
  1727. #self._set(save_as)
  1728. return fpath
  1729. def _backup(self,filename,data,labels,save_as):
  1730. if save_as:
  1731. xfname = save_as +"/"+str(filename)+".sav"
  1732. else:
  1733. xfname = self.show_path+"/"+str(filename)+".sav"
  1734. print("backup",xfname)
  1735. f = open(xfname,"w")
  1736. for key in data:
  1737. line = data[key]
  1738. #print(line)
  1739. label = "label"
  1740. if key in labels:
  1741. label = labels[key]
  1742. if label == "Name-"+str(key):
  1743. label = ""
  1744. #print(xfname,"load",key,label,len(line))
  1745. f.write( "{}\t{}\t{}\n".format( key,label,json.dumps(line) ) )
  1746. f.close()
  1747. return 1
  1748. def hex_to_rgb(hex):
  1749. return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
  1750. class cb():
  1751. def __init__(self,win):
  1752. self.win = win
  1753. def _callback(self,event):
  1754. clobj=event.widget
  1755. ## undermouse=find_withtag(master.CURRENT)
  1756. undermouse=self.win.find_closest(self.win.CURRENT)
  1757. print( repr(undermouse))
  1758. def callback(self,event):
  1759. print(__file__,self,"callback",event)
  1760. cnv = self.win
  1761. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  1762. tags = cnv.gettags(item)
  1763. #cnv.itemconfigure(self.tag, text=tags[0])
  1764. print(tags,item)
  1765. color = cnv.itemcget(item, "fill")
  1766. cnv.itemconfig("all", width=1)#filla="green")
  1767. cnv.itemconfig(item, width=3)#filla="green")
  1768. print(color)
  1769. print( hex_to_rgb(color[1:]))
  1770. class Elem_Container():
  1771. def __init__(self):
  1772. self.commands = []
  1773. self.val = {}
  1774. self.elem = {}
  1775. class MASTER():
  1776. def __init__(self):
  1777. #super().__init__()
  1778. self.base = Base ()
  1779. self.load()
  1780. self._XX = 0
  1781. self.all_attr =["DIM","PAN","TILT"]
  1782. self.elem_attr = {}
  1783. self.fx_moves = Elem_Container()
  1784. self.fx_moves.commands =["REC-FX","FX OFF","\n"
  1785. ,"FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  1786. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  1787. ]
  1788. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  1789. self.fx = Elem_Container()
  1790. self.fx.commands =[
  1791. "FX:DIM","FX:RED", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  1792. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","FX-X:\n-","FX:MODE"
  1793. ]
  1794. self.fx_generic = Elem_Container()
  1795. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON"]
  1796. self.commands = Elem_Container()
  1797. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  1798. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  1799. ,"BLIND","CLEAR","REC","EDIT","COPY","-","\n"
  1800. ]
  1801. self.elem_presets = {}
  1802. for i in range(8*8*8):
  1803. if i not in PRESETS.val_presets:
  1804. name = "Preset:"+str(i+1)+":\nXYZ"
  1805. #self.presets[i] = [i]
  1806. PRESETS.val_presets[i] = OrderedDict() # FIX
  1807. PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
  1808. PRESETS.label_presets[i] = "-"
  1809. modes.set_cb(self.xcb)
  1810. def button_refresh(self,name,color,color2=None,text="",fg=None):
  1811. cprint("button_refresh",name,color)
  1812. #if color == "gold":
  1813. # color2 = "yellow"
  1814. if color2 is None:
  1815. color2 = color
  1816. if text:
  1817. text = "\n"+str(text)
  1818. if name in self.commands.elem:
  1819. self.commands.elem[name]["bg"] = color
  1820. self.commands.elem[name]["text"] = name+ text
  1821. self.commands.elem[name].config(activebackground=color2)
  1822. if fg:
  1823. self.commands.elem[name]["fg"] = fg
  1824. elif name in self.fx.elem:
  1825. #todo
  1826. self.fx.elem[name]["bg"] = color
  1827. self.fx.elem[name].config(activebackground=color2)
  1828. if fg:
  1829. self.fx.elem[name]["fg"] = fg
  1830. # new version
  1831. for elems in [self.fx_moves]:
  1832. if name in elems.elem:
  1833. elem = elems.elem[name]
  1834. cprint("elem",elem)
  1835. elem.config(bg = color)
  1836. elem.config(text = name+text)
  1837. elem.config(activebackground=color2)
  1838. if fg and "fg" in elem:
  1839. elem["fg"] = fg
  1840. def btn_cfg(self,nr,testing=0):
  1841. cfg = PRESETS._btn_cfg(nr)
  1842. button = PRESETS.btn_cfg(nr)
  1843. label = PRESETS.label(nr)
  1844. def _cb(data):
  1845. print(self,"btn_cfg._cb()",data)
  1846. if data:
  1847. if "Button" in data and type(data["Button"]) is str:
  1848. txt = data["Button"]
  1849. PRESETS.btn_cfg(nr,txt)
  1850. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1851. if "Label" in data and type(data["Label"]) is str:
  1852. txt = data["Label"]
  1853. PRESETS.label(nr,txt)
  1854. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1855. modes.val("CFG-BTN",0)
  1856. master._refresh_exec(nr=nr)
  1857. dialog._cb = _cb
  1858. if 1: # testing:
  1859. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  1860. else:
  1861. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  1862. def label(self,nr):
  1863. txt = PRESETS.label(nr)
  1864. def _cb(data):
  1865. txt = data["Value"]
  1866. print(self,"label._cb()",nr,txt)
  1867. if txt:
  1868. PRESETS.label(nr,txt)
  1869. self.elem_presets[nr].configure(text = PRESETS.get_btn_txt(nr))
  1870. modes.val("LABEL", 0)
  1871. master._refresh_exec(nr=nr)
  1872. dialog._cb= _cb #_x(nr)
  1873. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  1874. def xcb(self,mode,value=None):
  1875. cprint("MODE CALLBACK",mode,value,color="green",end="")
  1876. #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
  1877. if value:
  1878. cprint("===== ON ======",color="red")
  1879. txt = ""
  1880. if mode == "REC-FX":
  1881. modes.val("REC",0)
  1882. modes.val("REC",1)
  1883. if value == 2:
  1884. if mode in ["MOVE","COPY"]:
  1885. txt="to"
  1886. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  1887. else:
  1888. if mode in ["MOVE","COPY"]:
  1889. txt="from"
  1890. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  1891. else:
  1892. cprint("===== OFF ======",color="red")
  1893. if mode == "REC-FX":
  1894. modes.val("REC",0)
  1895. self.button_refresh(mode,color="lightgrey")#,fg="black")
  1896. def load(self,fname=""):
  1897. pass
  1898. def exit(self):
  1899. print("__del__",self)
  1900. PRESETS.backup_presets()
  1901. #print("********************************************************")
  1902. FIXTURES.backup_patch()
  1903. #print("*********del",self,"***********************************************")
  1904. def refresh_exec(self):
  1905. refresher_exec.reset() # = Refresher()
  1906. def _refresh_exec(self,nr=-1):
  1907. s = time.time()
  1908. cprint("PRESET.refresh_exec()")
  1909. refresher_exec.reset() # = Refresher()
  1910. self._XX +=1
  1911. self._nr_ok = 0
  1912. for k in PRESETS.val_presets:
  1913. _bg = "grey"
  1914. _ba = "grey"
  1915. _fg = "lightgrey"
  1916. _text = "N/V"
  1917. if nr >= 0:
  1918. if self._nr_ok:
  1919. break
  1920. if nr != k:
  1921. continue
  1922. else:
  1923. self._nr_ok = 1
  1924. label = ""
  1925. if k not in self.elem_presets:
  1926. cprint("ERROR",k ,"not in elem_presets continue")
  1927. continue
  1928. if k in PRESETS.label_presets:
  1929. label = PRESETS.label_presets[k]
  1930. #print([label])
  1931. b = self.elem_presets[k]
  1932. ifval = 0
  1933. fx_only = 0
  1934. if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
  1935. sdata = PRESETS.val_presets[k]
  1936. #print("sdata7654",sdata)
  1937. BTN="go"
  1938. if "CFG" in sdata:#["BUTTON"] = "GO"
  1939. if "BUTTON" in sdata["CFG"]:
  1940. BTN = sdata["CFG"]["BUTTON"]
  1941. #txt=str(k+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+label
  1942. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  1943. _text = txt
  1944. if b.text != txt: # TODO
  1945. #txt+=str(self._XX)
  1946. #b.configure(text= txt)
  1947. _text = txt
  1948. _bg="yellow"
  1949. _ba="yellow"
  1950. if len(sdata) > 1:
  1951. ifval = 1
  1952. fx_color = 0
  1953. val_color = 0
  1954. for fix in sdata:
  1955. if fix == "CFG":
  1956. continue
  1957. #print( "$$$$",fix,sdata[fix])
  1958. for attr in sdata[fix]:
  1959. if "FX2" in sdata[fix][attr]:
  1960. if sdata[fix][attr]["FX2"]:
  1961. fx_color = 1
  1962. if "FX" in sdata[fix][attr]:
  1963. if sdata[fix][attr]["FX"]:
  1964. fx_color = 1
  1965. if "VALUE" in sdata[fix][attr]:
  1966. if sdata[fix][attr]["VALUE"] is not None:
  1967. val_color = 1
  1968. b.configure(fg= "black")
  1969. if val_color:
  1970. _bg = "gold"
  1971. _ba = "#ffaa55"
  1972. if fx_color:
  1973. _fg = "blue"
  1974. else:
  1975. if fx_color:
  1976. fx_only = 1
  1977. else:
  1978. _bg = "grey"
  1979. _ba = "#aaa"
  1980. if "\n" in txt:
  1981. txt1 = txt.split("\n")[0]
  1982. _fg = "black"
  1983. if ifval:
  1984. if fx_only:
  1985. _bg = "cyan"
  1986. _ba = "#55d4ff"
  1987. if "SEL" in txt1:
  1988. b.configure(bg="#77f")
  1989. _bg = "#77f"
  1990. else:
  1991. _bg = "grey"
  1992. _fg = "darkgrey"
  1993. if "SEL" in txt1:
  1994. _fg = "blue"
  1995. elif "ON" in txt1:
  1996. _fg = "#040"
  1997. elif "GO" in txt1:
  1998. _fg = "#555"
  1999. if "FL" in txt1:
  2000. _fg = "#00e"
  2001. b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
  2002. time.sleep(0.01)
  2003. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  2004. #time.sleep(0.01)
  2005. def refresh_fix(self):
  2006. refresher_fix.reset() # = Refresher()
  2007. def _refresh_fix(self):
  2008. s=time.time(); _XXX=0
  2009. c_d =0
  2010. c_f =0
  2011. c_a =0
  2012. for fix in FIXTURES.fixtures:
  2013. sdata = FIXTURES.fixtures[fix]
  2014. _c_a = 0
  2015. if fix not in self.elem_attr:
  2016. cprint("_refresh_fix fix not in self.elem_attr (no Button)",fix,color="red")
  2017. continue
  2018. elem_attr_fix = self.elem_attr[fix]
  2019. _dim_in_flag = 0
  2020. if "DIM" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 1:
  2021. _dim_in_flag = 1
  2022. for attr in sdata["ATTRIBUT"]:
  2023. row = sdata["ATTRIBUT"][attr]
  2024. if attr.endswith("-FINE"):
  2025. continue
  2026. b_attr = attr
  2027. if b_attr == "_ACTIVE":
  2028. b_attr = "S"
  2029. if b_attr not in elem_attr_fix:
  2030. continue
  2031. elem = elem_attr_fix[b_attr]
  2032. if not elem:
  2033. continue
  2034. if not attr.startswith("_"):
  2035. v2 = row["VALUE"]
  2036. _text = "{} {:0.2f}".format(attr,v2) # ~0.2 sec
  2037. if elem["text"] != _text: #"{} {:0.2f}".format(attr,v2)
  2038. elem["text"] = _text #"{} {:0.2f}".format(attr,v2)
  2039. if row["ACTIVE"]:
  2040. if elem["bg"] != "yellow":
  2041. elem["bg"] = "yellow"
  2042. elem.config(activebackground="yellow")
  2043. #if "DIM" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 1:
  2044. if _dim_in_flag:
  2045. c_d+=1
  2046. else:
  2047. _c_a += 1
  2048. else:
  2049. if elem["bg"] != "grey":
  2050. elem["bg"] = "grey"
  2051. elem.config(activebackground="grey")
  2052. if "FX2" not in row: # insert FX2 excetption
  2053. row["FX2"] = OrderedDict()
  2054. if row["FX"]:
  2055. elem["fg"] = "blue"
  2056. elif row["FX2"]:
  2057. elem["fg"] = "red"
  2058. else:
  2059. elem["fg"] = "black"
  2060. c_a += _c_a
  2061. if _c_a>0:
  2062. c_f +=1
  2063. c_a2=0
  2064. cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
  2065. if c_f > 0:
  2066. c_a2 = round(c_a/c_f,2)
  2067. if c_a2 % 1 > 0:
  2068. gui_menu.config("FIXTURES","bg","orange")
  2069. gui_menu.config("FIXTURES","activebackground","orange")
  2070. else:
  2071. gui_menu.config("FIXTURES","bg","yellow")
  2072. gui_menu.config("FIXTURES","activebackground","yellow")
  2073. else:
  2074. gui_menu.config("FIXTURES","bg","")
  2075. gui_menu.config("FIXTURES","activebackground","")
  2076. gui_menu.update("FIXTURES","{} : {}".format(c_f,c_a2))
  2077. if c_d > 0:
  2078. gui_menu.config("DIMMER","bg","yellow")
  2079. gui_menu.config("DIMMER","activebackground","yellow")
  2080. else:
  2081. gui_menu.config("DIMMER","bg","")
  2082. gui_menu.config("DIMMER","activebackground","")
  2083. gui_menu.update("DIMMER","{}".format(c_d))
  2084. cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
  2085. def preset_rec(self,nr):
  2086. print("------- STORE PRESET")
  2087. data = FIXTURES.get_active()
  2088. if modes.val("REC-FX"):
  2089. PRESETS.rec(nr,data,"REC-FX")
  2090. modes.val("REC-FX",0)
  2091. else:
  2092. PRESETS.rec(nr,data)
  2093. sdata=data
  2094. PRESETS.val_presets[nr] = sdata
  2095. master._refresh_exec()
  2096. return 1
  2097. def preset_select(self,nr):
  2098. print("SELECT PRESET")
  2099. sdata = PRESETS.val_presets[nr]
  2100. cmd = ""
  2101. for fix in sdata:
  2102. if fix == "CFG":
  2103. continue
  2104. for attr in sdata[fix]:
  2105. v2 = sdata[fix][attr]["VALUE"]
  2106. v2_fx = sdata[fix][attr]["FX"]
  2107. #print( self.data.elem_attr)
  2108. if fix in self.elem_attr:
  2109. if attr in self.elem_attr[fix]:
  2110. elem = self.elem_attr[fix][attr]
  2111. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  2112. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2113. #elem["bg"] = "yellow"
  2114. def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  2115. t_start = time.time()
  2116. if xfade is None and FADE._is():
  2117. xfade = FADE.val()
  2118. if ptfade is None and FADE_move._is():
  2119. ptfade = FADE_move.val()
  2120. print("GO PRESET FADE",nr,val)
  2121. rdata = PRESETS.get_raw_map(nr)
  2122. if not rdata:
  2123. return 0
  2124. print("???????")
  2125. cfg = PRESETS.get_cfg(nr)
  2126. print("''''''''")
  2127. #virtcmd = FIXTURES.get_virtual(rdata)
  2128. if not cfg:
  2129. cprint("NO CFG",cfg,nr)
  2130. return 0
  2131. xFLASH = 0
  2132. value=None
  2133. cprint("preset_go",nr,cfg)
  2134. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  2135. self.preset_select(nr)
  2136. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  2137. xFLASH = 1
  2138. xfade = 0
  2139. if type(val) is not type(None) and val == 0 :
  2140. value = "off"
  2141. if event:
  2142. if str(event.type) == "ButtonRelease" or event.type == '5' :
  2143. value = "off"
  2144. cprint("preset_go() FLUSH",value,color="red")
  2145. fcmd = FIXTURES.update_raw(rdata,update=0)
  2146. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  2147. elif not val:
  2148. cprint("preset_go() STOP",value,color="red")
  2149. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  2150. fcmd = FIXTURES.update_raw(rdata)
  2151. self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  2152. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  2153. fcmd = FIXTURES.update_raw(rdata)
  2154. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  2155. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  2156. self.refresh_exec()
  2157. self.refresh_fix()
  2158. cprint("preset_go",time.time()-t_start)
  2159. def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  2160. if xfade is None and FADE._is():
  2161. xfade = FADE.val()
  2162. if ptfade is None and FADE_move._is():
  2163. ptfade = FADE_move.val()
  2164. cprint("PRESETS._preset_go() len=",len(rdata),cfg)
  2165. if xfade is None:
  2166. xfade = cfg["FADE"]
  2167. if ptfade is None:
  2168. ptfade = cfg["FADE"]
  2169. #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
  2170. #cprint(rdata,color="red")
  2171. vcmd = reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
  2172. cmd = []
  2173. delay=0
  2174. for i,v in enumerate(fcmd):
  2175. #print("go",i,v)
  2176. if xFLASH:
  2177. vcmd[i]["FLASH"] = 1
  2178. DMX = fcmd[i]["DMX"]
  2179. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  2180. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  2181. if value is not None:
  2182. vcmd[i]["VALUE"] = value
  2183. if value == "off":
  2184. if "FX2" in vcmd:
  2185. vcmd[i]["FX2"]["TYPE"] = value
  2186. if "FIX" in fcmd:
  2187. vcmd[i]["FIX"] = fcmd["FIX"]
  2188. if DMX and vcmd[i]:
  2189. vcmd[i]["DMX"] = DMX
  2190. if "VIRTUAL" in fcmd[i]:
  2191. for a in fcmd[i]["VIRTUAL"]:
  2192. DMX = fcmd[i]["VIRTUAL"][a]
  2193. if DMX and vcmd[i]:
  2194. vcmd[i]["DMX"] = DMX
  2195. if type(nr) is not type(None):
  2196. vcmd[i]["EXEC"] = str(int(nr)+1)
  2197. #cprint(vcmd[i],color="red")
  2198. cmd.append(vcmd[i])
  2199. if cmd and not modes.val("BLIND"):
  2200. jclient_send(cmd)
  2201. def render(self):
  2202. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  2203. #self.draw_input()
  2204. pass
  2205. ##draw_sub_dim
  2206. class InputEventBlocker():
  2207. def __init__(self):
  2208. self.__init = 0
  2209. self.cursor = "88888"
  2210. def set(self,el,txt):
  2211. self.e = el
  2212. self.e_txt = txt
  2213. self.cursor = "88888"
  2214. def init(self):
  2215. if self.__init == 0:
  2216. try:
  2217. self.el = tk.Button()
  2218. self.e_txt = tk.StringVar()
  2219. self.__init = 1
  2220. except Exception as e:
  2221. pirnt("init() exception",e)
  2222. def _lock(self):
  2223. global _global_short_key
  2224. _global_short_key = 0
  2225. master.commands.elem["S-KEY"]["bg"] = "red"
  2226. def _unlock(self):
  2227. global _global_short_key
  2228. _global_short_key = 1
  2229. master.commands.elem["S-KEY"]["bg"] = "green"
  2230. def lock(self):
  2231. self._lock()
  2232. #self.e["bg"] = "red"
  2233. #self.el.config({"background": "grey"})
  2234. #self.e.focus()
  2235. def unlock(self):
  2236. self._unlock()
  2237. #self.e["bg"] = "blue"
  2238. #self.el.config({"background": "yellow"})
  2239. #self.el.focus_set()
  2240. def event(self,event,**args):
  2241. self.init()
  2242. #print()
  2243. print(self,event,args)
  2244. #print("###-",self.e_txt,dir(self.e_txt))
  2245. if "S-KEY" not in master.commands.elem:
  2246. return
  2247. if "num" in dir(event):
  2248. self.lock()
  2249. if "keysym" in dir(event):
  2250. t=self.e_txt.get()
  2251. if t and t[-1] == "<":
  2252. t = t[:-1]
  2253. if event.keysym == "Return" or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  2254. self.unlock()
  2255. #self.e_txt.set(t)
  2256. print("filter: get()",_global_short_key,t)
  2257. t2 = t
  2258. if _global_short_key == 0:
  2259. if event.keysym == "BackSpace":
  2260. if len(t) > 1:
  2261. t2 = t[:-1]
  2262. else:
  2263. t2=""
  2264. elif event.keysym == "Escape":
  2265. t2=""
  2266. elif event.keysym == "space":
  2267. t2=t+" "
  2268. elif event.char in "äöüÄÖÜ-_,.;:#'*+~":
  2269. t2=t+event.char
  2270. elif len(event.keysym) == 1:
  2271. t2=t+event.keysym
  2272. #self.e_txt.set(t2+"<")
  2273. #time.sleep(0.2)
  2274. #_global_short_key = 1
  2275. input_event_blocker = InputEventBlocker()
  2276. from tkgui.dialog import *
  2277. dialog = Dialog()
  2278. from tkgui.draw import *
  2279. from tkgui.GUI import *
  2280. #draw_enc
  2281. class LOAD_FIXTURE():
  2282. def __init__(self,name="",master=None):
  2283. self.name=name
  2284. self.master=master
  2285. def cb(self,event=None):
  2286. print("LOAD_FIXTURE",self.name,event)
  2287. if self.master is not None:
  2288. #for i in dir(self.master): #.load_MH2()
  2289. # print(i)
  2290. if "SPARX" in self.name:
  2291. self.master.load_MH2()
  2292. else:
  2293. self.master.load_DIM()
  2294. print(dir(self.master))
  2295. class LOAD_SHOW_AND_RESTAT():
  2296. def __init__(self,fname=""):
  2297. self.fname=fname
  2298. self.base = Base()
  2299. def cb(self,event=None,force=0):
  2300. print("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
  2301. if not self.fname and not force:
  2302. return 0
  2303. if self.base.show_name == self.fname and not force:
  2304. cprint("filename is the same",self.fname)
  2305. return 0
  2306. if not force:
  2307. self.base._set(self.fname)
  2308. print("LOAD SHOW:",event,self.fname)
  2309. print(sys.executable, os.path.abspath(__file__), *sys.argv)
  2310. os.execl("/usr/bin/python3", "/opt/LibreLight/Xdesk/_LibreLightDesk.py", "_LibreLightDesk.py")
  2311. sys.exit()
  2312. class PopupList():
  2313. 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"):
  2314. self.name = name
  2315. self.frame = None
  2316. self.bg=bg
  2317. self.cb = cb
  2318. if cb is None:
  2319. cb = DummyCallback #("load_show_list.cb")
  2320. #w = Window(self.name,master=master,width=width,height=height,exit=exit,left=left,top=top,cb=cb)
  2321. args = {"title":self.name,"master":master,"width":width,"height":height,"exit":exit,"left":left,"top":top,"cb":cb}
  2322. w = Window(args)
  2323. self.w = w
  2324. w.show()
  2325. def sframe(self,line1="<line1>",line2="<line2>",data=[]):
  2326. xframe=self.w.tk
  2327. if self.bg:
  2328. xframe.configure(bg=self.bg)
  2329. self.w.tk.configure(bg=self.bg)
  2330. c=0
  2331. r=0
  2332. b = tk.Label(xframe,bg="grey",text=line1,anchor="w")
  2333. b.pack(side="top",expand=0,fill="x" )
  2334. b = tk.Label(xframe,bg="grey",text=line2,anchor="w")
  2335. b.pack(side="top",expand=0,fill="x" )
  2336. b = tk.Label(xframe,bg="black",fg="black",text="")
  2337. if self.bg:
  2338. b.configure(fg=self.bg)
  2339. b.configure(bg=self.bg)
  2340. b.pack(side="top")
  2341. b = tk.Entry(xframe,width=10,text="")#,anchor="w")
  2342. b.pack(side="top",expand=0,fill="x")
  2343. b.focus()
  2344. #frame = tk.Frame(xframe,heigh=2800)
  2345. #frame.pack(fill=tk.BOTH,expand=1, side=tk.TOP)
  2346. frame = ScrollFrame(xframe,width=300,height=500,bd=1,bg=self.bg)
  2347. #frame.pack(side="left") #fill=tk.BOTH,expand=1, side=tk.TOP)
  2348. #self.frame = frame
  2349. self.w.tk.state(newstate='normal')
  2350. self.w.tk.attributes('-topmost',True)
  2351. return frame
  2352. class DummyCallback():
  2353. def __init__(self,name="name"):
  2354. self.name = name
  2355. def cb(self,event=None):
  2356. print("DummyCallback.cb",[self.name,event])
  2357. def _load_show_list(frame,cb=None):
  2358. c=0
  2359. r=0
  2360. base = Base()
  2361. for i in ["name","stamp"]: #,"create"]:
  2362. b = tk.Label(frame,bg="grey",text=i)
  2363. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2364. c+=1
  2365. r+=1
  2366. blist = base._list()
  2367. for i in range(10):
  2368. blist.append(["",""])
  2369. if cb is None:
  2370. cb = DummyCallback #("load_show_list.cb")
  2371. for i in blist:
  2372. #print(i)
  2373. c=0
  2374. for j in i:
  2375. bg="lightgrey"
  2376. dbg="lightgrey"
  2377. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2378. dbg = "lightgreen"
  2379. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2380. dbg = "green"
  2381. if c > 0:
  2382. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2383. b.config(activebackground=dbg)
  2384. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2385. else:
  2386. if base.show_name == i[0]:
  2387. bg="green"
  2388. _cb = cb(j)
  2389. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2390. if base.show_name == i[0]:
  2391. b.config(activebackground=bg)
  2392. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2393. c+=1
  2394. r+=1
  2395. def _load_fixture_list(frame,cb=None,master=None,bg="black"):
  2396. frame.configure(bg=bg)
  2397. c=0
  2398. r=0
  2399. base = Base()
  2400. for i in ["name","stamp"]: #,"create"]:
  2401. b = tk.Label(frame,bg="grey",text=i)
  2402. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2403. c+=1
  2404. r+=1
  2405. blist = [] #base._list()
  2406. blist.append(["MAC-500","martin","z"])
  2407. blist.append(["MAC-2000","martin","z"])
  2408. blist.append(["MAC-VIPER","martin","z"])
  2409. blist.append(["SPARX-7","JB","z"])
  2410. blist.append(["SPARX-11","JB","z"])
  2411. blist.append(["JB-P6","JB","z"])
  2412. blist.append(["JB-P7","JB","z"])
  2413. blist.append(["JB-A7","JB","z"])
  2414. blist.append(["TMH-12","Eurolight","z"])
  2415. for i in range(10):
  2416. blist.append(["",""])
  2417. if cb is None:
  2418. cb = DummyCallback #("load_show_list.cb")
  2419. for i in blist:
  2420. #print(i)
  2421. c=0
  2422. for j in i:
  2423. bg="lightgrey"
  2424. dbg="lightgrey"
  2425. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2426. dbg = "lightgreen"
  2427. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2428. dbg = "green"
  2429. if c > 0:
  2430. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2431. b.config(activebackground=dbg)
  2432. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2433. else:
  2434. if base.show_name == i[0]:
  2435. bg="green"
  2436. _cb=cb(j)
  2437. _cb.master=master
  2438. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2439. if base.show_name == i[0]:
  2440. b.config(activebackground=bg)
  2441. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2442. c+=1
  2443. r+=1
  2444. class Fixtures():
  2445. def __init__(self):
  2446. #super().__init__()
  2447. self.base=Base()
  2448. #self.load()
  2449. self.fixtures = OrderedDict()
  2450. self.gui = GUIHandler()
  2451. def load_patch(self):
  2452. filename="patch"
  2453. #self.base._init()
  2454. d,l = self.base._load(filename)
  2455. self.fixtures = OrderedDict()
  2456. for i in l:
  2457. sdata = d[i]
  2458. new_f = OrderedDict()
  2459. #print("++++")
  2460. for k,j in sdata.items():
  2461. overide=0 # only for repair
  2462. if overide:
  2463. if k in ["TYPE","VENDOR"]: #ignor
  2464. continue
  2465. new_f[k] = j
  2466. if k =="NAME":
  2467. #print("AAAADDDDDD")
  2468. if "TYPE" not in sdata and not overide:
  2469. if len( sdata["ATTRIBUT"]) == 1:
  2470. new_f["TYPE"] = "DIMMER"
  2471. elif "PAN" in sdata["ATTRIBUT"]:
  2472. new_f["TYPE"] = "MOVER"
  2473. elif "RED" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 3:
  2474. new_f["TYPE"] = "RGB"
  2475. elif "RED" in sdata["ATTRIBUT"]:
  2476. new_f["TYPE"] = "LED"
  2477. elif "CYAN" in sdata["ATTRIBUT"]:
  2478. new_f["TYPE"] = "COLOR"
  2479. else:
  2480. new_f["TYPE"] = ""
  2481. if "VENDOR" not in sdata and not overide:
  2482. new_f["VENDOR"] = ""
  2483. #print(k,j)#,sdata)
  2484. sdata = new_f
  2485. if "ACTIVE" not in sdata:
  2486. sdata["ACTIVE"] = 0
  2487. sdata["ATTRIBUT"]["_ACTIVE"] = OrderedDict()
  2488. sdata["ATTRIBUT"]["_ACTIVE"]["NR"] = 0
  2489. sdata["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2490. sdata["ATTRIBUT"]["_ACTIVE"]["VALUE"] = 0
  2491. for attr in sdata["ATTRIBUT"]:
  2492. sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
  2493. #print("load",filename,sdata)
  2494. #if "CFG" not in sdata:
  2495. # sdata["CFG"] = OrderedDict()
  2496. self.fixtures[str(i)] = sdata
  2497. #PRESETS.label_presets = l
  2498. self.fx_off("all")
  2499. def backup_patch(self,save_as=""):
  2500. filename = "patch"
  2501. #self.fx_off("all")
  2502. data = self.fixtures
  2503. labels = {}
  2504. for k in data:
  2505. labels[k] = k
  2506. #self.base._init()
  2507. self.base._backup(filename,data,labels,save_as)
  2508. def fx_get(self,fix=None):
  2509. out={}
  2510. if not fix or fix == "all":
  2511. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2512. for fix in self.fixtures:
  2513. data = self.fixtures[fix]
  2514. for attr in data["ATTRIBUT"]:
  2515. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX"]
  2516. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX2"]
  2517. return out
  2518. def fx_off(self,fix=None):
  2519. if not fix or fix == "all":
  2520. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2521. for fix in self.fixtures:
  2522. data = self.fixtures[fix]
  2523. for attr in data["ATTRIBUT"]:
  2524. data["ATTRIBUT"][attr]["FX"] = ""
  2525. data["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  2526. def get_attr(self,fix,attr):
  2527. if fix in self.fixtures:
  2528. data = self.fixtures[fix]
  2529. if "ATTRIBUT" in data:
  2530. if attr in data["ATTRIBUT"]:
  2531. return data["ATTRIBUT"][attr]
  2532. def get_max_dmx_nr(self,fix):
  2533. max_dmx = 0
  2534. used_dmx = 0
  2535. if fix not in self.fixtures:
  2536. return (used_dmx,max_dmx)
  2537. data = self.fixtures[fix]
  2538. used_dmx = len(data["ATTRIBUT"])
  2539. for a in data["ATTRIBUT"]:
  2540. attr = data["ATTRIBUT"][a]
  2541. if "NR" in attr:
  2542. try:
  2543. _n = int(attr["NR"])
  2544. if _n > max_dmx:
  2545. max_dmx=_n
  2546. except ValueError:pass
  2547. return (used_dmx,max_dmx)
  2548. def get_dmx(self,fix,attr):
  2549. #cprint("get_dmx",[fix,attr])
  2550. if fix in self.fixtures:
  2551. data = self.fixtures[fix]
  2552. DMX = -99
  2553. if "DMX" in data:
  2554. DMX = int(data["DMX"])
  2555. if DMX < 1: # ignore attribute with DMX lower 1
  2556. return -22
  2557. else:
  2558. return -1
  2559. if "UNIVERS" in data:
  2560. if int(data["UNIVERS"]) >= 0:
  2561. DMX += (int(data["UNIVERS"])*512)
  2562. else:
  2563. return -33
  2564. adata = self.get_attr(fix,attr)
  2565. #-hier ende 8.2.22
  2566. #cprint("adata",adata,DMX)
  2567. if adata:
  2568. if "NR" in adata:
  2569. NR = adata["NR"]
  2570. if NR >= 1:
  2571. DMX+=NR-1
  2572. else:
  2573. return -44
  2574. return DMX
  2575. return -4
  2576. return -3
  2577. def update_raw(self,rdata,update=1):
  2578. cprint("update_raw",len(rdata))
  2579. cmd = []
  2580. for i,d in enumerate(rdata):
  2581. xcmd = {"DMX":""}
  2582. #print("fix:",i,d)
  2583. fix = d["FIX"]
  2584. attr = d["ATTR"]
  2585. v2 = d["VALUE"]
  2586. v2_fx = d["FX"]
  2587. if fix not in self.fixtures:
  2588. continue
  2589. sdata = self.fixtures[fix] #shortcat
  2590. ATTR = sdata["ATTRIBUT"]
  2591. sDMX = 0
  2592. if sdata["DMX"] > 0:
  2593. #print( sdata)
  2594. sDMX = (sdata["UNIVERS"]*512)+sdata["DMX"]
  2595. #sDMX =sdata["DMX"]
  2596. #else:
  2597. # continue
  2598. if attr not in ATTR:
  2599. continue
  2600. #DMX = FIXTURES.get_dmx(fix)
  2601. if ATTR[attr]["NR"] >= 0:
  2602. DMX = sDMX+ATTR[attr]["NR"]-1
  2603. xcmd["DMX"] = str(DMX)
  2604. else:
  2605. if attr == "DIM" and ATTR[attr]["NR"] < 0:
  2606. xcmd["VIRTUAL"] = {}
  2607. for a in ATTR:
  2608. if ATTR[a]["MASTER"]:
  2609. xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
  2610. #print( "VIRTUAL",xcmd)
  2611. cmd.append(xcmd)
  2612. v=ATTR[attr]["VALUE"]
  2613. if v2 is not None and update:
  2614. ATTR[attr]["VALUE"] = v2
  2615. if d["FX2"] and update:
  2616. ATTR[attr]["FX2"] = d["FX2"]
  2617. #self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
  2618. text = str(attr)+' '+str(round(v,2))
  2619. #self.gui.update(fix,attr,args={"text":text})
  2620. #print("END 5454 _=_=_=_=_==_")
  2621. #cprint("update_raw",cmd,color="red")
  2622. return cmd
  2623. def encoder(self,fix,attr,xval="",xfade=0,xdelay=0,blind=0):
  2624. _blind = 0
  2625. if modes.val("BLIND"):
  2626. _blind = 1
  2627. if blind:
  2628. _blind = 1
  2629. if not _blind:
  2630. cprint("FIXTURES.encoder",fix,attr,xval,xfade,color="yellow")
  2631. if attr == "CLEAR":
  2632. self.clear()
  2633. return 0
  2634. if attr == "ALL":
  2635. x=self.select(fix,attr,mode="toggle")
  2636. return x
  2637. if attr == "INV-ATTR":
  2638. print("-x-x-x-x-x-x-x-X-")
  2639. x=self.select(fix,attr,mode="swap")
  2640. #x=self.select(fix,"ALL",mode="swap")
  2641. master.refresh_fix()
  2642. return x
  2643. if attr == "INV-FIX":
  2644. print("-x-x-x-x-x-x-x-x-")
  2645. x=self.select(fix,attr,mode="swap")
  2646. #x=self.select(fix,"ALL",mode="swap")
  2647. return x
  2648. out = []
  2649. if fix not in self.fixtures:
  2650. print(" activate Fixture in fixture list on encoder click ")
  2651. #jdata=[{"MODE":"---"}]
  2652. ii =0
  2653. #jclient_send(jdata)
  2654. delay=0
  2655. print("-->A HIER <--")
  2656. sub_data = []
  2657. for fix in self.fixtures:
  2658. ii+=1
  2659. #cprint(fix,attr,xval)
  2660. data = self.fixtures[fix]
  2661. if "-FINE" in attr.upper():
  2662. continue
  2663. elif (attr in data["ATTRIBUT"] ) and "-FINE" not in attr.upper() :
  2664. if xval == "click":
  2665. self.select(fix,attr,mode="on")
  2666. elif data["ATTRIBUT"][attr]["ACTIVE"]:
  2667. if fix: # prevent endless recursion
  2668. #print("------",end="")
  2669. #self.encoder(fix,attr,xval,xfade,delay)
  2670. sub_data.append([fix,attr,xval,xfade,delay])
  2671. if DELAY._is():
  2672. delay += DELAY.val()/100
  2673. sub_jdata = []
  2674. for dd in sub_data:
  2675. #print("---",len(sub_data),end="")
  2676. #self.encoder(fix,attr,xval,xfade,delay)
  2677. _x123 = self.encoder(dd[0],dd[1],dd[2],dd[3],dd[4],blind=1)
  2678. sub_jdata.append(_x123)
  2679. if sub_jdata:
  2680. print("--- SEND MASTER ENCODER:",len(sub_data),sub_data[0],"... _blind:",_blind)#,end="")
  2681. jclient_send(sub_jdata)
  2682. jdata=[{"MODE":ii}]
  2683. print("-->B HIER <--")
  2684. jclient_send(jdata)
  2685. return 0
  2686. data = self.fixtures[fix]
  2687. if xval == "click":
  2688. #cprint(data)
  2689. return self.select(fix,attr,mode="toggle")
  2690. v2=data["ATTRIBUT"][attr]["VALUE"]
  2691. change=0
  2692. increment = 4.11
  2693. jdata = {"MODE":"ENC"}
  2694. if xval == "++":
  2695. v2+= increment
  2696. jdata["INC"] = increment
  2697. change=1
  2698. elif xval == "--":
  2699. jdata["INC"] = increment*-1
  2700. v2-= increment
  2701. change=1
  2702. elif xval == "+":
  2703. increment = 0.5
  2704. v2+= increment
  2705. jdata["INC"] = increment
  2706. change=1
  2707. elif xval == "-":
  2708. increment = 0.5
  2709. jdata["INC"] = increment*-1
  2710. v2-= increment
  2711. change=1
  2712. elif type(xval) is int or type(xval) is float:
  2713. v2 = xval
  2714. change=1
  2715. if v2 < 0:
  2716. v2=0
  2717. elif v2 > 256:
  2718. v2=256
  2719. jdata["VALUE"] = round(v2,4)
  2720. jdata["FIX"] = fix
  2721. jdata["ATTR"] = attr
  2722. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  2723. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  2724. out = {}
  2725. if change:
  2726. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2727. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2728. data["ATTRIBUT"][attr]["VALUE"] = round(v2,4)
  2729. jdata["FADE"] = 0
  2730. if xfade:
  2731. jdata["FADE"] = xfade
  2732. if xdelay:
  2733. #if attr not in ["PAN","TILT"] and 1:
  2734. jdata["DELAY"] = xdelay
  2735. if not _blind:
  2736. jdata = [jdata]
  2737. #print("ENC",jdata)
  2738. jclient_send(jdata)
  2739. time.sleep(0.001)
  2740. return jdata
  2741. return v2
  2742. def get_active(self):
  2743. cprint("get_active",self)
  2744. CFG = OrderedDict()
  2745. sdata = OrderedDict()
  2746. sdata["CFG"] = CFG # OrderedDict()
  2747. sdata["CFG"]["FADE"] = FADE.val()
  2748. sdata["CFG"]["DEALY"] = 0
  2749. #sdata["CFG"]["BUTTON"] = "GO"
  2750. for fix in self.fixtures:
  2751. data = self.fixtures[fix]
  2752. for attr in data["ATTRIBUT"]:
  2753. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2754. if fix not in sdata:
  2755. sdata[fix] = {}
  2756. if attr not in sdata[fix]:
  2757. sdata[fix][attr] = OrderedDict()
  2758. if not modes.val("REC-FX"):
  2759. sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
  2760. #sdata[fix][attr]["FADE"] = FADE.val() #fade
  2761. else:
  2762. sdata[fix][attr]["VALUE"] = None #data["ATTRIBUT"][attr]["VALUE"]
  2763. if "FX" not in data["ATTRIBUT"][attr]:
  2764. data["ATTRIBUT"][attr]["FX"] =""
  2765. if "FX2" not in data["ATTRIBUT"][attr]:
  2766. data["ATTRIBUT"][attr]["FX2"] ={}
  2767. sdata[fix][attr]["FX"] = data["ATTRIBUT"][attr]["FX"]
  2768. sdata[fix][attr]["FX2"] = data["ATTRIBUT"][attr]["FX2"]
  2769. return sdata
  2770. def get_active2(self):
  2771. pass
  2772. def _deselect_all(self,fix=None):
  2773. cprint("FIXTURES._deselect_all()",fix,"ALL",color="yellow")
  2774. c=0
  2775. if fix in self.fixtures:
  2776. data = self.fixtures[fix]
  2777. for attr in data["ATTRIBUT"]:
  2778. #print("SELECT ALL",fix,attr)
  2779. if "-FINE" in attr.upper():
  2780. pass
  2781. else:
  2782. c+=self.select(fix,attr,mode="off",mute=1)
  2783. return c
  2784. def _select_all(self,fix=None,mode="toggle",mute=0):
  2785. if not mute:
  2786. cprint("FIXTURES._select_all()",fix,"ALL",mode,color="yellow")
  2787. c=0
  2788. if fix in self.fixtures:
  2789. data = self.fixtures[fix]
  2790. for attr in data["ATTRIBUT"]:
  2791. #print("SELECT ALL",fix,attr)
  2792. if "-FINE" in attr.upper():
  2793. continue
  2794. if mode == "toggle":
  2795. c+=self.select(fix,attr,mode="on",mute=mute)
  2796. elif mode == "swap":
  2797. if not attr.startswith("_"):
  2798. c+=self.select(fix,attr,mode="toggle",mute=mute)
  2799. if not c and mode == "toggle": # unselect all
  2800. c= self._deselect_all(fix=fix)
  2801. return c
  2802. def select(self,fix=None,attr=None,mode="on",mute=0):
  2803. if not mute:
  2804. cprint("FIXTURES.select() >>",fix,attr,mode,color="yellow")
  2805. out = 0
  2806. if fix == "SEL":
  2807. if attr.upper() == "INV-ATTR":
  2808. fixs = self.get_active()
  2809. print("selected:",len(fixs))
  2810. for fix in fixs:
  2811. x=self._select_all(fix=fix,mode=mode,mute=1)
  2812. return None
  2813. if fix in self.fixtures:
  2814. if attr.upper() == "ALL":
  2815. x=self._select_all(fix=fix,mode=mode)
  2816. return x
  2817. data = self.fixtures[fix]
  2818. if attr in data["ATTRIBUT"]:
  2819. if mode == "on":
  2820. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  2821. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2822. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2823. out = 1
  2824. elif mode == "off":
  2825. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2826. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2827. out = 1
  2828. elif mode == "toggle":
  2829. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2830. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2831. else:
  2832. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2833. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2834. out = 1
  2835. return out
  2836. def clear(self):
  2837. out = 0
  2838. for fix in self.fixtures:
  2839. data = self.fixtures[fix]
  2840. for attr in data["ATTRIBUT"]:
  2841. #if attr.endswith("-FINE"):
  2842. # continue
  2843. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2844. out +=1
  2845. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2846. return out
  2847. def CFG_CHECKER(sdata):
  2848. "repair CFG "
  2849. ok = 0
  2850. if "CFG" not in sdata:
  2851. sdata["CFG"] = OrderedDict()
  2852. ok += 1
  2853. if "FADE" not in sdata["CFG"]:
  2854. sdata["CFG"]["FADE"] = 4
  2855. ok += 1
  2856. if "DELAY" not in sdata["CFG"]:
  2857. sdata["CFG"]["DELAY"] = 0
  2858. ok += 1
  2859. if "BUTTON" not in sdata["CFG"]:
  2860. sdata["CFG"]["BUTTON"] = "GO"
  2861. ok += 1
  2862. if "HTP-MASTER" not in sdata["CFG"]:
  2863. sdata["CFG"]["HTP-MASTER"] = 100 #%
  2864. ok += 1
  2865. if "SIZE-MASTER" not in sdata["CFG"]:
  2866. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  2867. ok += 1
  2868. if "SPEED-MASTER" not in sdata["CFG"]:
  2869. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  2870. ok += 1
  2871. if "OFFSET-MASTER" not in sdata["CFG"]:
  2872. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  2873. ok += 1
  2874. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  2875. #except:pass
  2876. return ok
  2877. class Presets():
  2878. def __init__(self):
  2879. #super().__init__()
  2880. self.base = Base()
  2881. #self.load()
  2882. self._last_copy = None
  2883. self._last_move = None
  2884. self.fx_buffer = {}
  2885. def load_presets(self):
  2886. #self._load()
  2887. filename="presets"
  2888. #self.base._init()
  2889. d,l = self.base._load(filename)
  2890. for i in d:
  2891. sdata = d[i]
  2892. ok = CFG_CHECKER(sdata)
  2893. self.val_presets = d
  2894. self.label_presets = l
  2895. def check_cfg(self,nr=None):
  2896. cprint("PRESETS.check_cfg()",nr)#,color="red")
  2897. ok = 0
  2898. if nr is not None:
  2899. if nr in self.val_presets:
  2900. sdata = self.val_presets[nr]
  2901. ok += self._check_cfg(sdata)
  2902. else:
  2903. cprint("nr not in data ",nr,color="red")
  2904. else:
  2905. for nr in self.val_presets:
  2906. sdata = self.val_presets[nr]
  2907. ok += self._check_cfg(sdata)
  2908. return ok
  2909. def _check_cfg(self,sdata):
  2910. cprint("PRESETS._check_cfg()")#,color="red")
  2911. ok = CFG_CHECKER(sdata)
  2912. if ok:
  2913. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  2914. return ok
  2915. def backup_presets(self,save_as=""):
  2916. filename = "presets"
  2917. data = self.val_presets
  2918. labels = self.label_presets
  2919. #self.base._init()
  2920. self.base._backup(filename,data,labels,save_as)
  2921. def get_cfg(self,nr):
  2922. cprint("PRESETS.get_cfg()",nr)
  2923. self.check_cfg(nr)
  2924. if nr not in self.val_presets:
  2925. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  2926. return {}
  2927. if "CFG" in self.val_presets[nr]:
  2928. return self.val_presets[nr]["CFG"]
  2929. def clean(self,nr):
  2930. if nr not in self.val_presets:
  2931. self.val_presets[nr] = OrderedDict()
  2932. #self.val_presets[nr]["VALUE"] = 0
  2933. #self.val_presets[nr]["FX"] = ""
  2934. sdata = self.val_presets[nr]
  2935. for fix in sdata:
  2936. #print("exec.clear()",nr,fix,sdata[fix])
  2937. for attr in sdata[fix]:
  2938. row = sdata[fix][attr]
  2939. if fix == "CFG":
  2940. continue
  2941. if "VALUE" not in row:
  2942. row["VALUE"] = None
  2943. if "FX" not in row:
  2944. row["FX"] = ""
  2945. if "FX2" not in row:
  2946. row["FX2"] = OrderedDict()
  2947. elif row["FX2"]:
  2948. for k in ["SIZE","SPEED","START","OFFSET"]:
  2949. row["FX2"][k] = int( row["FX2"][k] )
  2950. row["FX"] = ""
  2951. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  2952. #"off:0:0:0:16909:-:"
  2953. x = row["FX"].split(":")
  2954. print("-fx",x,len(x))
  2955. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  2956. if len(x) >= 6:
  2957. row["FX2"]["TYPE"] = x[0]
  2958. row["FX2"]["SIZE"] = int(x[1])
  2959. row["FX2"]["SPEED"] = int(x[2])
  2960. row["FX2"]["START"] = int(x[3])
  2961. row["FX2"]["OFFSET"] = int(x[4])
  2962. row["FX2"]["BASE"] = x[5]
  2963. row["FXOLD"] = row["FX"]
  2964. row["FX"] = ""
  2965. #cprint("exec.clear()",nr,fix,row)
  2966. def get_raw_map(self,nr):
  2967. self.clean(nr)
  2968. print("get_raw_map",nr)
  2969. sdata = self.val_presets[nr]
  2970. cmd = ""
  2971. out = []
  2972. dmx=-1
  2973. for fix in sdata:
  2974. if fix == "CFG":
  2975. #print("CFG",nr,sdata[fix])
  2976. continue
  2977. for attr in sdata[fix]:
  2978. x = {}
  2979. #print("RAW",attr)
  2980. x["FIX"] = fix
  2981. x["ATTR"] = attr
  2982. x["VALUE"] = sdata[fix][attr]["VALUE"]
  2983. x["FX"] = sdata[fix][attr]["FX"]
  2984. x["FX2"] = sdata[fix][attr]["FX2"]
  2985. #x["DMX"] = sdata[fix][attr]["NR"]
  2986. out.append(x)
  2987. return out
  2988. def get_btn_txt(self,nr):
  2989. sdata=self.val_presets[nr]
  2990. BTN="go"
  2991. if "CFG" in sdata:
  2992. if "BUTTON" in sdata["CFG"]:
  2993. BTN = sdata["CFG"]["BUTTON"]
  2994. _label = self.label_presets[nr] # = label
  2995. #txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  2996. #txt=str(nr+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+_label
  2997. txt="{} {} {}\n{}".format(nr+1,BTN,len(sdata)-1,_label)
  2998. print("get_btn_txt",nr,[txt])
  2999. return txt
  3000. def _btn_cfg(self,nr,txt=None):
  3001. if nr not in self.val_presets:
  3002. return ""
  3003. if "CFG" not in self.val_presets[nr]:
  3004. self.val_presets[nr]["CFG"] = OrderedDict()
  3005. return self.val_presets[nr]["CFG"]
  3006. def btn_cfg(self,nr,txt=None):
  3007. if nr not in self.val_presets:
  3008. return ""
  3009. if "CFG" not in self.val_presets[nr]:
  3010. self.val_presets[nr]["CFG"] = OrderedDict()
  3011. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  3012. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3013. if type(txt) is str:
  3014. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  3015. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  3016. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3017. master._refresh_exec(nr=nr)
  3018. print("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  3019. return self.val_presets[nr]["CFG"]["BUTTON"]
  3020. def label(self,nr,txt=None):
  3021. if nr not in self.label_presets:
  3022. return ""
  3023. if type(txt) is str:
  3024. self.label_presets[nr] = txt
  3025. print("set label",nr,[txt])
  3026. print("??? ?? set label",nr,[txt])
  3027. return self.label_presets[nr]
  3028. def clear_move(self):
  3029. cprint("PRESETS.clear_move()",end=" ")
  3030. self.clear_copy()
  3031. def clear_copy(self):
  3032. cprint("PRESETS.clear_copy()",end=" ")
  3033. if self._last_copy is not None:
  3034. cprint("=OK=",color="red")
  3035. self._last_copy = None
  3036. else:
  3037. cprint("=NONE=",color="green")
  3038. def copy(self,nr,overwrite=1):
  3039. cprint("PRESETS._copy",nr,"last",self._last_copy)
  3040. if nr >= 0:
  3041. if self._last_copy is not None:
  3042. if modes.val("COPY"):
  3043. modes.val("COPY",3)
  3044. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  3045. return ok #ok
  3046. else:
  3047. if modes.val("COPY"):
  3048. modes.val("COPY",2)
  3049. self._last_copy = nr
  3050. cprint("PRESETS.copy START ",color="red")
  3051. return 0
  3052. return 1 # on error reset move
  3053. def _copy(self,nr_from,nr_to,overwrite=1):
  3054. cprint("PRESETS._copy",nr_from,"to",nr_to)
  3055. self.check_cfg(nr_from)
  3056. if type(self._last_copy) is None:
  3057. cprint("PRESETS._copy last nr is None",color="red")
  3058. return 0
  3059. cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
  3060. if nr_from in self.val_presets and nr_to in self.val_presets:
  3061. fdata = self.val_presets[nr_from]
  3062. tdata = self.val_presets[nr_to]
  3063. #cprint(fdata)
  3064. flabel = self.label_presets[nr_from]
  3065. tlabel = self.label_presets[nr_to]
  3066. self.val_presets[nr_to] = copy.deepcopy(fdata)
  3067. self.label_presets[nr_to] = flabel
  3068. if not overwrite: #default
  3069. cprint("overwrite",overwrite)
  3070. self.val_presets[nr_from] = copy.deepcopy(tdata)
  3071. self.label_presets[nr_from] = tlabel
  3072. #self.label_presets[nr_from] = "MOVE"
  3073. self.clear_copy()
  3074. cprint("PRESETS.copy OK",color="green")
  3075. return 1
  3076. def move(self,nr):
  3077. cprint("PRESETS.move",self._last_copy,"to",nr)
  3078. if nr >= 0:
  3079. last = self._last_copy
  3080. if modes.val("MOVE"):
  3081. modes.val("MOVE",2)
  3082. ok= self.copy(nr,overwrite=0)
  3083. if ok and last >= 0:
  3084. if modes.val("MOVE"):
  3085. modes.val("MOVE",3)
  3086. cprint("PRESETS.move OK",color="red")
  3087. #self.delete(last)
  3088. return ok,nr,last #ok
  3089. return 0,nr,last # on error reset move
  3090. def delete(self,nr):
  3091. cprint("PRESETS.delete",nr)
  3092. ok=0
  3093. if nr in self.val_presets:
  3094. self.val_presets[nr] = OrderedDict()
  3095. self.label_presets[nr] = "-"
  3096. ok = 1
  3097. self.check_cfg(nr)
  3098. return ok
  3099. def rec(self,nr,data,arg=""):
  3100. cprint("rec",self,"rec()",len(data),arg)
  3101. self.check_cfg(nr)
  3102. self._check_cfg(data) #by ref
  3103. odata=self.val_presets[nr]
  3104. #print("odata",odata)
  3105. if "CFG" in odata:
  3106. if "BUTTON" in odata["CFG"]:
  3107. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  3108. self.val_presets[nr] = data
  3109. return 1
  3110. class FixtureEditor():
  3111. def __init__(self,dmx=1):
  3112. pass
  3113. self.elem=[]
  3114. self.dmx=dmx
  3115. print("init FixtureEditor",dmx)
  3116. def event(self,a1="",a2=""):
  3117. print([self.dmx,a1,a2])
  3118. j=[]
  3119. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
  3120. j.append(jdata)
  3121. jclient_send(j)
  3122. class MasterWing():
  3123. def __init__(self,dmx=1):
  3124. pass
  3125. self.elem=[]
  3126. self.dmx=dmx
  3127. print("init MasterWing",dmx)
  3128. def event(self,a1="",a2=""):
  3129. print([self.dmx,a1,a2])
  3130. jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
  3131. j=[]
  3132. j.append(jdata)
  3133. jclient_send(j)
  3134. class BufferVar():
  3135. def __init__(self,elem):
  3136. self.elem = elem
  3137. def change_dmx(self,event=""):
  3138. nr=1
  3139. txt=""
  3140. def cb(data):
  3141. txt = data["Value"]
  3142. dialog._cb = _cb
  3143. dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
  3144. print("change_dmx",[event,self])
  3145. # GUI_FaderLayout():
  3146. lf_nr = 0
  3147. from tkinter import PhotoImage
  3148. _shift_key = 0
  3149. class Window():
  3150. def __init__(self,args): #title="title",master=0,width=100,height=100,left=None,top=None,exit=0,cb=None,resize=1):
  3151. global lf_nr
  3152. self.args = {"title":"title","master":0,"width":100,"height":100,"left":None,"top":None,"exit":0,"cb":None,"resize":1}
  3153. self.args.update(args)
  3154. cprint("Window.init()",id(self.args),color="yellow")
  3155. cprint(" ",self.args,color="yellow")
  3156. ico_path="./icon/"
  3157. self.cb = cb
  3158. if self.args["master"]:
  3159. self.tk = tkinter.Tk()
  3160. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3161. self.tk.withdraw() # do not draw
  3162. self.tk.resizable(self.args["resize"],self.args["resize"])
  3163. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  3164. print(defaultFont)
  3165. defaultFont.configure(family="FreeSans",
  3166. size=10,
  3167. weight="bold")
  3168. # MAIN MENUE
  3169. try:
  3170. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"main.png"))
  3171. except Exception as e:
  3172. print("Exception GUIWindow.__init__",e)
  3173. else:
  3174. # addtional WINDOW
  3175. self.tk = tkinter.Toplevel()
  3176. self.tk.iconify()
  3177. #self.tk.withdraw() # do not draw
  3178. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3179. self.tk.resizable(self.args["resize"],self.args["resize"])
  3180. try:
  3181. if "COLORPICKER" in self.args["title"]:
  3182. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"picker.png"))
  3183. elif "ENCODER" in self.args["title"]:
  3184. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"enc.png"))
  3185. elif "EXEC" in self.args["title"]:
  3186. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  3187. elif "FX" in self.args["title"]:
  3188. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"fx.png"))
  3189. else:
  3190. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png"))
  3191. except Exception as e:
  3192. print("Exception on load window icon",self.args["title"])
  3193. print("Exception:",e)
  3194. #time.sleep(3)
  3195. self.tk.deiconify()
  3196. self.tk["bg"] = "black"
  3197. self.tk.bind("<Button>",self.callback)
  3198. self.tk.bind("<Key>",self.callback)
  3199. self.tk.bind("<KeyRelease>",self.callback)
  3200. self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3201. lf_nr+=1
  3202. #self.tk.geometry("270x600+0+65")
  3203. geo ="{}x{}".format(self.args["width"],self.args["height"])
  3204. if self.args["left"] is not None:
  3205. geo += "+{}".format(self.args["left"])
  3206. if self.args["top"] is not None:
  3207. geo += "+{}".format(self.args["top"])
  3208. #self._event_clear = Xevent(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
  3209. self.tk.geometry(geo)
  3210. self.show()
  3211. def update_idle_task(self):
  3212. if INIT_OK:
  3213. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3214. pass
  3215. def close_app_win(self,event=None):
  3216. cprint("close_app_win",self,event,self.args["title"],color="red")
  3217. if exit:
  3218. if self.title == "MAIN":
  3219. save_window_position()
  3220. self.tk.destroy()
  3221. try:
  3222. self.cb("<exit>").cb()
  3223. except Exception as e:
  3224. cprint("EXCETPION: close_app_win",e,self,color="red")
  3225. def title(self,title=None):
  3226. if title is None:
  3227. return self.tk.title()
  3228. else:
  3229. #return self.tk.title(title)
  3230. self.args["title"] = title
  3231. return self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3232. def show(self):
  3233. self.tk.deiconify()
  3234. pass
  3235. def mainloop(self):
  3236. #save_window_position_loop() #like autosave
  3237. try:
  3238. self.tk.mainloop()
  3239. finally:
  3240. self.tk.quit()
  3241. def callback(self,event,data={}):#value=255):
  3242. global _global_short_key
  3243. #time.sleep(0.1)
  3244. if not _global_short_key:
  3245. #cprint("<GLOBAL-GUI-EVENT-DISABLED>",event,color="red")
  3246. return 1
  3247. global _shift_key
  3248. #cprint("<GUI>",event,color="yellow")
  3249. #cprint("<GUI>",event.state,data,[event.type,event.keysym],color="yellow")
  3250. value = 255
  3251. if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
  3252. value = 0
  3253. if "keysym" in dir(event):
  3254. if "Escape" == event.keysym:
  3255. FIXTURES.clear()
  3256. modes.val("ESC",1)
  3257. master.refresh_fix()
  3258. elif event.keysym in ["Shift_L","Shift_R"]:
  3259. #cprint(event.type)
  3260. if "KeyRelease" in str(event.type) or str(event.type) in ["3"]:
  3261. _shift_key = 0
  3262. else:
  3263. _shift_key = 1
  3264. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3265. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3266. global _ENCODER_WINDOW
  3267. if _shift_key:
  3268. _ENCODER_WINDOW.title("SHIFT/FINE ")
  3269. else:
  3270. _ENCODER_WINDOW.title("ENCODER")
  3271. elif event.keysym in "ebfclrms" and value:
  3272. if "e" == event.keysym:
  3273. modes.val("EDIT",1)
  3274. elif "b" == event.keysym:
  3275. modes.val("BLIND",1)
  3276. elif "f" == event.keysym:
  3277. modes.val("FLASH",1)
  3278. elif "c" == event.keysym:
  3279. modes.val("CFG-BTN",1)
  3280. elif "l" == event.keysym:
  3281. modes.val("LABEL",1)
  3282. elif "r" == event.keysym:
  3283. modes.val("REC",1)
  3284. elif "m" == event.keysym:
  3285. x=modes.val("MOVE",1)
  3286. if not x:
  3287. PRESETS.clear_move()
  3288. elif "s" == event.keysym:
  3289. modes.val("SELECT",1)
  3290. elif event.keysym in ["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]:
  3291. nr = int( event.keysym[1:]) # F:1-12
  3292. nr = nr-1+81
  3293. cprint("F-KEY",value,nr,event.keysym)
  3294. #print(event)
  3295. master.preset_go(nr-1,xfade=None,val=value)
  3296. elif event.keysym in ["1","2","3","4","5","6","7","8","9","0"]:
  3297. nr = int( event.keysym)
  3298. if nr == 0:
  3299. nr = 10
  3300. nr = nr-1+161
  3301. cprint("NUM-KEY",value,nr)
  3302. master.preset_go(nr-1,xfade=None,val=value)
  3303. elif "numbersign" == event.keysym and value: # is char "#"
  3304. PRESETS.backup_presets()
  3305. FIXTURES.backup_patch()
  3306. #save_window_position()
  3307. #e = Xevent(fix=0,elem=None,attr="SAVE\nSHOW",mode="SETUP")
  3308. #e.cb(event=event)
  3309. elif "End" == event.keysym:
  3310. FIXTURES.fx_off("all")
  3311. CONSOLE.fx_off("all")
  3312. CONSOLE.flash_off("all")
  3313. elif "Delete" == event.keysym:
  3314. #PRESETS.delete(nr)
  3315. if value:
  3316. modes.val("DEL",1)
  3317. class WindowManager():
  3318. def __init__(self):
  3319. self.windows = {}
  3320. self.obj = {}
  3321. self.nr= 0
  3322. self.first=""
  3323. def new(self,w,name="",obj=None):
  3324. if not self.first:
  3325. if name:
  3326. self.first = name
  3327. else:
  3328. self.first = str(self.nr)
  3329. w.tk.state(newstate='normal')
  3330. w.tk.attributes('-topmost',True)
  3331. if name:
  3332. self.windows[str(name)] = w
  3333. self.obj[str(name)] = obj
  3334. else:
  3335. self.windows[str(self.nr)] = w
  3336. self.obj[str(self.nr)] = obj
  3337. self.nr+=1
  3338. #w.show()
  3339. def mainloop(self):
  3340. self.windows[self.first].mainloop()
  3341. def get(self,name):
  3342. print(self,".get(name) =",name)
  3343. name = str(name)
  3344. if name in self.windows:
  3345. out = self.windows[name]
  3346. print(out)
  3347. return out
  3348. def get_obj(self,name):
  3349. #print(self,".get(name) =",name)
  3350. name = str(name)
  3351. if name in self.windows:
  3352. out = self.obj[name]
  3353. #print(out)
  3354. return out
  3355. def top(self,name):
  3356. name = str(name)
  3357. for n in self.windows:
  3358. print("TOP",n) #self.get("")
  3359. if name in self.windows:
  3360. self.windows[name].tk.state(newstate='normal')
  3361. self.windows[name].tk.attributes('-topmost',True)
  3362. self.windows[name].tk.attributes('-topmost',False)
  3363. self.windows[name].tk.update_idletasks()# gui_menu_gui.tk)
  3364. #print("redraw",name)
  3365. #if name == "PATCH":
  3366. # gui_patch.draw()
  3367. #if name == "DIMMER":
  3368. # gui_fix.draw()
  3369. if name == "EXEC":
  3370. master._refresh_exec()
  3371. #self.windows[name].tk.update_idletasks()# gui_menu_gui.tk)
  3372. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3373. else:
  3374. print(name,"not in self.windows",self.windows.keys())
  3375. class Console():
  3376. def __init__(self):
  3377. pass
  3378. def flash_off(self,fix):
  3379. pass#client.send("df0:alloff:::,")
  3380. def fx_off(self,fix):
  3381. cprint("Console.fx_off()",fix)
  3382. if not fix or fix == "all":
  3383. #client.send("fx0:alloff:,fxf:alloff:,")
  3384. #client.send("df0:alloff:::,")
  3385. j = []
  3386. if 0:
  3387. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  3388. j.append(jdata)
  3389. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  3390. j.append(jdata)
  3391. else:
  3392. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  3393. j.append(jdata)
  3394. jclient_send(j)
  3395. return 0
  3396. def test_1():
  3397. #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
  3398. pass
  3399. window_manager = WindowManager()
  3400. CONSOLE = Console()
  3401. PRESETS = Presets()
  3402. FIXTURES = Fixtures()
  3403. def LOAD_SHOW():
  3404. PRESETS.load_presets()
  3405. FIXTURES.load_patch()
  3406. #draw_enc(gui,root2)
  3407. #master._refresh_fix()
  3408. #master._refresh_exec()
  3409. LOAD_SHOW()
  3410. master = MASTER()
  3411. class Refresher():
  3412. def __init__(self):
  3413. self.time = time.time()
  3414. self.time_max = time.time()
  3415. self.time_delta = 15
  3416. self.update = 1
  3417. self.name = "fix" # exec
  3418. def reset(self):
  3419. self.time = time.time() #+.1
  3420. self.update = 1
  3421. def refresh(self):
  3422. #print("refresh",self.update,int((self.time-time.time())*1000))
  3423. #if self.time_max+self.time_delta < time.time():
  3424. # #print("----- MAX REFRES TIMEOUT -----")
  3425. # self._refresh()
  3426. if self.update:
  3427. if self.time+self.time_delta < time.time():
  3428. self._refresh()
  3429. else:
  3430. self.time = time.time() #+.1
  3431. def _refresh(self):
  3432. print(self,"_refresh()")
  3433. if not INIT_OK:
  3434. return
  3435. self.time_max = time.time()
  3436. self.time = time.time()
  3437. self.update = 0
  3438. try:
  3439. if self.name == "fix": # exec
  3440. master._refresh_fix()
  3441. else:
  3442. master._refresh_exec()
  3443. except Exception as e:
  3444. print("_refresh except:",e)
  3445. traceback.print_exc()
  3446. print()
  3447. print("t=",self.time_max- time.time())
  3448. def loop(self,args={}):
  3449. while 1:
  3450. try:
  3451. if INIT_OK:
  3452. self.refresh()
  3453. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3454. except Exception as e:
  3455. print("loop exc",e)
  3456. traceback.print_exc()
  3457. cprint("== cb EXCEPT",e,color="red")
  3458. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  3459. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  3460. time.sleep(0.2)
  3461. print("main",__name__)
  3462. __run_main = 0
  3463. if __name__ == "__main__":
  3464. __run_main = 1
  3465. else:
  3466. import __main__
  3467. if "unittest" not in dir(__main__):
  3468. __run_main = 1
  3469. refresher_fix = Refresher()
  3470. refresher_fix.time_delta = 0.25
  3471. refresher_fix.name = "fix"
  3472. refresher_exec = Refresher()
  3473. refresher_exec.time_delta = 30
  3474. refresher_exec.name = "exec"
  3475. def loops(**args):
  3476. time.sleep(15) # wait until draw all window's
  3477. thread.start_new_thread(refresher_fix.loop,())
  3478. thread.start_new_thread(refresher_exec.loop,())
  3479. class window_create_buffer():
  3480. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  3481. self.args = args.copy()
  3482. self.cls = cls
  3483. self.cb_ok = cb_ok
  3484. self.data = data
  3485. self.scroll = scroll
  3486. self.gui = gui
  3487. def create(self):
  3488. cprint()
  3489. cprint("window_create_buffer.create()",id(self),self.args["title"],color="green")
  3490. obj = None
  3491. w = Window(self.args)
  3492. if self.scroll:
  3493. w1 = ScrollFrame(w.tk,width=self.args["width"],height=self.args["height"])
  3494. else:
  3495. w1 = tk.Frame(w.tk,width=self.args["width"],height=self.args["height"])
  3496. w1.pack()
  3497. if self.gui:
  3498. self.cls(self.gui,w1,self.data) #PRESETS):
  3499. else:
  3500. obj=self.cls(w1,self.data)
  3501. return w,obj,self.cb_ok
  3502. window_init_buffer = {}
  3503. if __run_main:
  3504. print("main")
  3505. #thread.start_new_thread(refresher_fix.loop,())
  3506. #thread.start_new_thread(refresher_exec.loop,())
  3507. TOP = _POS_TOP + 15
  3508. L0 = _POS_LEFT
  3509. L1 = _POS_LEFT + 95
  3510. L2 = _POS_LEFT + 920
  3511. W1 = 810
  3512. H1 = 550
  3513. HTB = 23 # hight of the titlebar from window manager
  3514. #w = Window("MAIN",master=1,width=95,height=H1//2,left=L0,top=TOP,resize=0)
  3515. args = {"title":"MAIN","master":1,"width":100,"height":H1,"left":L0,"top":TOP,"resize":1}
  3516. #w = Window("MAIN",master=1,width=100,height=H1,left=L0,top=TOP,resize=1)
  3517. w = Window(args)
  3518. gui_menu_gui = w
  3519. data = []
  3520. #data.append({"text":"COMMAND"})
  3521. #data.append({"text":"CONFIG"})
  3522. data.append({"text":"PATCH"})
  3523. data.append({"text":"DIMMER"})
  3524. data.append({"text":"FIXTURES"})
  3525. data.append({"text":"EXEC","name":"EXEC-BTN"})
  3526. data.append({"text":"EXEC-WING"})
  3527. data.append({"text":"---"})
  3528. data.append({"text":"ENCODER"})
  3529. data.append({"text":"COMMAND"})
  3530. data.append({"text":"COLORPICKER","name":"COLOR"})
  3531. data.append({"text":"FX"})
  3532. gui_menu = GUI_menu(w.tk,data)
  3533. window_manager = gui_menu.window_manager #= window_manager
  3534. window_manager.new(w)
  3535. name="EXEC"
  3536. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3537. cls = draw_exec #GUI_ExecWingLayout
  3538. cb_ok = None #set_exec_fader_all
  3539. data = PRESETS
  3540. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,scroll=1,gui=master)
  3541. window_init_buffer[name] = c
  3542. w,obj,cb_ok = c.create()
  3543. window_manager.new(w,name,obj=obj)
  3544. if cb_ok:
  3545. cb_ok()
  3546. if 0: # draw EXEC -BTN second time fail TODO
  3547. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,scroll=1,gui=master)
  3548. window_init_buffer[name] = c
  3549. w,obj,cb_ok = c.create()
  3550. window_manager.update(w,name,obj=obj)
  3551. name="CONFIG"
  3552. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3553. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3554. w = Window(args)
  3555. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3556. #frame_exe = w.tk
  3557. #draw_preset(master,w1)#w.tk)
  3558. #window_manager.new(w,name)
  3559. name="DIMMER"
  3560. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3561. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3562. w = Window(args)
  3563. w2 = ScrollFrame(w.tk,width=W1,height=H1)
  3564. #frame_dim = w1 # w.tk
  3565. #master.draw_dim(w1.tk)
  3566. window_manager.new(w,name)
  3567. name="FIXTURES"
  3568. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3569. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3570. w = Window(args)
  3571. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3572. #frame_fix = w1 #w.tk
  3573. #draw_fix(master,w1,w2)#.tk)
  3574. gui_fix = GUI_FIX(master,w1,w2)
  3575. gui_fix.draw(FIXTURES)
  3576. window_manager.new(w,name)
  3577. name="FIXTURE-EDITOR"
  3578. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3579. w = Window(args)
  3580. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3581. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3582. data=[]
  3583. for i in range((24+12)*15):
  3584. data.append({"text"+str(i):"test"})
  3585. GUI_FaderLayout(w1,data)
  3586. window_manager.new(w,name)
  3587. name="MASTER-WING"
  3588. #w = Window(name,master=0,width=730,height=205,left=L1-80,top=TOP+H1-200)
  3589. #w = Window(name,master=0,width=75,height=405,left=L0,top=TOP+H1-220)
  3590. args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220}
  3591. w = Window(args)
  3592. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3593. w1 = tk.Frame(w.tk,width=W1,height=H1)
  3594. w1.pack()
  3595. data=[]
  3596. for i in range(2):
  3597. data.append({"MASTER"+str(i):"MASTER"})
  3598. GUI_MasterWingLayout(w1,data)
  3599. window_manager.new(w,name)
  3600. name="EXEC-WING"
  3601. args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
  3602. data=[]
  3603. for i in range(10*3):
  3604. data.append({"EXEC"+str(i):"EXEC"})
  3605. cls = GUI_ExecWingLayout
  3606. cb_ok = set_exec_fader_all
  3607. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok)
  3608. window_init_buffer[name] = c
  3609. w,obj,cb_ok = c.create()
  3610. window_manager.new(w,name,obj)
  3611. if cb_ok:
  3612. cb_ok()
  3613. name="ENCODER"
  3614. #w = Window(name,master=0,width=620,height=113,left=L0+710,top=TOP+H1+15+HTB*2)
  3615. args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
  3616. w = Window(args)
  3617. _ENCODER_WINDOW = w
  3618. draw_enc(master,w.tk)#Xroot)
  3619. window_manager.new(w,name)
  3620. #name="REMOTE-CONTROL"
  3621. #w = Window(name,master=0,width=220,height=113,left=L0+710,top=TOP+H1+HTB*2+123)
  3622. #_ENCODER_WINDOW = w
  3623. #draw_enc(master,w.tk)#Xroot)
  3624. name = "SETUP"
  3625. #w = Window(name,master=0,width=415,height=42,left=L1+10+W1,top=TOP,resize=0)
  3626. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP,"resize":0}
  3627. w = Window(args)
  3628. w.tk.title("SETUP SHOW:"+master.base.show_name)
  3629. draw_setup(master,w.tk)
  3630. window_manager.new(w,name)
  3631. name = "COMMAND"
  3632. args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":0}
  3633. w = Window(args)
  3634. #w = Window(name,master=0,width=415,height=130,left=L1+10+W1,top=TOP+81,resize=0)#+96)
  3635. draw_command(master,w.tk)
  3636. window_manager.new(w,name)
  3637. name = "LIVE"
  3638. #w = Window(name,master=0,width=415,height=42,left=L1+10+W1,top=TOP+235,resize=0)#250)
  3639. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":0}
  3640. w = Window(args)
  3641. draw_live(master,w.tk)
  3642. window_manager.new(w,name)
  3643. name = "CLOCK"
  3644. #w = Window(name,master=0,width=335,height=102,left=L1+10+W1+80,top=TOP+H1+HTB+160,resize=0)#250)
  3645. args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
  3646. w = Window(args)
  3647. draw_clock(master,w.tk)
  3648. window_manager.new(w,name)
  3649. name="FX"
  3650. #w = Window(name,master=0,width=415,height=297,left=L1+10+W1,top=TOP+302,resize=0)#317)
  3651. args = {"title":name,"master":0,"width":415,"height":297,"left":L1+10+W1,"top":TOP+302,"resize":0}
  3652. w = Window(args)
  3653. #frame_fx = w.tk
  3654. draw_fx(master,w.tk)
  3655. window_manager.new(w,name)
  3656. name="PATCH"
  3657. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3658. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3659. w = Window(args)
  3660. w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3661. main_preset_frame = w1
  3662. gui_patch = GUI_PATCH(master,main_preset_frame)
  3663. gui_patch.draw(FIXTURES)
  3664. window_manager.new(w,name)
  3665. #LibreLightDesk
  3666. name="COLORPICKER"
  3667. #w = Window(name,master=0,width=600,height=113,left=L1+5,top=TOP+5+HTB*2+H1)
  3668. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  3669. w = Window(args)
  3670. draw_colorpicker(master,w.tk,FIXTURES,master)
  3671. window_manager.new(w,name)
  3672. name="TableA"
  3673. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3674. #space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
  3675. #x=TableFrame(root=w.tk)#,left=80,top=620)
  3676. #w.show()
  3677. #data =[]
  3678. #for a in range(40):
  3679. # data.append(["E","E{}".format(a+1)])
  3680. #x.draw(data=data,head=["E","C"],config=[12,5,5])
  3681. #w=x.bframe
  3682. #window_manager.new(w,name)
  3683. #Xroot = tk.Tk()
  3684. #Xroot["bg"] = "black" #white
  3685. #Xroot.title( xtitle+" "+str(rnd_id) )
  3686. #Xroot.geometry("1024x800+130+65")
  3687. master.render()
  3688. window_manager.top("Table")
  3689. #w = frame_fix #Window("OLD",master=0,width=W1,height=500,left=130,top=TOP)
  3690. window_manager.new(w,name)
  3691. load_window_position()
  3692. #thread.start_new_thread(refresher_fix.loop,())
  3693. #thread.start_new_thread(refresher_exec.loop,())
  3694. thread.start_new_thread(loops,())
  3695. try:
  3696. #root.mainloop()
  3697. #tk.mainloop()
  3698. window_manager.mainloop()
  3699. finally:
  3700. master.exit()