Browse Source

cleanup: draw_setup

micha 3 months ago
parent
commit
2f39eb6707
5 changed files with 108 additions and 65 deletions
  1. 7 0
      lib/cprint.py
  2. 2 0
      lib/libtk.py
  3. 10 4
      lib/meta.py
  4. 31 12
      lib/tkevent.py
  5. 58 49
      tkgui/draw.py

+ 7 - 0
lib/cprint.py

@@ -1,6 +1,9 @@
 #!/usr/bin/python3
 import sys
 
+#if "--err-log" in sys.argv:
+#f=open("/tmp/librelight-err.log","a")
+
 icolor = 1
 def cprint(*text,color="blue",space=" ",end="\n"):
     #return 0 #disable print dbg
@@ -12,6 +15,10 @@ def cprint(*text,color="blue",space=" ",end="\n"):
         txt = '\033[92m'
     elif color == "red":
         txt = '\033[0;31m\033[1m'
+        try:
+            f.write(str(text)+";\n")
+            f.flush()
+        except:pass
     elif color == "yellow":
         txt = '\033[93m\033[1m'
     elif color == "cyan":

+ 2 - 0
lib/libtk.py

@@ -401,12 +401,14 @@ def tk_keyboard_callback(event,data={}):#value=255):
     if not MAIN._global_short_key:
         return 1
 
+    #cprint(sys._getframe().f_code.co_name,color="yellow")
     #global MAIN #_shift_key
     #cprint("<GUI>",event,color="yellow")
     value = 255
     if "Release" in str(event.type) or str(event.type) == '5' or str(event.type) == '3':
         value = 0
     cprint("<GUI>",event.state,data,value,[event.type,event.keysym],color="yellow")
+
     #print(event)
     if "state" in dir(event) and "keysym" in dir(event):
         #print([event.state,event.keysym,event.type])

+ 10 - 4
lib/meta.py

@@ -3,13 +3,14 @@
 class ValueBuffer():
     def __init__(self,val=2,_min=0,_max=255,_inc=1):
         self._value = val
+        self._init_value = val
         self._on = _inc
         self._inc = 0.1
         self._min=_min
         self._max=_max
         print(self,val)
     def check(self):
-        print(":::",self,self._value,self._min,self._max)
+        #print(":::",self,self._value,self._min,self._max)
         if self._value < self._min:
             self._value = self._min
             print(self,"MIN !")
@@ -44,7 +45,10 @@ class ValueBuffer():
         self._value = value
         self.check()
         return float(self._value)
-
+    def reset(self):
+        self._value = self._init_value
+        self.check()
+        return 1
     def on(self):
         self._on = 1
 
@@ -61,8 +65,7 @@ DELAY = ValueBuffer(val=0.2,_min=-10,_max=10,_inc=0.1)
 DELAY.off()
 
 FADE_move = ValueBuffer(val=4.0)  #2 #0.1 #1.13
-FADE_move_delay = ValueBuffer(val=0)  #2 #0.1 #1.13
-
+FADE_move_delay = ValueBuffer(val=0.2,_min=-10,_max=10,_inc=0.1)  
 
 
 class Elem_Container():
@@ -76,6 +79,9 @@ 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}
 
+live_prm = Elem_Container()
+live_prm.labels = ["FADE","DELAY","PAN/TILT\nFADE","PAN/TILT\nDELAY","-","-"]
+
 #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"]

+ 31 - 12
lib/tkevent.py

@@ -16,6 +16,9 @@ import tkgui.dialog as dialoglib
 import lib.tkrefresh as tkrefresh
 import lib.fixlib as fixlib
 
+from idlelib.tooltip import Hovertip
+#myTip = Hovertip(b,'Strg + S ')
+
 dialog = dialoglib.Dialog()
 
 class tk_event():
@@ -131,6 +134,7 @@ class tk_event():
             MAIN.save_show()
             MAIN.modes.val(self.attr,1)
             time.sleep(1)
+            print("SETUP",[self.attr])
             import lib.restart as restart
             restart.pro()
 
@@ -138,6 +142,7 @@ class tk_event():
             MAIN.save_show()
             MAIN.modes.val(self.attr,1)
             time.sleep(1)
+            print("SETUP",[self.attr])
             import lib.restart as restart
             restart.easy()
         else:
@@ -165,19 +170,30 @@ class tk_event():
                 cprint(" ",ct,color="red")
                 return
             value = ct.val()
-            cprint("EVENT CHANGE:",self.mode,value,self.attr)
+            cprint("EVENT CHANGE:",[self.mode,value,self.attr])
+    
+            b = None        
+            if MAIN.meta.live_prm.elem[self.attr]:
+                b = MAIN.meta.live_prm.elem[self.attr]
+            if b is None:
+                cprint("err LIVE live_prm has no elem:",self.attr,color="red")
+                return 0
 
             if event.num == 1:
                 if ct._is():
                     ct.off()# = 0
