瀏覽代碼

cleanup: Easy-mode/Pro-mode

micha 1 年之前
父節點
當前提交
579c72dcbf
共有 5 個文件被更改,包括 171 次插入138 次删除
  1. 1 1
      LibreLightDesk.py
  2. 36 71
      Start.py
  3. 81 46
      _LibreLightDesk.py
  4. 28 17
      tkgui/draw.py
  5. 25 3
      tool/sdl_elm.py

+ 1 - 1
LibreLightDesk.py

@@ -1 +1 @@
-_LibreLightDesk.py
+Start.py

+ 36 - 71
Start.py

@@ -11,6 +11,7 @@ sys.path.insert(0,"/opt/LibreLight/Xdesk/")
 print(sys.path)
 print()
 
+from lib.xcolor import *
 
 
 # ===== GUI =========
@@ -18,7 +19,7 @@ import pygame
 import pygame.gfxdraw
 import pygame.font
 pg = pygame
-main_size=(600,500)
+main_size=(550,400)
 window = pygame.display.set_mode(main_size,pg.RESIZABLE,32)
 
 pg = pygame
@@ -67,7 +68,7 @@ font   = pygame.font.SysFont("freemonobold",22)
 font10 = pygame.font.SysFont("freemonobold",10)
 font12 = pygame.font.SysFont("freemonobold",12)
 font15 = pygame.font.SysFont("freemonobold",15)
-font22 = pygame.font.SysFont("FreeSans",22)
+font22 = pygame.font.SysFont("FreeSans-bold",42)
 #font  = pygame.font.SysFont(None,30)
 
 fr = font.render("hallo" ,1, (200,0,255))
@@ -75,46 +76,40 @@ fr = font.render("hallo" ,1, (200,0,255))
 start = time.time()
 table = []
 
-r = 80
-i = 1
-
-bx = sdl_elm.Button(window,pos=[20,r,80,40])
-bx.text = "FIX:{}\n<val>\nx".format(i+1)
-bx.bg_on = [255,0,255]
-bx.btn1.color_on = [255,0,155]
-bx.btn1.type = "flash"
+x = 80
+y = 120
+import os
+import lib.fork as fork
+BASE_PATH = "/opt/LibreLight/Xdesk/"
+
+                
+import lib.restart as restart
+
+def exit(args):
+    pygame.quit()
+    sys.exit()
+bx = sdl_elm.Button(window,pos=[x,y,400,60])
+bx.text = "       EASY" 
+bx.font0 = pygame.font.SysFont("freesans-bold",85)
+bx.btn1.color = GREEN
+bx.btn1.cb_on.set(restart.easy)
 table.append(bx)
-r+=bx.get_rect()[3]
+y+=bx.get_rect()[3]+20
 
-i += 1
-bx = sdl_elm.Button(window,pos=[20,r,80,40])
-bx.text = "FIX:{}\n<val>\nx".format(i+1)
+bx = sdl_elm.Button(window,pos=[x,y,400,60])
+bx.text = "        PRO" 
+bx.btn1.color = GOLD
+bx.btn1.cb_on.set(restart.pro)
+bx.font0 = pygame.font.SysFont("freesans-bold",85)
 table.append(bx)
-r+=bx.get_rect()[3]
-
-i += 1
-r+=bx.get_rect()[3]
-bx = sdl_elm.Button(window,pos=[20,r,80,40])
-bx.text = "FIX:{}\n<val>\nx".format(i+1)
-bx.font0 = pygame.font.SysFont("freesans",20)
-bx.btn4.val.set( 100)
-bx.fader = 0
-table.append(bx)
-r+=bx.get_rect()[3]
+y+=bx.get_rect()[3]+30
 
-i += 1
-bx = sdl_elm.Button(window,pos=[30,r,190,60])
-bx.text = "FIX:{}\n<val>\nx".format(i+1)
-bx.font0 = pygame.font.SysFont("freesans-bold",20)
-bx.btn1.type = "flash"
+bx = sdl_elm.Button(window,pos=[x,y,400,60])
+bx.text = "        Exit"
+bx.btn1.cb_on.set(exit)
+bx.font0 = pygame.font.SysFont("freesans-bold",80)
 table.append(bx)
-r+=bx.get_rect()[3]
 
