_LibreLightDesk.py 146 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519
  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") #= WindowManager()
  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. window_list_buffer[k] = [1,k,geo]
  1188. except Exception as e:
  1189. cprint("-A save_window_position Exception:",e,color="red")
  1190. lines = ""
  1191. for k,data in window_list_buffer.items():
  1192. try:
  1193. print("-- save:win:pos",k,data)
  1194. if not data[2]:
  1195. continue
  1196. line ="{} {} {}\n"
  1197. line = line.format(data[0],k,data[2])
  1198. lines += line
  1199. except Exception as e:
  1200. cprint("-A save_window_position Exception:",e,color="red")
  1201. try:
  1202. f = open(fname,"w")
  1203. f.write( lines )
  1204. except Exception as e:
  1205. cprint("-B save_window_position Exception:",e,color="red")
  1206. finally:
  1207. f.close() #f.flush()
  1208. def save_window_position_loop(): # like autosave
  1209. def loop():
  1210. time.sleep(20)
  1211. try:
  1212. while 1:
  1213. save_window_position()
  1214. time.sleep(60)
  1215. except Exception as e:
  1216. print("save_loop",e)
  1217. thread.start_new_thread(loop,())
  1218. def load_window_position(_filter=""):
  1219. global window_list_buffer
  1220. print()
  1221. cprint("load_window_position",[_filter])
  1222. try:
  1223. base = Base()
  1224. fname = HOME+"/LibreLight"
  1225. fname = base.show_path1 +base.show_name
  1226. fname += "/gui.txt"
  1227. cprint("- fname:",fname)
  1228. f = open(fname,"r")
  1229. lines = f.readlines()
  1230. f.close()
  1231. data = {}
  1232. for line in lines:
  1233. line = line.strip()
  1234. print(line)
  1235. if " " in line:
  1236. if line.count(" ") >= 2:
  1237. show,k,geo = line.split(" ",2)
  1238. elif line.count(" ") == 1:
  1239. k,geo = line.split(" ",1)
  1240. show = 1
  1241. data[k] = [show,k,geo]
  1242. window_list_buffer[k] = [show,k,geo]
  1243. for k,win in window_manager.windows.items():
  1244. if not win:
  1245. continue
  1246. if k not in data:
  1247. continue
  1248. if _filter:
  1249. if _filter != k:
  1250. continue
  1251. w = data[k][2]
  1252. cprint("- set_win_pos","filter:",[_filter],"Name: {:<20}".format(k),w,win)
  1253. try:
  1254. win.tk.geometry(w)
  1255. except Exception as e:
  1256. cprint("- load_window_position 544 Exception:",e,color="red")
  1257. #print("winfo",k,win.tk.geometry())
  1258. f.close()
  1259. except Exception as e:
  1260. cprint("- load_window_position 345 Exception:",e,color="red")
  1261. return
  1262. class BLINKI():
  1263. def __init__(self,e):
  1264. self.e = e
  1265. def blink(self):
  1266. e = self.e
  1267. e.config(bg='green')
  1268. duration = 150
  1269. for i in range(8):
  1270. d = i * duration
  1271. if i % 2 == 0:
  1272. e.after(d, lambda: e.config(bg='white')) # after 1000ms
  1273. e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
  1274. else:
  1275. e.after(d, lambda: e.config(bg='orange')) # after 1000ms
  1276. e.after(d, lambda: e.config(activebackground='orange')) # after 1000ms
  1277. i+=1
  1278. duration = 150
  1279. e.after(d, lambda: e.config(bg='white')) # after 1000ms
  1280. e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
  1281. class Xevent():
  1282. """ global input event Handeler for short cut's ... etc
  1283. """
  1284. def __init__(self,fix,elem,attr=None,data=None,mode=None):
  1285. self.fix = fix
  1286. self.data=data
  1287. self.attr = attr
  1288. self.elem = elem
  1289. self.mode = mode
  1290. def setup(self,event):
  1291. cprint("xevent.SETUP",[self.mode,self.attr],color="red")
  1292. if self.mode == "SETUP":
  1293. if self.attr == "SAVE\nSHOW":
  1294. self.elem["bg"] = "orange"
  1295. self.elem["text"] = "SAVING..."
  1296. self.elem["bg"] = "red"
  1297. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  1298. #self.elem["fg"] = "orange"
  1299. self.elem.config(activebackground="orange")
  1300. modes.val(self.attr,1)
  1301. PRESETS.backup_presets()
  1302. FIXTURES.backup_patch()
  1303. save_window_position()
  1304. #time.sleep(1)
  1305. #modes.val(self.attr,0)
  1306. self.elem["bg"] = "lightgrey"
  1307. #self.elem["fg"] = "lightgrey"
  1308. self.elem.config(activebackground="lightgrey")
  1309. b = BLINKI(self.elem)
  1310. b.blink()
  1311. elif self.attr == "LOAD\nSHOW":
  1312. name = "LOAD-SHOW"
  1313. base = Base()
  1314. line1 = "PATH: "+base.show_path1 +base.show_name
  1315. line2 = "DATE: "+ time.strftime("%Y-%m-%d %X", time.localtime(time.time()))
  1316. class cb():
  1317. def __init__(self,name=""):
  1318. self.name=name
  1319. print("cb",name)
  1320. def cb(self,event=None,**args):
  1321. print("cdb",self.name,event,args)
  1322. if self.name != "<exit>":
  1323. print("-----------------------:")
  1324. LOAD_SHOW_AND_RESTAT(self.name).cb()
  1325. #self.elem["bg"] = "lightgrey"
  1326. #self.elem.config(activebackground="lightgrey")
  1327. pw = PopupList(name,cb=cb)
  1328. frame = pw.sframe(line1=line1,line2=line2)
  1329. r = _load_show_list(frame,cb=cb)
  1330. #self.elem["bg"] = "red"# "lightgrey"
  1331. #self.elem.config(activebackground="red")
  1332. #self.elem.config(activebackground="lightgrey")
  1333. #w.tk.attributes('-topmost',False)
  1334. elif self.attr == "SAVE\nSHOW AS":
  1335. base = Base()
  1336. #def _cb(fname):
  1337. def _cb(data):
  1338. if not data:
  1339. print("err443",self,"_cb",data)
  1340. return None
  1341. fname = data["Value"]
  1342. print(self,"save_show._cb()",fname)
  1343. fpath,fname = base.build_path(fname)
  1344. cprint("SAVE AS",fpath,fname)
  1345. if base._create_path(fpath):
  1346. a=PRESETS.backup_presets(save_as=fpath)
  1347. b=FIXTURES.backup_patch(save_as=fpath)
  1348. #base._set(fname)
  1349. save_window_position(save_as=fpath)
  1350. LOAD_SHOW_AND_RESTAT(fname).cb()
  1351. dialog._cb = _cb
  1352. dialog.askstring("SAVE SHOW AS","SAVE SHOW AS:")
  1353. elif self.attr == "SAVE &\nRESTART":
  1354. self.elem["bg"] = "orange"
  1355. self.elem["text"] = "SAVING..."
  1356. self.elem["bg"] = "red"
  1357. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  1358. #self.elem["fg"] = "orange"
  1359. self.elem.config(activebackground="orange")
  1360. modes.val(self.attr,1)
  1361. PRESETS.backup_presets()
  1362. FIXTURES.backup_patch()
  1363. save_window_position()
  1364. self.elem["text"] = "RESTARTING..."
  1365. #time.sleep(1)
  1366. #modes.val(self.attr,0)
  1367. self.elem["bg"] = "lightgrey"
  1368. #self.elem["fg"] = "lightgrey"
  1369. self.elem.config(activebackground="lightgrey")
  1370. LOAD_SHOW_AND_RESTAT("").cb(force=1)
  1371. elif self.attr == "DRAW\nGUI":
  1372. #self.elem["bg"] = "orange"
  1373. old_text = self.elem["text"]
  1374. self.elem["text"] = "DRAWING..."
  1375. #self.elem["bg"] = "red"
  1376. #time.sleep(0.05)
  1377. #print("redraw",name)
  1378. #if name == "PATCH":
  1379. # gui_patch.draw()
  1380. #if name == "DIMMER":
  1381. # gui_fix.draw()
  1382. self.elem["text"] = "PATCH..."
  1383. window_manager.top("PATCH")
  1384. gui_patch.draw(FIXTURES)
  1385. self.elem["text"] = "FIX..."
  1386. gui_fix.draw(FIXTURES)
  1387. window_manager.top("FIXTURES")
  1388. master._refresh_exec()
  1389. self.elem["text"] = old_text
  1390. else:
  1391. r=tkinter.messagebox.showwarning(message="{}\nnot implemented".format(self.attr.replace("\n"," ")),parent=None)
  1392. return 1
  1393. def live(self,event):
  1394. if self.mode == "LIVE":
  1395. if "FADE" in self.attr or "DELAY" in self.attr:
  1396. if self.attr == "FADE":
  1397. ct = FADE
  1398. if self.attr == "DELAY":
  1399. ct = DELAY
  1400. if "PAN/TILT\nFADE" in self.attr:
  1401. ct = FADE_move
  1402. value = ct.val()
  1403. #print("EVENT CHANGE ",[self.attr])
  1404. print("EVENT CHANGE:",self.mode,value,self.attr)
  1405. if value < 0.01:
  1406. ct.val(0.01)
  1407. elif value > 100.0:
  1408. pass #value = 100
  1409. if event.num == 4:
  1410. value *= 1.1
  1411. elif event.num == 5:
  1412. value /= 1.1
  1413. elif event.num == 1:
  1414. if ct._is():
  1415. ct.off()# = 0
  1416. self.data.commands.elem[self.attr]["bg"] = "grey"
  1417. self.elem.config(activebackground="grey")
  1418. else:
  1419. ct.on()# = 1
  1420. self.data.commands.elem[self.attr]["bg"] = "green"
  1421. self.elem.config(activebackground="lightgreen")
  1422. elif event.num == 2:
  1423. if value > 1 and value < 4:
  1424. value = 4
  1425. elif value > 3 and value < 6:
  1426. value = 6
  1427. elif value > 5 and value < 7:
  1428. value = 8
  1429. elif value > 7 and value < 9:
  1430. value = 10
  1431. elif value > 9:
  1432. value = 0.01
  1433. elif value < 1:
  1434. value = 1.1
  1435. value = round(value,3)
  1436. value = ct.val(value)
  1437. if self.attr == "FADE":
  1438. self.data.commands.elem[self.attr]["text"] = "FADE:\n{:0.2f}".format(value)
  1439. if self.attr == "DELAY":
  1440. self.data.commands.elem[self.attr]["text"] = "DELAY:\n{:0.3f}".format(value)
  1441. if "PAN/TILT\nFADE" in self.attr:
  1442. self.data.commands.elem[self.attr]["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
  1443. def command(self,event):
  1444. if self.mode == "COMMAND":
  1445. if self.attr == "CLEAR":
  1446. if event.num == 1:
  1447. ok = FIXTURES.clear()
  1448. if ok:
  1449. master._refresh_fix()
  1450. modes.val(self.attr,0)
  1451. elif self.attr == "SAVE":
  1452. modes.val(self.attr,1)
  1453. PRESETS.backup_presets()
  1454. FIXTURES.backup_patch()
  1455. #time.sleep(1)
  1456. modes.val(self.attr,0)
  1457. elif self.attr == "S-KEY":
  1458. global _global_short_key
  1459. if _global_short_key:
  1460. _global_short_key = 0
  1461. master.commands.elem["S-KEY"]["bg"] = "red"
  1462. master.commands.elem["S-KEY"]["activebackground"] = "red"
  1463. else:
  1464. _global_short_key = 1
  1465. master.commands.elem["S-KEY"]["bg"] = "green"
  1466. master.commands.elem["S-KEY"]["activebackground"] = "green"
  1467. print("s-key",_global_short_key)
  1468. else:
  1469. if event.num == 1:
  1470. print("ELSE",self.attr)
  1471. modes.val(self.attr,1)
  1472. return 0
  1473. def encoder(self,event):
  1474. global _shift_key
  1475. cprint("Xevent","ENC",self.fix,self.attr,self.mode)
  1476. cprint("SHIFT_KEY",_shift_key,"??????????")
  1477. if self.mode == "ENCODER":
  1478. if self._encoder(event):
  1479. master.refresh_fix() # delayed
  1480. refresher_fix.reset() # = Refresher()
  1481. if self.mode == "ENCODER2":
  1482. if self._encoder(event):
  1483. master.refresh_fix() # delayed
  1484. refresher_fix.reset() # = Refresher()
  1485. if self.mode == "INVERT":
  1486. print("INVERT",event)
  1487. if self._encoder(event):
  1488. master.refresh_fix() # delayed
  1489. refresher_fix.reset() # = Refresher()
  1490. def _encoder(self,event):
  1491. global _shift_key
  1492. if 1: #self.mode == "ENCODER" or self.mode == "ENCODER2":
  1493. cprint("-- Xevent","_ENC",self.fix,self.attr,self.mode)
  1494. cprint("-- SHIFT_KEY",_shift_key,"??????????")
  1495. #cprint(self.data)
  1496. val=""
  1497. if event.num == 1:
  1498. val ="click"
  1499. elif event.num == 4:
  1500. val ="++"
  1501. if _shift_key:
  1502. val = "+"
  1503. elif event.num == 5:
  1504. val ="--"
  1505. if _shift_key:
  1506. val = "-"
  1507. #print("SHIFT",val,_shift_key)
  1508. if val:
  1509. FIXTURES.encoder(fix=self.fix,attr=self.attr,xval=val)
  1510. return 1
  1511. def cb(self,event):
  1512. cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
  1513. print(["type",event.type,"num",event.num])
  1514. global INIT_OK
  1515. INIT_OK = 1
  1516. try:
  1517. change = 0
  1518. if "keysym" in dir(event):
  1519. if "Escape" == event.keysym:
  1520. ok = FIXTURES.clear()
  1521. master._refresh_fix()
  1522. print()
  1523. return 0
  1524. if self.mode == "SETUP":
  1525. self.setup(event)
  1526. elif self.mode == "COMMAND":
  1527. self.command(event)
  1528. elif self.mode == "LIVE":
  1529. self.live(event)
  1530. elif self.mode == "ENCODER":
  1531. self.encoder(event)
  1532. master._refresh_fix()
  1533. elif self.mode == "ENCODER2":
  1534. self.encoder(event)
  1535. elif self.mode == "INVERT":
  1536. self.encoder(event)
  1537. elif self.mode == "FX":
  1538. cprint("Xevent CALLING FX WRONG EVENT OBJECT !!",color="red")
  1539. elif self.mode == "ROOT":
  1540. if event.keysym=="Escape":
  1541. pass
  1542. elif self.mode == "INPUT":
  1543. print("INP",self.data.entry.get())
  1544. if event.keycode == 36:
  1545. x=self.data.entry.get()
  1546. #client.send(x)
  1547. elif self.mode == "INPUT2":
  1548. print("INP2",self.data.entry2.get())
  1549. if event.keycode == 36:
  1550. x=self.data.entry2.get()
  1551. #client.send(x)
  1552. elif self.mode == "INPUT3":
  1553. print("INP3",self.data.entry3.get())
  1554. if event.keycode == 36:
  1555. x=self.data.entry3.get()
  1556. #client.send(x)
  1557. elif self.mode == "PRESET":
  1558. nr = self.attr #int(self.attr.split(":")[1])-1
  1559. if event.num == 3: # right click for testing
  1560. if str(event.type) == '4': #4 ButtonPress
  1561. if modes.val("CFG-BTN"):
  1562. master.btn_cfg(nr,testing=1)
  1563. if event.num == 1:
  1564. if str(event.type) == '4': #4 ButtonPress
  1565. if modes.val("REC"):
  1566. self.data.preset_rec(nr)
  1567. modes.val("REC",0)
  1568. time.sleep(0.05)
  1569. master._refresh_exec(nr=nr)
  1570. elif modes.val("DEL"):
  1571. ok=PRESETS.delete(nr)
  1572. if ok:
  1573. modes.val("DEL",0)
  1574. #master.refresh_exec()
  1575. master._refresh_exec(nr=nr)
  1576. elif modes.val("COPY"):
  1577. ok=PRESETS.copy(nr)
  1578. if ok:
  1579. modes.val("COPY",0)
  1580. master._refresh_exec(nr=nr)
  1581. elif modes.val("MOVE"):
  1582. ok,cnr,bnr=PRESETS.move(nr)
  1583. if ok:
  1584. #modes.val("MOVE",0) # keep MOVE on
  1585. master._refresh_exec(nr=nr)
  1586. master._refresh_exec(nr=bnr)
  1587. elif modes.val("CFG-BTN"):
  1588. master.btn_cfg(nr)
  1589. #master._refresh_exec(nr=nr)
  1590. elif modes.val("LABEL"):#else:
  1591. master.label(nr)
  1592. #master._refresh_exec(nr=nr)
  1593. elif modes.val("EDIT"):
  1594. FIXTURES.clear()
  1595. self.data.preset_select(nr)
  1596. self.data.preset_go(nr,xfade=0,event=event,val=255,button="go")
  1597. modes.val("EDIT", 0)
  1598. master.refresh_fix()
  1599. elif modes.val("SELECT"):
  1600. self.data.preset_select(nr)
  1601. else:
  1602. self.data.preset_go(nr,event=event,val=255)
  1603. else:
  1604. self.data.preset_go(nr,xfade=0,event=event,val=0)
  1605. if event.num == 3:
  1606. if not modes.val("REC"):
  1607. if str(event.type) == '4': #4 ButtonPress
  1608. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=255)
  1609. else:
  1610. self.data.preset_go(nr,xfade=0,ptfade=0,event=event,val=0)
  1611. print()
  1612. return 0
  1613. elif self.mode == "INPUT":
  1614. print()
  1615. return 0
  1616. except Exception as e:
  1617. cprint("== cb EXCEPT",e,color="red")
  1618. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  1619. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  1620. print()
  1621. return 1
  1622. def wheel(event,d=None):
  1623. print("wheel",event,d)
  1624. class Element():
  1625. def __init__(self):
  1626. self.__data = {}
  1627. def set(self,key,val):
  1628. self.__data[key] = val
  1629. class Base():
  1630. def __init__(self):
  1631. cprint("Base.init()",color="red")
  1632. self._init()
  1633. def _init(self):
  1634. show_name = "DemoShow"
  1635. self.show_path0 = HOME +"/LibreLight/"
  1636. self.show_path = self.show_path0
  1637. self.show_path1 = self.show_path0 + "show/"
  1638. try:
  1639. f = open(self.show_path+"init.txt","r")
  1640. for line in f.readlines():
  1641. #cprint(line)
  1642. if not line.startswith("#"):
  1643. show_name = line.strip()
  1644. show_name = show_name.replace(".","")
  1645. show_name = show_name.replace("\\","")
  1646. show_name = show_name.replace("/","")
  1647. self.show_name = show_name
  1648. except Exception as e:
  1649. cprint("show name exception",color="red")
  1650. msg="Error Exception:{}".format(e)
  1651. r=tkinter.messagebox.showwarning(message=msg,parent=None)
  1652. finally:
  1653. f.close()
  1654. fpath = self.show_path1 +show_name
  1655. if not os.path.isdir(fpath):
  1656. cprint(fpath)
  1657. print( os.path.isdir(fpath))
  1658. msg="'{}'\n Show Does Not Exist\n\n".format(show_name)
  1659. msg += "please check\n"
  1660. msg += "-{}init.txt\n".format(self.show_path0)
  1661. msg += "-{}".format(self.show_path1)
  1662. showwarning(msg=msg,title="Show Error")
  1663. exit()
  1664. self._check()
  1665. def _set(self,fname):
  1666. ok= os.path.isdir(self.show_path1+"/"+fname)
  1667. ini = self.show_path0+"init.txt"
  1668. print("SET SHOW NAME",fname,ok,ini)
  1669. try:
  1670. f = open( ini ,"r")
  1671. lines = f.readlines()
  1672. f.close()
  1673. if len(lines) >= 10: # cut show history
  1674. print("_set",ini,len(lines))
  1675. lines = lines[-10:]
  1676. f = open( ini ,"w")
  1677. f.writelines(lines)
  1678. f.close()
  1679. exit()
  1680. except:pass
  1681. if ok:
  1682. #self.show_name = fname
  1683. f = open( ini ,"a")
  1684. f.write(fname+"\n")
  1685. f.close()
  1686. return 1
  1687. def _check(self):
  1688. if not os.path.isdir(self.show_path):
  1689. os.mkdir(self.show_path)
  1690. self.show_path += "/show/"
  1691. if not os.path.isdir(self.show_path):
  1692. os.mkdir(self.show_path)
  1693. self.show_path += "/" +self.show_name +"/"
  1694. if not os.path.isdir(self.show_path):
  1695. os.mkdir(self.show_path)
  1696. pass
  1697. def _list(self):
  1698. #self._check()
  1699. show_list = list(os.listdir( self.show_path1 ))
  1700. out = []
  1701. for fname in show_list:
  1702. #print(fname)
  1703. ctime = os.path.getmtime(self.show_path1+fname)
  1704. ctime = time.strftime("%Y-%m-%d %X", time.localtime(ctime)) #1650748726.6604707))
  1705. try:
  1706. mtime = os.path.getmtime(self.show_path1+fname+"/patch.sav")
  1707. mtime = time.strftime("%Y-%m-%d %X", time.localtime(mtime)) #1650748726.6604707))
  1708. except:
  1709. mtime = 0
  1710. if mtime:
  1711. out.append([fname,mtime])#,ctime])
  1712. from operator import itemgetter
  1713. out=sorted(out, key=itemgetter(1))
  1714. out.reverse()
  1715. return out
  1716. def _load(self,filename):
  1717. xfname = self.show_path+"/"+str(filename)+".sav"
  1718. print("load",xfname)
  1719. try:
  1720. f = open(xfname,"r")
  1721. lines = f.readlines()
  1722. f.close()
  1723. except Exception as e:
  1724. msg = "Exception: {}".format(e)
  1725. msg += "\n\ncheck\n-init.txt"
  1726. cprint(msg,color="red")
  1727. showwarning(msg=msg,title="load Error")
  1728. data = OrderedDict()
  1729. labels = OrderedDict()
  1730. i=0
  1731. for line in lines:
  1732. if line.count("\t") < 2:
  1733. cprint("Error line.count('\\t') < 2 (is:{})".format(line.count("\t")),color="red",end=" ")
  1734. cprint("file:{}".format(xfname),color="red")
  1735. continue
  1736. key,label,rdata = line.split("\t",2)
  1737. key = int(key)
  1738. jdata = json.loads(rdata,object_pairs_hook=OrderedDict)
  1739. nrnull = 0
  1740. if "ATTRIBUT" in jdata: # translate old FIXTURES.fixtures start with 0 to 1
  1741. if nrnull:
  1742. print("DMX NR IS NULL",attr,"CHANGE +1")
  1743. for attr in jdata["ATTRIBUT"]:
  1744. if "NR" in jdata["ATTRIBUT"][attr]:
  1745. nr = jdata["ATTRIBUT"][attr]["NR"]
  1746. if nr >= 0:
  1747. jdata["ATTRIBUT"][attr]["NR"] +=1
  1748. data[key] = jdata
  1749. labels[key] = label
  1750. return data,labels
  1751. def _clean_path(self,fpath):
  1752. _path=[]
  1753. for i in fpath:
  1754. fpath = fpath.replace(" ","_")
  1755. if i in string.ascii_letters+string.digits+"äöüßÖÄÜ_-":
  1756. _path.append(i)
  1757. path = "".join(_path)
  1758. return path
  1759. def build_path(self,save_as):
  1760. save_as = self._clean_path(save_as)
  1761. path = self.show_path.split("/")
  1762. path = "/".join(path[:-2])
  1763. fpath = path+"/"+save_as
  1764. return fpath,save_as
  1765. def _create_path(self,fpath):
  1766. if os.path.isdir(fpath):
  1767. cprint("STOP SHOW EXIST !",color="red")
  1768. return 0
  1769. else:
  1770. cprint("CREATE DIR ",fpath,color="green")
  1771. os.mkdir(fpath)
  1772. #self._set(save_as)
  1773. return fpath
  1774. def _backup(self,filename,data,labels,save_as):
  1775. if save_as:
  1776. xfname = save_as +"/"+str(filename)+".sav"
  1777. else:
  1778. xfname = self.show_path+"/"+str(filename)+".sav"
  1779. print("backup",xfname)
  1780. f = open(xfname,"w")
  1781. for key in data:
  1782. line = data[key]
  1783. #print(line)
  1784. label = "label"
  1785. if key in labels:
  1786. label = labels[key]
  1787. if label == "Name-"+str(key):
  1788. label = ""
  1789. #print(xfname,"load",key,label,len(line))
  1790. f.write( "{}\t{}\t{}\n".format( key,label,json.dumps(line) ) )
  1791. f.close()
  1792. return 1
  1793. def hex_to_rgb(hex):
  1794. return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4))
  1795. class cb():
  1796. def __init__(self,win):
  1797. self.win = win
  1798. def _callback(self,event):
  1799. clobj=event.widget
  1800. ## undermouse=find_withtag(master.CURRENT)
  1801. undermouse=self.win.find_closest(self.win.CURRENT)
  1802. print( repr(undermouse))
  1803. def callback(self,event):
  1804. print(__file__,self,"callback",event)
  1805. cnv = self.win
  1806. item = cnv.find_closest(cnv.canvasx(event.x), cnv.canvasy(event.y))[0]
  1807. tags = cnv.gettags(item)
  1808. #cnv.itemconfigure(self.tag, text=tags[0])
  1809. print(tags,item)
  1810. color = cnv.itemcget(item, "fill")
  1811. cnv.itemconfig("all", width=1)#filla="green")
  1812. cnv.itemconfig(item, width=3)#filla="green")
  1813. print(color)
  1814. print( hex_to_rgb(color[1:]))
  1815. class Elem_Container():
  1816. def __init__(self):
  1817. self.commands = []
  1818. self.val = {}
  1819. self.elem = {}
  1820. class MASTER():
  1821. def __init__(self):
  1822. #super().__init__()
  1823. self.base = Base ()
  1824. self.load()
  1825. self._XX = 0
  1826. self.all_attr =["DIM","PAN","TILT"]
  1827. self.elem_attr = {}
  1828. self.fx_moves = Elem_Container()
  1829. self.fx_moves.commands =["REC-FX","FX OFF","\n"
  1830. ,"FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
  1831. "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
  1832. ]
  1833. #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
  1834. self.fx = Elem_Container()
  1835. self.fx.commands =[
  1836. "FX:DIM","FX:RED", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
  1837. ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","FX-X:\n-","FX:MODE"
  1838. ]
  1839. self.fx_generic = Elem_Container()
  1840. self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON"]
  1841. self.commands = Elem_Container()
  1842. self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
  1843. ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
  1844. ,"BLIND","CLEAR","REC","EDIT","COPY","-","\n"
  1845. ]
  1846. self.elem_presets = {}
  1847. for i in range(8*8*8):
  1848. if i not in PRESETS.val_presets:
  1849. name = "Preset:"+str(i+1)+":\nXYZ"
  1850. #self.presets[i] = [i]
  1851. PRESETS.val_presets[i] = OrderedDict() # FIX
  1852. PRESETS.val_presets[i]["CFG"] = OrderedDict() # CONFIG
  1853. PRESETS.label_presets[i] = "-"
  1854. modes.set_cb(self.xcb)
  1855. def button_refresh(self,name,color,color2=None,text="",fg=None):
  1856. cprint("button_refresh",name,color)
  1857. #if color == "gold":
  1858. # color2 = "yellow"
  1859. if color2 is None:
  1860. color2 = color
  1861. if text:
  1862. text = "\n"+str(text)
  1863. if name in self.commands.elem:
  1864. self.commands.elem[name]["bg"] = color
  1865. self.commands.elem[name]["text"] = name+ text
  1866. self.commands.elem[name].config(activebackground=color2)
  1867. if fg:
  1868. self.commands.elem[name]["fg"] = fg
  1869. elif name in self.fx.elem:
  1870. #todo
  1871. self.fx.elem[name]["bg"] = color
  1872. self.fx.elem[name].config(activebackground=color2)
  1873. if fg:
  1874. self.fx.elem[name]["fg"] = fg
  1875. # new version
  1876. for elems in [self.fx_moves]:
  1877. if name in elems.elem:
  1878. elem = elems.elem[name]
  1879. cprint("elem",elem)
  1880. elem.config(bg = color)
  1881. elem.config(text = name+text)
  1882. elem.config(activebackground=color2)
  1883. if fg and "fg" in elem:
  1884. elem["fg"] = fg
  1885. def btn_cfg(self,nr,testing=0):
  1886. cfg = PRESETS._btn_cfg(nr)
  1887. button = PRESETS.btn_cfg(nr)
  1888. label = PRESETS.label(nr)
  1889. def _cb(data):
  1890. if not data:
  1891. print("err443",self,"_cb",data)
  1892. return None
  1893. print(self,"btn_cfg._cb()",data)
  1894. if data:
  1895. if "Button" in data and type(data["Button"]) is str:
  1896. txt = data["Button"]
  1897. PRESETS.btn_cfg(nr,txt)
  1898. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1899. if "Label" in data and type(data["Label"]) is str:
  1900. txt = data["Label"]
  1901. PRESETS.label(nr,txt)
  1902. self.elem_presets[nr].configure(text= PRESETS.get_btn_txt(nr))
  1903. modes.val("CFG-BTN",0)
  1904. master._refresh_exec(nr=nr)
  1905. dialog._cb = _cb
  1906. if 1: # testing:
  1907. dialog.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  1908. else:
  1909. dialog.askstring("CFG-BTN","GO=GO FL=FLASH\nSEL=SELECT EXE:"+str(nr+1),initialvalue=txt)
  1910. def label(self,nr):
  1911. txt = PRESETS.label(nr)
  1912. def _cb(data):
  1913. if not data:
  1914. print("err443",self,"_cb",data)
  1915. return None
  1916. txt = data["Value"]
  1917. print(self,"label._cb()",nr,txt)
  1918. if txt:
  1919. PRESETS.label(nr,txt)
  1920. self.elem_presets[nr].configure(text = PRESETS.get_btn_txt(nr))
  1921. modes.val("LABEL", 0)
  1922. master._refresh_exec(nr=nr)
  1923. dialog._cb= _cb #_x(nr)
  1924. dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
  1925. def xcb(self,mode,value=None):
  1926. cprint("MODE CALLBACK",mode,value,color="green",end="")
  1927. #cprint(self,"xcb","MODE CALLBACK",mode,value,color="green")
  1928. if value:
  1929. cprint("===== ON ======",color="red")
  1930. txt = ""
  1931. if mode == "REC-FX":
  1932. modes.val("REC",0)
  1933. modes.val("REC",1)
  1934. if value == 2:
  1935. if mode in ["MOVE","COPY"]:
  1936. txt="to"
  1937. self.button_refresh(mode,color="orange",text=txt)#,fg="blue")
  1938. else:
  1939. if mode in ["MOVE","COPY"]:
  1940. txt="from"
  1941. self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
  1942. else:
  1943. cprint("===== OFF ======",color="red")
  1944. if mode == "REC-FX":
  1945. modes.val("REC",0)
  1946. self.button_refresh(mode,color="lightgrey")#,fg="black")
  1947. def load(self,fname=""):
  1948. pass
  1949. def exit(self):
  1950. print("__del__",self)
  1951. PRESETS.backup_presets()
  1952. #print("********************************************************")
  1953. FIXTURES.backup_patch()
  1954. #print("*********del",self,"***********************************************")
  1955. def refresh_exec(self):
  1956. refresher_exec.reset() # = Refresher()
  1957. def _refresh_exec(self,nr=-1):
  1958. s = time.time()
  1959. cprint("PRESET.refresh_exec()")
  1960. refresher_exec.reset() # = Refresher()
  1961. self._XX +=1
  1962. self._nr_ok = 0
  1963. for k in PRESETS.val_presets:
  1964. _bg = "grey"
  1965. _ba = "grey"
  1966. _fg = "lightgrey"
  1967. _text = "N/V"
  1968. if nr >= 0:
  1969. if self._nr_ok:
  1970. break
  1971. if nr != k:
  1972. continue
  1973. else:
  1974. self._nr_ok = 1
  1975. label = ""
  1976. if k not in self.elem_presets:
  1977. cprint("ERROR",k ,"not in elem_presets continue")
  1978. continue
  1979. if k in PRESETS.label_presets:
  1980. label = PRESETS.label_presets[k]
  1981. #print([label])
  1982. b = self.elem_presets[k]
  1983. ifval = 0
  1984. fx_only = 0
  1985. if k in PRESETS.val_presets and len(PRESETS.val_presets[k]) :
  1986. sdata = PRESETS.val_presets[k]
  1987. #print("sdata7654",sdata)
  1988. BTN="go"
  1989. if "CFG" in sdata:#["BUTTON"] = "GO"
  1990. if "BUTTON" in sdata["CFG"]:
  1991. BTN = sdata["CFG"]["BUTTON"]
  1992. #txt=str(k+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+label
  1993. txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
  1994. _text = txt
  1995. if b.text != txt: # TODO
  1996. #txt+=str(self._XX)
  1997. #b.configure(text= txt)
  1998. _text = txt
  1999. _bg="yellow"
  2000. _ba="yellow"
  2001. if len(sdata) > 1:
  2002. ifval = 1
  2003. fx_color = 0
  2004. val_color = 0
  2005. for fix in sdata:
  2006. if fix == "CFG":
  2007. continue
  2008. #print( "$$$$",fix,sdata[fix])
  2009. for attr in sdata[fix]:
  2010. if "FX2" in sdata[fix][attr]:
  2011. if sdata[fix][attr]["FX2"]:
  2012. fx_color = 1
  2013. if "FX" in sdata[fix][attr]:
  2014. if sdata[fix][attr]["FX"]:
  2015. fx_color = 1
  2016. if "VALUE" in sdata[fix][attr]:
  2017. if sdata[fix][attr]["VALUE"] is not None:
  2018. val_color = 1
  2019. try:b.configure(fg= "black")
  2020. except:pass
  2021. if val_color:
  2022. _bg = "gold"
  2023. _ba = "#ffaa55"
  2024. if fx_color:
  2025. _fg = "blue"
  2026. else:
  2027. if fx_color:
  2028. fx_only = 1
  2029. else:
  2030. _bg = "grey"
  2031. _ba = "#aaa"
  2032. if "\n" in txt:
  2033. txt1 = txt.split("\n")[0]
  2034. _fg = "black"
  2035. if ifval:
  2036. if fx_only:
  2037. _bg = "cyan"
  2038. _ba = "#55d4ff"
  2039. if "SEL" in txt1:
  2040. b.configure(bg="#77f")
  2041. _bg = "#77f"
  2042. else:
  2043. _bg = "grey"
  2044. _fg = "darkgrey"
  2045. if "SEL" in txt1:
  2046. _fg = "blue"
  2047. elif "ON" in txt1:
  2048. _fg = "#040"
  2049. elif "GO" in txt1:
  2050. _fg = "#555"
  2051. if "FL" in txt1:
  2052. _fg = "#00e"
  2053. b.configure(fg=_fg,bg=_bg,activebackground=_ba,text=_text)
  2054. time.sleep(0.01)
  2055. #tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  2056. #time.sleep(0.01)
  2057. def refresh_fix(self):
  2058. refresher_fix.reset() # = Refresher()
  2059. def _refresh_fix(self):
  2060. s=time.time(); _XXX=0
  2061. c_d =0
  2062. c_f =0
  2063. c_a =0
  2064. for fix in FIXTURES.fixtures:
  2065. sdata = FIXTURES.fixtures[fix]
  2066. _c_a = 0
  2067. if fix not in self.elem_attr:
  2068. cprint("_refresh_fix fix not in self.elem_attr (no Button)",fix,color="red")
  2069. continue
  2070. elem_attr_fix = self.elem_attr[fix]
  2071. _dim_in_flag = 0
  2072. if "DIM" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 1:
  2073. _dim_in_flag = 1
  2074. for attr in sdata["ATTRIBUT"]:
  2075. row = sdata["ATTRIBUT"][attr]
  2076. if attr.endswith("-FINE"):
  2077. continue
  2078. b_attr = attr
  2079. if b_attr == "_ACTIVE":
  2080. b_attr = "S"
  2081. if b_attr not in elem_attr_fix:
  2082. continue
  2083. elem = elem_attr_fix[b_attr]
  2084. if not elem:
  2085. continue
  2086. try:
  2087. if not attr.startswith("_"):
  2088. v2 = row["VALUE"]
  2089. _text = "{} {:0.2f}".format(attr,v2) # ~0.2 sec
  2090. try:
  2091. if elem["text"] != _text: #"{} {:0.2f}".format(attr,v2)
  2092. elem["text"] = _text #"{} {:0.2f}".format(attr,v2)
  2093. except:
  2094. cprint("err778",attr,elem)
  2095. if row["ACTIVE"]:
  2096. try:
  2097. if elem["bg"] != "yellow":
  2098. elem["bg"] = "yellow"
  2099. elem.config(activebackground="yellow")
  2100. except:
  2101. cprint("err778",attr,elem)
  2102. #if "DIM" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 1:
  2103. if _dim_in_flag:
  2104. c_d+=1
  2105. else:
  2106. _c_a += 1
  2107. else:
  2108. try:
  2109. if elem["bg"] != "grey":
  2110. elem["bg"] = "grey"
  2111. elem.config(activebackground="grey")
  2112. except:
  2113. cprint("err778",attr,elem)
  2114. if "FX2" not in row: # insert FX2 excetption
  2115. row["FX2"] = OrderedDict()
  2116. try:
  2117. if row["FX"]:
  2118. elem["fg"] = "blue"
  2119. elif row["FX2"]:
  2120. elem["fg"] = "red"
  2121. else:
  2122. elem["fg"] = "black"
  2123. except:
  2124. cprint("err778",attr,elem)
  2125. except Exception as e:
  2126. cprint("EXCEPTON 2406 ",e,color="red")
  2127. cprint("err778",attr,elem)
  2128. c_a += _c_a
  2129. if _c_a>0:
  2130. c_f +=1
  2131. c_a2=0
  2132. cprint("fix:",_XXX,round(time.time()-s,2),color="red");_XXX += 1
  2133. if c_f > 0:
  2134. c_a2 = round(c_a/c_f,2)
  2135. if c_a2 % 1 > 0:
  2136. gui_menu.config("FIXTURES","bg","orange")
  2137. gui_menu.config("FIXTURES","activebackground","orange")
  2138. else:
  2139. gui_menu.config("FIXTURES","bg","yellow")
  2140. gui_menu.config("FIXTURES","activebackground","yellow")
  2141. else:
  2142. gui_menu.config("FIXTURES","bg","")
  2143. gui_menu.config("FIXTURES","activebackground","")
  2144. gui_menu.update("FIXTURES","{} : {}".format(c_f,c_a2))
  2145. if c_d > 0:
  2146. gui_menu.config("DIMMER","bg","yellow")
  2147. gui_menu.config("DIMMER","activebackground","yellow")
  2148. else:
  2149. gui_menu.config("DIMMER","bg","")
  2150. gui_menu.config("DIMMER","activebackground","")
  2151. gui_menu.update("DIMMER","{}".format(c_d))
  2152. cprint("fix:",_XXX,round(time.time()-s),color="red"); _XXX += 1
  2153. def preset_rec(self,nr):
  2154. print("------- STORE PRESET")
  2155. data = FIXTURES.get_active()
  2156. if modes.val("REC-FX"):
  2157. PRESETS.rec(nr,data,"REC-FX")
  2158. modes.val("REC-FX",0)
  2159. else:
  2160. PRESETS.rec(nr,data)
  2161. sdata=data
  2162. PRESETS.val_presets[nr] = sdata
  2163. master._refresh_exec()
  2164. return 1
  2165. def preset_select(self,nr):
  2166. print("SELECT PRESET")
  2167. sdata = PRESETS.val_presets[nr]
  2168. cmd = ""
  2169. for fix in sdata:
  2170. if fix == "CFG":
  2171. continue
  2172. for attr in sdata[fix]:
  2173. v2 = sdata[fix][attr]["VALUE"]
  2174. v2_fx = sdata[fix][attr]["FX"]
  2175. #print( self.data.elem_attr)
  2176. if fix in self.elem_attr:
  2177. if attr in self.elem_attr[fix]:
  2178. elem = self.elem_attr[fix][attr]
  2179. FIXTURES.fixtures[fix]["ATTRIBUT"][attr]["ACTIVE"] = 1
  2180. FIXTURES.fixtures[fix]["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2181. #elem["bg"] = "yellow"
  2182. def preset_go(self,nr,val=None,xfade=None,event=None,button="",ptfade=None):
  2183. t_start = time.time()
  2184. if xfade is None and FADE._is():
  2185. xfade = FADE.val()
  2186. if ptfade is None and FADE_move._is():
  2187. ptfade = FADE_move.val()
  2188. print("GO PRESET FADE",nr,val)
  2189. rdata = PRESETS.get_raw_map(nr)
  2190. if not rdata:
  2191. return 0
  2192. print("???????")
  2193. cfg = PRESETS.get_cfg(nr)
  2194. print("''''''''")
  2195. #virtcmd = FIXTURES.get_virtual(rdata)
  2196. if not cfg:
  2197. cprint("NO CFG",cfg,nr)
  2198. return 0
  2199. xFLASH = 0
  2200. value=None
  2201. cprint("preset_go",nr,cfg)
  2202. if modes.val("SELECT") or ( "BUTTON" in cfg and cfg["BUTTON"] == "SEL") and val and not button: #FLASH
  2203. self.preset_select(nr)
  2204. elif modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL") and not button: #FLASH
  2205. xFLASH = 1
  2206. xfade = 0
  2207. if type(val) is not type(None) and val == 0 :
  2208. value = "off"
  2209. if event:
  2210. if str(event.type) == "ButtonRelease" or event.type == '5' :
  2211. value = "off"
  2212. cprint("preset_go() FLUSH",value,color="red")
  2213. fcmd = FIXTURES.update_raw(rdata,update=0)
  2214. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,nr=nr)
  2215. elif not val:
  2216. cprint("preset_go() STOP",value,color="red")
  2217. elif button == "on" or ( modes.val("ON") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["on","ON"])):
  2218. fcmd = FIXTURES.update_raw(rdata)
  2219. self._preset_go(rdata,cfg,fcmd,value,xfade=0,xFLASH=xFLASH)
  2220. elif button == "go" or ( modes.val("GO") or ( "BUTTON" in cfg and cfg["BUTTON"] in ["go","GO"])):
  2221. fcmd = FIXTURES.update_raw(rdata)
  2222. self._preset_go(rdata,cfg,fcmd,value,xfade=xfade,xFLASH=xFLASH,ptfade=ptfade,nr=nr)
  2223. if not (modes.val("FLASH") or ( "BUTTON" in cfg and cfg["BUTTON"] == "FL")): #FLASH
  2224. self.refresh_exec()
  2225. self.refresh_fix()
  2226. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  2227. #print(len(self.elem_presets) )
  2228. if len(self.elem_presets) > nr: # RED BUTTON IF PRESSED
  2229. #print("IIIIIIIIIIIiiiiiiiiiiiiiiiiiii",nr,val)
  2230. if val:# or value:
  2231. #self.elem_presets[nr].config(borderwidth=1)
  2232. self.elem_presets[nr].config(bg="red")
  2233. else:
  2234. self._refresh_exec()
  2235. cprint("preset_go",time.time()-t_start)
  2236. def _preset_go(self,rdata,cfg,fcmd,value=None,xfade=None,event=None,xFLASH=0,ptfade=0,nr=None):
  2237. if xfade is None and FADE._is():
  2238. xfade = FADE.val()
  2239. if ptfade is None and FADE_move._is():
  2240. ptfade = FADE_move.val()
  2241. cprint("PRESETS._preset_go() len=",len(rdata),cfg)
  2242. if xfade is None:
  2243. xfade = cfg["FADE"]
  2244. if ptfade is None:
  2245. ptfade = cfg["FADE"]
  2246. #vcmd = reshape_preset( rdata ,value,[],xfade=xfade,fx=1)
  2247. #cprint(rdata,color="red")
  2248. vcmd = reshape_preset( rdata ,value,xfade=xfade,ptfade=ptfade)
  2249. cmd = []
  2250. delay=0
  2251. for i,v in enumerate(fcmd):
  2252. #print("go",i,v)
  2253. if xFLASH:
  2254. vcmd[i]["FLASH"] = 1
  2255. DMX = fcmd[i]["DMX"]
  2256. if "VALUE" in vcmd[i] and type(vcmd[i]["VALUE"]) is type(float):
  2257. vcmd[i]["VALUE"] = round(vcmd[i]["VALUE"],3)
  2258. if value is not None:
  2259. vcmd[i]["VALUE"] = value
  2260. if value == "off":
  2261. if "FX2" in vcmd:
  2262. vcmd[i]["FX2"]["TYPE"] = value
  2263. if "FIX" in fcmd:
  2264. vcmd[i]["FIX"] = fcmd["FIX"]
  2265. if DMX and vcmd[i]:
  2266. vcmd[i]["DMX"] = DMX
  2267. if "VIRTUAL" in fcmd[i]:
  2268. for a in fcmd[i]["VIRTUAL"]:
  2269. DMX = fcmd[i]["VIRTUAL"][a]
  2270. if DMX and vcmd[i]:
  2271. vcmd[i]["DMX"] = DMX
  2272. if type(nr) is not type(None):
  2273. vcmd[i]["EXEC"] = str(int(nr)+1)
  2274. #cprint(vcmd[i],color="red")
  2275. cmd.append(vcmd[i])
  2276. if cmd and not modes.val("BLIND"):
  2277. jclient_send(cmd)
  2278. def render(self):
  2279. #Xroot.bind("<Key>",Xevent(fix=0,elem=None,attr="ROOT",data=self,mode="ROOT").cb)
  2280. #self.draw_input()
  2281. pass
  2282. ##draw_sub_dim
  2283. class InputEventBlocker():
  2284. def __init__(self):
  2285. self.__init = 0
  2286. self.cursor = "88888"
  2287. def set(self,el,txt):
  2288. self.e = el
  2289. self.e_txt = txt
  2290. self.cursor = "88888"
  2291. def init(self):
  2292. if self.__init == 0:
  2293. try:
  2294. self.el = tk.Button()
  2295. self.e_txt = tk.StringVar()
  2296. self.__init = 1
  2297. except Exception as e:
  2298. pirnt("init() exception",e)
  2299. def _lock(self):
  2300. global _global_short_key
  2301. _global_short_key = 0
  2302. master.commands.elem["S-KEY"]["bg"] = "red"
  2303. def _unlock(self):
  2304. global _global_short_key
  2305. _global_short_key = 1
  2306. master.commands.elem["S-KEY"]["bg"] = "green"
  2307. def lock(self):
  2308. self._lock()
  2309. #self.e["bg"] = "red"
  2310. #self.el.config({"background": "grey"})
  2311. #self.e.focus()
  2312. def unlock(self):
  2313. self._unlock()
  2314. #self.e["bg"] = "blue"
  2315. #self.el.config({"background": "yellow"})
  2316. #self.el.focus_set()
  2317. def event(self,event,**args):
  2318. self.init()
  2319. #print()
  2320. print(self,event,args)
  2321. #print("###-",self.e_txt,dir(self.e_txt))
  2322. if "S-KEY" not in master.commands.elem:
  2323. return
  2324. if "num" in dir(event):
  2325. self.lock()
  2326. if "keysym" in dir(event):
  2327. t=self.e_txt.get()
  2328. if t and t[-1] == "<":
  2329. t = t[:-1]
  2330. if event.keysym == "Return" or event.keysym == "Tab" or event.keysym == "ISO_Left_Tab":
  2331. self.unlock()
  2332. #self.e_txt.set(t)
  2333. print("filter: get()",_global_short_key,t)
  2334. t2 = t
  2335. if _global_short_key == 0:
  2336. if event.keysym == "BackSpace":
  2337. if len(t) > 1:
  2338. t2 = t[:-1]
  2339. else:
  2340. t2=""
  2341. elif event.keysym == "Escape":
  2342. t2=""
  2343. elif event.keysym == "space":
  2344. t2=t+" "
  2345. elif event.char in "äöüÄÖÜ-_,.;:#'*+~":
  2346. t2=t+event.char
  2347. elif len(event.keysym) == 1:
  2348. t2=t+event.keysym
  2349. #self.e_txt.set(t2+"<")
  2350. #time.sleep(0.2)
  2351. #_global_short_key = 1
  2352. input_event_blocker = InputEventBlocker()
  2353. from tkgui.dialog import *
  2354. dialog = Dialog()
  2355. from tkgui.draw import *
  2356. from tkgui.GUI import *
  2357. #draw_enc
  2358. class LOAD_SHOW_AND_RESTAT():
  2359. def __init__(self,fname=""):
  2360. self.fname=fname
  2361. self.base = Base()
  2362. def cb(self,event=None,force=0):
  2363. print("LOAD_SHOW_AND_RESTART.cb force={} name={}".format(force,self.fname) )
  2364. if not self.fname and not force:
  2365. return 0
  2366. if self.base.show_name == self.fname and not force:
  2367. cprint("filename is the same",self.fname)
  2368. return 0
  2369. if not force:
  2370. self.base._set(self.fname)
  2371. print("LOAD SHOW:",event,self.fname)
  2372. print(sys.executable, os.path.abspath(__file__), *sys.argv)
  2373. os.execl("/usr/bin/python3", "/opt/LibreLight/Xdesk/_LibreLightDesk.py", "_LibreLightDesk.py")
  2374. sys.exit()
  2375. class PopupList():
  2376. 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"):
  2377. self.name = name
  2378. self.frame = None
  2379. self.bg=bg
  2380. self.cb = cb
  2381. if cb is None:
  2382. cb = DummyCallback #("load_show_list.cb")
  2383. #w = Window(self.name,master=master,width=width,height=height,exit=exit,left=left,top=top,cb=cb)
  2384. args = {"title":self.name,"master":master,"width":width,"height":height,"exit":exit,"left":left,"top":top,"cb":cb}
  2385. w = Window(args)
  2386. self.w = w
  2387. w.show()
  2388. def sframe(self,line1="<line1>",line2="<line2>",data=[]):
  2389. xframe=self.w.tk
  2390. if self.bg:
  2391. xframe.configure(bg=self.bg)
  2392. self.w.tk.configure(bg=self.bg)
  2393. c=0
  2394. r=0
  2395. b = tk.Label(xframe,bg="grey",text=line1,anchor="w")
  2396. b.pack(side="top",expand=0,fill="x" )
  2397. b = tk.Label(xframe,bg="grey",text=line2,anchor="w")
  2398. b.pack(side="top",expand=0,fill="x" )
  2399. b = tk.Label(xframe,bg="black",fg="black",text="")
  2400. if self.bg:
  2401. b.configure(fg=self.bg)
  2402. b.configure(bg=self.bg)
  2403. b.pack(side="top")
  2404. b = tk.Entry(xframe,width=10,text="")#,anchor="w")
  2405. b.pack(side="top",expand=0,fill="x")
  2406. b.focus()
  2407. #frame = tk.Frame(xframe,heigh=2800)
  2408. #frame.pack(fill=tk.BOTH,expand=1, side=tk.TOP)
  2409. frame = ScrollFrame(xframe,width=300,height=500,bd=1,bg=self.bg)
  2410. #frame.pack(side="left") #fill=tk.BOTH,expand=1, side=tk.TOP)
  2411. #self.frame = frame
  2412. self.w.tk.state(newstate='normal')
  2413. self.w.tk.attributes('-topmost',True)
  2414. return frame
  2415. class DummyCallback():
  2416. def __init__(self,name="name"):
  2417. self.name = name
  2418. def cb(self,event=None):
  2419. print("DummyCallback.cb",[self.name,event])
  2420. def _load_show_list(frame,cb=None):
  2421. c=0
  2422. r=0
  2423. base = Base()
  2424. for i in ["name","stamp"]: #,"create"]:
  2425. b = tk.Label(frame,bg="grey",text=i)
  2426. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2427. c+=1
  2428. r+=1
  2429. blist = base._list()
  2430. for i in range(10):
  2431. blist.append(["",""])
  2432. if cb is None:
  2433. cb = DummyCallback #("load_show_list.cb")
  2434. for i in blist:
  2435. #print(i)
  2436. c=0
  2437. for j in i:
  2438. bg="lightgrey"
  2439. dbg="lightgrey"
  2440. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2441. dbg = "lightgreen"
  2442. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2443. dbg = "green"
  2444. if c > 0:
  2445. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2446. b.config(activebackground=dbg)
  2447. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2448. else:
  2449. if base.show_name == i[0]:
  2450. bg="green"
  2451. _cb = cb(j)
  2452. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2453. if base.show_name == i[0]:
  2454. b.config(activebackground=bg)
  2455. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2456. c+=1
  2457. r+=1
  2458. def _parse_fixture_name(name):
  2459. out = ["FIX","MAN","CH","PATH"]
  2460. if name.count(".") == 2:
  2461. m,n,e = name.split(".")
  2462. out = [n,m,"0",name]
  2463. elif name.count("_") == 2:
  2464. name,e = name.split(".")
  2465. m,n,c = name.split("_")
  2466. out = [n,m,c,name]
  2467. else:
  2468. out = [name]
  2469. return out
  2470. def _load_fixture_list(frame,cb=None,master=None,bg="black"):
  2471. frame.configure(bg=bg)
  2472. c=0
  2473. r=0
  2474. base = Base()
  2475. for i in ["source","name","manufacturer","channel's","file","path"]: #,"create"]:
  2476. b = tk.Label(frame,bg="grey",text=i)
  2477. b.grid(row=r, column=c, sticky=tk.W) #+tk.E)
  2478. c+=1
  2479. r+=1
  2480. blist = [] #base._list()
  2481. try:
  2482. p = HOME+"/LibreLight/fixtures/"
  2483. ls = os.listdir(p)
  2484. ls.sort()
  2485. for l in ls:
  2486. b = _parse_fixture_name(l)
  2487. b.append(p)
  2488. b.insert(0,"user")
  2489. blist.append(b)
  2490. except Exception as e:
  2491. print("Exce 877 ",e)
  2492. try:
  2493. p="/opt/LibreLight/Xdesk/fixtures/"
  2494. ls = os.listdir(p )
  2495. ls.sort()
  2496. for l in ls:
  2497. b = _parse_fixture_name(l)
  2498. b.append(p)
  2499. b.insert(0,"base")
  2500. blist.append(b)
  2501. except Exception as e:
  2502. print("Exce 878 ",e)
  2503. if not blist:
  2504. blist.append(["MAC-500","martin","Demo"])
  2505. blist.append(["MAC-2000","martin","Demo"])
  2506. blist.append(["MAC-VIPER","martin","Demo"])
  2507. blist.append(["SPARX-7","JB","Demo"])
  2508. blist.append(["SPARX-11","JB","Demo"])
  2509. blist.append(["JB-P6","JB","Demo"])
  2510. blist.append(["JB-P7","JB","Demo"])
  2511. blist.append(["JB-A7","JB","Demo"])
  2512. blist.append(["TMH-12","Eurolight","Demo"])
  2513. if len(blist) < 30:
  2514. for i in range(30-len(blist)):
  2515. blist.append(["{:0>4}".format(len(blist)+i+1),"",""])
  2516. if cb is None:
  2517. cb = DummyCallback #("load_show_list.cb")
  2518. _tmp_name = ""
  2519. _tmp_flag = 0
  2520. for i in blist:
  2521. #print(i)
  2522. if i[0] != _tmp_name:
  2523. _tmp_flag = "#aaf"
  2524. if i[0] == "user":
  2525. _tmp_flag = "#aaf"
  2526. if i[0] == "base":
  2527. _tmp_flag = "#0f0"
  2528. c=0
  2529. for j in i:
  2530. bg="lightgrey"
  2531. dbg="lightgrey"
  2532. if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)):
  2533. dbg = "lightgreen"
  2534. elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)):
  2535. dbg = "green"
  2536. if _tmp_flag:
  2537. bg = "{}".format(_tmp_flag)
  2538. if c == 1:
  2539. if base.show_name == i[0]:
  2540. bg="green"
  2541. _cb=cb(j)
  2542. _cb.master=master
  2543. b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb)
  2544. if base.show_name == i[0]:
  2545. b.config(activebackground=bg)
  2546. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2547. else:#ief c > 0:
  2548. b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken")
  2549. b.config(activebackground=dbg)
  2550. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  2551. c+=1
  2552. r+=1
  2553. class Fixtures():
  2554. def __init__(self):
  2555. #super().__init__()
  2556. self.base=Base()
  2557. #self.load()
  2558. self.fixtures = OrderedDict()
  2559. self.gui = GUIHandler()
  2560. def load_patch(self):
  2561. filename="patch"
  2562. #self.base._init()
  2563. d,l = self.base._load(filename)
  2564. self.fixtures = OrderedDict()
  2565. for i in l:
  2566. sdata = d[i]
  2567. new_f = OrderedDict()
  2568. #print("++++")
  2569. for k,j in sdata.items():
  2570. overide=0 # only for repair
  2571. if overide:
  2572. if k in ["TYPE","VENDOR"]: #ignor
  2573. continue
  2574. new_f[k] = j
  2575. if k =="NAME":
  2576. #print("AAAADDDDDD")
  2577. if "TYPE" not in sdata and not overide:
  2578. if len( sdata["ATTRIBUT"]) == 1:
  2579. new_f["TYPE"] = "DIMMER"
  2580. elif "PAN" in sdata["ATTRIBUT"]:
  2581. new_f["TYPE"] = "MOVER"
  2582. elif "RED" in sdata["ATTRIBUT"] and len(sdata["ATTRIBUT"]) == 3:
  2583. new_f["TYPE"] = "RGB"
  2584. elif "RED" in sdata["ATTRIBUT"]:
  2585. new_f["TYPE"] = "LED"
  2586. elif "CYAN" in sdata["ATTRIBUT"]:
  2587. new_f["TYPE"] = "COLOR"
  2588. else:
  2589. new_f["TYPE"] = ""
  2590. if "VENDOR" not in sdata and not overide:
  2591. new_f["VENDOR"] = ""
  2592. #print(k,j)#,sdata)
  2593. sdata = new_f
  2594. if "ACTIVE" not in sdata:
  2595. sdata["ACTIVE"] = 0
  2596. sdata["ATTRIBUT"]["_ACTIVE"] = OrderedDict()
  2597. sdata["ATTRIBUT"]["_ACTIVE"]["NR"] = 0
  2598. sdata["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2599. sdata["ATTRIBUT"]["_ACTIVE"]["VALUE"] = 0
  2600. for attr in sdata["ATTRIBUT"]:
  2601. sdata["ATTRIBUT"][attr]["ACTIVE"] = 0
  2602. #print("load",filename,sdata)
  2603. #if "CFG" not in sdata:
  2604. # sdata["CFG"] = OrderedDict()
  2605. self.fixtures[str(i)] = sdata
  2606. #PRESETS.label_presets = l
  2607. self.fx_off("all")
  2608. def backup_patch(self,save_as=""):
  2609. filename = "patch"
  2610. #self.fx_off("all")
  2611. data = self.fixtures
  2612. labels = {}
  2613. for k in data:
  2614. labels[k] = k
  2615. #self.base._init()
  2616. self.base._backup(filename,data,labels,save_as)
  2617. def fx_get(self,fix=None):
  2618. out={}
  2619. if not fix or fix == "all":
  2620. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2621. for fix in self.fixtures:
  2622. data = self.fixtures[fix]
  2623. for attr in data["ATTRIBUT"]:
  2624. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX"]
  2625. out[str(fix)+"."+str(attr)+".fx"] = data["ATTRIBUT"][attr]["FX2"]
  2626. return out
  2627. def fx_off(self,fix=None):
  2628. if not fix or fix == "all":
  2629. #self.data.fx.elem[self.attr]["bg"] = "magenta"
  2630. for fix in self.fixtures:
  2631. data = self.fixtures[fix]
  2632. for attr in data["ATTRIBUT"]:
  2633. data["ATTRIBUT"][attr]["FX"] = ""
  2634. data["ATTRIBUT"][attr]["FX2"] = OrderedDict()
  2635. def get_attr(self,fix,attr):
  2636. if fix in self.fixtures:
  2637. data = self.fixtures[fix]
  2638. if "ATTRIBUT" in data:
  2639. if attr in data["ATTRIBUT"]:
  2640. return data["ATTRIBUT"][attr]
  2641. def get_max_dmx_nr(self,fix):
  2642. max_dmx = 0
  2643. used_dmx = 0
  2644. if fix not in self.fixtures:
  2645. return (used_dmx,max_dmx)
  2646. data = self.fixtures[fix]
  2647. used_dmx = len(data["ATTRIBUT"])
  2648. for a in data["ATTRIBUT"]:
  2649. attr = data["ATTRIBUT"][a]
  2650. if "NR" in attr:
  2651. try:
  2652. _n = int(attr["NR"])
  2653. if _n > max_dmx:
  2654. max_dmx=_n
  2655. except ValueError:pass
  2656. return (used_dmx,max_dmx)
  2657. def get_dmx(self,fix,attr):
  2658. #cprint("get_dmx",[fix,attr])
  2659. if fix in self.fixtures:
  2660. data = self.fixtures[fix]
  2661. DMX = -99
  2662. if "DMX" in data:
  2663. DMX = int(data["DMX"])
  2664. if DMX < 1: # ignore attribute with DMX lower 1
  2665. return -22
  2666. else:
  2667. return -1
  2668. if "UNIVERS" in data:
  2669. if int(data["UNIVERS"]) >= 0:
  2670. DMX += (int(data["UNIVERS"])*512)
  2671. else:
  2672. return -33
  2673. adata = self.get_attr(fix,attr)
  2674. #-hier ende 8.2.22
  2675. #cprint("adata",adata,DMX)
  2676. if adata:
  2677. if "NR" in adata:
  2678. NR = adata["NR"]
  2679. if NR >= 1:
  2680. DMX+=NR-1
  2681. else:
  2682. return -44
  2683. return DMX
  2684. return -4
  2685. return -3
  2686. def update_raw(self,rdata,update=1):
  2687. cprint("update_raw",len(rdata))
  2688. cmd = []
  2689. for i,d in enumerate(rdata):
  2690. xcmd = {"DMX":""}
  2691. #print("fix:",i,d)
  2692. fix = d["FIX"]
  2693. attr = d["ATTR"]
  2694. v2 = d["VALUE"]
  2695. v2_fx = d["FX"]
  2696. if fix not in self.fixtures:
  2697. continue
  2698. sdata = self.fixtures[fix] #shortcat
  2699. ATTR = sdata["ATTRIBUT"]
  2700. sDMX = 0
  2701. if sdata["DMX"] > 0:
  2702. #print( sdata)
  2703. sDMX = (sdata["UNIVERS"]*512)+sdata["DMX"]
  2704. #sDMX =sdata["DMX"]
  2705. #else:
  2706. # continue
  2707. if attr not in ATTR:
  2708. continue
  2709. #DMX = FIXTURES.get_dmx(fix)
  2710. if ATTR[attr]["NR"] >= 0:
  2711. DMX = sDMX+ATTR[attr]["NR"]-1
  2712. xcmd["DMX"] = str(DMX)
  2713. else:
  2714. if attr == "DIM" and ATTR[attr]["NR"] < 0:
  2715. xcmd["VIRTUAL"] = {}
  2716. for a in ATTR:
  2717. if ATTR[a]["MASTER"]:
  2718. xcmd["VIRTUAL"][a] = sDMX+ATTR[a]["NR"]-1
  2719. #print( "VIRTUAL",xcmd)
  2720. cmd.append(xcmd)
  2721. v=ATTR[attr]["VALUE"]
  2722. if v2 is not None and update:
  2723. ATTR[attr]["VALUE"] = v2
  2724. if d["FX2"] and update:
  2725. ATTR[attr]["FX2"] = d["FX2"]
  2726. #self.data.elem_attr[fix][attr]["text"] = str(attr)+' '+str(round(v,2))
  2727. text = str(attr)+' '+str(round(v,2))
  2728. #self.gui.update(fix,attr,args={"text":text})
  2729. #print("END 5454 _=_=_=_=_==_")
  2730. #cprint("update_raw",cmd,color="red")
  2731. return cmd
  2732. def encoder(self,fix,attr,xval="",xfade=0,xdelay=0,blind=0):
  2733. _blind = 0
  2734. if modes.val("BLIND"):
  2735. _blind = 1
  2736. if blind:
  2737. _blind = 1
  2738. if not _blind:
  2739. cprint("FIXTURES.encoder",fix,attr,xval,xfade,color="yellow")
  2740. if attr == "CLEAR":
  2741. self.clear()
  2742. return 0
  2743. if attr == "ALL":
  2744. x=self.select(fix,attr,mode="toggle")
  2745. return x
  2746. if attr == "INV-ATTR":
  2747. print("-x-x-x-x-x-x-x-X-")
  2748. x=self.select(fix,attr,mode="swap")
  2749. #x=self.select(fix,"ALL",mode="swap")
  2750. master.refresh_fix()
  2751. return x
  2752. if attr == "INV-FIX":
  2753. print("-x-x-x-x-x-x-x-x-")
  2754. x=self.select(fix,attr,mode="swap")
  2755. #x=self.select(fix,"ALL",mode="swap")
  2756. return x
  2757. out = []
  2758. if fix not in self.fixtures:
  2759. print(" activate Fixture in fixture list on encoder click ")
  2760. #jdata=[{"MODE":"---"}]
  2761. ii =0
  2762. #jclient_send(jdata)
  2763. delay=0
  2764. print("-->A HIER <--")
  2765. sub_data = []
  2766. for fix in self.fixtures:
  2767. ii+=1
  2768. #cprint(fix,attr,xval)
  2769. data = self.fixtures[fix]
  2770. if "-FINE" in attr.upper():
  2771. continue
  2772. elif (attr in data["ATTRIBUT"] ) and "-FINE" not in attr.upper() :
  2773. if xval == "click":
  2774. self.select(fix,attr,mode="on")
  2775. elif data["ATTRIBUT"][attr]["ACTIVE"]:
  2776. if fix: # prevent endless recursion
  2777. #print("------",end="")
  2778. #self.encoder(fix,attr,xval,xfade,delay)
  2779. sub_data.append([fix,attr,xval,xfade,delay])
  2780. if DELAY._is():
  2781. delay += DELAY.val()/100
  2782. sub_jdata = []
  2783. for dd in sub_data:
  2784. #print("---",len(sub_data),end="")
  2785. #self.encoder(fix,attr,xval,xfade,delay)
  2786. _x123 = self.encoder(dd[0],dd[1],dd[2],dd[3],dd[4],blind=1)
  2787. sub_jdata.append(_x123)
  2788. if sub_jdata:
  2789. print("--- SEND MASTER ENCODER:",len(sub_data),sub_data[0],"... _blind:",_blind)#,end="")
  2790. jclient_send(sub_jdata)
  2791. jdata=[{"MODE":ii}]
  2792. print("-->B HIER <--")
  2793. jclient_send(jdata)
  2794. return 0
  2795. data = self.fixtures[fix]
  2796. if xval == "click":
  2797. #cprint(data)
  2798. return self.select(fix,attr,mode="toggle")
  2799. v2=data["ATTRIBUT"][attr]["VALUE"]
  2800. change=0
  2801. increment = 4.11
  2802. jdata = {"MODE":"ENC"}
  2803. if xval == "++":
  2804. v2+= increment
  2805. jdata["INC"] = increment
  2806. change=1
  2807. elif xval == "--":
  2808. jdata["INC"] = increment*-1
  2809. v2-= increment
  2810. change=1
  2811. elif xval == "+":
  2812. increment = 0.5
  2813. v2+= increment
  2814. jdata["INC"] = increment
  2815. change=1
  2816. elif xval == "-":
  2817. increment = 0.5
  2818. jdata["INC"] = increment*-1
  2819. v2-= increment
  2820. change=1
  2821. elif type(xval) is int or type(xval) is float:
  2822. v2 = xval
  2823. change=1
  2824. if v2 < 0:
  2825. v2=0
  2826. elif v2 > 256:
  2827. v2=256
  2828. jdata["VALUE"] = round(v2,4)
  2829. jdata["FIX"] = fix
  2830. jdata["ATTR"] = attr
  2831. jdata["DMX"] = FIXTURES.get_dmx(fix,attr)
  2832. jdata["DMX-FINE"] = FIXTURES.get_dmx(fix,attr+"-FINE")
  2833. out = {}
  2834. if change:
  2835. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2836. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2837. data["ATTRIBUT"][attr]["VALUE"] = round(v2,4)
  2838. jdata["FADE"] = 0
  2839. if xfade:
  2840. jdata["FADE"] = xfade
  2841. if xdelay:
  2842. #if attr not in ["PAN","TILT"] and 1:
  2843. jdata["DELAY"] = xdelay
  2844. if not _blind:
  2845. jdata = [jdata]
  2846. #print("ENC",jdata)
  2847. jclient_send(jdata)
  2848. time.sleep(0.001)
  2849. return jdata
  2850. return v2
  2851. def get_active(self):
  2852. cprint("get_active",self)
  2853. CFG = OrderedDict()
  2854. sdata = OrderedDict()
  2855. sdata["CFG"] = CFG # OrderedDict()
  2856. sdata["CFG"]["FADE"] = FADE.val()
  2857. sdata["CFG"]["DEALY"] = 0
  2858. #sdata["CFG"]["BUTTON"] = "GO"
  2859. for fix in self.fixtures:
  2860. data = self.fixtures[fix]
  2861. for attr in data["ATTRIBUT"]:
  2862. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2863. if fix not in sdata:
  2864. sdata[fix] = {}
  2865. if attr not in sdata[fix]:
  2866. sdata[fix][attr] = OrderedDict()
  2867. if not modes.val("REC-FX"):
  2868. sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
  2869. #sdata[fix][attr]["FADE"] = FADE.val() #fade
  2870. else:
  2871. sdata[fix][attr]["VALUE"] = None #data["ATTRIBUT"][attr]["VALUE"]
  2872. if "FX" not in data["ATTRIBUT"][attr]:
  2873. data["ATTRIBUT"][attr]["FX"] =""
  2874. if "FX2" not in data["ATTRIBUT"][attr]:
  2875. data["ATTRIBUT"][attr]["FX2"] ={}
  2876. sdata[fix][attr]["FX"] = data["ATTRIBUT"][attr]["FX"]
  2877. sdata[fix][attr]["FX2"] = data["ATTRIBUT"][attr]["FX2"]
  2878. return sdata
  2879. def get_active2(self):
  2880. pass
  2881. def _deselect_all(self,fix=None):
  2882. cprint("FIXTURES._deselect_all()",fix,"ALL",color="yellow")
  2883. c=0
  2884. if fix in self.fixtures:
  2885. data = self.fixtures[fix]
  2886. for attr in data["ATTRIBUT"]:
  2887. #print("SELECT ALL",fix,attr)
  2888. if "-FINE" in attr.upper():
  2889. pass
  2890. else:
  2891. c+=self.select(fix,attr,mode="off",mute=1)
  2892. return c
  2893. def _select_all(self,fix=None,mode="toggle",mute=0):
  2894. if not mute:
  2895. cprint("FIXTURES._select_all()",fix,"ALL",mode,color="yellow")
  2896. c=0
  2897. if fix in self.fixtures:
  2898. data = self.fixtures[fix]
  2899. for attr in data["ATTRIBUT"]:
  2900. #print("SELECT ALL",fix,attr)
  2901. if "-FINE" in attr.upper():
  2902. continue
  2903. if mode == "toggle":
  2904. c+=self.select(fix,attr,mode="on",mute=mute)
  2905. elif mode == "swap":
  2906. if not attr.startswith("_"):
  2907. c+=self.select(fix,attr,mode="toggle",mute=mute)
  2908. if not c and mode == "toggle": # unselect all
  2909. c= self._deselect_all(fix=fix)
  2910. return c
  2911. def select(self,fix=None,attr=None,mode="on",mute=0):
  2912. if not mute:
  2913. cprint("FIXTURES.select() >>",fix,attr,mode,color="yellow")
  2914. out = 0
  2915. if fix == "SEL":
  2916. if attr.upper() == "INV-ATTR":
  2917. fixs = self.get_active()
  2918. print("selected:",len(fixs))
  2919. for fix in fixs:
  2920. x=self._select_all(fix=fix,mode=mode,mute=1)
  2921. return None
  2922. if fix in self.fixtures:
  2923. if attr.upper() == "ALL":
  2924. x=self._select_all(fix=fix,mode=mode)
  2925. return x
  2926. data = self.fixtures[fix]
  2927. if attr in data["ATTRIBUT"]:
  2928. if mode == "on":
  2929. if not data["ATTRIBUT"][attr]["ACTIVE"]:
  2930. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2931. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2932. out = 1
  2933. elif mode == "off":
  2934. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2935. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2936. out = 1
  2937. elif mode == "toggle":
  2938. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2939. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2940. else:
  2941. data["ATTRIBUT"][attr]["ACTIVE"] = 1
  2942. data["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] = 1
  2943. out = 1
  2944. return out
  2945. def clear(self):
  2946. out = 0
  2947. for fix in self.fixtures:
  2948. data = self.fixtures[fix]
  2949. for attr in data["ATTRIBUT"]:
  2950. #if attr.endswith("-FINE"):
  2951. # continue
  2952. if data["ATTRIBUT"][attr]["ACTIVE"]:
  2953. out +=1
  2954. data["ATTRIBUT"][attr]["ACTIVE"] = 0
  2955. return out
  2956. def CFG_CHECKER(sdata):
  2957. "repair CFG "
  2958. ok = 0
  2959. if "CFG" not in sdata:
  2960. sdata["CFG"] = OrderedDict()
  2961. ok += 1
  2962. if "FADE" not in sdata["CFG"]:
  2963. sdata["CFG"]["FADE"] = 4
  2964. ok += 1
  2965. if "DELAY" not in sdata["CFG"]:
  2966. sdata["CFG"]["DELAY"] = 0
  2967. ok += 1
  2968. if "BUTTON" not in sdata["CFG"]:
  2969. sdata["CFG"]["BUTTON"] = "GO"
  2970. ok += 1
  2971. if "HTP-MASTER" not in sdata["CFG"]:
  2972. sdata["CFG"]["HTP-MASTER"] = 100 #%
  2973. ok += 1
  2974. if "SIZE-MASTER" not in sdata["CFG"]:
  2975. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  2976. ok += 1
  2977. if "SPEED-MASTER" not in sdata["CFG"]:
  2978. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  2979. ok += 1
  2980. if "OFFSET-MASTER" not in sdata["CFG"]:
  2981. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  2982. ok += 1
  2983. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  2984. #except:pass
  2985. return ok
  2986. class Presets():
  2987. def __init__(self):
  2988. #super().__init__()
  2989. self.base = Base()
  2990. #self.load()
  2991. self._last_copy = None
  2992. self._last_move = None
  2993. self.fx_buffer = {}
  2994. def load_presets(self):
  2995. #self._load()
  2996. filename="presets"
  2997. #self.base._init()
  2998. d,l = self.base._load(filename)
  2999. for i in d:
  3000. sdata = d[i]
  3001. ok = CFG_CHECKER(sdata)
  3002. self.val_presets = d
  3003. self.label_presets = l
  3004. def check_cfg(self,nr=None):
  3005. cprint("PRESETS.check_cfg()",nr)#,color="red")
  3006. ok = 0
  3007. if nr is not None:
  3008. if nr in self.val_presets:
  3009. sdata = self.val_presets[nr]
  3010. ok += self._check_cfg(sdata)
  3011. else:
  3012. cprint("nr not in data ",nr,color="red")
  3013. else:
  3014. for nr in self.val_presets:
  3015. sdata = self.val_presets[nr]
  3016. ok += self._check_cfg(sdata)
  3017. return ok
  3018. def _check_cfg(self,sdata):
  3019. cprint("PRESETS._check_cfg()")#,color="red")
  3020. ok = CFG_CHECKER(sdata)
  3021. if ok:
  3022. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  3023. return ok
  3024. def backup_presets(self,save_as=""):
  3025. filename = "presets"
  3026. data = self.val_presets
  3027. labels = self.label_presets
  3028. #self.base._init()
  3029. self.base._backup(filename,data,labels,save_as)
  3030. def get_cfg(self,nr):
  3031. cprint("PRESETS.get_cfg()",nr)
  3032. self.check_cfg(nr)
  3033. if nr not in self.val_presets:
  3034. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  3035. return {}
  3036. if "CFG" in self.val_presets[nr]:
  3037. return self.val_presets[nr]["CFG"]
  3038. def clean(self,nr):
  3039. if nr not in self.val_presets:
  3040. self.val_presets[nr] = OrderedDict()
  3041. #self.val_presets[nr]["VALUE"] = 0
  3042. #self.val_presets[nr]["FX"] = ""
  3043. sdata = self.val_presets[nr]
  3044. for fix in sdata:
  3045. #print("exec.clear()",nr,fix,sdata[fix])
  3046. for attr in sdata[fix]:
  3047. row = sdata[fix][attr]
  3048. if fix == "CFG":
  3049. continue
  3050. if "VALUE" not in row:
  3051. row["VALUE"] = None
  3052. if "FX" not in row:
  3053. row["FX"] = ""
  3054. if "FX2" not in row:
  3055. row["FX2"] = OrderedDict()
  3056. elif row["FX2"]:
  3057. for k in ["SIZE","SPEED","START","OFFSET"]:
  3058. row["FX2"][k] = int( row["FX2"][k] )
  3059. row["FX"] = ""
  3060. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  3061. #"off:0:0:0:16909:-:"
  3062. x = row["FX"].split(":")
  3063. print("-fx",x,len(x))
  3064. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  3065. if len(x) >= 6:
  3066. row["FX2"]["TYPE"] = x[0]
  3067. row["FX2"]["SIZE"] = int(x[1])
  3068. row["FX2"]["SPEED"] = int(x[2])
  3069. row["FX2"]["START"] = int(x[3])
  3070. row["FX2"]["OFFSET"] = int(x[4])
  3071. row["FX2"]["BASE"] = x[5]
  3072. row["FXOLD"] = row["FX"]
  3073. row["FX"] = ""
  3074. #cprint("exec.clear()",nr,fix,row)
  3075. def get_raw_map(self,nr):
  3076. self.clean(nr)
  3077. print("get_raw_map",nr)
  3078. sdata = self.val_presets[nr]
  3079. cmd = ""
  3080. out = []
  3081. dmx=-1
  3082. for fix in sdata:
  3083. if fix == "CFG":
  3084. #print("CFG",nr,sdata[fix])
  3085. continue
  3086. for attr in sdata[fix]:
  3087. x = {}
  3088. #print("RAW",attr)
  3089. x["FIX"] = fix
  3090. x["ATTR"] = attr
  3091. x["VALUE"] = sdata[fix][attr]["VALUE"]
  3092. x["FX"] = sdata[fix][attr]["FX"]
  3093. x["FX2"] = sdata[fix][attr]["FX2"]
  3094. #x["DMX"] = sdata[fix][attr]["NR"]
  3095. out.append(x)
  3096. return out
  3097. def get_btn_txt(self,nr):
  3098. sdata=self.val_presets[nr]
  3099. BTN="go"
  3100. if "CFG" in sdata:
  3101. if "BUTTON" in sdata["CFG"]:
  3102. BTN = sdata["CFG"]["BUTTON"]
  3103. _label = self.label_presets[nr] # = label
  3104. #txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  3105. #txt=str(nr+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+_label
  3106. txt="{} {} {}\n{}".format(nr+1,BTN,len(sdata)-1,_label)
  3107. print("get_btn_txt",nr,[txt])
  3108. return txt
  3109. def _btn_cfg(self,nr,txt=None):
  3110. if nr not in self.val_presets:
  3111. return ""
  3112. if "CFG" not in self.val_presets[nr]:
  3113. self.val_presets[nr]["CFG"] = OrderedDict()
  3114. return self.val_presets[nr]["CFG"]
  3115. def btn_cfg(self,nr,txt=None):
  3116. if nr not in self.val_presets:
  3117. return ""
  3118. if "CFG" not in self.val_presets[nr]:
  3119. self.val_presets[nr]["CFG"] = OrderedDict()
  3120. if "BUTTON" not in self.val_presets[nr]["CFG"]:
  3121. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3122. if type(txt) is str:
  3123. self.val_presets[nr]["CFG"]["BUTTON"] = txt
  3124. if self.val_presets[nr]["CFG"]["BUTTON"] is None:
  3125. self.val_presets[nr]["CFG"]["BUTTON"] = ""
  3126. master._refresh_exec(nr=nr)
  3127. print("EEE", self.val_presets[nr]["CFG"]["BUTTON"] )
  3128. return self.val_presets[nr]["CFG"]["BUTTON"]
  3129. def label(self,nr,txt=None):
  3130. if nr not in self.label_presets:
  3131. return ""
  3132. if type(txt) is str:
  3133. self.label_presets[nr] = txt
  3134. print("set label",nr,[txt])
  3135. print("??? ?? set label",nr,[txt])
  3136. return self.label_presets[nr]
  3137. def clear_move(self):
  3138. cprint("PRESETS.clear_move()",end=" ")
  3139. self.clear_copy()
  3140. def clear_copy(self):
  3141. cprint("PRESETS.clear_copy()",end=" ")
  3142. if self._last_copy is not None:
  3143. cprint("=OK=",color="red")
  3144. self._last_copy = None
  3145. else:
  3146. cprint("=NONE=",color="green")
  3147. def copy(self,nr,overwrite=1):
  3148. cprint("PRESETS._copy",nr,"last",self._last_copy)
  3149. if nr >= 0:
  3150. if self._last_copy is not None:
  3151. if modes.val("COPY"):
  3152. modes.val("COPY",3)
  3153. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  3154. return ok #ok
  3155. else:
  3156. if modes.val("COPY"):
  3157. modes.val("COPY",2)
  3158. self._last_copy = nr
  3159. cprint("PRESETS.copy START ",color="red")
  3160. return 0
  3161. return 1 # on error reset move
  3162. def _copy(self,nr_from,nr_to,overwrite=1):
  3163. cprint("PRESETS._copy",nr_from,"to",nr_to)
  3164. self.check_cfg(nr_from)
  3165. if type(self._last_copy) is None:
  3166. cprint("PRESETS._copy last nr is None",color="red")
  3167. return 0
  3168. cprint("------ PRESETS._copy", nr_from in self.val_presets , nr_to in self.val_presets)
  3169. if nr_from in self.val_presets and nr_to in self.val_presets:
  3170. fdata = self.val_presets[nr_from]
  3171. tdata = self.val_presets[nr_to]
  3172. #cprint(fdata)
  3173. flabel = self.label_presets[nr_from]
  3174. tlabel = self.label_presets[nr_to]
  3175. self.val_presets[nr_to] = copy.deepcopy(fdata)
  3176. self.label_presets[nr_to] = flabel
  3177. if not overwrite: #default
  3178. cprint("overwrite",overwrite)
  3179. self.val_presets[nr_from] = copy.deepcopy(tdata)
  3180. self.label_presets[nr_from] = tlabel
  3181. #self.label_presets[nr_from] = "MOVE"
  3182. self.clear_copy()
  3183. cprint("PRESETS.copy OK",color="green")
  3184. return 1
  3185. def move(self,nr):
  3186. cprint("PRESETS.move",self._last_copy,"to",nr)
  3187. if nr >= 0:
  3188. last = self._last_copy
  3189. if modes.val("MOVE"):
  3190. modes.val("MOVE",2)
  3191. ok= self.copy(nr,overwrite=0)
  3192. if ok and last >= 0:
  3193. if modes.val("MOVE"):
  3194. modes.val("MOVE",3)
  3195. cprint("PRESETS.move OK",color="red")
  3196. #self.delete(last)
  3197. return ok,nr,last #ok
  3198. return 0,nr,last # on error reset move
  3199. def delete(self,nr):
  3200. cprint("PRESETS.delete",nr)
  3201. ok=0
  3202. if nr in self.val_presets:
  3203. self.val_presets[nr] = OrderedDict()
  3204. self.label_presets[nr] = "-"
  3205. ok = 1
  3206. self.check_cfg(nr)
  3207. return ok
  3208. def rec(self,nr,data,arg=""):
  3209. cprint("rec",self,"rec()",len(data),arg)
  3210. self.check_cfg(nr)
  3211. self._check_cfg(data) #by ref
  3212. odata=self.val_presets[nr]
  3213. #print("odata",odata)
  3214. if "CFG" in odata:
  3215. if "BUTTON" in odata["CFG"]:
  3216. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  3217. self.val_presets[nr] = data
  3218. return 1
  3219. class FixtureEditor():
  3220. def __init__(self,dmx=1):
  3221. pass
  3222. self.elem=[]
  3223. self.dmx=dmx
  3224. print("init FixtureEditor",dmx)
  3225. def event(self,a1="",a2=""):
  3226. print([self.dmx,a1,a2])
  3227. j=[]
  3228. jdata = {'VALUE': int(a1), 'args': [] , 'FADE': 0,'DMX': str(self.dmx)}
  3229. j.append(jdata)
  3230. jclient_send(j)
  3231. class MasterWing():
  3232. def __init__(self,dmx=1):
  3233. pass
  3234. self.elem=[]
  3235. self.dmx=dmx
  3236. print("init MasterWing",dmx)
  3237. def event(self,a1="",a2=""):
  3238. print([self.dmx,a1,a2])
  3239. jdata = {'CMD': "MASTER", 'NAME': str(a1),'VALUE':str(a2) }
  3240. j=[]
  3241. j.append(jdata)
  3242. jclient_send(j)
  3243. class BufferVar():
  3244. def __init__(self,elem):
  3245. self.elem = elem
  3246. def change_dmx(self,event=""):
  3247. nr=1
  3248. txt=""
  3249. def cb(data):
  3250. txt = data["Value"]
  3251. dialog._cb = _cb
  3252. dialog.askstring("FADER-DMX-START",""+str(nr+1),initialvalue=txt)
  3253. print("change_dmx",[event,self])
  3254. # GUI_FaderLayout():
  3255. lf_nr = 0
  3256. from tkinter import PhotoImage
  3257. _shift_key = 0
  3258. class Window():
  3259. def __init__(self,args): #title="title",master=0,width=100,height=100,left=None,top=None,exit=0,cb=None,resize=1):
  3260. global lf_nr
  3261. self.args = {"title":"title","master":0,"width":100,"height":100,"left":None,"top":None,"exit":0,"cb":None,"resize":1}
  3262. self.args.update(args)
  3263. cprint("Window.init()",id(self.args),color="yellow")
  3264. cprint(" ",self.args,color="yellow")
  3265. ico_path="./icon/"
  3266. self.cb = cb
  3267. if self.args["master"]:
  3268. self.tk = tkinter.Tk()
  3269. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3270. self.tk.withdraw() # do not draw
  3271. self.tk.resizable(self.args["resize"],self.args["resize"])
  3272. defaultFont = tkinter.font.nametofont("TkDefaultFont")
  3273. print(defaultFont)
  3274. defaultFont.configure(family="FreeSans",
  3275. size=10,
  3276. weight="bold")
  3277. # MAIN MENUE
  3278. try:
  3279. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"main.png"))
  3280. except Exception as e:
  3281. print("Exception GUIWindow.__init__",e)
  3282. else:
  3283. # addtional WINDOW
  3284. self.tk = tkinter.Toplevel()
  3285. self.tk.iconify()
  3286. #self.tk.withdraw() # do not draw
  3287. self.tk.protocol("WM_DELETE_WINDOW", self.close_app_win)
  3288. self.tk.resizable(self.args["resize"],self.args["resize"])
  3289. try:
  3290. if "COLORPICKER" in self.args["title"]:
  3291. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"picker.png"))
  3292. elif "ENCODER" in self.args["title"]:
  3293. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"enc.png"))
  3294. elif "EXEC" in self.args["title"]:
  3295. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  3296. elif "FX" in self.args["title"]:
  3297. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"fx.png"))
  3298. else:
  3299. self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png"))
  3300. except Exception as e:
  3301. print("Exception on load window icon",self.args["title"])
  3302. print("Exception:",e)
  3303. #time.sleep(3)
  3304. self.tk.deiconify()
  3305. self.tk["bg"] = "black"
  3306. self.tk.bind("<Button>",self.callback)
  3307. self.tk.bind("<Key>",self.callback)
  3308. self.tk.bind("<KeyRelease>",self.callback)
  3309. self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3310. lf_nr+=1
  3311. #self.tk.geometry("270x600+0+65")
  3312. geo ="{}x{}".format(self.args["width"],self.args["height"])
  3313. if self.args["left"] is not None:
  3314. geo += "+{}".format(self.args["left"])
  3315. if self.args["top"] is not None:
  3316. geo += "+{}".format(self.args["top"])
  3317. #self._event_clear = Xevent(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
  3318. self.tk.geometry(geo)
  3319. self.show()
  3320. def update_idle_task(self):
  3321. if INIT_OK:
  3322. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3323. pass
  3324. def close_app_win(self,event=None):
  3325. cprint("close_app_win",self,event,self.args["title"],color="red")
  3326. if exit:
  3327. if self.title == "MAIN":
  3328. save_window_position()
  3329. self.tk.destroy()
  3330. try:
  3331. self.cb("<exit>").cb()
  3332. except Exception as e:
  3333. cprint("EXCETPION: close_app_win",e,self,color="red")
  3334. def title(self,title=None):
  3335. if title is None:
  3336. return self.tk.title()
  3337. else:
  3338. #return self.tk.title(title)
  3339. self.args["title"] = title
  3340. return self.tk.title(""+str(self.args["title"])+" "+str(lf_nr)+":"+str(rnd_id))
  3341. def show(self):
  3342. self.tk.deiconify()
  3343. pass
  3344. def mainloop(self):
  3345. #save_window_position_loop() #like autosave
  3346. try:
  3347. self.tk.mainloop()
  3348. finally:
  3349. self.tk.quit()
  3350. def callback(self,event,data={}):#value=255):
  3351. global _global_short_key
  3352. #time.sleep(0.1)
  3353. if not _global_short_key:
  3354. #cprint("<GLOBAL-GUI-EVENT-DISABLED>",event,color="red")
  3355. return 1
  3356. global _shift_key
  3357. #cprint("<GUI>",event,color="yellow")
  3358. value = 255
  3359. if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
  3360. value = 0
  3361. #cprint("<GUI>",event.state,data,value,[event.type,event.keysym],color="yellow")
  3362. if "keysym" in dir(event):
  3363. if "Escape" == event.keysym:
  3364. FIXTURES.clear()
  3365. modes.val("ESC",1)
  3366. master.refresh_fix()
  3367. elif event.keysym in ["Shift_L","Shift_R"]:
  3368. #cprint(event.type)
  3369. if "KeyRelease" in str(event.type) or str(event.type) in ["3"]:
  3370. _shift_key = 0
  3371. else:
  3372. _shift_key = 1
  3373. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3374. #cprint("SHIFT_KEY",_shift_key,"??????????")
  3375. global _ENCODER_WINDOW
  3376. if _shift_key:
  3377. _ENCODER_WINDOW.title("SHIFT/FINE ")
  3378. else:
  3379. _ENCODER_WINDOW.title("ENCODER")
  3380. elif event.keysym in "ebfclrms" and value:
  3381. if "e" == event.keysym:
  3382. modes.val("EDIT",1)
  3383. elif "b" == event.keysym:
  3384. modes.val("BLIND",1)
  3385. elif "f" == event.keysym:
  3386. modes.val("FLASH",1)
  3387. elif "c" == event.keysym:
  3388. modes.val("CFG-BTN",1)
  3389. elif "l" == event.keysym:
  3390. modes.val("LABEL",1)
  3391. elif "r" == event.keysym:
  3392. modes.val("REC",1)
  3393. elif "m" == event.keysym:
  3394. x=modes.val("MOVE",1)
  3395. if not x:
  3396. PRESETS.clear_move()
  3397. elif "s" == event.keysym:
  3398. modes.val("SELECT",1)
  3399. elif event.keysym in ["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]:
  3400. nr = int( event.keysym[1:]) # F:1-12
  3401. nr = nr-1+81
  3402. cprint("F-KEY",value,nr,event.keysym)
  3403. #print(event)
  3404. master.preset_go(nr-1,xfade=None,val=value)
  3405. elif event.keysym in ["1","2","3","4","5","6","7","8","9","0"]:
  3406. nr = int( event.keysym)
  3407. if nr == 0:
  3408. nr = 10
  3409. nr = nr-1+161
  3410. cprint("NUM-KEY",value,nr)
  3411. master.preset_go(nr-1,xfade=None,val=value)
  3412. elif "numbersign" == event.keysym and value: # is char "#"
  3413. print("numbersign !!")
  3414. e = master.commands.elem["SAVE\nSHOW"]
  3415. print(e)
  3416. PRESETS.backup_presets()
  3417. FIXTURES.backup_patch()
  3418. save_window_position()
  3419. b = BLINKI(e)
  3420. b.blink()
  3421. #e = Xevent(fix=0,elem=None,attr="SAVE\nSHOW",mode="SETUP")
  3422. #e.cb(event=event)
  3423. elif "End" == event.keysym:
  3424. FIXTURES.fx_off("all")
  3425. CONSOLE.fx_off("all")
  3426. CONSOLE.flash_off("all")
  3427. elif "Delete" == event.keysym:
  3428. #PRESETS.delete(nr)
  3429. if value:
  3430. modes.val("DEL",1)
  3431. class WindowManager():
  3432. def __init__(self):
  3433. self.windows = {}
  3434. self.obj = {}
  3435. self.nr= 0
  3436. self.first=""
  3437. def new(self,w,name="",obj=None):
  3438. if not w:
  3439. return
  3440. if not self.first:
  3441. if name:
  3442. self.first = name
  3443. else:
  3444. self.first = str(self.nr)
  3445. w.tk.state(newstate='normal')
  3446. w.tk.attributes('-topmost',True)
  3447. if name:
  3448. self.windows[str(name)] = w
  3449. self.obj[str(name)] = obj
  3450. else:
  3451. self.windows[str(self.nr)] = w
  3452. self.obj[str(self.nr)] = obj
  3453. self.nr+=1
  3454. #w.show()
  3455. def mainloop(self):
  3456. self.windows[self.first].mainloop()
  3457. def get(self,name):
  3458. print(self,".get(name) =",name)
  3459. name = str(name)
  3460. if name in self.windows:
  3461. out = self.windows[name]
  3462. print(out)
  3463. return out
  3464. def get_obj(self,name):
  3465. #print(self,".get(name) =",name)
  3466. name = str(name)
  3467. if name in self.windows:
  3468. out = self.obj[name]
  3469. #print(out)
  3470. return out
  3471. def top(self,name):
  3472. name = str(name)
  3473. for n in self.windows:
  3474. print("TOP",n) #self.get("")
  3475. if name in self.windows:
  3476. self.windows[name].tk.state(newstate='normal')
  3477. self.windows[name].tk.attributes('-topmost',True)
  3478. self.windows[name].tk.attributes('-topmost',False)
  3479. self.windows[name].tk.update_idletasks()# gui_menu_gui.tk)
  3480. #print("redraw",name)
  3481. #if name == "PATCH":
  3482. # gui_patch.draw()
  3483. #if name == "DIMMER":
  3484. # gui_fix.draw()
  3485. if name == "EXEC":
  3486. master._refresh_exec()
  3487. #self.windows[name].tk.update_idletasks()# gui_menu_gui.tk)
  3488. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3489. else:
  3490. print(name,"not in self.windows",self.windows.keys())
  3491. class Console():
  3492. def __init__(self):
  3493. pass
  3494. def flash_off(self,fix):
  3495. pass#client.send("df0:alloff:::,")
  3496. def fx_off(self,fix):
  3497. cprint("Console.fx_off()",fix)
  3498. if not fix or fix == "all":
  3499. #client.send("fx0:alloff:,fxf:alloff:,")
  3500. #client.send("df0:alloff:::,")
  3501. j = []
  3502. if 0:
  3503. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2, 'DMX': '0'}
  3504. j.append(jdata)
  3505. jdata = {'VALUE': None, 'args': [], 'FX': 'alloff::::', 'FADE': 2,'FLASH':1, 'DMX': '0'}
  3506. j.append(jdata)
  3507. else:
  3508. jdata = {'VALUE': None, 'args': [], 'FX2': {"TYPE":"alloff"}, 'FADE': 2,'FLASH':1, 'DMX': '1'}
  3509. j.append(jdata)
  3510. jclient_send(j)
  3511. return 0
  3512. def test_1():
  3513. #LibreLight --no-gui --show=unitest --dmx-out=on --exec="sel fix 1-10; go preset 2; encoder DIM sel; encoder DIM ++"
  3514. pass
  3515. window_manager = WindowManager()
  3516. CONSOLE = Console()
  3517. PRESETS = Presets()
  3518. FIXTURES = Fixtures()
  3519. def LOAD_SHOW():
  3520. PRESETS.load_presets()
  3521. FIXTURES.load_patch()
  3522. #draw_enc(gui,root2)
  3523. #master._refresh_fix()
  3524. #master._refresh_exec()
  3525. LOAD_SHOW()
  3526. master = MASTER()
  3527. class Refresher():
  3528. def __init__(self):
  3529. self.time = time.time()
  3530. self.time_max = time.time()
  3531. self.time_delta = 15
  3532. self.update = 1
  3533. self.name = "fix" # exec
  3534. def reset(self):
  3535. self.time = time.time() #+.1
  3536. self.update = 1
  3537. def refresh(self):
  3538. #print("refresh",self.update,int((self.time-time.time())*1000))
  3539. #if self.time_max+self.time_delta < time.time():
  3540. # #print("----- MAX REFRES TIMEOUT -----")
  3541. # self._refresh()
  3542. if self.update:
  3543. if self.time+self.time_delta < time.time():
  3544. self._refresh()
  3545. else:
  3546. self.time = time.time() #+.1
  3547. def _refresh(self):
  3548. print(self,"_refresh()")
  3549. if not INIT_OK:
  3550. return
  3551. self.time_max = time.time()
  3552. self.time = time.time()
  3553. self.update = 0
  3554. try:
  3555. if self.name == "fix": # exec
  3556. master._refresh_fix()
  3557. else:
  3558. master._refresh_exec()
  3559. except Exception as e:
  3560. print("_refresh except:",e)
  3561. traceback.print_exc()
  3562. print()
  3563. print("t=",self.time_max- time.time())
  3564. def loop(self,args={}):
  3565. while 1:
  3566. try:
  3567. if INIT_OK:
  3568. self.refresh()
  3569. tkinter.Tk.update_idletasks(gui_menu_gui.tk)
  3570. except Exception as e:
  3571. print("loop exc",e)
  3572. traceback.print_exc()
  3573. cprint("== cb EXCEPT",e,color="red")
  3574. cprint("Error on line {}".format(sys.exc_info()[-1].tb_lineno),color="red")
  3575. cprint(''.join(traceback.format_exception(None, e, e.__traceback__)),color="red")
  3576. time.sleep(0.2)
  3577. print("main",__name__)
  3578. __run_main = 0
  3579. if __name__ == "__main__":
  3580. __run_main = 1
  3581. else:
  3582. import __main__
  3583. if "unittest" not in dir(__main__):
  3584. __run_main = 1
  3585. refresher_fix = Refresher()
  3586. refresher_fix.time_delta = 0.25
  3587. refresher_fix.name = "fix"
  3588. refresher_exec = Refresher()
  3589. refresher_exec.time_delta = 10 #0
  3590. refresher_exec.name = "exec"
  3591. def loops(**args):
  3592. time.sleep(15) # wait until draw all window's
  3593. thread.start_new_thread(refresher_fix.loop,())
  3594. thread.start_new_thread(refresher_exec.loop,())
  3595. class window_create_buffer():
  3596. def __init__(self,args,cls,data,cb_ok=None,scroll=0,gui=None):
  3597. self.args = args.copy()
  3598. self.cls = cls
  3599. self.cb_ok = cb_ok
  3600. self.data = data
  3601. self.scroll = scroll
  3602. self.gui = gui
  3603. def create(self,hidde=0):
  3604. cprint()
  3605. cprint("window_create_buffer.create()",id(self),self.args["title"],color="green")
  3606. obj = None
  3607. w = Window(self.args)
  3608. if self.scroll:
  3609. w1 = ScrollFrame(w.tk,width=self.args["width"],height=self.args["height"])
  3610. else:
  3611. w1 = tk.Frame(w.tk,width=self.args["width"],height=self.args["height"])
  3612. w1.pack()
  3613. if self.gui:
  3614. self.cls(self.gui,w1,self.data) #PRESETS):
  3615. else:
  3616. obj=self.cls(w1,self.data)
  3617. return w,obj,self.cb_ok
  3618. window_init_buffer = {}
  3619. if __run_main:
  3620. print("main")
  3621. #thread.start_new_thread(refresher_fix.loop,())
  3622. #thread.start_new_thread(refresher_exec.loop,())
  3623. TOP = _POS_TOP + 15
  3624. L0 = _POS_LEFT
  3625. L1 = _POS_LEFT + 95
  3626. L2 = _POS_LEFT + 920
  3627. W1 = 810
  3628. H1 = 550
  3629. HTB = 23 # hight of the titlebar from window manager
  3630. #w = Window("MAIN",master=1,width=95,height=H1//2,left=L0,top=TOP,resize=0)
  3631. args = {"title":"MAIN","master":1,"width":100,"height":H1,"left":L0,"top":TOP,"resize":1}
  3632. #w = Window("MAIN",master=1,width=100,height=H1,left=L0,top=TOP,resize=1)
  3633. w = Window(args)
  3634. gui_menu_gui = w
  3635. data = []
  3636. #data.append({"text":"COMMAND"})
  3637. #data.append({"text":"CONFIG"})
  3638. data.append({"text":"PATCH"})
  3639. data.append({"text":"DIMMER"})
  3640. data.append({"text":"FIXTURES"})
  3641. data.append({"text":"EXEC","name":"EXEC-BTN"})
  3642. data.append({"text":"EXEC-WING"})
  3643. data.append({"text":"---"})
  3644. data.append({"text":"ENCODER"})
  3645. data.append({"text":"COMMAND"})
  3646. data.append({"text":"COLORPICKER","name":"COLOR"})
  3647. data.append({"text":"FX"})
  3648. data.append({"text":"---"})
  3649. data.append({"text":"FIXTURE-EDITOR","name":"FIX-EDIT"})
  3650. #data.append({"text":"CLOCK"})
  3651. data.append({"text":"CONFIG"})
  3652. gui_menu = GUI_menu(w.tk,data)
  3653. window_manager = gui_menu.window_manager #= window_manager
  3654. window_manager.new(w)
  3655. name="EXEC"
  3656. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3657. cls = draw_exec #GUI_ExecWingLayout
  3658. cb_ok = None #set_exec_fader_all
  3659. data = PRESETS
  3660. hidde = 1
  3661. if name in window_list_buffer:
  3662. if window_list_buffer[name][0]:
  3663. hidde = 0
  3664. else:
  3665. hidde = 0
  3666. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,scroll=1,gui=master)
  3667. window_init_buffer[name] = c
  3668. if hidde:
  3669. window_manager.new(None,name)
  3670. else:
  3671. w,obj,cb_ok = c.create(hidde=hidde)
  3672. window_manager.new(w,name,obj=obj)
  3673. if cb_ok:
  3674. cb_ok()
  3675. if 0: # draw EXEC -BTN second time fail TODO
  3676. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,scroll=1,gui=master)
  3677. window_init_buffer[name] = c
  3678. w,obj,cb_ok = c.create()
  3679. window_manager.update(w,name,obj=obj)
  3680. name="CONFIG"
  3681. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3682. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3683. #w = Window(args)
  3684. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3685. #frame_exe = w.tk
  3686. #draw_config(master,w1)#.tk)#Xroot)
  3687. cls = GUI_CONF
  3688. data = []
  3689. ##draw_enc(master,w.tk)#Xroot)
  3690. ##draw_preset(master,w1)#w.tk)
  3691. #window_manager.new(w,name)
  3692. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3693. window_init_buffer[name] = c
  3694. #w,obj,cb_ok = c.create()
  3695. #window_manager.new(w,name,obj)
  3696. window_manager.new(None,name) #,obj)
  3697. name="DIMMER"
  3698. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3699. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3700. #w = Window(args)
  3701. #w2 = ScrollFrame(w.tk,width=W1,height=H1)
  3702. ##frame_dim = w1 # w.tk
  3703. ##master.draw_dim(w1.tk)
  3704. #window_manager.new(w,name)
  3705. cls = GUI_DIM
  3706. #gui_fix.draw(FIXTURES)
  3707. data = FIXTURES
  3708. #window_manager.new(w,name)
  3709. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3710. window_init_buffer[name] = c
  3711. w,obj,cb_ok = c.create()
  3712. window_manager.new(w,name,obj)
  3713. name="FIXTURES"
  3714. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3715. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3716. #w = Window(args)
  3717. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3718. #frame_fix = w1 #w.tk
  3719. #draw_fix(master,w1,w2)#.tk)
  3720. #gui_fix = GUI_FIX(master,w1,w2)
  3721. cls = GUI_FIX
  3722. #gui_fix.draw(FIXTURES)
  3723. data = FIXTURES
  3724. #window_manager.new(w,name)
  3725. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3726. window_init_buffer[name] = c
  3727. w,obj,cb_ok = c.create()
  3728. window_manager.new(w,name,obj)
  3729. name="FIXTURE-EDITOR"
  3730. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3731. #w = Window(args)
  3732. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3733. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3734. data=[]
  3735. #for i in range((24+12)*15):
  3736. for i in range(12*6):
  3737. data.append({"text"+str(i):"test"})
  3738. #GUI_FaderLayout(w1,data)
  3739. cls = GUI_FaderLayout
  3740. #window_manager.new(w,name)
  3741. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok)
  3742. window_init_buffer[name] = c
  3743. #w,obj,cb_ok = c.create()
  3744. #window_manager.new(w,name,obj)
  3745. window_manager.new(None,name)
  3746. name="MASTER-WING"
  3747. #w = Window(name,master=0,width=730,height=205,left=L1-80,top=TOP+H1-200)
  3748. #w = Window(name,master=0,width=75,height=405,left=L0,top=TOP+H1-220)
  3749. args = {"title":name,"master":0,"width":75,"height":405,"left":L0,"top":TOP+H1-220}
  3750. w = Window(args)
  3751. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3752. w1 = tk.Frame(w.tk,width=W1,height=H1)
  3753. w1.pack()
  3754. data=[]
  3755. for i in range(2):
  3756. data.append({"MASTER"+str(i):"MASTER"})
  3757. GUI_MasterWingLayout(w1,data)
  3758. window_manager.new(w,name)
  3759. name="EXEC-WING"
  3760. args = {"title":name,"master":0,"width":600,"height":415,"left":L1,"top":TOP+H1+HTB*2,"H1":H1,"W1":W1}
  3761. data=[]
  3762. for i in range(10*3):
  3763. data.append({"EXEC"+str(i):"EXEC"})
  3764. cls = GUI_ExecWingLayout
  3765. cb_ok = set_exec_fader_all
  3766. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok)
  3767. window_init_buffer[name] = c
  3768. w,obj,cb_ok = c.create()
  3769. window_manager.new(w,name,obj)
  3770. if cb_ok:
  3771. cb_ok()
  3772. name="ENCODER"
  3773. #w = Window(name,master=0,width=620,height=113,left=L0+710,top=TOP+H1+15+HTB*2)
  3774. args = {"title":name,"master":0,"width":620,"height":113,"left":L0+710,"top":TOP+H1+15+HTB*2}
  3775. w = Window(args)
  3776. _ENCODER_WINDOW = w
  3777. draw_enc(master,w.tk)#Xroot)
  3778. window_manager.new(w,name)
  3779. #name="REMOTE-CONTROL"
  3780. #w = Window(name,master=0,width=220,height=113,left=L0+710,top=TOP+H1+HTB*2+123)
  3781. #_ENCODER_WINDOW = w
  3782. #draw_enc(master,w.tk)#Xroot)
  3783. name = "SETUP"
  3784. #w = Window(name,master=0,width=415,height=42,left=L1+10+W1,top=TOP,resize=0)
  3785. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP,"resize":0}
  3786. w = Window(args)
  3787. w.tk.title("SETUP SHOW:"+master.base.show_name)
  3788. draw_setup(master,w.tk)
  3789. window_manager.new(w,name)
  3790. name = "COMMAND"
  3791. args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":0}
  3792. w = Window(args)
  3793. #w = Window(name,master=0,width=415,height=130,left=L1+10+W1,top=TOP+81,resize=0)#+96)
  3794. draw_command(master,w.tk)
  3795. window_manager.new(w,name)
  3796. name = "LIVE"
  3797. #w = Window(name,master=0,width=415,height=42,left=L1+10+W1,top=TOP+235,resize=0)#250)
  3798. args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":0}
  3799. w = Window(args)
  3800. draw_live(master,w.tk)
  3801. window_manager.new(w,name)
  3802. name = "CLOCK"
  3803. #w = Window(name,master=0,width=335,height=102,left=L1+10+W1+80,top=TOP+H1+HTB+160,resize=0)#250)
  3804. args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
  3805. w = Window(args)
  3806. cclock = X_CLOCK()
  3807. cclock.draw_clock(master,w.tk)
  3808. window_manager.new(w,name)
  3809. name="FX"
  3810. #w = Window(name,master=0,width=415,height=297,left=L1+10+W1,top=TOP+302,resize=0)#317)
  3811. args = {"title":name,"master":0,"width":415,"height":297,"left":L1+10+W1,"top":TOP+302,"resize":0}
  3812. w = Window(args)
  3813. #frame_fx = w.tk
  3814. draw_fx(master,w.tk)
  3815. window_manager.new(w,name)
  3816. name="PATCH"
  3817. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3818. args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
  3819. #w = Window(args)
  3820. #w1 = ScrollFrame(w.tk,width=W1,height=H1)
  3821. #main_preset_frame = w1
  3822. #gui_patch = GUI_PATCH(master,main_preset_frame)
  3823. cls = GUI_PATCH
  3824. #gui_patch.draw(FIXTURES)
  3825. data = FIXTURES
  3826. #window_manager.new(w,name)
  3827. c = window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
  3828. window_init_buffer[name] = c
  3829. #w,obj,cb_ok = c.create()
  3830. #window_manager.new(w,name,obj)
  3831. window_manager.new(None,name) #,obj)
  3832. #LibreLightDesk
  3833. name="COLORPICKER"
  3834. #w = Window(name,master=0,width=600,height=113,left=L1+5,top=TOP+5+HTB*2+H1)
  3835. args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
  3836. w = Window(args)
  3837. draw_colorpicker(master,w.tk,FIXTURES,master)
  3838. window_manager.new(w,name)
  3839. name="TableA"
  3840. #w = Window(name,master=0,width=W1,height=H1,left=L1,top=TOP)
  3841. #space_font = tk.font.Font(family="FreeSans", size=1 ) #, weight="bold")
  3842. #x=TableFrame(root=w.tk)#,left=80,top=620)
  3843. #w.show()
  3844. #data =[]
  3845. #for a in range(40):
  3846. # data.append(["E","E{}".format(a+1)])
  3847. #x.draw(data=data,head=["E","C"],config=[12,5,5])
  3848. #w=x.bframe
  3849. #window_manager.new(w,name)
  3850. #Xroot = tk.Tk()
  3851. #Xroot["bg"] = "black" #white
  3852. #Xroot.title( xtitle+" "+str(rnd_id) )
  3853. #Xroot.geometry("1024x800+130+65")
  3854. master.render()
  3855. window_manager.top("Table")
  3856. #w = frame_fix #Window("OLD",master=0,width=W1,height=500,left=130,top=TOP)
  3857. window_manager.new(w,name)
  3858. load_window_position()
  3859. #thread.start_new_thread(refresher_fix.loop,())
  3860. #thread.start_new_thread(refresher_exec.loop,())
  3861. thread.start_new_thread(loops,())
  3862. try:
  3863. #root.mainloop()
  3864. #tk.mainloop()
  3865. window_manager.mainloop()
  3866. finally:
  3867. master.exit()