Răsfoiți Sursa

add: external TK-EXEC refresh (Memcached)

micha 8 luni în urmă
părinte
comite
af44d80586
4 a modificat fișierele cu 239 adăugiri și 54 ștergeri
  1. 11 0
      _LibreLightDesk.py
  2. 24 11
      lib/execlib.py
  3. 12 3
      test-mc-exec.py
  4. 192 40
      tkgui/EXEC.py

+ 11 - 0
_LibreLightDesk.py

@@ -1605,6 +1605,17 @@ window_manager = WindowManager()
 
 CONSOLE = Console()
 EXEC = execlib.EXEC()
+     
+def refresh_exec_mc():
+    time.sleep(10)
+    while 1:
+        try:
+            execlib.exec_set_mc(EXEC.label_exec,EXEC.val_exec)
+        except Exception as e:
+            print("refresh_exec_mc ERR",e)
+        time.sleep(10)
+
+thread.start_new_thread(refresh_exec_mc,())
 
 FIXTURES = fixlib.Fixtures()
 FIXTURES.gui = GUIHandler()

+ 24 - 11
lib/execlib.py

@@ -119,7 +119,28 @@ def EXEC_CFG_CHECKER(sdata):
     #except:pass
 
     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("EXEC-INDEX",json.dumps(index))
+        print("---------------------------------------")
+        #,start - time.time())
+        #
 
 class EXEC(): #Presets():
     def __init__(self):
@@ -136,21 +157,13 @@ class EXEC(): #Presets():
             sdata = d[i]
             ok = EXEC_CFG_CHECKER(sdata)
         start = time.time()
-        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-LABEL-"+str(i) 
-                mc.set(key2,l[i] )
-            mc.set("EXEC-INDEX",json.dumps(index))
-            print("---------------------------------------",start - time.time())
+
 
         self.val_exec = d
         self.label_exec = l
 
+        exec_set_mc(self.label_exec,self.val_exec)
+
     def check_cfg(self,nr=None):
         cprint("EXEC.check_cfg()",nr)#,color="red")
         ok = 0

+ 12 - 3
test-mc-exec.py

@@ -35,8 +35,17 @@ if len(sys.argv) >= 2:
         nr=int(sys.argv[1])
     except:pass
 y = mc.get("EXEC-"+str(nr)) #,json.dumps(index))
-
 if y:
     print(len(y))
-    print(json.loads(y))
-
+    try:
+        print(json.loads(y))
+    except Exception as e:
+        print("ERR",e)
+
+k = "EXEC-META-"+str(nr)
+y = mc.get(k) #,json.dumps(index))
+y = json.loads(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))

+ 192 - 40
tkgui/EXEC.py

@@ -13,7 +13,7 @@ import __main__ as MAIN
 
 sys.path.insert(0,"/opt/LibreLight/Xdesk/")
 
-
+INIT_OK = 1
 IS_GUI = 0
 import tkgui.draw as draw
 
@@ -25,6 +25,7 @@ import lib.libtk as libtk
 from lib.cprint import cprint
 
 
+
 try:
     import memcache
     mc = memcache.Client(['127.0.0.1:11211'], debug=0)
@@ -81,69 +82,209 @@ 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)
-        #_XX +=1
-        # _nr_ok = 0
+
 
         nr = 14-1
-        jdata = {}
-        keys = []
-        
-        labels = []
-        if 10:
-            nr = 0
-            for i in range(512):
-                nr = i #+1
-                label = "err-{}".format(nr)
-                try:
-                    label = mc.get("EXEC-LABEL-"+str(nr)) #,json.dumps(index))
-                except Exception as e:
-                    print("  ER1R mc...",e)
-                labels.append(label)
 
+        METAS = []
+        for i in range(512):
+            nr = i #+1
             try:
-                y = mc.get("EXEC-"+str(nr)) #,json.dumps(index))
-                jdata = json.loads(y)
-                keys  = jdata.keys()
+                data = mc.get("EXEC-META-"+str(nr)) #,json.dumps(index))
+                data = json.loads(data)
+                METAS.append(data)
             except Exception as e:
-                print("  ER2R mc...",e,nr)
-        
-        #for nr in EXEC.val_exec: 
-        #for nr in range(200):
+                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"
+            _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"] = "grey"
-            out["ba"] = "grey"
-            out["fg"] = "#999" #black" #grey"
-            out["text"] = "? "+str(nr+1)
+            out["bg"] = _bg # "grey"
+            out["ba"] = _ba #"grey"
+            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}
             
-        
             try: 
-                out["text"] = "GO\n"+str(labels[nr])
-                if len(labels[nr]) >= 3:
-                    out["bg"] = "orange" #yellow"
-                    out["fg"] = "black" #grey"
+                META = METAS[nr]
+                label = "{} {} {}\n{}".format(nr+1,META["CFG"]["BUTTON"],META["LEN"],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)
                 time.sleep(0.001)
-            #xout["fx"] = fx_color
-            #xout["bg"] = _bg
-            #xout["ba"] = _ba
-            #xout["fg"] = _fg
-            #out["text"] = _text
+            try:
+                txt1 = META["CFG"]["BUTTON"]
+            except:
+                pass
+                
+            if META["LEN"]:
+                _fg = "black"
+                _bg = "gold"
+                _ba = "#ffaa55"
+                if "SEL" in txt1:
+                    #_bg = "blue"
+                    #_fg = "blue"
+                    _bg = "#77f"
+                elif "ON" in txt1:
+                    _fg = "#040"
+                    _fg = "black"
+                elif "GO" in txt1:
+                    _fg = "#555"
+                    _fg = "black"
+
+            if "FL" in txt1:
+                _fg = "#00e"
             
-            #return out
-            cfg = out #get_exec_btn_cfg(nr)
+            out["fg"] = _fg #= "#00e"
+            out["bg"] = _bg #= "#00e"
+            cfg = out 
 
             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)
 
 gui  = Gui()
 
 
+
+
+
 root = tk.Tk()
 
 #root.withdraw() # do not draw
@@ -166,4 +307,15 @@ xframe = libtk.ScrollFrame(root,width=820,height=400,bd=1,bg="black",head=None,f
 draw.draw_exec(gui,xframe,EXEC)
 #xframe.pack()
 root.title("DEMO TK-EXEC 2")
+
+
+def _refr_loop():
+    time.sleep(3)
+    while 1:
+        gui._refresh_exec()
+        time.sleep(3)
+thread.start_new_thread(_refr_loop,())
+
+
+
 root.mainloop()