_LibreLightDesk.py 140 KB

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