Browse Source

create meta.py add: FX3.py

micha 3 months ago
parent
commit
fa03c018e0
6 changed files with 873 additions and 58 deletions
  1. 36 49
      _LibreLightDesk.py
  2. 1 1
      lib/fixlib.py
  3. 3 3
      lib/libtk.py
  4. 68 0
      lib/meta.py
  5. 760 0
      tkgui/FX3.py
  6. 5 5
      tkgui/draw.py

+ 36 - 49
_LibreLightDesk.py

@@ -1058,7 +1058,7 @@ class Elem_Container():
 
 
 import lib.execlib as execlib
-
+import lib.meta as meta
 
 class MASTER():
     def __init__(self):
@@ -1066,56 +1066,19 @@ class MASTER():
         self.load()
         self._XX = 0
 
-        self.all_attr =["DIM","PAN","TILT"]
+        self.all_attr =["DIM","PAN","TILT"] # encoder
         self.elem_attr = {}
         
-        self.setup_elem = {} # Elem_Container()
-        self.setup_cmd  = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI","PRO\nMODE"]
-        self.setup_cmd  = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","PRO\nMODE"]
-
-        self.fx_main = Elem_Container()
-        self.fx_main.commands =["REC-FX","FX OFF","\n"]
-        self.fx_moves = Elem_Container()
-        self.fx_moves.commands =[
-                "FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
-                "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
-                ]
-        self.fx_3 = Elem_Container()
-        self.fx_3.commands =[
-                "FX:ATTR","PAN","TILT","ATTR3","ATTR4","\n",
-                "TYPE:","SIN","COS"," "," ","\n",
-                "WIDTH:","25","25","25","25","\n",
-                "SIZE:","255","255","255","255","\n",
-                "SPEED:","10","10","10","10","\n",
-                "OFFSET:","100","100","100","100","\n",
-                "START:","0","0","0","0","\n",
-                "SHUFFLE:","0","0","0","0","\n",
-                "DIR:","1","1","1","1","\n",
-                "INVERT:","1","1","1","1","\n",
-                " ","\n",
-                " ","PLAY","STOP","OFF","\n",
-                "  ","CIRCL","PAN","TILT","FLAY","\n",
-                " ","RED","GREEN","BLUE","MAGENTA","\n",
-                "\n",
-                ]
-                #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
-
-        self.fx = Elem_Container()
-        self.fx.commands =[
-                "FX:DIM"," ", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
-                ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","2D-X:\n-","2D:MODE"
-                ]
-        self.fx_generic = Elem_Container()
-        self.fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","FX:STATIC"]
-
-        self.fx_color = Elem_Container()
-        self.fx_color.commands =["FX:RED","FX-C:A","FX-C:B"] 
-
-        self.commands = Elem_Container()
-        self.commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
-                ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
-                ,"BLIND","CLEAR","REC","EDIT","COPY",".","\n" 
-                ]
+        self.setup = meta.setup
+
+        self.fx_main = meta.fx_main # Elem_Container()
+        self.fx_moves = meta.fx_moves
+        self.fx_3 = meta.fx_3
+        self.fx = meta.fx
+
+        self.fx_generic = meta.fx_generic
+        self.fx_color = meta.fx_color
+        self.commands = meta.commands
         
         for i in range(8*8*8):
             if i not in EXEC.val_exec:
@@ -2642,6 +2605,30 @@ if __run_main:
         window_manager.top(name)
 
 
+    # =======================================================================
+    if 0:
+        name="FX3" #"TK-EXEC"
+        def sdl_starter():
+            cmd="/usr/bin/python3 /opt/LibreLight/Xdesk/tkgui/FX3.py " #&"
+            print(cmd)
+
+            def xyz123(cmd):
+                os.system(cmd)
+            thread.start_new_thread(xyz123,(cmd,))
+            return [None,None,None]
+        args = {"title":name,"master":0,"width":W1,"height":H1,"left":L1,"top":TOP}
+        geo = libwin.filter_window_geo(geo_list,name)
+        if geo:
+            args.update(geo)
+
+        data = []
+        cls = sdl_starter #: None #GUI_CONF
+        cb_ok = None
+
+        c = window_create_sdl_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=1)
+        window_manager.new(None,name,wcb=c)
+        if libwin.split_window_show(geo_list,_filter=name):
+            window_manager.top(name)
     # =======================================================================
     name="FX3"
     args = {"title":name,"master":0,"width":364,"height":418+30,"left":L1+10+W1,"top":TOP+302,"resize":1}

+ 1 - 1
lib/fixlib.py

