Browse Source

extend: TK-EXEC META(DATA) add:btn-press/release

micha 8 months ago
parent
commit
d8e24df72d
4 changed files with 64 additions and 141 deletions
  1. 13 1
      _LibreLightDesk.py
  2. 11 1
      lib/execlib.py
  3. 19 6
      test-mc-exec.py
  4. 21 133
      tkgui/EXEC.py

+ 13 - 1
_LibreLightDesk.py

@@ -802,6 +802,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
 
             BTN="go"
             if "CFG" in sdata:#["BUTTON"] = "GO"
@@ -816,6 +819,9 @@ def get_exec_btn_cfg(nr):
                 for fix in sdata:
                     if fix == "CFG":
                         continue
+
+                    sdata["CFG"]["FIX-COUNT"] += 1
+
                     for attr in sdata[fix]:
                         if "FX2" in sdata[fix][attr]:
                             if sdata[fix][attr]["FX2"]:
@@ -826,6 +832,12 @@ def get_exec_btn_cfg(nr):
                         if "VALUE" in sdata[fix][attr]:
                             if sdata[fix][attr]["VALUE"] is not None:
                                 val_color = 1
+                    
+                if val_color:
+                    sdata["CFG"]["HAVE-VAL"] += 1
+                if fx_color:
+                    sdata["CFG"]["HAVE-FX"] += 1
+
 
                 if val_color:
                     _bg = "gold"
@@ -1614,7 +1626,7 @@ def refresh_exec_mc():
         except Exception as e:
             print("refresh_exec_mc ERR",e)
             time.sleep(5) # extra time
-        time.sleep(10) # refresh time
+        time.sleep(3) # refresh time
 
 thread.start_new_thread(refresh_exec_mc,())
 

+ 11 - 1
lib/execlib.py

@@ -114,6 +114,15 @@ def EXEC_CFG_CHECKER(sdata):
     if "OFFSET-MASTER" not in sdata["CFG"]:
         sdata["CFG"]["OFFSET-MASTER"] = 100 #%
         ok += 1
+    if "HAVE-FX" not in sdata["CFG"]:
+        sdata["CFG"]["HAVE-FX"] = 0  # yes/no
+        ok += 1
+    if "HAVE-VAL" not in sdata["CFG"]:
+        sdata["CFG"]["HAVE-VAL"] = 0  # yes/no
+        ok += 1
+    if "FIX-COUNT" not in sdata["CFG"]:
+        sdata["CFG"]["FIX-COUNT"] = 0  # yes/no
+        ok += 1
 
     #try:del sdata["CFG"]["SPEED-MASTER"] #= 100 #%
     #except:pass
@@ -133,7 +142,8 @@ def exec_set_mc(excec_labels,exec_data):
             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}
+            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}) )

+ 19 - 6
test-mc-exec.py

@@ -11,7 +11,8 @@ import time
 
 start = time.time()
 if mc:
-    while 1:
+    #while 1:
+    for i in range(512):
         #index=[]
         #for i,v in enumerate(l):
         #    key=l[v].replace(" ","_")
@@ -21,11 +22,22 @@ if mc:
         #    index.append(key)
         #mc.set("EXEC-INDEX",json.dumps(index))
 
-        x = mc.get("EXEC-INDEX") #,json.dumps(index))
-        for i in json.loads(x):
-            y = mc.get(i) #,json.dumps(index))
-            print(i,len(y))
-        break
+        #x = mc.get("EXEC-INDEX") #,json.dumps(index))
+        x = mc.get("EXEC-META-"+str(i)) #,json.dumps(index))
+        print( i, json.loads(x) )
+
+        #for j in json.loads(x):
+        #    y = mc.get(i) #,json.dumps(index))
+        #   print(i,len(y))
+        #break
+print()
+i=77-1
+x = mc.get("EXEC-META-"+str(i)) #,json.dumps(index))
+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(start- time.time())
 import sys
@@ -34,6 +46,7 @@ if len(sys.argv) >= 2:
     try:
         nr=int(sys.argv[1])
     except:pass
+#y = mc.get("EXEC-"+str(nr)) #,json.dumps(index))
 y = mc.get("EXEC-"+str(nr)) #,json.dumps(index))
 if y:
     print(len(y))

+ 21 - 133
tkgui/EXEC.py

@@ -15,16 +15,13 @@ sys.path.insert(0,"/opt/LibreLight/Xdesk/")
 
 INIT_OK = 1
 IS_GUI = 0
-import tkgui.draw as draw
-
-#import lib.mytklib as mytklib
-import lib.libtk as libtk
-#import lib.tkevent as tkevent
-#import lib.fixlib as fixlib
-
 from lib.cprint import cprint
 
+import tkgui.draw as draw
+import lib.libtk as libtk
+import lib.zchat as chat
 
+cmd_client = chat.Client(port=30003)
 
 try:
     import memcache
@@ -34,9 +31,6 @@ except:
 
 
 
-
-
-
 class Refresher():
     def __init__(self,*arg,**args):
         print(self,"__init__",arg,args)
@@ -63,9 +57,9 @@ refresher_fix =  Refresher_fix()
 
 class Modes():
     def __init__(self,*arg,**args):
-        print("refresh_fix",arg,args)
+        print("Modes.__init__",arg,args)
     def val(self,*arg,**args):
