_LibreLightDesk.py 147 KB

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