dmx.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. from pyray import *
  2. import pyray
  3. ConfigFlags(FLAG_MSAA_4X_HINT) #|FLAG_WINDOW_RESIZABLE )
  4. #ConfigFlags(FLAG_WINDOW_RESIZABLE )
  5. ConfigFlags(FLAG_WINDOW_HIGHDPI )
  6. init_window(800, 450, "RAY-DMX",10,10,10,10)
  7. #pyray.TextureFilter(font1,1)
  8. import sys
  9. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  10. import tool.tk_elm as tk_elm
  11. img = "/opt/LibreLight/Xdesk/icon/scribble.png"
  12. IMG = load_image(img)
  13. print(set_window_icon(IMG))
  14. #SetWindowIcon(Image image)
  15. #for d in dir():
  16. # if "image" in d.lower():
  17. # print(d)
  18. import time
  19. import memcache
  20. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  21. #x=mc.get(k)
  22. old_x = -10
  23. old_y = -10
  24. start = time.time()
  25. frame_count = 0
  26. fps_count = 0
  27. #a = "resources/pixantiqua.ttf"
  28. #a = "/lib/firefox-esr/fonts/TwemojiMozilla.ttf"
  29. #a = "/lib/python3/dist-packages/pygame/freesansbold.ttf"
  30. #a = "/usr/share/fonts/truetype/freefont/FreeMono.ttf"
  31. #a = "/usr/share/fonts/truetype/freefont/FreeSerif.ttf"
  32. #a = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf"
  33. a = "/usr/share/fonts/truetype/freefont/FreeSans.ttf"
  34. #a = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf"
  35. k=200
  36. i= 40 #60
  37. #font1 = load_font_ex(a, i, pyray.ffi.new('int *', 6), 1024);
  38. font1 = load_font_ex(a, i, None, 0);
  39. #font1 = load_font(a ) #, i, pyray.ffi.new('int *', 2), k);
  40. # `SetTextureFilter(font.texture, TEXTURE_FILTER_TRILINEAR)` did the trick.
  41. # `TEXTURE_FILTER_BILINEAR` also worked fine, but the trilinear option worked better.
  42. pyray.TextureFilter(3)
  43. while not window_should_close():
  44. begin_drawing()
  45. for o in dir(font1):
  46. print(o)
  47. print()
  48. print(font1.texture) # (3)
  49. clear_background(BLACK)
  50. Color(255,0,0,0)
  51. rl_enable_smooth_lines()
  52. if 0: # font test
  53. draw_line(2, 2, 100, 2, (255,225,0,220))
  54. print(load_font_ex.__doc__) #("resources/pixantiqua.ttf", 32, 0, 250);
  55. i = 20
  56. draw_text_ex(font1,b"73qwertzuio", [30,12], 45, 0, YELLOW)# VIOLET)
  57. draw_text_ex(font1,"11a", [37,212], 45, 0, YELLOW)# VIOLET)
  58. draw_text_ex(font1,"a1131", [44,302], 45, 0, YELLOW)# VIOLET)
  59. draw_text(str("{} {}".format(i,k)), 50, 75, 34, YELLOW)# VIOLET)
  60. if 10:
  61. btn = tk_elm.Button(None,pos=[350,12])
  62. x=btn.btn1.name
  63. a = btn.pos
  64. draw_text(str(x), 5, a[0] , a[1], YELLOW)# VIOLET)
  65. x=btn.btn2.name
  66. draw_text(str(x), 5, a[0]+15, a[1], YELLOW)# VIOLET)
  67. x=btn.btn3.name
  68. draw_text(str(x), 5, a[0]+30, a[1], YELLOW)# VIOLET)
  69. x=btn.btn4.name
  70. font_size = 14
  71. try:
  72. y=mc.get("index")#cmd)
  73. GREY = [122,122,122,255]
  74. p=0
  75. keys = []
  76. for k in y:
  77. keys.append(k)
  78. keys.sort()
  79. k=keys[2]
  80. for i,v in enumerate(range(20+1)):
  81. # COL NUMBER -> 1 2... 20
  82. x2 = 180+i*30
  83. y2 = 5 #+i*13
  84. txt=str(i+1)
  85. #draw_text(txt, x2, y2, 11, YELLOW)
  86. draw_text_ex(font1,txt, [x2,y2], font_size, 0, YELLOW)
  87. i+=1
  88. if i % 20 == 0:
  89. break
  90. xi=0
  91. yi=0
  92. for i,v in enumerate(mc.get(k)):
  93. #print(i,v)
  94. txt = str(i)+":"+str(v)
  95. txt = str(v)
  96. x2 = 180+xi*30
  97. y2 = 25+yi*16
  98. try:
  99. draw_rectangle(x2-2, y2-2,24,13,[255,255,255,int(v)])
  100. except:
  101. draw_rectangle(x2-2, y2-2,24,13,[255,2,2,255])
  102. try:
  103. int(v)
  104. except:
  105. v=0
  106. if int(v) > 100:
  107. draw_text_ex(font1,txt, [x2,y2], font_size, 0, BLACK)# VIOLET)
  108. else:
  109. draw_text_ex(font1,txt, [x2,y2], font_size, 0, GREY)# VIOLET)
  110. xi+=1
  111. if xi % 20 == 0:
  112. txt = str(int(yi*20)+1)
  113. draw_text_ex(font1,txt, [170-30,y2], font_size, 0, YELLOW)# VIOLET)
  114. xi = 0
  115. yi += 1
  116. txt = str(int(yi*20)+1)
  117. draw_text_ex(font1,txt, [170-30,y2], font_size, 0, YELLOW)# VIOLET)
  118. p=0
  119. for k in keys:
  120. # HOST LIST
  121. x2 = 10
  122. y2 = 20+p
  123. txt =":"+str(k)
  124. #draw_text(txt, x2, y2, 20, GREY)# VIOLET)
  125. draw_text_ex(font1,txt, [x2,y2], font_size, 0, YELLOW)# VIOLET)
  126. p+=20
  127. x=100
  128. y=100
  129. w=200
  130. h=50
  131. #draw_rectangle(x, y,w,h,[255,0,20,255])
  132. x=200
  133. y=200
  134. #draw_rectangle_lines(x,y,w,h,[255,200,20,255])
  135. #for i in MouseButton:
  136. # if is_key_down(i):
  137. # print(i)
  138. #for i in range(0,512):
  139. # if is_key_down(i):
  140. # print(i)
  141. draw_text("FPS:{}".format(fps_count), 3, 3, 3, VIOLET)
  142. #Color(255,0,0,0)
  143. m=get_mouse_position()
  144. if m.x != old_x or m.y != old_y:
  145. old_x = m.x
  146. old_y = m.y
  147. print(m.x,m.y)
  148. draw_rectangle(int(old_x-10),int(old_y-1),20,2,[255,0,255,255])
  149. draw_rectangle(int(old_x-1),int(old_y-10),2,20,[255,0,255,255])
  150. end_drawing()
  151. time.sleep(0.1)
  152. frame_count += 1
  153. if time.time()-start > 1:
  154. start = time.time()
  155. fps_count = frame_count
  156. frame_count = 0
  157. except KeyboardInterrupt as e:
  158. raise e
  159. except Exception as e:# KeyInterupt
  160. print("err",e)
  161. time.sleep(1)
  162. #raise e
  163. close_window()