浏览代码

refactory: TK-EXEC, remote-key, REC-FX, cprint/BROKEN-PIPE

micha 8 月之前
父节点
当前提交
05a9cd54c8
共有 11 个文件被更改,包括 335 次插入134 次删除
  1. 86 39
      _LibreLightDesk.py
  2. 5 1
      lib/cprint.py
  3. 41 19
      lib/execlib.py
  4. 5 4
      lib/fixlib.py
  5. 26 5
      lib/jsbc.py
  6. 4 2
      lib/libtk.py
  7. 20 17
      lib/tkevent.py
  8. 18 14
      test-mc-exec.py
  9. 106 23
      tkgui/EXEC.py
  10. 10 8
      tkgui/draw.py
  11. 14 2
      tool/movewin.py

+ 86 - 39
_LibreLightDesk.py

@@ -123,6 +123,9 @@ class Modes():
             return self.set(mode,value)
         elif mode in self.modes:
             return self.modes[mode]
+    def info(self):
+        for m in self.modes:
+            print("modes",m,self.val(m))
     def get(self,mode,value=None):
         return self.val(mode,value)
     def __check(self,mode):
@@ -804,6 +807,9 @@ class cb():
         cprint(color)
         cprint( hex_to_rgb(color[1:]))
 
+
+import copy
+
 def get_exec_btn_cfg(nr):
     k = nr
     if 1:
@@ -830,9 +836,9 @@ def get_exec_btn_cfg(nr):
         fx_color = 0
         if k in EXEC.val_exec and len(EXEC.val_exec[k]) :
             sdata = EXEC.val_exec[k]
-            sdata["CFG"]["HAVE-FX"] = 0
-            sdata["CFG"]["HAVE-VAL"] = 0
-            sdata["CFG"]["FIX-COUNT"] = 0
+            have_fx  = 0
+            have_val = 0
+            fix_count = 0
 
             BTN="go"
             if "CFG" in sdata:#["BUTTON"] = "GO"
@@ -848,23 +854,28 @@ def get_exec_btn_cfg(nr):
                     if fix == "CFG":
                         continue
 
-                    sdata["CFG"]["FIX-COUNT"] += 1
+                    fix_count += 1
 
                     for attr in sdata[fix]:
+                        if attr.startswith("_"):
+                            continue
                         if "FX2" in sdata[fix][attr]:
                             if sdata[fix][attr]["FX2"]:
                                 fx_color = 1
+                                have_fx  += 1
                         if "FX" in sdata[fix][attr]:
                             if sdata[fix][attr]["FX"]:
                                 fx_color = 1
+                                have_fx  += 1
                         if "VALUE" in sdata[fix][attr]:
                             if sdata[fix][attr]["VALUE"] is not None:
                                 val_color = 1
+                                have_val += 1
                     
-                if val_color:
-                    sdata["CFG"]["HAVE-VAL"] += 1
-                if fx_color:
-                    sdata["CFG"]["HAVE-FX"] += 1
+                #if val_color:
+                #    have_val += 1
+                #if fx_color:
+                #    have_fx  += 1
 
 
                 if val_color:
@@ -879,6 +890,10 @@ def get_exec_btn_cfg(nr):
                 _bg = "grey"
                 _ba = "#aaa"
 
+            sdata["CFG"]["HAVE-FX"]   = have_fx  
+            sdata["CFG"]["HAVE-VAL"]  = have_val 
+            sdata["CFG"]["FIX-COUNT"] = fix_count 
+
 
         if "\n" in txt:
             txt1 = txt.split("\n")[0]
@@ -992,28 +1007,30 @@ class MASTER():
                 color2 = color
             if text:
                 text = "\n"+str(text)
-            if name in self.commands.elem:
-                self.commands.elem[name]["bg"] = color
-                self.commands.elem[name]["text"] = name+ text
-                self.commands.elem[name].config(activebackground=color2)
-                if fg:
-                    self.commands.elem[name]["fg"] = fg
-            elif name in self.fx.elem:
-                #todo
-                self.fx.elem[name]["bg"] = color
-                self.fx.elem[name].config(activebackground=color2)
-                if fg:
-                    self.fx.elem[name]["fg"] = fg
+
+            for elem in [self.commands.elem,self.fx.elem,self.fx_main.elem]:#,self.fx_moves]:
+                if name in elem:
+                    print(" in xx.elem OK ",[name,color,name,text,color2])
+                    if name in ["BLIND","CLEAR"] and color == "lightgrey":
+                        color = "grey"
+                        color2 = "grey"
+
+                    elem[name]["bg"] = color
+                    elem[name]["text"] = name+ text
+                    elem[name].config(activebackground=color2)
+                    if fg:
+                        elem[name]["fg"] = fg
 
             # new version
             for elems in [self.fx_moves]:
                 if name in elems.elem:
+                    print(" in fx_moves_elem OK",name)
                     elem = elems.elem[name]
                     cprint("elem",elem)
                     elem.config(bg = color)
                     elem.config(text = name+text)
                     elem.config(activebackground=color2)
