Переглянути джерело

add: startup_all_sdl 1sec delay and store_sdl_pos

micha 11 місяців тому
батько
коміт
2536ec7048
5 змінених файлів з 53 додано та 17 видалено
  1. 7 0
      _LibreLightDesk.py
  2. 1 1
      tksdl/dmx.py
  3. 1 1
      tksdl/fix.py
  4. 2 2
      tksdl/midi.py
  5. 42 13
      tool/movewin.py

+ 7 - 0
_LibreLightDesk.py

@@ -1151,6 +1151,7 @@ class Xevent():
         PRESETS.backup_presets()
         FIXTURES.backup_patch()
         libwin.save_window_position()
+        movewin.store_all_sdl()
         self.elem["bg"] = "lightgrey"
         self.elem.config(activebackground="lightgrey")
         b = BLINKI(self.elem)
@@ -1232,6 +1233,7 @@ class Xevent():
                 PRESETS.backup_presets()
                 FIXTURES.backup_patch()
 
+                movewin.store_all_sdl()
                 libwin.save_window_position()
                 self.elem["text"] = "RESTARTING..."
                 self.elem["bg"] = "lightgrey"
@@ -3023,6 +3025,10 @@ class window_create_buffer():
             obj=self.cls(self.gui,w1,self.data) 
         return w,obj,self.cb_ok
 
+def open_sdl_window():
+    cprint("open_sdl_window ... delay 1sec",color="yellow")
+    time.sleep(1)
+    movewin.startup_all_sdl()
 
 if __run_main:
     cprint("main")
@@ -3618,6 +3624,7 @@ if __run_main:
             time.sleep(1/10)
 
     thread.start_new_thread(mc_fix_loop,())
+    thread.start_new_thread(open_sdl_window,())
     
     try:
         window_manager.mainloop()

+ 1 - 1
tksdl/dmx.py

@@ -367,7 +367,7 @@ while 1:
 
         print("event",event)
         if event.type == pygame.QUIT:
-            movewin.store_all_sdl()
+            #movewin.store_all_sdl()
             pygame.quit()
             sys.exit(0)
         elif event.type == pygame.VIDEORESIZE:

+ 1 - 1
tksdl/fix.py

@@ -742,7 +742,7 @@ while 1:
                         cmd_client.send(msg)
 
             if event.type == pygame.QUIT:
-                movewin.store_all_sdl()
+                #movewin.store_all_sdl()
                 pygame.quit()
                 sys.exit(0)
             elif event.type == pygame.VIDEORESIZE:

+ 2 - 2
tksdl/midi.py

@@ -379,7 +379,7 @@ while 1:
 
         print("event",event)
         if event.type == pygame.QUIT:
-            movewin.store_all_sdl()
+            #movewin.store_all_sdl()
             pygame.quit()
             sys.exit(0)
         elif event.type == pygame.VIDEORESIZE:
@@ -430,7 +430,7 @@ while 1:
     try:
         clock.tick(10)
     except KeyboardInterrupt as e:
-        movewin.store_all_sdl()
+        #movewin.store_all_sdl()
         pygame.quit()
         raise e
 

+ 42 - 13
tool/movewin.py

@@ -5,6 +5,7 @@ import time
 import psutil
 import json    
 import inspect
+import _thread as thread
 
 HOME = os.getenv('HOME')
 show_path = HOME+"/LibreLight/"
@@ -13,6 +14,10 @@ show_path2 = HOME+"/LibreLight/show/"
 # python3 movewin.py window-title x y
 # python3 movewin.py COMMA 723 943
 
+sys.path.insert(0,"/opt/LibreLight/Xdesk/")
+print(sys.path)
+from lib.cprint import cprint
+
 class Control():
     def __init__(self):
         self.title = "WinfoWinName"
@@ -120,7 +125,7 @@ def winfo2(name="WinfoWinName"):
     print("--------------")
     return _data
 
-def get_store_line():
+def get_store_sdl_line():
     print()
     print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
     lines = winfo2(name="SDL-")
@@ -151,6 +156,23 @@ def load_all_sdl(title="X"):
             if title in line:
                 return json.loads(line)
 
+
+def _start_sub(cmd,name,mute=0):
+    r = os.popen(cmd)
+    while 1:
+        #print(dir(r))
+        line = r.readline()
+        if not line:
+            break
+        line = line.strip()
+        if mute == 0:
+            cprint(name,":",[line],color="blue")
+    cprint("EXIT:",name,cmd)
+    #BrokenPipeError: [Errno 32] Broken pipe
+
+def start_sub(cmd,name="<PROCESS>",mute=0):
+    thread.start_new_thread(_start_sub,(cmd,name,mute)) # SERVER
+
 def startup_all_sdl():
     print()
     print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
@@ -169,17 +191,24 @@ def startup_all_sdl():
             elif line.startswith("#"):
                 continue
             else:
-                line = json.loads(line)
-                cmd = "python3 /opt/LibreLight/Xdesk/tksdl/{}"
-                if line[1] == "SDL-MIDI":
-                    cmd.format("midi.py")
-                    os.system(cmd)
-                elif line[1] == "SDL-DMX":
-                    cmd.format("dmx.py")
-                    os.system(cmd)
-                elif line[1] == "SDL-FIX-LIST":
-                    cmd.format("fix.py")
-                    os.system(cmd)
+                print("    line >> ",[line])
+                try:
+                    line = json.loads(line)
+                    cmd = "python3 /opt/LibreLight/Xdesk/tksdl/{}"
+                    if line[1] == "SDL-MIDI":
+                        cmd=cmd.format("midi.py")
+                        #r=os.popen(cmd)
+                        start_sub(cmd,"SDL-MIDI",mute=1)
+                    elif line[1] == "SDL-DMX":
+                        cmd=cmd.format("dmx.py")
+                        #os.popen(cmd)
+                        start_sub(cmd,"SDL-DMX",mute=1)
+                    elif line[1] == "SDL-FIX-LIST":
+                        cmd=cmd.format("fix.py")
+                        #r=os.popen(cmd)
+                        start_sub(cmd,"SDL-FIX",mute=1)
+                except json.decoder.JSONDecodeError as e:
+                    cprint("ERR",e,color="red")
 
 def _read_init_txt():#show_path):
     fname = show_path+"init.txt"
@@ -236,7 +265,7 @@ def store_all_sdl():
         for line in in_lines:
             print(" R:",[line])
 
-    lines = get_store_line()
+    lines = get_store_sdl_line()
     ap_line = []
     pop = []
     for line in lines: