_LibreLightDesk.py 143 KB

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