-
+            
                     if fg and "fg" in elem:
                         elem["fg"] = fg
         except Exception as e:cprint("exc",self,e)
@@ -1094,13 +1111,14 @@ class MASTER():
         dialog.askstring("LABEL","EXE:"+str(nr+1),initialvalue=txt)
 
     def xcb(self,mode,value=None):
-        cprint("MODE CALLBACK",mode,value,color="green",end="")
+        cprint("  Master.xcb mode:",str(mode).rjust(10," "),value,color="yellow",end="")
         if value:
-            cprint("===== ON  ======",color="red")
+            cprint("===== ON  ======",color="green")
             txt = ""
             if mode == "REC-FX":
-                modes.val("REC",0)
-                modes.val("REC",1)
+                modes.modes["REC"] = 1 # HACK !
+                self.button_refresh("REC",color="red",text=txt)#,fg="blue")
+                self.button_refresh(mode,color="red",text=txt)#,fg="blue")
             if value == 2:
                 if mode in ["MOVE","COPY"]:
                     txt="to"
@@ -1111,9 +1129,13 @@ class MASTER():
                 self.button_refresh(mode,color="red",text=txt)#,fg="blue",text="from")
         else:
             cprint("===== OFF ======",color="red")
+            if mode == "REC":
+                modes.val("REC-FX",0)
             if mode == "REC-FX":
-                modes.val("REC",0)
+                modes.modes["REC"] = 0 # HACK !
+                self.button_refresh("REC",color="lightgrey")#,fg="black")
             self.button_refresh(mode,color="lightgrey")#,fg="black")
+        #modes.info()
 
     def load(self,fname=""):
         pass
@@ -1131,15 +1153,19 @@ class MASTER():
         
         self._XX +=1
         self._nr_ok = 0
-
+        ERR=""
         for nr in EXEC.val_exec: 
             cfg = get_exec_btn_cfg(nr)
-
-            b = self.elem_exec[nr]
-            b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"],fx=cfg["fx"])
-
-
+            try:
+                b = self.elem_exec[nr]
+                b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"],fx=cfg["fx"])
+            except Exception as e:
+                ERR="EXEC WINDOW DOES NOT EXIST !"
+                #cprint(" ERR MASTER._refresh_exec:",e,color="red")
+        #if ERR:
+        #    cprint(" ERR MASTER._refresh_exec:",ERR,color="red")
         time.sleep(0.01)
+
     def refresh_fix(self):
         refresher_fix.reset() # = tkrefresh.Refresher()
     def _refresh_fix(self):
@@ -1279,17 +1305,21 @@ class MASTER():
 
     def exec_rec(self,nr):
         cprint("------- STORE EXEC")
-        data = fixlib.get_active(FIXTURES.fixtures)
+        _filter=""
         if modes.val("REC-FX"):
-            EXEC.rec(nr,data,"REC-FX")
-            modes.val("REC-FX",0)
-        else:
-            EXEC.rec(nr,data)
+            _filter="ONLY-FX"
+
+        data = fixlib.get_active(FIXTURES.fixtures,_filter=_filter)
+        EXEC.rec(nr,data)
             
         sdata=data
         EXEC.val_exec[nr] = sdata
         
-        master._refresh_exec()
+        modes.val("REC-FX",0)
+        modes.val("REC",0)
+        
+        cfg = get_exec_btn_cfg(nr)
+        #master._refresh_exec()
         return 1
 
 
@@ -1650,6 +1680,7 @@ def refresh_exec_mc():
     time.sleep(10)
     while 1:
         try:
+            pass#
             execlib.exec_set_mc(EXEC.label_exec,EXEC.val_exec)
         except Exception as e:
             print("refresh_exec_mc ERR",e)
@@ -1723,11 +1754,22 @@ def open_sdl_window():
 
 thread.start_new_thread(open_sdl_window,())
 
-
 mc_fix = MC_FIX()
 def mc_fix_loop():
+    global master
     time.sleep(5)
+    c=0
     while 1:
+        try:
+            if c >= 1:
+                #master._refresh_exec()
+                c=0
+                for nr in EXEC.val_exec: 
+                    cfg = get_exec_btn_cfg(nr)
+        except Exception as e:
+            print("MC_FIX EXCEPTION",e)
+            #raise e
+        c+=1
         try:
             data = FIXTURES.fixtures 
             mc_fix.set(index="fix",data=data)
@@ -1750,6 +1792,11 @@ if __run_main:
     HTB = 23 # hight of the titlebar from window manager
 
     pos_list = libwin.read_window_position()
+    #geo = libwin.split_window_position(pos_list,name)
+    #args = {"title":name,"master":0,"width":600,"height":113,"left":L1+5,"top":TOP+5+HTB*2+H1}
+    #geo = libwin.split_window_position(pos_list,name)
+    #if geo:
+    #   args.update(geo)
     
 
     data = []

+ 5 - 1
lib/cprint.py

@@ -32,5 +32,9 @@ def cprint(*text,color="blue",space=" ",end="\n"):
     txt += '\033[0m'
     print(txt,end=end)
     #return txt