-        print("val",arg,args)
+        print("Modes.val",arg,args)
 
 master = MASTER() #{}
 modes = Modes()
@@ -81,13 +75,9 @@ EXEC = Exec()
 class Gui():
     def __init__(self):
         self.elem_exec = []
-    def _refresh_exec(self,*arg,**args):
-        self.A_refresh_exec(arg,args)
-        #self.B_refresh_exec(arg,args)
-
-    def A_refresh_exec(self,*arg,**args):
-        print("Gui",arg,args)
 
+    def _refresh_exec(self,*arg,**args):
+        print("Gui._refresh_exec",arg,args)
 
         nr = 14-1
 
@@ -102,15 +92,6 @@ class Gui():
                 print("  ER1R mc...",e)
 
 
-        #try:
-        #    y = mc.get("EXEC-"+str(nr)) #,json.dumps(index))
-        #    _jdata = json.loads(y)
-        #    keys  = _jdata.keys()
-        #except Exception as e:
-        #    print("  ER2R mc...",e,nr)
-
-
-
         for nr,b in enumerate( self.elem_exec): #[nr]
             _bg = "grey"
             _ba = "grey"
@@ -162,6 +143,9 @@ class Gui():
                     _fg = "#555"
                     _fg = "black"
 
+            if  META["CFG"]["HAVE-FX"] >= 1 and META["CFG"]["HAVE-VAL"] == 0:
+                _bg = "cyan"
+
             if "FL" in txt1:
                 _fg = "#00e"
             
@@ -172,112 +156,16 @@ class Gui():
             b = self.elem_exec[nr]
             b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"],fx=cfg["fx"])
 
-    def B_refresh_exec(self,*arg,**args):
-        #def OLD_get_exec_btn_cfg(nr):
-        k = nr
-        if 1:
-            
-            _bg = "grey"
-            _ba = "grey"
-            _fg = "lightgrey"
-            _text = "N/V"
-            txt = "None/nNone"
-            txt1 = "None/nNone"
-
-            if nr >= 0:
-                if nr != k:
-                    return #continue
-
-
-            label = ""
-
-            if k in EXEC.label_exec:
-                label = EXEC.label_exec[k]
-            
-            ifval = 0
-            fx_only = 0
-            fx_color = 0
-            if k in EXEC.val_exec and len(EXEC.val_exec[k]) :
-                sdata = EXEC.val_exec[k]
-
-                BTN="go"
-                if "CFG" in sdata:#["BUTTON"] = "GO"
-                    if "BUTTON" in sdata["CFG"]:
-                        BTN = sdata["CFG"]["BUTTON"]
-                txt="{} {} {}\n{}".format(k+1,BTN,len(sdata)-1,label)
-                _text = txt
-
-                if len(sdata) > 1:
-                    ifval = 1
-                    val_color = 0
-                    for fix in sdata:
-                        if fix == "CFG":
-                            continue
-                        for attr in sdata[fix]:
-                            if "FX2" in sdata[fix][attr]:
-                                if sdata[fix][attr]["FX2"]:
-                                    fx_color = 1
-                            if "FX" in sdata[fix][attr]:
-                                if sdata[fix][attr]["FX"]:
-                                    fx_color = 1
-                            if "VALUE" in sdata[fix][attr]:
-                                if sdata[fix][attr]["VALUE"] is not None:
-                                    val_color = 1
-
-                    if val_color:
-                        _bg = "gold"
-                        _ba = "#ffaa55"
-                        if fx_color:
-                            _fg = "blue"
-                    else:   
-                        if fx_color:
-                            fx_only = 1
-                else:
-                    _bg = "grey"
-                    _ba = "#aaa"
-
-
-            if "\n" in txt:
-                txt1 = txt.split("\n")[0]
-
-            _fg = "black"
-            if ifval:
-                if fx_only:
-                    _bg = "cyan"
-                    _ba = "#55d4ff"
-
-                if "SEL" in txt1:
-                    _bg = "#77f"
-            else: 
-                _bg = "grey"
-                _fg = "darkgrey"
-
-                if "SEL" in txt1:
-                    _fg = "blue"
-                elif "ON" in txt1:
-                    _fg = "#040"
-                elif "GO" in txt1:
-                    _fg = "#555"
-
-            if "FL" in txt1:
-                _fg = "#00e"
-            
-            out = {} # default
-            out["fx"] = ""
-            out["bg"] = "lightgrey"
-            out["ba"] = "grey"
-            out["fg"] = "grey"
-            out["text"] = "?"
-            
-            out["fx"] = fx_color
-            out["bg"] = _bg
-            out["ba"] = _ba
-            out["fg"] = _fg
-            out["text"] = _text
-            
-            return out
-    def exec_go(*arg,**args):
-        print("Gui",arg,args)
+    def exec_go(self,*arg,**args):
+        print("Gui.exec_go",arg,args)
+        #print(" ",dir(arg))
+        #print(" ",self)
+        btn_nr = arg[0]+1
+        btn_nr_raw=0
+        v=args["val"]
+        msg=json.dumps([{"event":"EXEC","EXEC":btn_nr,"VAL":v,"NR-KEY":btn_nr_raw}]).encode("utf-8")
+        print("SPCIAL-KEY",msg)
+        cmd_client.send(msg)
 
 gui  = Gui()