_LibreLightDesk.py 141 KB

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