Browse Source

cleanup: tkray/dmx.py; tksdl/dmx.py 30% to 14% CPU

micha 6 tháng trước cách đây
mục cha
commit
2515b1e117
3 tập tin đã thay đổi với 63 bổ sung88 xóa
  1. 54 76
      tkray/dmx.py
  2. 6 3
      tkray/test.py
  3. 3 9
      tksdl/dmx.py

+ 54 - 76
tkray/dmx.py

@@ -3,8 +3,8 @@ import pyray
 ConfigFlags(FLAG_MSAA_4X_HINT) #|FLAG_WINDOW_RESIZABLE  )
 #ConfigFlags(FLAG_WINDOW_RESIZABLE  )
 ConfigFlags(FLAG_WINDOW_HIGHDPI )
-init_window(800, 450, "RAY-DMX")#,10,10,10,10)
-#pyray.TextureFilter(font1,1)
+init_window(760, 450, "RAY-DMX")#,10,10,10,10)
+#pyray.TextureFilter(font10,1)
 
 import sys
 sys.path.insert(0,"/opt/LibreLight/Xdesk/")
@@ -14,19 +14,9 @@ img = "/opt/LibreLight/Xdesk/icon/scribble.png"
 IMG = load_image(img)
 print(set_window_icon(IMG)) 
 
-
-
-#SetWindowIcon(Image image) 
-#for d in dir():
-#    if "image" in d.lower():
-#        print(d)
-
 import time
-
 import memcache
 mc = memcache.Client(['127.0.0.1:11211'], debug=0)
-
-
 #x=mc.get(k)
 
 old_x = -10
@@ -42,44 +32,29 @@ fps_count = 0
 #a = "/usr/share/fonts/truetype/freefont/FreeSerif.ttf"
 #a = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf"
 a = "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
-#a = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf"
+a = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf"
 
 
 k=200
-i= 40 #60
-#font1 = load_font_ex(a, i, pyray.ffi.new('int *', 6), 1024);
-font1 = load_font_ex(a, i, None, 0);
-#font1 = load_font(a ) #, i, pyray.ffi.new('int *', 2), k);
-
-# `SetTextureFilter(font.texture, TEXTURE_FILTER_TRILINEAR)` did the trick. 
-# `TEXTURE_FILTER_BILINEAR` also worked fine, but the trilinear option worked better. 
+font10 = load_font_ex(a, 10, None, 0);
+font20 = load_font_ex(a, 20, None, 0);
+a = "/usr/share/fonts/truetype/freefont/FreeMono.ttf"
+font25 = load_font_ex(a, 25, None, 0);
 
 pyray.TextureFilter(3)
 
+grid_x = 250
+grid_y = 60
+
 while not window_should_close():
     begin_drawing()
-    #for o in dir(font1):
-    #    print(o)
-    #print()
-    #print(font1.texture) # (3)
 
     clear_background(BLACK)
     Color(255,0,0,0)
     rl_enable_smooth_lines()
-    if 0: # font test
-        draw_line(2, 2, 100, 2, (255,225,0,220))
-        #print(load_font_ex.__doc__) #("resources/pixantiqua.ttf", 32, 0, 250);
-
-        i = 20
-        
-        draw_text_ex(font1,b"73qwertzuio", [30,12], 45, 0, YELLOW)# VIOLET)
-        draw_text_ex(font1,"11a", [37,212], 45, 0, YELLOW)# VIOLET)
-        draw_text_ex(font1,"a1131", [44,302], 45, 0, YELLOW)# VIOLET)
-
-        draw_text(str("{} {}".format(i,k)), 50, 75, 34, YELLOW)# VIOLET)
 
     if 10:
-        btn = tk_elm.Button(None,pos=[350,12])
+        btn = tk_elm.Button(None,pos=[390,12])
         x=btn.btn1.name
         a = btn.pos
         draw_text(str(x), 5, a[0]   , a[1], YELLOW)# VIOLET)