-    sys.stdout.flush() # to grep output
+    try:
+        sys.stdout.flush() # to grep output
+    except BrokenPipeError as e:
+        print("BROKEN PIPE ERROR CPRINT = EXIT")
+        #exit()
 

+ 41 - 19
lib/execlib.py

@@ -96,6 +96,17 @@ def EXEC_CFG_CHECKER(sdata):
     if "FADE" not in sdata["CFG"]:
         sdata["CFG"]["FADE"] = 4
         ok += 1
+
+    if "HAVE-FX" not in sdata["CFG"]:
+        sdata["CFG"]["HAVE-FX"] = 0
+    if "HAVE-VAL" not in sdata["CFG"]:
+        sdata["CFG"]["HAVE-VAL"] = 0
+    if "FIX-COUNT" not in sdata["CFG"]:
+        sdata["CFG"]["FIX-COUNT"] = 0
+
+    if "DEALY" in sdata["CFG"]: # REMOVE TYPO ! 
+        del sdata["CFG"]["DEALY"]
+
     if "DELAY" not in sdata["CFG"]:
         sdata["CFG"]["DELAY"] = 0
         ok += 1
@@ -130,28 +141,39 @@ def EXEC_CFG_CHECKER(sdata):
     return ok
 
 import time
+
 def exec_set_mc(excec_labels,exec_data):
     l = excec_labels
     d = exec_data
     
-    if mc:
-        index=[]
-        for i,v in enumerate(l):
-            key="EXEC-"+str(i) 
-            mc.set(key,json.dumps(d[v]))
-            index.append(key)
-
-            key2="EXEC-META-"+str(i) 
-            cfg = {'FADE': 3.0, 'DEALY': 0, 'DELAY': 4.0, 'BUTTON': 'ON', 'HTP-MASTER': 100
-                    , 'SIZE-MASTER': 100, 'SPEED-MASTER': 100, 'OFFSET-MASTER': 100, 'OUT-FADE': 10.0}
-            if "CFG" in d[v]:
-                cfg = d[v]["CFG"]
-            mc.set(key2,json.dumps({"LABEL":l[i],"LEN":len(d[v])-1,"CFG":cfg}) )
-            #mc.set(key2,json.dumps({"label":l[i],"LEN":len(d[v])-1,"CFG":cfg}) )
-        mc.set("EXEC-INDEX",json.dumps(index))
-        print("---------------------------------------")
-        #,start - time.time())
-        #
+    if not mc:
+        #cprint("MC not connected !")
+        return 
+
+    index=[]
+    for i,k in enumerate(l):
+        nr = i
+        data = d[k]
+        label=l[nr]
+
+        exec_set_mc_single(nr,label,data)
+    #print("--------------exec_set_mc-------EXEC-META---------------------")
+
+def exec_set_mc_single(nr,label,data):
+    #data = d[v]
+    key="EXEC-"+str(nr) 
+    mc.set(key,json.dumps(data))
+
+    key2="EXEC-META-"+str(nr) 
+    cfg = {'FADE': 2.0, 'DELAY': 0, 'BUTTON': 'GO', 'HTP-MASTER': 100
+            ,'SIZE-MASTER': 100, 'SPEED-MASTER': 100, 'OFFSET-MASTER': 100, 'OUT-FADE': 10.0
+            ,'HAVE-FX': 0, 'HAVE-VAL': 0, 'FIX-COUNT': 11
+          }
+
+    if "CFG" in data:
+        cfg.update(data["CFG"])
+        mc.set(key2,json.dumps({"LABEL":label,"CFG":cfg}) )
+
 
 class EXEC(): #Presets():
     def __init__(self):
@@ -416,7 +438,7 @@ class EXEC(): #Presets():
         return ok
 
     def rec(self,nr,data,arg=""):
-        cprint("rec",self,"rec()",len(data),arg)
+        cprint("rec",self,"rec()",len(data),arg,color="red")
         self.check_cfg(nr)
         self._check_cfg(data) #by ref
 

+ 5 - 4
lib/fixlib.py

@@ -330,7 +330,7 @@ def get_dmx(fixtures,fix,attr):
                 return DMX
     return -199
 
-def get_active(fixtures):
+def get_active(fixtures,_filter=""): #_filter only-fx
     cprint("get_active",id(fixtures))
     CFG = OrderedDict()
 
@@ -352,10 +352,11 @@ def get_active(fixtures):
             if attr not in sdata[fix]:
                 sdata[fix][attr] = OrderedDict()
 
-                if not MAIN.modes.val("REC-FX"):
-                    sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
-                else:
+                if "ONLY-FX" in _filter:
+                    cprint( "          ONLY FX !!!     -------------------- ")
                     sdata[fix][attr]["VALUE"] = None 
+                else:
+                    sdata[fix][attr]["VALUE"] = data["ATTRIBUT"][attr]["VALUE"]
 
                 if "FX" not in data["ATTRIBUT"][attr]: 
                      data["ATTRIBUT"][attr]["FX"] = ""

+ 26 - 5
lib/jsbc.py

@@ -76,7 +76,8 @@ def JSCB(x,sock=None):
                     MAIN.modes.val("REC",1)
                     OK = 1
                 elif "FX-OFF" == msg["event"]:
-                    MAIN.modes.val("FX-OFF",1)
+                    #MAIN.modes.val("FX-OFF",1)
+                    MAIN.CONSOLE.fx_off("all") #"FX-OFF",1)
                     #OK = 1
                 elif "SAVE\nSHOW" == msg["event"]:
                     MAIN.save_show()
@@ -88,8 +89,29 @@ def JSCB(x,sock=None):
                 elif "REC-FX" == msg["event"]:
                     MAIN.modes.val("REC-FX",1)
                     OK = 1
+                elif "REC-EXEC" == msg["event"]:
+                    print("  JSCB.REC-EXEC")
+                    val = -1
+                    exec_nr = -1
+                    try:
+                        if "VAL" in msg:
+                            val = int(msg["VAL"])
+                        if "EXEC" in msg:
+                            exec_nr = int(msg["EXEC"])
+
+                        if val >= 1 and exec_nr > 0: # VAL >=1 !!!
+                            print(" EXEC_GOOO",exec_nr)
+                            s = time.time()
+                            MAIN.master.exec_rec(exec_nr-1)
+                            e = time.time()
+                            print("EXE TIME:","{:0.02f}".format(e-s),int(e*100)/100)
+                            print()
+                            OK = 1
+                    except Exception as e:
+                        print("REC-EXEC ERR:",[e])
+                        raise e
                 elif "EXEC" == msg["event"]:
-                    print("  EXEC EXEC")
+                    print("  JSCB.EXEC")
                     val = -1
                     exec_nr = -1
                     try:
@@ -102,9 +124,6 @@ def JSCB(x,sock=None):
                             s = time.time()
                             MAIN.master.exec_go(exec_nr-1,xfade=None,val=val)
                             e = time.time()
-                            #print("time:",e-s,e)
-                            #print("TIME:",int((e-s)*1000),int(e*10)-1_703_800_000)
-                            #print("TIME:",int((e-s)*1000),int(e*10)/10)
                             print("EXE TIME:","{:0.02f}".format(e-s),int(e*100)/100)
                             print()
                             OK = 1
@@ -113,6 +132,8 @@ def JSCB(x,sock=None):
             
                 if OK:
                     cprint(" remote-key:",msg ,color="green")
+                    if "REC-EXEC" in msg["event"]:
+                        MAIN.execlib.exec_set_mc(MAIN.EXEC.label_exec,MAIN.EXEC.val_exec)
                 else:
                     cprint(" remote-key:",msg ,color="red")
     except Exception as e:

+ 4 - 2
lib/libtk.py

@@ -338,6 +338,7 @@ class BLINKI():
         self.e = e
     def blink(self):
         e = self.e
+        bg = e["bg"]
         e.config(bg='green')
         duration = 150
         for i in range(8):
@@ -350,8 +351,8 @@ class BLINKI():
                 e.after(d, lambda: e.config(activebackground='orange')) # after 1000ms
         i+=1
         duration = 150
-        e.after(d, lambda: e.config(bg='white')) # after 1000ms
-        e.after(d, lambda: e.config(activebackground='white')) # after 1000ms
+        e.after(d, lambda: e.config(bg=bg)) # after 1000ms
+        e.after(d, lambda: e.config(activebackground=bg)) # after 1000ms
 
 class on_focus():
     def __init__(self,name,mode):
@@ -576,6 +577,7 @@ class WindowContainer():
 
         #self._event_clear = MAIN.tk_event(fix=0,elem=None,attr="CLEAR",data=self,mode="ROOT").cb
         self.tk.geometry(geo)
+        print(" INIT.OK?",self.callback,self.args)
         self.show()
 
     def update_idle_task(self):

+ 20 - 17
lib/tkevent.py

@@ -434,9 +434,9 @@ class tk_event_fx():
                 cprint("2D-X: CHANGE",MAIN.fx_prm,color="red")
                 txt = "2D-X:" 
                 MAIN.fx_prm["2D:MODE"] += 1
-                if MAIN.fx_prm["2D:MODE"] >= len(fx_x_modes):
+                if MAIN.fx_prm["2D:MODE"] >= len(MAIN.fx_x_modes):
                     MAIN.fx_prm["2D:MODE"]=0
-                txt = "2D:MODE\n"+fx_x_modes[MAIN.fx_prm["2D:MODE"]]
+                txt = "2D:MODE\n"+MAIN.fx_x_modes[MAIN.fx_prm["2D:MODE"]]
 
                 MAIN.master.fx.elem["2D:MODE"]["text"] = txt
             elif event.num == 5:
@@ -444,8 +444,8 @@ class tk_event_fx():
                 txt = "2D-X:" 
                 MAIN.fx_prm["2D:MODE"] -= 1
                 if MAIN.fx_prm["2D:MODE"] < 0:
-                    MAIN.fx_prm["2D:MODE"]= len(fx_x_modes)-1
-                txt = "2D:MODE\n"+fx_x_modes[MAIN.fx_prm["2D:MODE"]]
+                    MAIN.fx_prm["2D:MODE"]= len(MAIN.fx_x_modes)-1
+                txt = "2D:MODE\n"+MAIN.fx_x_modes[MAIN.fx_prm["2D:MODE"]]
                 MAIN.master.fx.elem["2D:MODE"]["text"] = txt
 
         elif event.num == 1:
@@ -473,7 +473,8 @@ class tk_event_fx():
 
 
     def command(self,event,mode=""):       
-        cprint("fx_command",self.mode)
+        cprint("tkevent.tk_event_fx.command")
+        cprint(" ",self.mode)
         if self.mode == "FX":
             prm = MAIN.fx_prm
             ct = self.data.fx 
@@ -511,7 +512,7 @@ class tk_event_fx():
                 if prm[k] == 6: #bug
                     prm[k] =5
                 ct.elem[self.attr]["text"] = "SIZE:\n{:0.0f}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("SPEED:"):#SIN":
                 #global prm
                 k = "SPEED"
@@ -551,7 +552,7 @@ class tk_event_fx():
                     ct.elem[self.attr]["text"] = "SPEED:\noff".format(prm[k])
                 else:
                     ct.elem[self.attr]["text"] = "SPEED:\n{:0.02f}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("START:"):#SIN":
                 #global prm
                 k = "START"
@@ -575,7 +576,7 @@ class tk_event_fx():
                     prm[k] =5
 
                 ct.elem[self.attr]["text"] = "START:\n{:0.0f}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("WIDTH:"):#SIN":
                 #global prm
                 k = "WIDTH"
@@ -631,7 +632,7 @@ class tk_event_fx():
                     prm[k] =100
 
                 ct.elem[self.attr]["text"] = "WIDTH:\n{:0.0f}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("DIR:"):#SIN":
                 #global prm
                 k = "DIR"
@@ -645,7 +646,7 @@ class tk_event_fx():
                     prm[k] =-1
                 txt = prm[k] 
                 ct.elem[self.attr]["text"] = "DIR:\n{}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("SHUFFLE:"):#SIN":
                 #global prm
                 k = "SHUFFLE"
@@ -660,7 +661,7 @@ class tk_event_fx():
                 if prm[k] == 6: #bug ?
                     prm[k] =5
                 ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("INVERT:"):#SIN":
                 #global prm
                 k = "INVERT"
@@ -675,7 +676,7 @@ class tk_event_fx():
                 if prm[k] == 6: #bug ?
                     prm[k] =5
                 ct.elem[self.attr]["text"] = k+":\n{}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("2D-X:"):#SIN":
                 #global prm
                 k = "2D-X"
@@ -694,7 +695,7 @@ class tk_event_fx():
                     
                 txt = prm[k] 
                 ct.elem[self.attr]["text"] = "2D-X:\n{}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("WING:"):#SIN":
                 #global prm
                 k = "WING"
@@ -713,7 +714,7 @@ class tk_event_fx():
                     
                 txt = prm[k] 
                 ct.elem[self.attr]["text"] = "WING:\n{}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("OFFSET:"):#SIN":
                 #global prm
                 k = "OFFSET"
@@ -739,7 +740,7 @@ class tk_event_fx():
                     prm[k] =5
 
                 ct.elem[self.attr]["text"] = "OFFSET:\n{:0.0f}".format(prm[k])
-                cprint(prm)
+                cprint("  ",prm)
             elif self.attr.startswith("BASE:"):
                 k = "BASE"
                 if event.num == 1:
@@ -766,13 +767,15 @@ class tk_event_fx():
 
                 #if event.num == 1:
             elif self.attr == "REC-FX":
-                cprint("ELSE",self.attr)
+                cprint("  ",self.attr)
                 MAIN.modes.val(self.attr,1)
+                #MAIN.modes.val(self.attr,1)
+                #MAIN.modes.val("REC",1)
 
             return 0
             
     def cb(self,event):
-        cprint("EVENT_fx cb",self.attr,self.mode,event,color='yellow')
+        cprint("tkevent.EVENT_fx.cb:",self.attr,self.mode,event,color='yellow')
         cprint(["type",event.type,"num",event.num])
         try:
             change = 0

+ 18 - 14
test-mc-exec.py

@@ -24,24 +24,24 @@ if mc:
 
         #x = mc.get("EXEC-INDEX") #,json.dumps(index))
         x = mc.get("EXEC-META-"+str(i)) #,json.dumps(index))
-        print( i, json.loads(x) )
+        #print( i, json.loads(x) )
 
         #for j in json.loads(x):
         #    y = mc.get(i) #,json.dumps(index))
         #   print(i,len(y))
         #break
-print()
+#print()
 i=77-1
 x = mc.get("EXEC-META-"+str(i)) #,json.dumps(index))
-print( i, json.loads(x) )
+#print( i, json.loads(x) )
 i=80-1
 x = mc.get("EXEC-META-"+str(i)) #,json.dumps(index))
-print( i, json.loads(x) )
-print()
+#print( i, json.loads(x) )
+#print()
 
-print(start- time.time())
+#print(start- time.time())
 import sys