@@ -499,7 +499,7 @@ def encoder(fixtures,fix,attr,xval="",xfade=0,xdelay=0,blind=0):
     if attr == "INV-ATTR":
         cprint("-x-x-x-x-x-x-x-X-")
         x=select(fixtures,fix,attr,mode="swap")
-        master.refresh_fix()
+        MAIN.master.refresh_fix()
         return x
     if attr == "INV-FIX":
         cprint("-x-x-x-x-x-x-x-x-")

+ 3 - 3
lib/libtk.py

@@ -414,7 +414,7 @@ def tk_keyboard_callback(event,data={}):#value=255):
             if str(event.keysym) == "s":
                 MAIN.save_show()
 
-                e = MAIN.master.setup_elem["SAVE\nSHOW"]
+                e = MAIN.master.setup.elem["SAVE\nSHOW"]
                 b = BLINKI(e)
                 b.blink()
             if str(event.keysym) == "c":
@@ -489,9 +489,9 @@ def tk_keyboard_callback(event,data={}):#value=255):
             cprint("numbersign !!")
             MAIN.save_show()
 
-            for e in MAIN.master.setup_cmd:
+            for e in MAIN.master.setup.commands:
                 cprint(e)
-            e =  MAIN.master.setup_elem["SAVE\nSHOW"]
+            e =  MAIN.master.setup.elem["SAVE\nSHOW"]
             cprint(e)
             b = BLINKI(e)
             b.blink()

+ 68 - 0
lib/meta.py

@@ -0,0 +1,68 @@
+#!/usr/bin/python3
+
+class Elem_Container():
+    def __init__(self):
+        self.commands = []
+        self.val = {}
+        self.elem = {}
+
+fx_prm_main = {}
+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}
+fx_prm_3 = {"SIZE":40,"SPEED":8,"OFFSET":100,"BASE":"0","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":0,"WING":2,"WIDTH":100}
+
+fx_color = {"A":"red","B":"blue"} 
+fx_prm = {"SIZE":255,"SPEED":10,"OFFSET":100,"BASE":"-","START":0,"MODE":0,"MO":0,"DIR":1,"INVERT":1,"SHUFFLE":0,"WING":2,"WIDTH":25,"2D-X":1,"2D:MODE":0}
+fx_x_modes = ["spiral","left","right","up","down","left_right","up_down"]
+
+fx_modes = ["RED","GREEN","BLUE","MAG","YELLOW","CYAN"]
+fx_mo    = ["fade","on","rnd","ramp","ramp2","cosinus","sinus","static"]
+
+
+# MASTER --------
+setup = Elem_Container()
+setup.commands = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI","PRO\nMODE"]
+setup.commands = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","PRO\nMODE"]
+
+fx_main = Elem_Container()
+fx_main.commands =["REC-FX","FX OFF","\n"]
+fx_moves = Elem_Container()
+fx_moves.commands =[
+        "FX:CIR","FX:PAN","FX:TILT", "WIDTH:\n100","DIR:\n0","INVERT:\n0","\n",
+        "SHUFFLE:\n0","SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","\n"
+        ]
+fx_3 = Elem_Container()
+fx_3.commands =[
+        "FX:ATTR","PAN","TILT","ATTR3","ATTR4","\n",
+        "TYPE:","SIN","COS"," "," ","\n",
+        "WIDTH:","25","25","25","25","\n",
+        "SIZE:","255","255","255","255","\n",
+        "SPEED:","10","10","10","10","\n",
+        "OFFSET:","100","100","100","100","\n",
+        "START:","0","0","0","0","\n",
+        "SHUFFLE:","0","0","0","0","\n",
+        "DIR:","1","1","1","1","\n",
+        "INVERT:","1","1","1","1","\n",
+        " ","\n",
+        " ","PLAY","STOP","OFF","\n",
+        "  ","CIRCL","PAN","TILT","FLAY","\n",
+        " ","RED","GREEN","BLUE","MAGENTA","\n",
+        "\n",
+        ]
+        #, "FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","BASE:\n-"] #,"FX:RND" ]
+
+fx = Elem_Container()
+fx.commands =[
+        "FX:DIM"," ", "WIDTH:\n25","WING:\n2","DIR:\n1","INVERT:\n1","\n","SHUFFLE:\n0"
+        ,"SIZE:\n","SPEED:\n","START:\n","OFFSET:\n","BASE:\n-","2D-X:\n-","2D:MODE"
+        ]
+fx_generic = Elem_Container()
+fx_generic.commands =["FX:SIN","FX:COS","FX:RAMP","FX:RAMP2","FX:FD","FX:ON","FX:STATIC"]
+
+fx_color = Elem_Container()
+fx_color.commands =["FX:RED","FX-C:A","FX-C:B"] 
+
+commands = Elem_Container()
+commands.commands =["\n","ESC","CFG-BTN","LABEL","-","DEL","-","\n"
+        ,"SELECT","FLASH","GO","-","MOVE","S-KEY","\n"
+        ,"BLIND","CLEAR","REC","EDIT","COPY",".","\n" 
+        ]

