_LibreLightDesk.py 128 KB

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