-nr=0
+nr=1
 if len(sys.argv) >= 2:
     try:
         nr=int(sys.argv[1])
@@ -49,16 +49,20 @@ if len(sys.argv) >= 2:
 #y = mc.get("EXEC-"+str(nr)) #,json.dumps(index))
 y = mc.get("EXEC-"+str(nr)) #,json.dumps(index))
 if y:
-    print(len(y))
+    # print(len(y))
     try:
-        print(json.loads(y))
+        pass
+        #print(json.loads(y))
     except Exception as e:
         print("ERR",e)
-
-k = "EXEC-META-"+str(nr)
+print()
+k = "EXEC-META-"+str(nr-1)
 y = mc.get(k) #,json.dumps(index))
+print(y)
+print()
 y = json.loads(y)
-y["LABEL"]=str(int(y["LABEL"])+100)
-print([k,y])
-y = mc.set(k,json.dumps(y)) #,json.dumps(index))
+print(k,y)
+#y["LABEL"]=str(int(y["LABEL"])+100)
+#print([k,y])
+#y = mc.set(k,json.dumps(y)) #,json.dumps(index))
 #y = mc.set("EXEC-META-"+str(nr),y) #,json.dumps(index))

+ 106 - 23
tkgui/EXEC.py

@@ -12,8 +12,12 @@ DIALOG = dialog.Dialog()
 #d = dialog.Dialog()
 #d.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
 
+CAPTION = "TK-EXEC"
+title = CAPTION
+
 import __main__ as MAIN
 
+_file_path = "/opt/LibreLight/Xdesk/"
 sys.path.insert(0,"/opt/LibreLight/Xdesk/")
 
 INIT_OK = 1
@@ -24,6 +28,10 @@ import tkgui.draw as draw
 import lib.libtk as libtk
 import lib.zchat as chat
 
+import tool.movewin as movewin
+#movewin.check_is_started(CAPTION,_file_path)
+movewin.check_is_started("EXEC","/opt/LibreLight/Xdesk/tkgui/EXEC.py")
+
 _global_short_key = 1
 root = None
 
@@ -95,9 +103,12 @@ class Gui(): # DUMMY
     def __init__(self):
         self.elem_exec = []
         self.elem_meta = [None]*512
+        self.METAS = []
+        for i in range(512):
+            self.METAS.append({})
 
     def _refresh_exec(self,*arg,**args):
-        print("EXEC_Gui._refresh_exec",arg,args)
+        #print("EXEC_Gui._refresh_exec",arg,args)
 
         nr = 14-1
 
@@ -111,8 +122,21 @@ class Gui(): # DUMMY
             except Exception as e:
                 print("  ER1R mc...",e)
 
+        self.METAS = METAS
 
         for nr,b in enumerate( self.elem_exec): #[nr]
+            self._refresh_exec_single(nr,b,METAS)
+
+    def _refresh_exec_single(self,nr,b,METAS=None):
+            if not METAS:
+                try:
+                    data = mc.get("EXEC-META-"+str(nr)) #,json.dumps(index))
+                    data = json.loads(data)
+                    self.METAS[nr] = data #.append(data)
+                except Exception as e:
+                    print("  ER1R mc...",e)
+
+                METAS = self.METAS
             _bg = "grey"
             _ba = "grey"
             _bg = "grey"
@@ -129,18 +153,16 @@ class Gui(): # DUMMY
             out["fg"] = _fg
             out["text"] = _text #"? "+str(nr+1)
 
-            META = {'LABEL': 'ERR', 'LEN': 2, 'CFG': {}}
-            META["CFG"] = {'FADE': 3.0, 'DEALY': 0, 'DELAY': 4.0, 'BUTTON': 'ON', 'HTP-MASTER': 100,
-                         'SIZE-MASTER': 100, 'SPEED-MASTER': 100, 'OFFSET-MASTER': 100, 'OUT-FADE': 10.0}
+            META = {'LABEL': 'ERR',  'CFG': {}}
+            META["CFG"] = {'FADE': 3.0, 'DEALY': 0, 'DELAY': 4.0, 'BUTTON': 'ON', 'HTP-MASTER': 100
+                           ,'SIZE-MASTER': 100, 'SPEED-MASTER': 100, 'OFFSET-MASTER': 100, 'OUT-FADE': 10.0
+                           ,'FIX-COUNT':0 ,'HAVE-FX':0,'HAVE-VAL':0
+                         }
             
             try: 
                 META = METAS[nr]
-                label = "{} {} {}\n{}".format(nr+1,META["CFG"]["BUTTON"],META["LEN"],META["LABEL"])
+                label = "{} {} {}\n{}".format(nr+1,META["CFG"]["BUTTON"],META["CFG"]["FIX-COUNT"],META["LABEL"])
                 out["text"] = str(label)
-                LEN = META["LEN"] #int(label.split("\n")[0].split()[-1])
-                if LEN: # >= 3:
-                    _bg = "orange" #yellow"
-                    _fg = "black" #grey"
 
             except Exception as e:
                 print("  ER4R",e,nr)
@@ -150,8 +172,10 @@ class Gui(): # DUMMY
             except:
                 pass
 