+ 760 - 0
tkgui/FX3.py

@@ -0,0 +1,760 @@
+
+import json
+import time
+import sys
+
+import tkinter as tk
+from tkinter import font
+
+import traceback
+import _thread as thread
+
+
+import dialog
+DIALOG = dialog.Dialog()
+
+GLOBAL_old_btn_nr = -1
+GLOBAL_mode_on = -1
+
+def refresh_exec_btn(btn_nr):
+    global GLOBAL_old_btn_nr 
+    nr2= GLOBAL_old_btn_nr
+    print()
+    print(" refresh_exec_btn:",btn_nr)
+    
+    time.sleep(0.5)
+    nr = btn_nr #+1 #-1
+    b = gui.elem_exec[nr]
+
+    print("---")
+    gui._refresh_exec_single(nr,b) #,METAS):
+    if nr2 >= 0 and nr2 != nr:
+        b = gui.elem_exec[nr2]
+        gui._refresh_exec_single(nr2,b) #,METAS):
+
+    GLOBAL_old_btn_nr = nr
+
+gui=None
+def dialog_cfg_open(btn_nr,META):
+    print("META",META)
+    cfg = META["CFG"]
+    label = META["LABEL"]
+    button = cfg["BUTTON"]
+    DIALOG._cb = dialog_cb_cfg(btn_nr+1)
+    DIALOG.ask_exec_config(str(btn_nr+1),button=button,label=label,cfg=cfg)
+    #print("INFO",master.commands.elem)
+
+def dialog_label_open(btn_nr,META):
+    print("META",META)
+    cfg    = META["CFG"]
+    label  = META["LABEL"]
+    button = cfg["BUTTON"]
+    DIALOG._cb = dialog_cb_label(btn_nr+1)
+    #DIALOG.ask_exec_config(str(btn_nr+1),button=button,label=label,cfg=cfg)
+    DIALOG.askstring("LABEL","LABEL EXE:"+str(btn_nr+1),initialvalue=label)
+    #print("INFO",master.commands.elem)
+
+def dialog_cb_cfg(exec_nr): #DAILOG CONFIG CALLBACK
+    def _Dcb(*args):
+        print("dialog_cb_cfg:",args)
+        msg=json.dumps([{"event":"EXEC-CFG","EXEC":exec_nr,"VALUE":255,"DATA":args[0]}]).encode("utf-8")
+        cprint("  SEND DIALOG.cb",msg,color="green")
+        cmd_client.send(msg)
+
+        thread.start_new_thread(refresh_exec_btn,(exec_nr,))
+    return _Dcb
+
+def dialog_cb_label(exec_nr): #DAILOG CONFIG CALLBACK
+    def _Dcb(*args):
+        cprint("dialog_cb_label:",args,"EXEC_NR:",exec_nr)
+        if not args:
+            cprint("  dialog_cb args_error !",color="red")
+            return
+        if args[0] is None:
+            cprint("  dialog_cb cancel !",color="red")
+            return 
+        if "Value" in args[0]:
+            DATA = {"Label":args[0]["Value"]}
+
+        msg=json.dumps([{"event":"EXEC-LABEL","EXEC":exec_nr,"VALUE":255,"DATA":DATA}]).encode("utf-8")
+        cprint("  SEND DIALOG.cb",msg,color="green")
+        cmd_client.send(msg) # send new meta-data
+
+        msg=json.dumps([{"event":"LABEL","EXEC":exec_nr,"VALUE":255,"DATA":{}}]).encode("utf-8")
+        cmd_client.send(msg) # diable LABEL mode
+
+        thread.start_new_thread(refresh_exec_btn,(exec_nr,))
+    return _Dcb
+
+DIALOG._cb = dialog_cb_cfg(-3)
+#d = dialog.Dialog()
+#d.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
+
+
+import __main__ as MAIN
+
+_file_path = "/opt/LibreLight/Xdesk/"
+sys.path.insert(0,"/opt/LibreLight/Xdesk/")
+
+import tool.git as git
+#CAPTION += git.get_all()
+
+CAPTION = "EXEC-BTN"
+title = CAPTION
+title += git.get_all()
+
+INIT_OK = 1
+IS_GUI = 0
+from lib.cprint import cprint
+
+
+import lib.libtk as libtk
+import lib.libtk2 as libtk2
+import lib.zchat as chat
+
+import lib.mytklib as mytklib
+import lib.tkevent as tkevent
+
+#import tkgui.draw as draw
+
+def draw_exec(gui,xframe,EXEC):
+    
+    i=0
+    c=0
+    r=0
+    root = xframe
+    
+    frame = tk.Frame(root,bg="black")
+    frame.pack(fill=tk.X, side=tk.TOP)
+
+    gui.elem_exec = {}
+    i=0
+    for k in EXEC.val_exec:
+        if i%(10*8)==0 or i ==0:
+            c=0
+            b = tk.Canvas(frame,bg="black", height=4,bd=0,width=6,highlightthickness=0) #,bd="black")
+            b.grid(row=r, column=c, sticky=tk.W+tk.E)
+            r+=1
+            c=0
+            b = tk.Button(frame,bg="lightblue", text="EXEC " )
+            b.grid(row=r, column=c, sticky=tk.W+tk.E)
+            c+=1
+            b = tk.Button(frame,bg="lightblue", text="BANK " + str(int(i/(8*8))+1) )
+            b.grid(row=r, column=c, sticky=tk.W+tk.E)
+            c+=1
+            b = tk.Button(frame,bg="lightblue", text="NAME"  )
+            b.grid(row=r, column=c, sticky=tk.W+tk.E)
+            c+=7
+            if i == 0:
+                b = tk.Button(frame,bg="darkgrey", text="HELP",command=libtk.online_help("librelight:20-exec")) #"0&do=index"))
+                b.grid(row=r, column=c, sticky=tk.W+tk.E)
+            r+=1
+            c=0
+        i+=1
+        v=0
+        label = ""
+
+        sdata=EXEC.val_exec[k]
+        BTN="go"
+        if "CFG" in sdata:#["BUTTON"] = "GO"
+            if "BUTTON" in sdata["CFG"]:
+                BTN = sdata["CFG"]["BUTTON"]
+
+
+        txt=str(k+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+label
+
+        b = mytklib.ExecButton(frame,text=txt)
+
+        b.bind("<Button>",       tkevent.tk_event(fix=0,elem=b,attr=k,data=gui,mode="EXEC").cb)
+        b.bind("<ButtonRelease>",tkevent.tk_event(fix=0,elem=b,attr=k,data=gui,mode="EXEC").cb)
+        
+        if k not in gui.elem_exec:
+            gui.elem_exec[k] = b
+        b.grid(row=r, column=c, sticky=tk.W+tk.E)
+
+        b.config(text="xx"+str(i))
+        c+=1
+        if c >=10:
+            c=0
+            r+=1
+    time.sleep(0.1)
+    gui._refresh_exec()
+    print("##################################")
+
+def _add_space(frame,r,c):
+    b = tk.Canvas(frame,bg="black", height=2,bd=0,width=6,highlightthickness=0) #,bd="black")
+    b.grid(row=r, column=c, sticky=tk.W+tk.E)
+    r+=1
+    c=0
+    return r,c
+
+def _draw_fx_3(frame,c,r,gui,mode="FX"):
+    ct  = gui.fx_3 #moves
+    prm = MAIN.fx_prm_3
+
+    for comm in ct.commands:
+        if comm == "\n\n":
+            b = tk.Label(frame,bg="black", text="-",font=space_font)
+            b.grid(row=r, column=c,pady=0,padx=0, sticky=tk.W+tk.E)
+            c=0
+            r+=1
+            continue
+        if comm == "\n":
+            c=0
+            r+=1
+            continue
+        v=0
+        if "PAN/TILT" in comm: 
+            b = tk.Button(frame,bg="grey", text=str(comm),width=6,height=1)
+        else:
+            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=1)
+        if 1:#comm not in ct.elem:
+            #comm = comm.replace("\n","")
+            ct.elem[comm] = b
+            ct.val[comm] = 0
+        b.bind("<Button>",tkevent.tk_event_fx(fix=0,elem=b,attr=comm,data=gui,mode=mode).cb)
+        if comm == "xREC-FX":
+            b["bg"] = "grey"
+        elif comm == "xFX OFF":
+            b["bg"] = "magenta"
+        elif comm[:3] == "xFX:" or comm[:3] == "x2D:":
+            b["text"] = comm
+            b["bg"] = "#ffbf00"
+        elif comm[:3] == "xMO:":
+            b["text"] = comm 
+            b["bg"] = "lightgreen"
+        elif comm.startswith( "xSIZE:"):
+            b["text"] = "SIZE:\n{:0.0f}".format(prm["SIZE"])
+            b["bg"] = "lightgreen"
+        elif comm.startswith( "xSPEED:"):
+            b["text"] = "SPEED:\n{:0.0f}".format(prm["SPEED"])
+            b["bg"] = "lightgreen"
+        elif comm.startswith("xSTART:"):
+            b["bg"] = "lightgreen"
+            b["text"] = "START:\n{:0.0f}".format(prm["START"])
+        elif comm.startswith( "xOFFSET:"):
+            b["bg"] = "lightgreen"
+            b["text"] = "OFFSET:\n{:0.0f}".format(prm["OFFSET"])
+        elif comm[:3] == "xBASE:":
+            b["bg"] = "lightgreen"
+            b["text"] = "BASE:\n{}".format(prm["BASE"])
+        elif comm[0] == "M":
+            b["text"] = comm 
+            b["bg"] = "lightgrey"
+
+        if comm:
+            b.grid(row=r, column=c, sticky=tk.W+tk.E)
+        c+=1
+        if c >=6:
+            c=0
+            r+=1
+    c=0
+    r+=1
+    return c,r
+
+def _draw_fx(frame,c,r,gui,mode="FX"):
+    if mode=="FX-MAIN":
+        ct  = gui.fx_main
+        prm = MAIN.fx_prm_main
+    elif mode=="FX-MOVE":
+        ct  = gui.fx_moves
+        prm = MAIN.fx_prm_move
+    elif mode=="FX":
+        ct  = gui.fx
+        prm = MAIN.fx_prm
+    elif mode=="FX-GENERIC":
+        ct  = gui.fx_generic
+        prm = MAIN.fx_prm #_generic
+    elif mode=="FX-COLOR":
+        ct  = gui.fx_color
+        prm = MAIN.fx_color #_generic
+    else:
+        ct = Elem_Container()
+        ct.commands =["err"]
+        prm = ["err"]
+
+    for comm in ct.commands:
+        if comm == "\n\n":
+            b = tk.Label(frame,bg="black", text="-",font=space_font)
+            b.grid(row=r, column=c,pady=0,padx=0, sticky=tk.W+tk.E)
+            c=0
+            r+=1
+            continue
+        if comm == "\n":
+            c=0
+            r+=1
+            continue
+        v=0
+        if "PAN/TILT" in comm: 
+            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 1:#comm not in ct.elem:
+            #comm = comm.replace("\n","")
+            ct.elem[comm] = b
+            ct.val[comm] = 0
+        b.bind("<Button>",tkevent.tk_event_fx(fix=0,elem=b,attr=comm,data=gui,mode=mode).cb)
+        if comm == "REC-FX":
+            b["bg"] = "grey"
+        elif comm == "FX OFF":
+            b["bg"] = "magenta"
+        elif comm[:3] == "FX:" or comm[:3] == "2D:":
+            b["text"] = comm
+            b["bg"] = "#ffbf00"
+        elif comm[:3] == "MO:":
+            b["text"] = comm 
+            b["bg"] = "lightgreen"
+        elif comm.startswith( "SIZE:"):
+            b["text"] = "SIZE:\n{:0.0f}".format(prm["SIZE"])
+            b["bg"] = "lightgreen"
+        elif comm.startswith( "SPEED:"):
+            b["text"] = "SPEED:\n{:0.0f}".format(prm["SPEED"])
+            b["bg"] = "lightgreen"
+        elif comm.startswith("START:"):
+            b["bg"] = "lightgreen"
+            b["text"] = "START:\n{:0.0f}".format(prm["START"])
+        elif comm.startswith( "OFFSET:"):
+            b["bg"] = "lightgreen"
+            b["text"] = "OFFSET:\n{:0.0f}".format(prm["OFFSET"])
+        elif comm[:3] == "BASE:":
+            b["bg"] = "lightgreen"
+            b["text"] = "BASE:\n{}".format(prm["BASE"])
+        elif comm[0] == "M":
+            b["text"] = comm 
+            b["bg"] = "lightgrey"
+
+        if comm:
+            b.grid(row=r, column=c, sticky=tk.W+tk.E)
+        c+=1
+        if c >=6:
+            c=0
+            r+=1
+    c=0
+    r+=1
+    return c,r
+
+def draw_fx_3(gui,xframe,data=[]):
+    frame_fx=xframe
+    i=0
+    c=0
+    r=0
+    
+    frame = tk.Frame(frame_fx,bg="black")
+    frame.pack(fill=tk.X, side=tk.TOP)
+   
+    # ------------------------------
+    b = tk.Button(frame,bg="lightblue", text="FX3",width=6)
+    b.grid(row=r, column=c, sticky=tk.W+tk.E)
+    c+=1
+
+    thread.start_new_thread(mytklib.tk_btn_bg_loop,(b,))
+    # ------------------------------
+
+
+    _add_space(frame,r,c)
+    c,r = _draw_fx(frame,c,r,gui,mode="FX-MAIN")
+
+    #r,c=_add_space(frame,r,c)
+    #c,r = _draw_fx(frame,c,r,gui,mode="FX-COLOR")
+
+    r,c=_add_space(frame,r,c)
+    c,r = _draw_fx_3(frame,c,r,gui,mode="FX-3")
+import tool.movewin as movewin
+#movewin.check_is_started(CAPTION,_file_path)
+movewin.check_is_started("EXEC-BTN","/opt/LibreLight/Xdesk/tkgui/EXEC-BTN.py")
+
+_global_short_key = 1
+root = None
+
+cmd_client = chat.Client(port=30003)
+
+try:
+    import memcache
+    mc = memcache.Client(['127.0.0.1:11211'], debug=0)
+    #data = mc.get("MODES")
+except:
+    mc = None
+
+
+
+class Refresher(): # DUMMY
+    def __init__(self,*arg,**args):
+        print(self,"__init__",arg,args)
+    def reset(*arg,**args):
+        print(self,"reset",arg,args)
+
+class Command():
+    def __init__(self):
+        self.elem = {}
+
+class MASTER(): # DUMMY
+    def __init__(self,*arg,**args):
+        print(self,"__init__",arg,args)
+        #self.refresh_fix = Refresher()
+        self.commands = Command()
+    def refresh_fix(self,*arg,**args):# = Refresher()
+        print(self,"refresh_fix",arg,args)
+    def exec_go(self,nr,*arg,**args): #val=None,xfade=None,event=None,button="",ptfade=None):
+        if _global_key_lock:
+            return
+        #def exec_go(nr,xfade=None,val=0):
+        print(self,"MASTER",nr,arg,args)
+        btn_nr = nr
+        v = args["val"]
+        
+        msg=json.dumps([{"event":"EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}]).encode("utf-8")
+        cprint("SEND MASTER.EXEC_GO:",msg,color="green")
+        cmd_client.send(msg)
+
+def refresh_fix(*arg,**args): # DUMMY
+    print("refresh_fix",arg,args)
+
+class Refresher_fix(): # DUMMY
+    def __init__(self,*arg,**args):
+        print(self,"init",arg,args)
+    def reset(self,*arg,**args):
+        print(self,"reset",arg,args)
+
+refresher_fix =  Refresher_fix()
+
+class Modes(): # DUMMY
+    def __init__(self,*arg,**args):
+        print("Modes.__init__",arg,args)
+        self.modes = {}
+    def val(self,*arg,**args):
+        #print("Modes.val",arg,args)
+        pass
+
+master = MASTER() #{}
+modes = Modes()
+
+import tkinter as tk
+class Exec(): # DUMMY
+    def __init__(self):
+        self.val_exec = {}
+        for i in range(512):
+            k=i #"ABC-{}".format(i+1)
+            self.val_exec[k] = {"NAME":"XX"}
+EXEC = Exec()
+class Gui(): # DUMMY
+    def __init__(self):
+        self.elem_exec = []
+        self.elem_meta = [None]*512
+        self.old_btn_nr = -1
+        self.METAS = []
+        for i in range(512):
+            self.METAS.append({})
+
+    def _load_meta(self,nr):
+        data = {}
+        try:
+            data = mc.get("EXEC-META-"+str(nr)) 
+            data = json.loads(data)
+        except Exception as e:
+            print("  ER1R mc...",e)
+        return data 
+
+    def _refresh_exec(self,*arg,**args):
+        #print("EXEC_Gui._refresh_exec",arg,args)
+        start = time.time()
+
+        METAS = []
+        for i in range(512):
+            nr = i #+1
+            METAS.append( self._load_meta(nr) )
+
+        self.METAS = METAS
+
+        for nr,b in enumerate( self.elem_exec): #[nr]
+            self._refresh_exec_single(nr,b,METAS)
+            #time.sleep(0.001)
+
+        print( "refres_exec:",time.time()-start )
+
+    def _refresh_exec_single(self,nr,b,METAS=None):
+        start = time.time()
+        no_meta = 0
+
+        if not METAS:
+            no_meta = 1
+            try:
+                data = mc.get("EXEC-META-"+str(nr)) #,json.dumps(index))
+                data = json.loads(data)
+                self.METAS[nr] = data #.append(data)
+                #print(time.time())
+                print("     _REFRESH_EXEC_SINGLE",nr,b,data["LABEL"])
+            except Exception as e:
+                print("  ER1R mc...",e)
+
+            METAS = self.METAS
+        _bg = "grey"
+        _ba = "grey"
+        _bg = "grey"
+        _fg = "#555" #darkgrey"
+        _text = "0 N/V 0\n N/V"
+
+        txt = "None/nNone"
+        txt1 = "None/nNone"
+
+        out = {} # default
+        out["fx"] = ""
+        out["bg"] = _bg # "grey"
+        out["ba"] = _ba #"grey"
+        out["fg"] = _fg
+        out["text"] = _text #"? "+str(nr+1)
+
+        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["CFG"]["FIX-COUNT"],META["LABEL"])
+            out["text"] = str(label)
+            if no_meta:
+                print("     no_meta:",[label])
+
+        except Exception as e:
+            print("  ER4R",e,nr)
+            time.sleep(0.001)
+        try:
+            txt1 = META["CFG"]["BUTTON"]
+        except:
+            pass
+
+        if  META["CFG"]["FIX-COUNT"]: 
+            _fg = "black"
+            
+        if  META["CFG"]["HAVE-VAL"]: 
+            _fg = "black"
+            _bg = "yellow"
+            _ba = "#ffaa55"
+            if "SEL" in txt1:
+                #_bg = "blue"
+                #_fg = "blue"
+                _bg = "gold"
+                _bg = "#77f"
+            elif "ON" in txt1:
+                _bg = "gold"
+                _fg = "#040"
+                _fg = "black"
+            elif "GO" in txt1:
+                _bg = "gold"
+                _fg = "#555"
+                _fg = "black"
+            elif "FL" in txt1:
+                _bg = "gold"
+
+        out["fx"] = ""
+        if  META["CFG"]["HAVE-FX"] >= 1:
+            out["fx"] = META["CFG"]["HAVE-FX"] # show FX on EXEC-BTN
+
+        if  META["CFG"]["HAVE-FX"] >= 1 and META["CFG"]["HAVE-VAL"] == 0:
+            _bg = "cyan"
+
+        if "FL" in txt1:
+            _fg = "#00e"
+        
+        out["fg"] = _fg #= "#00e"
+        out["bg"] = _bg #= "#00e"
+        cfg = out 
+        
+        self.elem_meta[nr] = META
+        #print(" -",nr, round(time.time()-start,4))
+        
+        b = self.elem_exec[nr]
+        b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"],fx=cfg["fx"])
+        #print(" -",nr, round(time.time()-start,4))
+
+    def exec_go(self,*arg,**args):
+        print("Gui.exec_go",arg,args)
+
+        btn_nr = arg[0]
+        v=args["val"]
+        if "CFG-BTN" in modes.modes:
+            button = self.elem_exec[btn_nr]
+            label = str(btn_nr) #self.elem_meta[nr] = META
+            
+            if v:
+                META = self.elem_meta[btn_nr] 
+                dialog_cfg_open(btn_nr,META)
+            return #STOP
+
+        if "LABEL" in modes.modes:
+            button = self.elem_exec[btn_nr]
+            label = str(btn_nr) #self.elem_meta[nr] = META
+            
+            if v:
+                META = self.elem_meta[btn_nr] 
+                dialog_label_open(btn_nr,META)
+            return #STOP
+
+        #REFRESH = 0
+        #for k in ["REC","COPY","MOVE","DEL","REC-FX","LABEL"]:
+        #    if k in modes.modes:
+        #        REFRESH = 1
+
+        print(" ",[arg,args])
+        edata={}
+        if "event" in args:
+            edata =  libtk2.serialize_event(args["event"])
+        print(" ",edata)
+
+        num = -1
+        MOUSE = ""
+        out={"event": "EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}
+        if "num" in edata:
+            num = edata["num"]
+            if num == 1:
+                out["MOUSE"]="LEFT"
+            if num == 3:
+                out["MOUSE"]="RIGHT"
+
+        msg=json.dumps([out]).encode("utf-8")
+
+        if not _global_key_lock:
+            cmd_client.send(msg)
+        cprint("SEND GUI.EXEC_GO",msg,color="green")
+
+        if v == 0: # release btn
+            thread.start_new_thread(refresh_exec_btn,(btn_nr,))
+
+gui  = Gui()
+ 
+
+
+
+import lib.libwin as libwin
+
+if 0:
+    name="FX3"
+    args = {"title":name,"master":0,"width":364,"height":418+30,"left":L1+10+W1,"top":TOP+302,"resize":1}
+    geo = libwin.filter_window_geo(geo_list,name)
+    if geo:
+        args.update(geo)
+    cls = draw_fx_3 #(master,w.tk)
+    data = []
+    cb_ok = None
+
+    c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
+    window_manager.new(None,name,wcb=c)
+    if libwin.split_window_show(geo_list,_filter=name):
+        window_manager.top(name)
+
+
+name="EXEC"
+pos_list = libwin.read_window_geo()
+geo = libwin.filter_window_geo(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()
+root.maxsize(830,2000)
+
+win_title="EXEC-BTN"
+store = movewin.load_all_sdl(win_title)
+print(store)
+W=850
+H=460
+POS=[10,10]
+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]))
+root.tk_setPalette(background='#bbb', foreground='black', activeBackground='#aaa', activeForeground="black")
+defaultFont = tk.font.nametofont("TkDefaultFont")
+defaultFont.configure(family="FreeSans",
+                       size=10,
+                       weight="bold")
+# MAIN MENUE
+try:
+    ico_path = "/opt/LibreLight/Xdesk/icon/"
+    root.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
+except Exception as e:
+    print(" Exception GUIWindowContainer.__init__",e)
+
+xframe = libtk.ScrollFrame(root,width=820,height=400,bd=1,bg="black",head=None,foot=None)
+draw_exec(gui,xframe,EXEC)
+draw_fx_3(gui,xframe,EXEC)
+root.title(title) #"TK-EXEC")
+
+root.bind("<Button>",libtk2.tk_event)#
+root.bind("<Key>",libtk2.tk_event)#,self.callback)
+root.bind("<KeyRelease>",libtk2.tk_event)#,self.callback)
+#root.bind("<FocusIn>",libtk2.tk_event)#, on_focus(self.args["title"],"In").cb)
+#root.bind("<FocusOut>",libtk2.tk_event)#, on_focus(self.args["title"],"Out").cb)
+
+import os
+
+_global_key_lock = 0
+def focus_in(event=None):
+    _global_short_key = 0 # protect key-press-repeat
+    cmd = "xset -display :0.0 r off"
+    print("FOCUS_IN1", cmd)
+    os.system(cmd)
+    time.sleep(0.3)
+    print("FOCUS_IN2", cmd)
+    os.system(cmd)
+    _global_short_key = 1 # protect key-press-repeat
+    time.sleep(0.3)
+    _global_key_lock = 0
+
+def focus_out(event=None):
+    _global_key_lock = 1
+    _global_short_key = 0
+    cmd="xset -display :0.0 r rate 240 20"
+    print("FOCUS_OUT", cmd)
+    #os.system(cmd) # DISABLED 
+
+root.bind("<FocusIn>", focus_in)
+root.bind("<FocusOut>", focus_out)
+
+
+def _refr_loop():
+    time.sleep(3)
+    while 1:
+        gui._refresh_exec()
+        time.sleep(3)
+
+thread.start_new_thread(_refr_loop,())
+
+def _refr_loop2():
+    time.sleep(3)
+    while 1:
+        try:
+            global root,title
+            data = mc.get("MODES")
+            title2 = title +"  "+str(data)
+            data = json.loads(data)
+            #print("MODES",data)
+            modes.modes = data
+            if root:
+                root.title(title2)
+            if "S-KEY" in data:
+                _global_short_key = 0
+                if data["S-KEY"]:
+                    _global_short_key = 1
+
+            for k in data:
+                #print("title",k)
+                for kk in ["RESTART","PRO","EASY","EXIT"]:
+                    if kk in str(k):
+                        print("RESTART !!! EXIT !!")
+                        time.sleep(0.1)
+                        root.quit()
+                        #sys.exit()
+
+        except Exception as e:
+            print("  ER7R mc...",e)
+            time.sleep(3)
+        time.sleep(0.1)
+
+thread.start_new_thread(_refr_loop2,())
+
+root.mainloop()

+ 5 - 5
tkgui/draw.py

@@ -42,7 +42,7 @@ def draw_command(gui,xframe,data):
             r+=1
             continue
         v=0
-        
+        print(dir(gui.commands))
         b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
         if 1:#comm not in gui.commands.elem:
             gui.commands.elem[comm] = b
@@ -656,8 +656,8 @@ def draw_setup(gui,xframe,data):
     if "--easy" in sys.argv:
         pro_mode=0
 
-    gui.setup_elem  = {}
-    comms = gui.setup_cmd # = Elem_Container()
+    gui.setup.elem  = {}
+    comms = gui.setup.commands # = Elem_Container()
     for comm in comms: 
         if comm == "\n":
             c=0
@@ -701,8 +701,8 @@ def draw_setup(gui,xframe,data):
             b = tk.Button(frame,bg="grey", text="",width=6,height=2)
 
         if 1:# comm not in gui.commands.elem:
-            gui.setup_elem[comm] = b
-            #gui.setup_elem.val[comm] = 0
+            gui.setup.elem[comm] = b
+            #gui.setup.elem.val[comm] = 0
 
         if ok:
             b.bind("<Button>",tkevent.tk_event(fix=0,elem=b,attr=comm,data=gui,mode="SETUP").cb)