Browse Source

cleanup: sdl_load

micha 6 months ago
parent
commit
417113a34e
1 changed files with 76 additions and 60 deletions
  1. 76 60
      tool/movewin.py

+ 76 - 60
tool/movewin.py

@@ -152,15 +152,17 @@ def get_store_sdl_line():
 
 def load_all_sdl(title="X"):
     fname = SHOW_PATH + "/gui-sdl.txt"
-    if os.path.isfile(fname):
-        f=open(fname,"r")
-        lines = f.readlines()
-        f.close()
+    if not os.path.isfile(fname):
+        return 
+
+    f=open(fname,"r")
+    lines = f.readlines()
+    f.close()
 
-        print("  load_all_sdl fname:",fname)
-        for line in lines:
-            if title in line:
-                return json.loads(line)
+    print("  load_all_sdl fname:",fname)
+    for line in lines:
+        if title in line:
+            return json.loads(line)
 
 
 def _start_sub(cmd,name,mute=0):
@@ -185,60 +187,74 @@ def startup_all_sdl():
     #print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
 
     fname = SHOW_PATH + "/gui-sdl.txt"
-    if os.path.isfile(fname):
-        f=open(fname,"r")
-        xlines = f.readlines()
-        f.close()
+    if not os.path.isfile(fname):
+        return 
 
-        print()
-        cprint("startup_all_sdl() ",fname,color="yellow")
-        for line in xlines:
-            line = line.strip()
-            if line.startswith("#-- history"):
-                break
-            elif line.startswith("#"):
-                continue
-            if not line:
-                continue
-            else:
-                #print("    line >> ",[line])
-                try:
-                    line = json.loads(line)
-                    cmd = "python3 /opt/LibreLight/Xdesk/tksdl/{}"
-                    if "--easy" in sys.argv:
-                        if line[1] == "EXEC-BTN":
-                            cmd = "python3 /opt/LibreLight/Xdesk/tkgui/{}"
-                            cmd=cmd.format("EXEC-BTN.py")
-                            #r=os.popen(cmd)
-                            start_sub(cmd,"EXEC-BTN",mute=1)
-                    else:
-                        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)
-                        elif line[1] == "EXEC-BTN":
-                            cmd = "python3 /opt/LibreLight/Xdesk/tkgui/{}"
-                            cmd=cmd.format("EXEC-BTN.py")
-                            #r=os.popen(cmd)
-                            start_sub(cmd,"EXEC-BTN",mute=1)
-                        elif line[1] == "EXEC-XWING":
-                            cmd = "python3 /opt/LibreLight/Xdesk/tkgui/{}"
-                            cmd=cmd.format("EXEC-XWING.py")
-                            #r=os.popen(cmd)
-                            start_sub(cmd,"EXEC-XWING",mute=1)
-                except json.decoder.JSONDecodeError as e:
-                    cprint("ERR",e,color="red")
-            time.sleep(0.3)
+    f=open(fname,"r")
+    xlines = f.readlines()
+    f.close()
 
-        print()
+    print()
+    cprint("startup_all_sdl() ",fname,color="yellow")
+    xlines2 = []
+    for line in xlines:
+        # cleanup and info loop
+        line = line.strip()
+        if line.startswith("#-- history"):
+            break
+        if line.startswith("#"):
+            continue
+        if not line:
+            continue
+
+        xlines2.append(line)
+        print("    line >> ",[line])
+
+    # ------------------
+
+
+    print()
+    for line in xlines2:
+        print("    line >> ",[line])
+        try:
+            line = json.loads(line)
+        except json.decoder.JSONDecodeError as e:
+            cprint("ERR",e,color="red")
+            continue
+
+        cmd = "python3 /opt/LibreLight/Xdesk/tksdl/{}"
+        if "--easy" in sys.argv:
+            if line[1] == "EXEC-BTN":
+                cmd = "python3 /opt/LibreLight/Xdesk/tkgui/{}"
+                cmd=cmd.format("EXEC-BTN.py")
+                #r=os.popen(cmd)
+                start_sub(cmd,"EXEC-BTN",mute=1)
+        else:
+            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)
+            elif line[1] == "EXEC-BTN":
+                cmd = "python3 /opt/LibreLight/Xdesk/tkgui/{}"
+                cmd=cmd.format("EXEC-BTN.py")
+                #r=os.popen(cmd)
+                start_sub(cmd,"EXEC-BTN",mute=1)
+            elif line[1] == "EXEC-XWING":
+                cmd = "python3 /opt/LibreLight/Xdesk/tkgui/{}"
+                cmd=cmd.format("EXEC-XWING.py")
+                #r=os.popen(cmd)
+                start_sub(cmd,"EXEC-XWING",mute=1)
+        time.sleep(0.3)
+
+    print()
 
 
 def store_all_sdl():