-i += 1
-bx = sdl_elm.Button(window,pos=[20,r,60,20])
-bx.text = "FIX:{}\n<val>\nx".format(i+1)
-bx.font0 = pygame.font.SysFont("freesans",12)
-table.append(bx)
 
 mouse_down = 0
 mouse_pos1 = [0,0]
@@ -142,43 +137,13 @@ while 1:
     pygame.draw.rect(window,(0,0,0),[0,0,main_size[0],main_size[1]])
 
     fr = font22.render("FPS:"+str(fps_old)  ,1, (200,200,200))
-    window.blit(fr,(10,10 ))
-
-    fr = font22.render("DEMO / TEST - MODE ! "  ,1, (200,200,200))
-    window.blit(fr,(10,30 ))
-
-    pos = [160,110,70+80,20]
-    pygame.draw.rect(window,rgb,pos)
-
-    t=(time.time()-start)
-    if t > 15:
-        start = time.time()
-    b= 80-int(t*10)
-    pos = [160,110,70+(b),20]
-    rgb = (0x00,0xff,0xff,0)
-    pygame.draw.rect(window,rgb,pos)
-    rgb = (0x00,0x00,0x00,0)
-    fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
-    window.blit(fr,pos[:2])
-    
-    pos = [160,200,80,20]
-    #fd = sdl_elm.Fader(window,pos)
-    #fd.draw()
-    
-    pos = [160,90,70+80,20]
-    pygame.draw.rect(window,rgb,pos)
-    b= int(t*10)
-    pos = [160,90,0+(b),20]
-    rgb = (0x00,0xff,0xff,0)
-    pygame.draw.rect(window,rgb,pos)
-    rgb = (0x00,0x00,0x00,0)
-    fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
-    window.blit(fr,pos[:2])
+    #window.blit(fr,(10,10 ))
+    fr = font22.render("           Lichtsteuerung"  ,1, (255,255,0))
+    window.blit(fr,(80,20 ))
 
 
-    rgb = (0xaa,0xaa,0xaa,0)
-    fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
-    window.blit(fr,(500,500))
+    fr = font22.render("           Modus wählen ! "  ,1, (255,255,0))
+    window.blit(fr,(80,60 ))
 
     for t in table:
         t.draw()

+ 81 - 46
_LibreLightDesk.py

@@ -79,6 +79,31 @@ INIT_OK = 0
 _global_short_key = 1
 
 
+path = "/home/user/LibreLight/"
+#os.chdir(path)
+if "--easy" in sys.argv:
+    f = open(path+"init.txt","a")
+    f.write("EASY\n")
+    f.close()
+    if not os.path.isdir(path+"show/EASY"):
+        cmd = "cp -vrf '/opt/LibreLight/Xdesk/home/LibreLight/show/EASY' '{}/show/EASY' ".format(path)
+        print(cmd)
+        #input()
+        os.system(cmd)
+    # check if EASY show exist !
+else:
+    f = open(path+"init.txt","r")
+    lines=f.readlines()
+    f.close()
+    out = []
+    for line in lines:
+        if line != "EASY\n":
+            out.append(line)
+    f = open(path+"init.txt","w")
+    f.writelines(out)
+    f.close()
+
+
 icolor = 1
 def cprint(*text,color="blue",space=" ",end="\n"):
     #return 0 #disable print dbg
@@ -1526,6 +1551,10 @@ def read_window_position():
                 elif line.count(" ") == 1:
                     name,geo = line.split(" ",1)
                     show = 1
+
+                if "--easy" in sys.argv:
+                    if name not in ["MAIN","EXEC","SETUP"]:
+                        show=0
             out.append([show,name,geo])
 
         return out
@@ -1631,27 +1660,26 @@ class Xevent():
         self.elem = elem
         self.mode = mode
 
+    def _save_show(self):
+        self.elem["bg"] = "orange"
+        self.elem["text"] = "SAVING..."
+        self.elem["bg"] = "red"
+        self.elem.config(activebackground="orange")
+        modes.val(self.attr,1)
+        PRESETS.backup_presets()
+        FIXTURES.backup_patch()
+        save_window_position()
+        self.elem["bg"] = "lightgrey"
+        self.elem.config(activebackground="lightgrey")
+        b = BLINKI(self.elem)
+        b.blink()
+        self.elem["text"] = "SAVE\nSHOW"
 
     def setup(self,event):       
         cprint("xevent.SETUP",[self.mode,self.attr],color="red")
         if self.mode == "SETUP":
             if self.attr == "SAVE\nSHOW":
-                self.elem["bg"] = "orange"
-                self.elem["text"] = "SAVING..."
-                self.elem["bg"] = "red"
-                self.elem.config(activebackground="orange")
-                modes.val(self.attr,1)
-                PRESETS.backup_presets()
-                FIXTURES.backup_patch()
-                save_window_position()
-                #time.sleep(1)
-                #modes.val(self.attr,0)
-                self.elem["bg"] = "lightgrey"
-                #self.elem["fg"] = "lightgrey"
-                self.elem.config(activebackground="lightgrey")
-                b = BLINKI(self.elem)
-                b.blink()
-                self.elem["text"] = "SAVE\nSHOW"
+                self._save_show()
             elif self.attr == "LOAD\nSHOW":
                 name = "LOAD-SHOW"
                 base = Base()
@@ -1666,19 +1694,11 @@ class Xevent():
                         if self.name != "<exit>":
                             cprint("-----------------------:")
                             LOAD_SHOW_AND_RESTAT(self.name).cb()
-                        #self.elem["bg"] = "lightgrey"
-                        #self.elem.config(activebackground="lightgrey")
 
                 pw = PopupList(name,cb=cb)
+                print(line1,line2)
                 frame = pw.sframe(line1=line1,line2=line2)
-                #r = _load_show_list(frame,cb=cb)
                 r = frame_of_show_list(frame,cb=cb)
-
-    
-                #self.elem["bg"] = "red"# "lightgrey"
-                #self.elem.config(activebackground="red")
-                #self.elem.config(activebackground="lightgrey")
-                #w.tk.attributes('-topmost',False)
             elif self.attr == "NEW\nSHOW":
                 base = Base()
 
@@ -1732,32 +1752,25 @@ class Xevent():
 
                 save_window_position()
                 self.elem["text"] = "RESTARTING..."
-                #time.sleep(1)
-                #modes.val(self.attr,0)
                 self.elem["bg"] = "lightgrey"
-                #self.elem["fg"] = "lightgrey"
                 self.elem.config(activebackground="lightgrey")
                 LOAD_SHOW_AND_RESTAT("").cb(force=1)
             elif self.attr == "DRAW\nGUI":
-                #self.elem["bg"] = "orange"
                 old_text = self.elem["text"]
-                #self.elem["text"] = "DRAWING..."
-                #self.elem["bg"] = "red"
-                #time.sleep(0.05)
-                #print("redraw",name)
-                #if name == "PATCH":
-                #    gui_patch.draw()
-                #if name == "DIMMER":
-                #    gui_fix.draw()
-                #self.elem["text"] = "PATCH..."
-                #self.elem["text"] = "PATCH..."
                 window_manager.top("PATCH")
                 gui_patch.draw(FIXTURES)
-                #self.elem["text"] = "FIX..."
                 gui_fix.draw(FIXTURES)
                 window_manager.top("FIXTURES")
                 master._refresh_exec()
                 self.elem["text"] = old_text  
+            elif self.attr == "PRO\nMODE":
+                self._save_show()
+                import lib.restart as restart
+                restart.pro()
+            elif self.attr == "EASY\nMODE":
+                self._save_show()
+                import lib.restart as restart
+                restart.easy()
             else:
                 r=tkinter.messagebox.showwarning(message="{}\nnot implemented".format(self.attr.replace("\n"," ")),parent=None)
         return 1
@@ -2121,6 +2134,8 @@ def _listdir(show_path):
     show_list =  list(os.listdir( show_path ))
     out = []
     for fname in show_list:
+        if fname == "EASY": #hidde EASY show in list !
+            continue
         #print(fname)
         ctime = os.path.getmtime(show_path+fname)
         ctime = time.strftime("%Y-%m-%d %X",  time.localtime(ctime)) #1650748726.6604707))
@@ -2237,7 +2252,7 @@ class Base():
     def _load(self,filename):
         xpath = self.show_path+"/"+str(filename)+".sav"
         if not os.path.isfile(xpath):
