浏览代码

add: SDL-window position and size storage

micha 1 年之前
父节点
当前提交
3e11417c92
共有 4 个文件被更改,包括 145 次插入20 次删除
  1. 20 2
      tksdl/dmx.py
  2. 25 2
      tksdl/fix.py
  3. 23 3
      tksdl/midi.py
  4. 77 13
      tool/movewin.py

+ 20 - 2
tksdl/dmx.py

@@ -22,13 +22,24 @@ import tool.movewin as movewin
 CAPTION = 'LibreLight SDL-DMX '
 movewin.check_is_started(CAPTION,_file_path)
 
+win_title =CAPTION.strip().split()[-1]
+store = movewin.load_all_sdl(win_title)
+print(store)
+W=850
+H=460
+POS=None
+if store:
+    W = store[-4]
+    H = store[-3]
+    POS=[store[-2],store[-1]]
+#exit()
 
 # ===== GUI =========
 import pygame
 import pygame.gfxdraw
 import pygame.font
 pg = pygame
-main_size=(850,460)
+main_size=(W,H)
 window = pygame.display.set_mode(main_size,pg.RESIZABLE,32)
 
 pg = pygame
@@ -38,7 +49,6 @@ clock = pygame.time.Clock()
 icon = pygame.image.load('icon/scribble.png')
 pygame.display.set_icon(icon)
 
-import tool.movewin as movewin
 import tool.sdl_elm as sdl_elm
 
 
@@ -159,6 +169,13 @@ delta = start
 #r+=bx.get_rect()[3]
 
 
+win_con = movewin.Control()
+win_con.title = win_title
+win_con.winfo()
+if POS:
+    win_con.move(POS[0],POS[1])
+print(POS,win_con.title)
+#exit()
 
 table={}
 btn1_press = [] #["10.10.10.13:0"]
@@ -350,6 +367,7 @@ while 1:
 
         print("event",event)
         if event.type == pygame.QUIT:
+            movewin.store_all_sdl()
             pygame.quit()
             sys.exit(0)
         elif event.type == pygame.VIDEORESIZE:

+ 25 - 2
tksdl/fix.py

@@ -13,13 +13,26 @@ sys.path.insert(0,"/opt/LibreLight/Xdesk/")
 print(sys.path)
 print()
 
-CAPTION = 'LibreLight FIXTURE-LIST '
+CAPTION = 'LibreLight SDL-FIX-LIST '
 
 
 sys.path.insert(0,"/opt/LibreLight/Xdesk/")
 import tool.movewin as movewin
 import tool.git as git
 
+
+win_title =CAPTION.strip().split()[-1]
+store = movewin.load_all_sdl(win_title)
+print(store)
+W=850
+H=460
+POS=None
+if store:
+    W = store[-4]
+    H = store[-3]
+    POS=[store[-2],store[-1]]
+#exit()
+
 #CAPTION += ':{}'.format(random.randint(100,999))
 CAPTION += git.get_all()
 
@@ -42,7 +55,7 @@ import pygame
 import pygame.gfxdraw
 import pygame.font
 pg = pygame
-main_size=(850,460)
+main_size=(W,H)#850,460)
 window = pygame.display.set_mode(main_size,pg.RESIZABLE,32)
 
 pg = pygame
@@ -293,6 +306,15 @@ def get_fix_type(fix_row):
 
     return "UNKNOWN"
 
+
+win_con = movewin.Control()
+win_con.title = win_title
+win_con.winfo()
+if POS:
+    win_con.move(POS[0],POS[1])
+print(POS,win_con.title)
+
+
 table={}
 table_grid={}
 btn1_press = [] #["10.10.10.13:0"]
@@ -663,6 +685,7 @@ while 1:
                     cmd_client.send(msg)
 
             if event.type == pygame.QUIT:
+                movewin.store_all_sdl()
                 pygame.quit()
                 sys.exit(0)
             elif event.type == pygame.VIDEORESIZE:

+ 23 - 3
tksdl/midi.py

@@ -14,6 +14,9 @@ sys.path.insert(0,"/opt/LibreLight/Xdesk/")
 import tool.movewin as movewin
 import tool.git as git
 
+win_title =CAPTION.strip().split()[-1]
+store = movewin.load_all_sdl(win_title)
+
 #CAPTION += ':{}'.format(random.randint(100,999))
 CAPTION += git.get_all()
 
@@ -29,6 +32,16 @@ movewin.check_is_started(CAPTION,_file_path)
 #os.system(c1)
 
 
+print(store)
+W=500
+H=100
+POS=None
+print()
+print("title:",win_title)
+if store:
+    W = store[-4]
+    H = store[-3]
+    POS=[store[-2],store[-1]]
 
 
 
@@ -39,7 +52,7 @@ import pygame.gfxdraw
 import pygame.font
 
 pg = pygame
-main_size=(500,100)
+main_size=(W,H)
 window = pygame.display.set_mode(main_size)#,pg.RESIZABLE,32)
 
 pg = pygame
@@ -137,7 +150,13 @@ import _thread as thread
 
 apc_main = None
 
