execlib.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. #/usr/bin/python3
  2. import copy
  3. import __main__ as MAIN
  4. from lib.cprint import cprint
  5. from collections import OrderedDict
  6. def reshape_exec(data ,value=None,xfade=0,flash=0,ptfade=0,DELAY=None):
  7. f=0 #fade
  8. out = []
  9. delay=0
  10. for row in data:
  11. #cprint("reshape_exec in:",row)
  12. line = {}
  13. line["DELAY"]=delay
  14. if type(value) is float:
  15. line["VALUE"] = value #round(value,3)
  16. else:
  17. line["VALUE"] = value
  18. if "FX" not in row:
  19. cprint("698 FX not in row...",row,color="red")
  20. row["FX"] = ""
  21. else:
  22. if type(row["FX"]) is not str:
  23. cprint("702 FX is not str...",row,color="red")
  24. row["FX"] = ""
  25. if value is not None:
  26. line["FX"] = row["FX"].split(":",1)[-1]
  27. else:
  28. line["FX"] = row["FX"]
  29. if row["FX2"]:
  30. line["FX2"] = row["FX2"]
  31. if row["FIX"]:
  32. line["FIX"] = row["FIX"]
  33. if row["ATTR"]:
  34. line["ATTR"] = row["ATTR"]
  35. if row["VALUE"] is not None:
  36. if value is None:
  37. v=row["VALUE"]
  38. if type(v) is float:
  39. line["VALUE"] = v #round(v,3)
  40. else:
  41. line["VALUE"] = v
  42. if row["ATTR"] in ["PAN","TILT"]:
  43. f = ptfade
  44. for a in ["DIM","ZOOM","FOCUS","RED","GREEN","BLUE","WHITE","AMBER","IRIS","BLADE"]:
  45. #FADE ATTRIBUTES
  46. if a in row["ATTR"]:
  47. f = xfade
  48. break
  49. if flash:
  50. xfade = 0
  51. if type( f ) is float:
  52. line["FADE"] = round(f,4)
  53. else:
  54. line["FADE"] = f
  55. if 0:
  56. cprint("reshape_exec j",line,color="red")
  57. #cprint("reshape_exec out:",line)
  58. out.append(line)
  59. if DELAY:
  60. if DELAY._is():
  61. delay+=DELAY.val()/100 #0.02
  62. return out
  63. import lib.showlib as showlib
  64. def EXEC_CFG_CHECKER(sdata):
  65. "repair CFG "
  66. ok = 0
  67. if "CFG" not in sdata:
  68. sdata["CFG"] = OrderedDict()
  69. ok += 1
  70. if "FADE" not in sdata["CFG"]:
  71. sdata["CFG"]["FADE"] = 4
  72. ok += 1
  73. if "DELAY" not in sdata["CFG"]:
  74. sdata["CFG"]["DELAY"] = 0
  75. ok += 1
  76. if "BUTTON" not in sdata["CFG"]:
  77. sdata["CFG"]["BUTTON"] = "GO"
  78. ok += 1
  79. if "HTP-MASTER" not in sdata["CFG"]:
  80. sdata["CFG"]["HTP-MASTER"] = 100 #%
  81. ok += 1
  82. if "SIZE-MASTER" not in sdata["CFG"]:
  83. sdata["CFG"]["SIZE-MASTER"] = 100 #%
  84. ok += 1
  85. if "SPEED-MASTER" not in sdata["CFG"]:
  86. sdata["CFG"]["SPEED-MASTER"] = 100 #%
  87. ok += 1
  88. if "OFFSET-MASTER" not in sdata["CFG"]:
  89. sdata["CFG"]["OFFSET-MASTER"] = 100 #%
  90. ok += 1
  91. #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
  92. #except:pass
  93. return ok
  94. class EXEC(): #Presets():
  95. def __init__(self):
  96. self.base = showlib.Base()
  97. self._last_copy = None
  98. self._last_move = None
  99. self.fx_buffer = {}
  100. def load_exec(self):
  101. filename="exec"
  102. filename="presets" # preset.sav
  103. d,l = self.base._load(filename)
  104. for i in d:
  105. sdata = d[i]
  106. ok = EXEC_CFG_CHECKER(sdata)
  107. self.val_exec = d
  108. self.label_exec = l
  109. def check_cfg(self,nr=None):
  110. cprint("EXEC.check_cfg()",nr)#,color="red")
  111. ok = 0
  112. if nr is not None:
  113. if nr in self.val_exec:
  114. sdata = self.val_exec[nr]
  115. ok += self._check_cfg(sdata)
  116. else:
  117. cprint("nr not in data ",nr,color="red")
  118. else:
  119. for nr in self.val_exec:
  120. sdata = self.val_exec[nr]
  121. ok += self._check_cfg(sdata)
  122. return ok
  123. def _check_cfg(self,sdata):
  124. cprint("EXEC._check_cfg()")#,color="red")
  125. ok = EXEC_CFG_CHECKER(sdata)
  126. if ok:
  127. cprint("REPAIR CFG's",ok,sdata["CFG"],color="red")
  128. return ok
  129. def backup_exec(self,save_as="",new=0):
  130. filename = "exec" # new
  131. filename = "presets" # preset.sav
  132. data = self.val_exec
  133. labels = self.label_exec
  134. if new:
  135. data = [] #*512
  136. labls = [""]*512
  137. r=self.base._backup(filename,data,labels,save_as)
  138. return r
  139. def get_cfg(self,nr):
  140. cprint("EXEC.get_cfg()",nr)
  141. self.check_cfg(nr)
  142. if nr not in self.val_exec:
  143. cprint("get_cfg",self,"error get_cfg no nr:",nr,color="red")
  144. return {}
  145. if "CFG" in self.val_exec[nr]:
  146. return self.val_exec[nr]["CFG"]
  147. def clean(self,nr):
  148. if nr not in self.val_exec:
  149. self.val_exec[nr] = OrderedDict()
  150. #self.val_exec[nr]["VALUE"] = 0
  151. #self.val_exec[nr]["FX"] = ""
  152. sdata = self.val_exec[nr]
  153. for fix in sdata:
  154. #print("exec.clear()",nr,fix,sdata[fix])
  155. for attr in sdata[fix]:
  156. row = sdata[fix][attr]
  157. if fix == "CFG":
  158. continue
  159. if "VALUE" not in row:
  160. row["VALUE"] = None
  161. if "FX" not in row:
  162. row["FX"] = ""
  163. if "FX2" not in row:
  164. row["FX2"] = OrderedDict()
  165. elif row["FX2"]:
  166. for k in ["SIZE","SPEED","START","OFFSET"]:
  167. row["FX2"][k] = int( row["FX2"][k] )
  168. row["FX"] = ""
  169. if "FX" in row and row["FX"] and not row["FX2"]: # rebuild old FX to Dict-FX2
  170. #"off:0:0:0:16909:-:"
  171. x = row["FX"].split(":")
  172. cprint("-fx",x,len(x))
  173. #'FX2': {'TYPE': 'sinus', 'SIZE': 200, 'SPEED': 30, 'START': 0, 'OFFSET': 2805, 'BASE': '-'}}
  174. if len(x) >= 6:
  175. row["FX2"]["TYPE"] = x[0]
  176. row["FX2"]["SIZE"] = int(x[1])
  177. row["FX2"]["SPEED"] = int(x[2])
  178. row["FX2"]["START"] = int(x[3])
  179. row["FX2"]["OFFSET"] = int(x[4])
  180. row["FX2"]["BASE"] = x[5]
  181. row["FXOLD"] = row["FX"]
  182. row["FX"] = ""
  183. #cprint("exec.clear()",nr,fix,row)
  184. def get_raw_map(self,nr):
  185. self.clean(nr)
  186. cprint("get_raw_map",nr)
  187. sdata = self.val_exec[nr]
  188. cmd = ""
  189. out = []
  190. dmx=-1
  191. for fix in sdata:
  192. if fix == "CFG":
  193. #print("CFG",nr,sdata[fix])
  194. continue
  195. for attr in sdata[fix]:
  196. x = {}
  197. #print("RAW",attr)
  198. x["FIX"] = fix
  199. x["ATTR"] = attr
  200. x["VALUE"] = sdata[fix][attr]["VALUE"]
  201. x["FX"] = sdata[fix][attr]["FX"]
  202. x["FX2"] = sdata[fix][attr]["FX2"]
  203. #x["DMX"] = sdata[fix][attr]["NR"]
  204. out.append(x)
  205. return out
  206. def get_btn_txt(self,nr):
  207. sdata=self.val_exec[nr]
  208. BTN="go"
  209. if "CFG" in sdata:
  210. if "BUTTON" in sdata["CFG"]:
  211. BTN = sdata["CFG"]["BUTTON"]
  212. _label = self.label_exec[nr] # = label
  213. #txt=str(nr+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+_label
  214. #txt=str(nr+1)+" "+str(BTN)+" "+str(len(sdata)-1)+"\n"+_label
  215. txt="{} {} {}\n{}".format(nr+1,BTN,len(sdata)-1,_label)
  216. cprint("get_btn_txt",nr,[txt])
  217. return txt
  218. def _btn_cfg(self,nr,txt=None):
  219. if nr not in self.val_exec:
  220. return ""
  221. if "CFG" not in self.val_exec[nr]:
  222. self.val_exec[nr]["CFG"] = OrderedDict()
  223. return self.val_exec[nr]["CFG"]
  224. def btn_cfg(self,nr,txt=None):
  225. if nr not in self.val_exec:
  226. return ""
  227. if "CFG" not in self.val_exec[nr]:
  228. self.val_exec[nr]["CFG"] = OrderedDict()
  229. if "BUTTON" not in self.val_exec[nr]["CFG"]:
  230. self.val_exec[nr]["CFG"]["BUTTON"] = ""
  231. if type(txt) is str:
  232. self.val_exec[nr]["CFG"]["BUTTON"] = txt
  233. if self.val_exec[nr]["CFG"]["BUTTON"] is None:
  234. self.val_exec[nr]["CFG"]["BUTTON"] = ""
  235. MAIN.master._refresh_exec(nr=nr)
  236. cprint("EEE", self.val_exec[nr]["CFG"]["BUTTON"] )
  237. return self.val_exec[nr]["CFG"]["BUTTON"]
  238. def label(self,nr,txt=None):
  239. if nr not in self.label_exec:
  240. return ""
  241. if type(txt) is str:
  242. self.label_exec[nr] = txt
  243. cprint("set label",nr,[txt])
  244. cprint("??? ?? set label",nr,[txt])
  245. return self.label_exec[nr]
  246. def clear_move(self):
  247. cprint("EXEC.clear_move()",end=" ")
  248. self.clear_copy()
  249. def clear_copy(self):
  250. cprint("EXEC.clear_copy()",end=" ")
  251. if self._last_copy is not None:
  252. cprint("=OK=",color="red")
  253. self._last_copy = None
  254. else:
  255. cprint("=NONE=",color="green")
  256. def copy(self,nr,overwrite=1):
  257. cprint("EXEC._copy",nr,"last",self._last_copy)
  258. if nr >= 0:
  259. if self._last_copy is not None:
  260. if MAIN.modes.val("COPY"):
  261. MAIN.modes.val("COPY",3)
  262. ok = self._copy(self._last_copy,nr,overwrite=overwrite)
  263. return ok #ok
  264. else:
  265. if MAIN.modes.val("COPY"):
  266. MAIN.modes.val("COPY",2)
  267. self._last_copy = nr
  268. cprint("EXEC.copy START ",color="red")
  269. return 0
  270. return 1 # on error reset move
  271. def _copy(self,nr_from,nr_to,overwrite=1):
  272. cprint("EXEC._copy",nr_from,"to",nr_to)
  273. self.check_cfg(nr_from)
  274. if type(self._last_copy) is None:
  275. cprint("EXEC._copy last nr is None",color="red")
  276. return 0
  277. cprint("------ EXEC._copy", nr_from in self.val_exec , nr_to in self.val_exec)
  278. if nr_from in self.val_exec and nr_to in self.val_exec:
  279. fdata = self.val_exec[nr_from]
  280. tdata = self.val_exec[nr_to]
  281. #cprint(fdata)
  282. flabel = self.label_exec[nr_from]
  283. tlabel = self.label_exec[nr_to]
  284. self.val_exec[nr_to] = copy.deepcopy(fdata)
  285. self.label_exec[nr_to] = flabel
  286. if not overwrite: #default
  287. cprint("overwrite",overwrite)
  288. self.val_exec[nr_from] = copy.deepcopy(tdata)
  289. self.label_exec[nr_from] = tlabel
  290. #self.label_exec[nr_from] = "MOVE"
  291. self.clear_copy()
  292. cprint("EXEC.copy OK",color="green")
  293. return 1
  294. def move(self,nr):
  295. cprint("EXEC.move",self._last_copy,"to",nr)
  296. if nr >= 0:
  297. last = self._last_copy
  298. if MAIN.modes.val("MOVE"):
  299. MAIN.modes.val("MOVE",2)
  300. ok= self.copy(nr,overwrite=0)
  301. if ok and last >= 0:
  302. if MAIN.modes.val("MOVE"):
  303. MAIN.modes.val("MOVE",3)
  304. cprint("EXEC.move OK",color="red")
  305. #self.delete(last)
  306. return ok,nr,last #ok
  307. return 0,nr,last # on error reset move
  308. def delete(self,nr):
  309. cprint("EXEC.delete",nr)
  310. ok=0
  311. if nr in self.val_exec:
  312. self.val_exec[nr] = OrderedDict()
  313. self.label_exec[nr] = "-"
  314. ok = 1
  315. self.check_cfg(nr)
  316. return ok
  317. def rec(self,nr,data,arg=""):
  318. cprint("rec",self,"rec()",len(data),arg)
  319. self.check_cfg(nr)
  320. self._check_cfg(data) #by ref
  321. odata=self.val_exec[nr]
  322. #print("odata",odata)
  323. if "CFG" in odata:
  324. if "BUTTON" in odata["CFG"]:
  325. data["CFG"]["BUTTON"] = odata["CFG"]["BUTTON"]
  326. self.val_exec[nr] = data
  327. return 1