-            msg = "Exception: {}".format(e)
+            msg = ""#"Exception: {}".format(e)
             msg += "\n\ncheck\n-init.txt"
             cprint(msg,color="red")
             showwarning(msg=msg,title="load Error")
@@ -2447,7 +2462,7 @@ class MASTER():
         self.elem_attr = {}
         
         self.setup_elem = {} # Elem_Container()
-        self.setup_cmd  = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI"]
+        self.setup_cmd  = ["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI","PRO\nMODE"]
 
         self.fx_moves = Elem_Container()
         self.fx_moves.commands =["REC-FX","FX OFF","\n"
@@ -3040,8 +3055,14 @@ class LOAD_SHOW_AND_RESTAT():
 
         cprint("LOAD SHOW:",event,self.fname)
 
-        cprint(sys.executable, os.path.abspath(__file__), *sys.argv)
-        os.execl("/usr/bin/python3", "/opt/LibreLight/Xdesk/_LibreLightDesk.py", "_LibreLightDesk.py")
+        BASE_PATH = "/opt/LibreLight/Xdesk/"
+        cmd="_LibreLightDesk.py"
+        arg = ""
+        print("fork",[BASE_PATH,cmd,arg])
+        if "--easy" in sys.argv:
+            arg = "--easy"
+        #time.sleep(1)
+        os.execl("/usr/bin/python3", BASE_PATH, cmd,arg)
         sys.exit()
                 
 class PopupList():
@@ -4970,8 +4991,12 @@ if __run_main:
         window_manager.top(name)
 
     name = "SETUP"
-    args = {"title":name +" SHOW:"+master.base.show_name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP,"resize":0}
+    args = {"title":name +" SHOW:"+master.base.show_name,
+                "master":0,"width":435,"height":42,"left":L1+10+W1,"top":TOP,"resize":0}
     args["title"]  = "SETUP SHOW:"+master.base.show_name
+    geo = split_window_position(pos_list,name)
+    if geo:
+        args.update(geo)
 
     cls = draw_setup #(master,w.tk)
     data = []
@@ -4985,6 +5010,9 @@ if __run_main:
 
     name = "COMMAND"
     args = {"title":name,"master":0,"width":415,"height":130,"left":L1+10+W1,"top":TOP+81,"resize":0}
+    geo = split_window_position(pos_list,name)
+    if geo:
+        args.update(geo)
     cls = draw_command #(master,w.tk)
     data = []
     cb_ok = None
@@ -4996,6 +5024,9 @@ if __run_main:
 
     name = "LIVE"
     args = {"title":name,"master":0,"width":415,"height":42,"left":L1+10+W1,"top":TOP+235,"resize":0}
+    geo = split_window_position(pos_list,name)
+    if geo:
+        args.update(geo)
     cls = draw_live #(master,w.tk)
     data = []
     cb_ok = None
@@ -5007,6 +5038,9 @@ if __run_main:
 
     name = "CLOCK"
     args = {"title":name,"master":0,"width":335,"height":102,"left":L1+10+W1+80,"top":TOP+H1+HTB+160,"resize":0}
+    geo = split_window_position(pos_list,name)
+    if geo:
+        args.update(geo)
     cclock = X_CLOCK()
     cls = cclock.draw_clock 
     data = []
@@ -5084,7 +5118,8 @@ if __run_main:
 
 
 
-    load_window_position()
+    #if "--easy" in sys.argv:
+    #load_window_position()
 
 
 

+ 28 - 17
tkgui/draw.py

@@ -573,15 +573,15 @@ def draw_setup(gui,xframe,data):
     frame = tk.Frame(frame_cmd,bg="black")
     frame.pack(fill=tk.X, side=tk.LEFT)
    
-    #b = tk.Button(frame,bg="lightblue", text="SETUP",width=6)
-    #b.bind("<Button>",Xevent(fix=fix,elem=b).cb)
-    
-    #b.grid(row=r, column=c, sticky=tk.W+tk.E)
-    #r+=1
     c+=1
+
+    pro_mode=1
+    if "--easy" in sys.argv:
+        pro_mode=0
+
     gui.setup_elem  = {}
     comms = gui.setup_cmd # = Elem_Container()
-    for comm in comms: #["SAVE\nSHOW","LOAD\nSHOW","NEW\nSHOW","SAVE\nSHOW AS","SAVE &\nRESTART","DRAW\nGUI"]:
+    for comm in comms: 
         if comm == "\n":
             c=0
             r+=1
@@ -589,20 +589,30 @@ def draw_setup(gui,xframe,data):
         v=0
         
         if comm == "SAVE\nSHOW":
-            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=5,height=2)
+            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=4,height=2)
             myTip = Hovertip(b,'Strg + S ')