-
+win_con = movewin.Control()
+win_con.title = win_title
+win_con.winfo()
+if POS:
+    win_con.move(POS[0],POS[1])
+print(":",POS,win_con.title)
+#exit()
 #while 1:
 #    if apc_main.buf:
 #        buf = apc_main.buf[:]
@@ -357,8 +376,8 @@ while 1:
 
         print("event",event)
         if event.type == pygame.QUIT:
+            movewin.store_all_sdl()
             pygame.quit()
-            #time.sleep(1)
             sys.exit(0)
         elif event.type == pygame.VIDEORESIZE:
             scrsize = event.size
@@ -408,6 +427,7 @@ while 1:
     try:
         clock.tick(10)
     except KeyboardInterrupt as e:
+        movewin.store_all_sdl()
         pygame.quit()
         raise e
 

+ 77 - 13
tool/movewin.py

@@ -4,6 +4,7 @@ import sys
 import time
 import psutil
 import json    
+import inspect
 
 # python3 movewin.py window-title x y
 # python3 movewin.py COMMA 723 943
@@ -116,10 +117,11 @@ def winfo2(name="WinfoWinName"):
     return _data
 
 def get_store_line():
+    print()
+    print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
     lines = winfo2(name="SDL-")
     out_lines=[]
     for line in lines:
-        #print(" ##",line)
         t=line[2].split()
         for k in t:
             k = k.replace(" ", "_")
@@ -128,58 +130,121 @@ def get_store_line():
                 p=line[-1]
 
                 # info: b x h + x + y
-                #out = "{} {} {} {} {} {}\n".format(1,k, s[0],s[1],p[0],p[1] )
                 out = [1,k, s[0],s[1],p[0],p[1] ]
-                #print("  --",k,out)
                 out_lines.append(out)
     return out_lines
 
+def load_all_sdl(title="X"):
+    fname ="/home/user/gui-sdl.txt"
+    if os.path.isfile(fname):
+        f=open(fname,"r")
+        lines = f.readlines()
+        f.close()
+
+        print("  read",fname)
+        for line in lines:
+            if title in line:
+                return json.loads(line)
+
+def startup_all_sdl():
+    print()
+    print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
+    fname ="/home/user/gui-sdl.txt"
+    if os.path.isfile(fname):
+        f=open(fname,"r")
+        xlines = f.readlines()
+        f.close()
 
+        print("  read",fname)
+        for line in xlines:
+            line = line.strip()
+            if line.startswith("#-- history"):
+                break
+            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)
+
+#example test use
+#python3 -i -c "import tool.movewin as w;d=w.Control();d.title='SDL-DMX';d.winfo()"
+#w.store_all_sdl()
+#d.get_winfo2()
+#d.move(100,100)
 def store_all_sdl():
+    print()
+    print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
     fname ="/home/user/gui-sdl.txt"
+    in_lines = []
+
     if os.path.isfile(fname):
         f=open(fname,"r")
         xlines = f.readlines()
         f.close()
 
-        in_lines = []
         print("  read",fname)
         for line in xlines:
             line = line.strip()
             if not line.startswith("#") and line:
-                #print(" ++",[line])
                 in_lines.append(line)
-        in_lines.append("[0,0,00,0,0,0]")
+        #in_lines.append('[0,"xx aa",0,0,0,0]')
+        for line in in_lines:
+            print(" R:",[line])
 
-    print("Öö"*20)
     lines = get_store_line()
     ap_line = []
+    pop = []
     for line in lines:
         ok = 0
         iline = ""
-        for iline in in_lines:
+        for j,iline in enumerate(in_lines):
             if line[1] in iline:
-                ok = 1 
-        if not ok and iline:
-           ap_line.append(iline)
+                if j not in pop:
+                    pop.append(j)
+                print(" del ",j,line)
 
+    for i in pop[::-1]:
+        try:
+            in_lines.pop(i)
+        except Exception as e:
+            print("ERR:",e) 
+    temp = {}
+    for i in in_lines:
+        k = json.loads(i)[1]
+        if k not in temp:
+            temp[k] = i
 
     f=open(fname,"w")
     f.write("#"+json.dumps(["on","title","w","h","x","y"])+"\n")
     for line in lines:
         f.write(json.dumps(line)+"\n")
 
-    for line in ap_line:
+    f.write("\n")
+    f.write("#-- history \n")
+    for k,line in temp.items(): #in_lines:
         print("+++>",line)
         f.write(line+"\n")
     f.write("\n")
     f.close()
 
 def movewin(_id="0xWinId",x=None,y=None):
+    print()
+    print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
     cmd="xdotool windowmove {} {} {}".format(_id,x,y)
     return cmd
 
 def sizewin(_id="0xWinId",x=None,y=None):
+    print()
+    print("-> def",inspect.currentframe().f_code.co_name,"-"*10)
     cmd="xdotool windowsize {} {} {}".format(_id,x,y)
     return cmd
 
@@ -236,7 +301,6 @@ def process_kill(path):
         p.terminate()
         p.wait()
 
-import inspect
 def get_lineno():
   callerframerecord = inspect.stack()[1]    # 0 represents this line
                                             # 1 represents line at caller