@@ -90,96 +65,100 @@ while not window_should_close():
         draw_text(str(x), 5, a[0]+30, a[1], YELLOW)# VIOLET)
         x=btn.btn4.name
 
-    font_size = 14
+    font_size = 10
     try:
-        y=mc.get("index")#cmd)
+        DATA=mc.get("index")#cmd)
         GREY = [122,122,122,255]
         p=0
         keys = []
-        for k in y:
+        host_list = {}
+        for k in DATA:
+            #print(DATA[k])
             keys.append(k)
+            host_list[k] = DATA[k] #[0]).ljust(" ",18) #,0,"=",0]
         keys.sort()
 
         k=keys[2]
-        for i,v in enumerate(range(20+1)):
+        for i,v in enumerate(range(20)):
             # COL NUMBER -> 1 2... 20
-            x2 = 180+i*30
-            y2 =   5 #+i*13
+            x2 = grid_x+i*25
+            y2 = grid_y-20
+
             txt=str(i+1)
-            #draw_text(txt, x2, y2, 11, YELLOW)
-            draw_text_ex(font1,txt, [x2,y2], font_size, 0, YELLOW)
+            draw_text_ex(font10,txt, [x2,y2], font_size, 0, [0,255,0,255]) #YELLOW)
             i+=1
-            if i % 20 == 0:
-                break
+
         xi=0
         yi=0
+        DMX=mc.get(k)
+        draw_text_ex(font25,"SRC:{}".format(k),[grid_x-20,5], 25, 0,  VIOLET)
 
-        for i,v in enumerate(mc.get(k)):
+        for i,v in enumerate(DMX):
             #print(i,v)
+            
+            if v:
+                host_list[k][-1] +=1
             txt = str(i)+":"+str(v)
             txt = str(v)
-            x2 = 180+xi*30
-            y2 =  25+yi*16
+            x2 = grid_x+xi*25
+            y2 = grid_y+yi*15
             try:
                 draw_rectangle(x2-2, y2-2,24,13,[255,255,255,int(v)])
             except:
                 draw_rectangle(x2-2, y2-2,24,13,[255,2,2,255])
+
             try:
                 int(v)
             except:
                 v=0
 
+
             if int(v) > 100:
-                draw_text_ex(font1,txt, [x2,y2], font_size, 0, BLACK)# VIOLET)
+                draw_text_ex(font10,txt, [x2,y2], font_size, 0, BLACK)# VIOLET)
             else:
-                draw_text_ex(font1,txt, [x2,y2], font_size, 0, GREY)# VIOLET)
+                draw_text_ex(font10,txt, [x2,y2], font_size, 0, GREY)# VIOLET)
             xi+=1
 
             if xi % 20 == 0:
                 txt = str(int(yi*20)+1)
-                draw_text_ex(font1,txt, [170-30,y2], font_size, 0, YELLOW)# VIOLET)
+                draw_text_ex(font10,txt, [grid_x-30,y2], font_size, 0, YELLOW)# VIOLET) # ROEW NR
+
                 xi = 0
                 yi += 1
-
-
-
         txt = str(int(yi*20)+1)
-        draw_text_ex(font1,txt, [170-30,y2], font_size, 0, YELLOW)# VIOLET)
+        draw_text_ex(font10,txt, [grid_x-30,y2], font_size, 0, YELLOW)# VIOLET) # ROEW NR
+
         p=0
-        for k in keys:
+        for k,v in host_list.items():
+            #for k in keys:
             # HOST LIST  
             x2 = 10
-            y2 =  20+p
-            txt =":"+str(k) 
-            #draw_text(txt, x2, y2, 20, GREY)# VIOLET)
-            draw_text_ex(font1,txt, [x2,y2], font_size, 0, YELLOW)# VIOLET)
+            y2 = grid_y+p
+            txt =str(k)+" "+str(v).replace(" ","").replace("[","").replace("]","") 
+            draw_rectangle(x2-2, y2-2,200,18,[125,125,125,255])
+            draw_text_ex(font10,txt, [x2,y2], font_size, 0, BLACK) # YELLOW)# VIOLET)
             p+=20
 
