_LibreLightDesk.py 151 KB

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