-        elif comm == "LOAD\nSHOW":
-            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=5,height=2)
-        elif comm == "SAVE\nSHOW AS":
+        elif comm == "LOAD\nSHOW" and pro_mode:
+            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=4,height=2)
+        elif comm == "SAVE\nSHOW AS" and pro_mode:
             b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
         elif comm == "SAVE &\nRESTART":
             b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-        elif comm == "NEW\nSHOW":
-            b = tk.Button(frame,bg="lightgreen", text=str(comm),width=6,height=2)
+        elif comm == "NEW\nSHOW" and pro_mode:
+            b = tk.Button(frame,bg="lightgreen", text=str(comm),width=5,height=2)
         elif comm == "DRAW\nGUI":
-            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
-        else:
-            b = tk.Button(frame,bg="grey", text=str(comm),width=5,height=2)
+            b = tk.Button(frame,bg="lightgrey", text=str(comm),width=5,height=2)
+        elif comm == "PRO\nMODE":
+            bg="lightgrey"
+            bg="yellow"
+            if pro_mode:
+                bg="green"
+                comm = "EASY\nMODE"
+            b = tk.Button(frame,bg=bg, text=str(comm),width=5,height=2)
+
+        elif pro_mode:
+            b = tk.Button(frame,bg="grey", text=str(comm),width=4,height=2)
+        else: #empty
+            b = tk.Button(frame,bg="grey", text="",width=4,height=2)
 
         if comm not in gui.commands.elem:
             gui.setup_elem[comm] = b
@@ -615,11 +625,12 @@ def draw_setup(gui,xframe,data):
         if comm:
             b.grid(row=r, column=c, sticky=tk.W+tk.E)
         c+=1
-        if c >=7:
+        if c >=17:
             c=0
             r+=1
 
-
+    c+=1
+    r=0
 
 
 

+ 25 - 3
tool/sdl_elm.py

@@ -54,13 +54,33 @@ class ELEM_KILLGROUP():
             i.clear()
         #elm.set(v)
         return v
-        
+
+class CALLBACK():
+    def __init__(self):
+        self._cb  = self.dummy
+        self.ok = 0
+    def cb(self,*args):
+        if self.ok:
+            print("CALLBACK.cb",args)
+            #try:
+            self._cb(args)
+            #except Exception as e:
+            #    print(" Exception CALLBACK.cb",args)
+    def dummy(self,arg):
+        print("CALLBACK.dummy",arg)
+    def set(self,cb):
+        self._cb = cb
+        self.ok = 1
+        print("CALLBACK",cb)
+
 
 class ELEM_BUF():
     def __init__(self,kill=None,name="ELEM_BUF"):
         self.val = VALUE() #0
         self.increment = 10 
         self.name = name
+        self.cb_on  = CALLBACK()
+        self.cb_off = CALLBACK()
         self.nr_on  = [0]
         self.nr_off = [0]
         self.color = [0,255,0]
@@ -83,7 +103,7 @@ class ELEM_BUF():
         print([self.name,self.type,self.val.get()])
         if self.type == "fader":
             self.inc(self.increment)
-            return
+
         if self.type == "toggle":
             if self.val.get():
                 self.val.set(0)
@@ -93,6 +113,8 @@ class ELEM_BUF():
         if self.type == "flash":
             self.val.set(1)
 
+        self.cb_on.cb("ho")
+
     def release(self):
         if self.type == "fader":
             self.inc(-self.increment)
@@ -237,7 +259,7 @@ class Button():
         self.text2 = []
 
     def check(self):
-        if 10:#dbg:
+        if 0:#dbg:
             self.text2 = []
             #self.text2.append(self.val)
             b = []