_LibreLightDesk.py 139 KB

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