_LibreLightDesk.py 146 KB

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