+            if  META["CFG"]["FIX-COUNT"]: 
+                _fg = "black"
                 
-            if META["LEN"]:
+            if  META["CFG"]["HAVE-VAL"]: 
                 _fg = "black"
                 _bg = "gold"
                 _ba = "#ffaa55"
@@ -187,8 +211,7 @@ class Gui(): # DUMMY
 
     def exec_go(self,*arg,**args):
         print("Gui.exec_go",arg,args)
-        #print(" ",dir(arg))
-        #print(" ",self)
+
         btn_nr = arg[0]
         v=args["val"]
         if "CFG-BTN" in modes.modes:
@@ -202,10 +225,23 @@ class Gui(): # DUMMY
                 label = META["LABEL"]
                 button = cfg["BUTTON"]
                 DIALOG.ask_exec_config(str(btn_nr+1),button=button,label=label,cfg=cfg)
-            return 
-        msg=json.dumps([{"event":"EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}]).encode("utf-8")
+            return #STOP
+
+        PREFIX = ""
+        for k in ["REC","EDIT"]: #,"DEL","SELECT","FLASH","GO","EDIT"]:
+            if k in modes.modes:
+                PREFIX = str(k) +"-"
+                
+
+        msg=json.dumps([{"event":PREFIX+ "EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}]).encode("utf-8")
         cprint("SEND GUI.EXEC_GO",msg,color="green")
         cmd_client.send(msg)
+        if "REC" in PREFIX:
+            time.sleep(0.2)
+            print("REC REFRESH !?")
+            nr = btn_nr
+            b = self.elem_exec[nr]
+            self._refresh_exec_single(nr,b) #,METAS):
 
 gui  = Gui()
  
@@ -220,9 +256,43 @@ gui  = Gui()
 #    time.sleep(1)
 
 
+import lib.libwin as libwin
+name="EXEC"
+pos_list = libwin.read_window_position()
+geo = libwin.split_window_position(pos_list,name)
+args = {"title":name,"master":0,"width":600,"height":113,"left":30+5,"top":30+5+400*2+10}
+if geo:
+   args.update(geo)
 
 root = tk.Tk()
 
+win_title="TK-EXEC"
+store = movewin.load_all_sdl(win_title)
+print(store)
+W=850
+H=460
+POS=None
+if store:
+    W = store[-4]
+    H = store[-3]
+    POS=[store[-2],store[-1]]
+
+
+root.geometry('%dx%d+%d+%d' % (W, H, POS[0],POS[1]))
+
+#win_con = movewin.Control()
+#win_con.title = win_title
+#def asdf(event=None):
+#    time.sleep(3)
+#    win_con.winfo()
+#    if POS:
+#        #print(" REPOS ---")
+#        win_con.move(POS[0],POS[1])
+#thread.start_new_thread(asdf,())
+#print(POS,win_con.title)
+
+
+
 #root.withdraw() # do not draw
 #root.resizable(1,1)
 root.tk_setPalette(background='#bbb', foreground='black', activeBackground='#aaa', activeForeground="black")
@@ -243,7 +313,7 @@ except Exception as e:
 xframe = libtk.ScrollFrame(root,width=820,height=400,bd=1,bg="black",head=None,foot=None)
 draw.draw_exec(gui,xframe,EXEC)
 #xframe.pack()
-root.title("TK-EXEC 2")
+root.title("TK-EXEC")
 
 def serialize_event(event):
     data = {}
@@ -256,15 +326,29 @@ def serialize_event(event):
         if type(v) not in [int,str,float]:
             continue
         data[k] = v
-    return data
+
+    data["event"] = str(event).split()[0][1:]
+    if "state" in data:
+        del data["state"]
+    if "time" in data:
+        del data["time"]
+    if "serial" in data:
+        del data["serial"]
+    keys = list(data.keys())
+    keys.sort()
+    data2={}
+    for k in keys:
+        data2[k] = data[k] 
+    return data2
 
 def tk_event(event,data={}):
-    print("tk_event",event,data)
+    #print("tk_event",event,data)
     if _global_key_lock:
         return
     #print("   ",dir(event)) #.dict())
     data =  serialize_event(event)
-    print("   ",data)
+
+    print("tk_event",data)
     ok=0
     if 'keysym' in data:
         if data['keysym'] == 'End':
@@ -318,17 +402,16 @@ def _refr_loop():
     time.sleep(3)
     while 1:
         gui._refresh_exec()
-        time.sleep(3)
+        time.sleep(0.2)
 thread.start_new_thread(_refr_loop,())
 
 def _refr_loop2():
     time.sleep(3)
     while 1:
         try:
-            global root
-            title = "TK-EXEC"
+            global root,title
             data = mc.get("MODES")
-            title += "  "+str(data)
+            title2 = title +"  "+str(data)
             data = json.loads(data)
             #print("MODES",data)
             modes.modes = data
@@ -337,7 +420,7 @@ def _refr_loop2():
                 if data["S-KEY"]:
                     _global_short_key = 1
             if root:
-                root.title(title)
+                root.title(title2)
         except Exception as e:
             print("  ER7R mc...",e)
             time.sleep(3)

+ 10 - 8
tkgui/draw.py

@@ -44,7 +44,7 @@ def draw_command(gui,xframe,data):
         v=0
         
         b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-        if comm not in gui.commands.elem:
+        if 1:#comm not in gui.commands.elem:
             gui.commands.elem[comm] = b
             gui.commands.val[comm] = 0
         if comm == "BLIND":
@@ -159,7 +159,6 @@ def draw_exec(gui,xframe,EXEC):
 
 
 def draw_input(gui,root2):
-
     i=0
     c=0
     r=0
@@ -513,7 +512,7 @@ def _draw_fx(frame,c,r,gui,mode="FX"):
             b = tk.Button(frame,bg="grey", text=str(comm),width=6,height=2)
         else:
             b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-        if comm not in ct.elem:
+        if 1:#comm not in ct.elem:
             #comm = comm.replace("\n","")
             ct.elem[comm] = b
             ct.val[comm] = 0
@@ -659,7 +658,7 @@ def draw_setup(gui,xframe,data):
         else: #empty
             b = tk.Button(frame,bg="grey", text="",width=6,height=2)
 
-        if comm not in gui.commands.elem:
+        if 1:# comm not in gui.commands.elem:
             gui.setup_elem[comm] = b
             #gui.setup_elem.val[comm] = 0
 
@@ -689,6 +688,8 @@ def draw_setup(gui,xframe,data):
 
 
 def draw_live(gui,xframe,data):
+    cprint("CREATE: draw_live")
+    cprint(" ",gui,xframe,data)
     frame_cmd=xframe
     i=0
     c=0
@@ -697,8 +698,9 @@ def draw_live(gui,xframe,data):
     frame = tk.Frame(frame_cmd,bg="black")
     frame.pack(fill="both",expand=1, side="left")#tk.TOP)
    
-    c+=1
-    for comm in ["FADE","DELAY","PAN/TILT\nFADE","PAN/TILT\nDELAY"]:
+    comms=["FADE","DELAY","PAN/TILT\nFADE","PAN/TILT\nDELAY","-","-"]
+
+    for comm in comms:
         if comm == "\n":
             c=0
             r+=1
@@ -706,7 +708,7 @@ def draw_live(gui,xframe,data):
         v=0
         
         b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-        if comm not in gui.commands.elem:
+        if 1:#comm not in gui.commands.elem:
             gui.commands.elem[comm] = b
             gui.commands.val[comm] = 0
         b.bind("<Button>",tkevent.tk_event(fix=0,elem=b,attr=comm,data=gui,mode="LIVE").cb)
@@ -724,7 +726,7 @@ def draw_live(gui,xframe,data):
         if comm:
             b.grid(row=r, column=c, sticky=tk.W+tk.E)
         c+=1
-        if c >=5:
+        if c >=7:
             c=0
             r+=1
 

+ 14 - 2
tool/movewin.py

@@ -38,6 +38,7 @@ class Control():
     def move(self,x=None,y=None):
         if self.winid:
             cmd=movewin(_id=self.winid,x=x,y=y)
+            print("movewin.move:",cmd)
             system(cmd)
     def size(self,x=None,y=None):
         if self.winid:
@@ -132,12 +133,13 @@ def get_store_sdl_line():
     #print()
     #print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
     lines = winfo2(name="SDL-")
+    lines.extend( winfo2(name="TK-"))
     out_lines=[]
     for line in lines:
         t=line[2].split()
         for k in t:
             k = k.replace(" ", "_")
-            if "SDL-" in k:
+            if "SDL-" in k or "TK-" in k:
                 s=line[-2]
                 p=line[-1]
 
@@ -213,6 +215,11 @@ def startup_all_sdl():
                         cmd=cmd.format("fix.py")
                         #r=os.popen(cmd)
                         start_sub(cmd,"SDL-FIX",mute=1)
+                    elif line[1] == "TK-EXEC":
+                        cmd = "python3 /opt/LibreLight/Xdesk/tkgui/{}"
+                        cmd=cmd.format("EXEC.py")
+                        #r=os.popen(cmd)
+                        start_sub(cmd,"TK-EXEC",mute=1)
                 except json.decoder.JSONDecodeError as e:
                     cprint("ERR",e,color="red")
             time.sleep(0.3)
@@ -287,6 +294,7 @@ def movewin(_id="0xWinId",x=None,y=None):
     print()
     #print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
     cmd="xdotool windowmove {} {} {}".format(_id,x,y)
+    print("movewin.movewin:",cmd)
     return cmd
 
 def sizewin(_id="0xWinId",x=None,y=None):
@@ -408,7 +416,11 @@ def check_is_started(CAPTION,_file_path,sleep=0):
         _ids = winfo(search)
         for _id in _ids:
             c3  = activate(_id)
-            print("check_is_started CMD:",c3)
+            print()
+            print(" check_is_started CMD:",c3)
+            print(" EXIT",_file_path,CAPTION)
             os.system(c3)
         time.sleep(1)
+        print(" EXIT",_file_path,CAPTION)
+        print()
         sys.exit()