_LibreLightDesk.py 115 KB

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