-        x=100
-        y=100
         w=200
         h=50
-        #draw_rectangle(x, y,w,h,[255,0,20,255])
+
         x=200
         y=200
-        #draw_rectangle_lines(x,y,w,h,[255,200,20,255])
-        #for i in  MouseButton:
-        #    if is_key_down(i):
-        #        print(i)
-        #for i in  range(0,512):
-        #    if is_key_down(i):
-        #        print(i)
-        draw_text("FPS:{}".format(fps_count), 3, 3, 3, VIOLET)
-        #Color(255,0,0,0)
+
+        draw_text_ex(font25,"FPS:{}".format(fps_count),[10,5], 25, 0,  VIOLET)
+
         m=get_mouse_position()
         if m.x != old_x or m.y != old_y:
             old_x = m.x
             old_y = m.y
-            print(m.x,m.y)
+            print("POS:",m.x,m.y)
+        draw_text_ex(font20,"POS:{}:{}".format(int(m.x),int(m.y)),[10,34], 20, 0,  VIOLET)
+
         draw_rectangle(int(old_x-10),int(old_y-1),20,2,[255,0,255,255])
         draw_rectangle(int(old_x-1),int(old_y-10),2,20,[255,0,255,255])
+
         end_drawing()
-        time.sleep(0.1)
+        time.sleep(1/10)
 
         frame_count += 1
         if time.time()-start > 1:
@@ -192,6 +171,5 @@ while not window_should_close():
     except Exception as e:# KeyInterupt
         print("err",e)
         time.sleep(1)
-        #raise e
 close_window()
 

+ 6 - 3
tkray/test.py

@@ -27,12 +27,13 @@ print(set_window_icon(IMG))
 
 a = "/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf"
 a = "/usr/share/fonts/truetype/liberation/LiberationMono-Bold.ttf"
-a = "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
-a = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf"
+#a = "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
+#a = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf"
 
 k=200
 i= 40 
 i= 140 
+i= 40 
 #font1 = load_font_ex(a, i, None, 0);
 font1 = load_font_ex(a, i, None, 0);
 
@@ -489,9 +490,11 @@ while not window_should_close():
         draw_text_ex(font1,txt2, [140,60], font_size, 0, YELLOW)
 
         draw_text("free fonts included with raylib", 250, 20, 20, GRAY);
+        draw_text_ex(font1,"free fonts included with raylib", 250, 20, 20, GRAY);
 
         draw_rectangle(x2-1, y2,24,13,[255,255,255,int(v)])
-        draw_text("FPS:{}".format(fps_count), 3, 3, 3, VIOLET)
+        #draw_text("FPS:{}".format(fps_count), 3, 3, 3, VIOLET)
+        #draw_text("FPS:{}".format(fps_count), 9, 9, 3, VIOLET)
 
         fonts = [None]*10
         #fonts[0] = load_font("resources/fonts/alagard.png");

+ 3 - 9
tksdl/dmx.py

@@ -290,7 +290,7 @@ while 1:
             key.sort()
             if len(btn1_press) == 0:
                 btn1_press = [key[0]]
-            rgb = (0x00,0,0xff,0)
+            rgb = (0x00,0xff,0xff,0)
             k2 = btn1_press[-1]
             fr = font22.render("SRC:"+str(k2) ,1, rgb) #(200,200,200))
             window.blit(fr,(300,1))
@@ -302,14 +302,8 @@ while 1:
                 v = y[k]
                 #print(k,v)
                 x=mc.get(k)
-                cccount = 0
-                for ch in x:
-                    try:
-                        if ch > 0:
-                            cccount +=1
-                    except:pass
-                txt = str([k,v,ch,"=",cccount]) #x[ch-1]])
-                #print(txt )#k,v,ch,"=",x[ch-1])
+
+                txt = str([k,v]) 
 
                 rgb = (0xaa,0xaa,0xaa,0)
                 fr = font22.render(str(txt) ,1, rgb) #(200,200,200))