-                    MAIN.meta.commands.elem[self.attr]["bg"] = "grey"
-                    self.elem.config(activebackground="grey")
+                    b["bg"] = "grey"
+                    b.config(activebackground="grey")
                 else:
                     ct.on()# = 1
-                    MAIN.meta.commands.elem[self.attr]["bg"] = "green"
-                    self.elem.config(activebackground="lightgreen")
+                    b["bg"] = "green"
+                    b.config(activebackground="lightgreen")
             elif event.num == 2:
-                ct.val(0)
+                if "DELAY" in self.attr:
+                    v = ct.val()
+                    ct.val(v*-1)
+                else:
+                    ct.reset()
             elif event.num == 4:
                 ct.inc() 
             elif event.num == 5:
@@ -185,12 +201,15 @@ class tk_event():
 
             value = ct.val()
 
+
             if self.attr == "FADE":
-                MAIN.meta.commands.elem[self.attr]["text"] = "FADE:\n{:0.2f}".format(value)
-            if self.attr == "DELAY":
-                MAIN.meta.commands.elem[self.attr]["text"] = "DELAY:\n{:0.3f}".format(value)
-            if "PAN/TILT\nFADE" in self.attr:
-                MAIN.meta.commands.elem[self.attr]["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
+                b["text"] = "FADE:\n{:0.2f}".format(value)
+            elif self.attr == "DELAY":
+                b["text"] = "DELAY:\n{:0.3f}".format(value)
+            elif "PAN/TILT\nFADE" in self.attr:
+                b["text"] = "PAN/TILT\nFADE:{:0.2f}".format(value)
+            elif "PAN/TILT\nDELAY" in self.attr:
+                b["text"] = "PAN/TILT\nD:{:0.2f}".format(value)
 
 
 
@@ -275,7 +294,7 @@ class tk_event():
 
             
     def cb(self,event):
-        cprint("EVENT cb",self.attr,self.mode,event,color='yellow')
+        cprint("EVENT cb",[self.attr],self.mode,event,color='yellow')
         cprint(["type",event.type,"num",event.num])
 
         MAIN.INIT_OK = 1

+ 58 - 49
tkgui/draw.py

@@ -22,6 +22,7 @@ if MAIN.IS_GUI:
 
     import tkinter.simpledialog
     from idlelib.tooltip import Hovertip
+    #myTip = Hovertip(b,'Strg + S ')
 
 
 
@@ -42,11 +43,12 @@ def draw_command(gui,xframe,data):
             r+=1
             continue
         v=0
-        print(dir(MAIN.meta.commands))
+        #print(dir(MAIN.meta.commands))
         b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-        if 1:#comm not in MAIN.meta.commands.elem:
-            MAIN.meta.commands.elem[comm] = b
-            MAIN.meta.commands.val[comm] = 0
+
+        MAIN.meta.commands.elem[comm] = b
+        MAIN.meta.commands.val[comm] = 0
+
         if comm == "BLIND":
             b["bg"] = "grey"
             myTip = Hovertip(b,'BLIND MODE\nNO CHANGE on DMX-OUTPUT')
@@ -643,21 +645,22 @@ def draw_fx(gui,xframe,data=[]):
 
 def draw_setup(gui,xframe,data):
     frame_cmd=xframe
-    i=0
-    c=0
-    r=0
     
     frame = tk.Frame(frame_cmd,bg="black")
     frame.pack(fill=tk.X, side=tk.LEFT)
    
-    c+=1
+    i=0
+    c=0
+    r=0
 
     pro_mode=1
     if "--easy" in sys.argv:
         pro_mode=0
+    
+    print("draw_setup") #,[txt,bg,comm])
 
     MAIN.meta.setup.elem  = {}
-    comms = MAIN.meta.setup.labels # = Elem_Container()
+    comms = MAIN.meta.setup.labels 
     for comm in comms: 
         if comm == "\n":
             c=0
@@ -665,52 +668,47 @@ def draw_setup(gui,xframe,data):
             continue
         v=0
         ok = 0
-        
-        if comm == "SAVE\nSHOW":
-            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-            myTip = Hovertip(b,'Strg + S ')
-            ok = 1
-        elif comm == "LOAD\nSHOW" and pro_mode:
-            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-            ok = 1
-        elif comm == "SAVE\nSHOW AS" and pro_mode:
-            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-            ok = 1
-        elif comm == "SAVE &\nRESTART":
-            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-            ok = 1
-        elif comm == "NEW\nSHOW" and pro_mode:
-            b = tk.Button(frame,bg="lightgreen", text=str(comm),width=6,height=2)
-            ok = 1
-        elif comm == "DRAW\nGUI" and pro_mode:
-            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
+        bg="lightgrey"
+        tip=""
+        txt=str(comm)
+        if pro_mode:
             ok = 1
-        elif comm == "PRO\nMODE":
-            bg="lightgrey"
+
+        if comm == "PRO\nMODE":
             bg="yellow"
+            ok = 1
             if pro_mode:
                 bg="green"
-                comm = "EASY\nMODE"
-            b = tk.Button(frame,bg=bg, text=str(comm),width=6,height=2)
+                txt = "EASY\nMODE"
+
+        if comm in ["NEW\nSHOW"]:
+            bg="lightgreen"
+
+        if comm in ["SAVE\nSHOW"]:
+            ok=1
+            tip ='Strg + S '
+
+        if comm in ["SAVE &\nRESTART"]:
             ok = 1
 
-        elif pro_mode:
-            b = tk.Button(frame,bg="grey", text=str(comm),width=6,height=2)
+        if comm in ["NEW\nSHOW"] and pro_mode:
             ok = 1
-        else: #empty
-            b = tk.Button(frame,bg="grey", text="",width=6,height=2)
 
-        if 1:# comm not in MAIN.meta.commands.elem:
-            MAIN.meta.setup.elem[comm] = b
-            #gui.setup.elem.val[comm] = 0
+        if not ok:
+            txt=""
+            bg="lightgrey"
+
+        print("   ",[txt,bg,comm])
+        b = tk.Button(frame,bg=bg, text=str(txt),width=6,height=2)
+        MAIN.meta.setup.elem[str(txt)] = b
 
+        if tip:
+            myTip = Hovertip(b,tip)
         if ok:
-            b.bind("<Button>",tkevent.tk_event(fix=0,elem=b,attr=comm,data=gui,mode="SETUP").cb)
+            b.bind("<Button>",tkevent.tk_event(fix=0,elem=b,attr=txt,data=gui,mode="SETUP").cb)
+
+        b.grid(row=r, column=c, sticky=tk.W+tk.E)
 
-        if comm == "BASE:":
-            b["text"] = "BASE:{}".format(prm["BASE"])
-        if comm:
-            b.grid(row=r, column=c, sticky=tk.W+tk.E)
         c+=1
         if c >=17:
             c=0
@@ -740,7 +738,8 @@ def draw_live(gui,xframe,data):
     frame = tk.Frame(frame_cmd,bg="black")
     frame.pack(fill="both",expand=1, side="left")#tk.TOP)
    
-    comms=["FADE","DELAY","PAN/TILT\nFADE","PAN/TILT\nDELAY","-","-"]
+    MAIN.meta.live_prm.elem  = {}
+    comms = MAIN.meta.live_prm.labels
 
     for comm in comms:
         if comm == "\n":
@@ -748,11 +747,10 @@ def draw_live(gui,xframe,data):
             r+=1
             continue
         v=0
-        
         b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-        if 1:#comm not in MAIN.meta.commands.elem:
-            MAIN.meta.commands.elem[comm] = b
-            MAIN.meta.commands.val[comm] = 0
+        MAIN.meta.live_prm.elem[comm] = b
+        print("live draw elem",[comm])
+
         b.bind("<Button>",tkevent.tk_event(fix=0,elem=b,attr=comm,data=gui,mode="LIVE").cb)
 
         if "FADE" == comm:
@@ -761,14 +759,25 @@ def draw_live(gui,xframe,data):
             b["text"] = "DELAY:\n{:0.2}".format(MAIN.meta.DELAY.val())
         if "PAN/TILT\nFADE" == comm:
             b["text"] = "PAN/TILT\nFADE:{:0.2}".format(MAIN.meta.FADE_move.val())
+        if "PAN/TILT\nDELAY" == comm:
+            b["text"] = "PAN/TILT\nD:{:0.2}".format(MAIN.meta.FADE_move_delay.val())
+            myTip = Hovertip(b,comm)
+
 
         if "FADE" in comm:
             b["bg"] = "green"
             b.config(activebackground="lightgreen")
         if comm:
             b.grid(row=r, column=c, sticky=tk.W+tk.E)
+        
+
         c+=1
         if c >=7:
             c=0
             r+=1
 
+    #for b in MAIN.meta.live_prm.elem:
+    for label in MAIN.meta.live_prm.labels:
+        print("live draw elem",label)
+        b= MAIN.meta.live_prm.elem[label]
+        print("live draw elem",label,b)