dmx.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. #!/usr/bin/python3
  2. import time
  3. boot = time.time()
  4. import random
  5. import os
  6. import sys
  7. #sys.path.insert(0,os.path.realpath(os.getcwd() + '/..'))
  8. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  9. print(sys.path)
  10. print()
  11. import pathlib
  12. _file_path=pathlib.Path(__file__)
  13. print("file:",_file_path)
  14. import tool.movewin as movewin
  15. CAPTION = 'LibreLight SDL-DMX '
  16. movewin.check_is_started(CAPTION,_file_path)
  17. # ===== GUI =========
  18. import pygame
  19. import pygame.gfxdraw
  20. import pygame.font
  21. pg = pygame
  22. main_size=(850,460)
  23. window = pygame.display.set_mode(main_size,pg.RESIZABLE,32)
  24. pg = pygame
  25. pygame.init()
  26. pygame.mixer.quit()
  27. clock = pygame.time.Clock()
  28. icon = pygame.image.load('icon/scribble.png')
  29. pygame.display.set_icon(icon)
  30. import tool.movewin as movewin
  31. import tool.sdl_elm as sdl_elm
  32. #CAPTION = 'LibreLight DMX '
  33. CAPTION += ':{}'.format(random.randint(100,999))
  34. import tool.git as git
  35. CAPTION += git.get_all()
  36. _id = movewin.winfo(CAPTION)
  37. c1 = movewin.movewin(_id,main_size[0],main_size[1]) #800,500)
  38. os.system(c1)
  39. c1 = movewin.activate(_id)
  40. os.system(c1)
  41. pg.display.set_caption(CAPTION)
  42. font0 = pygame.font.SysFont("freesans",10)
  43. font0b = pygame.font.SysFont("freesansbold",10)
  44. font = pygame.font.SysFont("freemonobold",22)
  45. font10 = pygame.font.SysFont("freemonobold",10)
  46. font12 = pygame.font.SysFont("freemonobold",12)
  47. font15 = pygame.font.SysFont("freemonobold",15)
  48. font16 = pygame.font.SysFont("freemonobold",16)
  49. font22 = pygame.font.SysFont("FreeSans",22)
  50. #font = pygame.font.SysFont(None,30)
  51. fr = font.render("hallo" ,1, (200,0,255))
  52. start = time.time()
  53. table = []
  54. r = 80
  55. i = 1
  56. bx = sdl_elm.Button(window,pos=[20,r,80,40])
  57. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  58. bx.bg_on = [255,0,255]
  59. bx.btn1.color_on = [255,0,155]
  60. bx.btn1.type = "flash"
  61. table.append(bx)
  62. r+=bx.get_rect()[3]
  63. i += 1
  64. bx = sdl_elm.Button(window,pos=[20,r,80,40])
  65. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  66. table.append(bx)
  67. r+=bx.get_rect()[3]
  68. i += 1
  69. r+=bx.get_rect()[3]
  70. bx = sdl_elm.Button(window,pos=[20,r,80,40])
  71. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  72. bx.font0 = pygame.font.SysFont("freesans",20)
  73. bx.btn4.val.set( 100)
  74. bx.fader = 0
  75. table.append(bx)
  76. r+=bx.get_rect()[3]
  77. i += 1
  78. bx = sdl_elm.Button(window,pos=[30,r,190,60])
  79. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  80. bx.font0 = pygame.font.SysFont("freesans-bold",20)
  81. bx.btn1.type = "flash"
  82. table.append(bx)
  83. r+=bx.get_rect()[3]
  84. i += 1
  85. bx = sdl_elm.Button(window,pos=[20,r,60,20])
  86. bx.text = "FIX:{}\n<val>\nx".format(i+1)
  87. bx.font0 = pygame.font.SysFont("freesans",12)
  88. table.append(bx)
  89. mouse_down = 0
  90. mouse_pos1 = [0,0]
  91. mouse_pos2 = [0,0]
  92. mouse_grab = []
  93. print(int((time.time()-boot)*10),"loop...")
  94. fps_t = time.time()
  95. fps = 0
  96. fps_old = 0
  97. import memcache
  98. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  99. mc.set("some_key", "Some value")
  100. value = mc.get("some_key")
  101. mc.set("another_key", 3)
  102. mc.delete("another_key")
  103. import time
  104. import json
  105. data = {}
  106. start = time.time()
  107. delta = start
  108. #for i in dir(mc):
  109. # print(i)#,[i.__doc__])
  110. # print()
  111. #for i in mc.get_stats():
  112. # print("keys",i)
  113. #fps_btn = []
  114. #fps_btn_press = []
  115. #i += 1
  116. #bx = sdl_elm.Button(window,pos=[30,r,190,60])
  117. #bx.text = "FIX:{}\n<val>\nx".format(i+1)
  118. #bx.font0 = pygame.font.SysFont("freesans-bold",20)
  119. #bx.btn1.type = "flash"
  120. #fps_btn.append(bx)
  121. #r+=bx.get_rect()[3]
  122. table={}
  123. btn1_press = [] #["10.10.10.13:0"]
  124. font0 = pygame.font.SysFont("freesans-bold",15)
  125. while 1:
  126. fps +=1
  127. t = time.time()
  128. if t-fps_t >= 1:
  129. #print("FPS:",fps)
  130. fps_old = fps
  131. fps=0
  132. fps_t =t
  133. pygame.display.flip()
  134. pos = [160,10,70,60]
  135. rgb = (0xdd,0xdd,0xdd,0)
  136. rgb = (0xaa,0xaa,0xaa,0)
  137. window.fill((5,5,5))
  138. pygame.draw.rect(window,(0,0,0),[0,0,main_size[0],main_size[1]])
  139. fr = font22.render("RAW DMX DATA" ,1, (200,200,200))
  140. window.blit(fr,(20,10 ))
  141. fr = font22.render("DEMO / TEST - MODE ! " ,1, (200,200,200))
  142. #window.blit(fr,(10,30 ))
  143. pos = [160,110,70+80,20]
  144. #pygame.draw.rect(window,rgb,pos)
  145. t=(time.time()-start)
  146. if t > 15:
  147. start = time.time()
  148. b= 80-int(t*10)
  149. pos = [160,110,70+(b),20]
  150. rgb = (0x00,0xff,0xff,0)
  151. #pygame.draw.rect(window,rgb,pos)
  152. rgb = (0x00,0x00,0x00,0)
  153. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  154. #window.blit(fr,pos[:2])
  155. pos = [160,200,80,20]
  156. #fd = sdl_elm.Fader(window,pos)
  157. #fd.draw()
  158. pos = [160,90,70+80,20]
  159. #pygame.draw.rect(window,rgb,pos)
  160. b= int(t*10)
  161. pos = [160,90,0+(b),20]
  162. rgb = (0x00,0xff,0xff,0)
  163. #pygame.draw.rect(window,rgb,pos)
  164. rgb = (0x00,0x00,0x00,0)
  165. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  166. # window.blit(fr,pos[:2])
  167. rgb = (0xaa,0xaa,0xaa,0)
  168. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  169. #window.blit(fr,(500,500))
  170. rgb = (0xff,0,0xaa,0)
  171. #for t in table:
  172. # t.draw()
  173. jjjj=330
  174. iiii=25
  175. for i in range(20):
  176. fr = font15.render(str(i+1) ,1, rgb) #(200,200,200))
  177. window.blit(fr,(jjjj,10+iiii))
  178. jjjj+=25
  179. jjjj=300
  180. iiii=40
  181. for i in range(26):
  182. fr = font15.render(str(i*20+1) ,1, rgb) #(200,200,200))
  183. window.blit(fr,(jjjj,10+iiii))
  184. iiii+=15
  185. r=40
  186. if 1:
  187. ch = 141
  188. send = 0
  189. #cmd="stats items"
  190. y=mc.get("index")#cmd)
  191. if y:
  192. #print(x)
  193. #print()
  194. iii = 0
  195. key=y.keys()
  196. key = list(key)
  197. key.sort()
  198. if len(btn1_press) == 0:
  199. btn1_press = [key[0]]
  200. rgb = (0x00,0,0xff,0)
  201. k2 = btn1_press[-1]
  202. fr = font22.render("SRC:"+str(k2) ,1, rgb) #(200,200,200))
  203. window.blit(fr,(300,1))
  204. fr = font22.render("FPS:"+str(fps_old) ,1, rgb) #(200,200,200))
  205. window.blit(fr,(600,1))
  206. for k in key:#y.items():
  207. v = y[k]
  208. #print(k,v)
  209. x=mc.get(k)
  210. cccount = 0
  211. for ch in x:
  212. try:
  213. if ch > 0:
  214. cccount +=1
  215. except:pass
  216. txt = str([k,v,ch,"=",cccount]) #x[ch-1]])
  217. #print(txt )#k,v,ch,"=",x[ch-1])
  218. rgb = (0xaa,0xaa,0xaa,0)
  219. fr = font22.render(str(txt) ,1, rgb) #(200,200,200))
  220. #window.blit(fr,(30,40+iii))
  221. i += 1
  222. if k not in table:
  223. bx = sdl_elm.Button(window,pos=[20,r,230,20])
  224. bx.btn1.color_on = [255,255,0]
  225. table[k] = bx
  226. bx = table[k]
  227. bx.text = str(txt) #+"\n<val>\n" #.format(i+1)
  228. bx.font0 = font0 #pygame.font.SysFont("freesans-bold",15)
  229. bx.btn1.bg_on = [0,255,255]
  230. #bx.dbg = 1
  231. #bx.btn4.val.set( 100)
  232. bx.btn1.type = "toggle"
  233. #bx.fader = 0
  234. #table.append(bx)
  235. bx.pos = [20,r,230,20]
  236. bx.draw()
  237. r+=bx.get_rect()[3]+2
  238. iii += 35
  239. iiii=40
  240. jjjj=330
  241. k2 = ""
  242. try:
  243. k2 = btn1_press[-1]
  244. except:pass
  245. if k2 == k:
  246. for l,m in enumerate(x):
  247. #fr = font15.render(str([l,m]) ,1, rgb) #(200,200,200))
  248. fr = font16.render(str(m) ,1, rgb) #(200,200,200))
  249. window.blit(fr,(jjjj,10+iiii))
  250. jjjj+=25
  251. if (l+1) % 20 == 0:
  252. iiii+=15
  253. jjjj=330
  254. #time.sleep(.13)
  255. last_k = ""
  256. for k in table:
  257. t = table[k]
  258. if t.btn1.val.get():
  259. if k not in btn1_press:
  260. btn1_press.append(k)
  261. #print(btn1_press)
  262. if len(btn1_press) > 1:
  263. for k in table:
  264. table[k].btn1.val.set(0)
  265. k = btn1_press[-1]
  266. if k in table:
  267. btn1_press = [k]
  268. try:
  269. k = btn1_press[-1]
  270. table[k].btn1.val.set(1)
  271. except:pass
  272. resize_changed = 0
  273. for event in pygame.event.get():
  274. if "scancode" in event.dict:
  275. if event.scancode == 9:
  276. for k in table:
  277. t = table[k]
  278. t.btn2.clean()
  279. print("event",event)
  280. if event.type == pygame.QUIT:
  281. pygame.quit()
  282. sys.exit(0)
  283. elif event.type == pygame.VIDEORESIZE:
  284. scrsize = event.size
  285. width = event.w
  286. hight = event.h
  287. resize_changed = True
  288. for t in table:
  289. print(t)
  290. table[t].event(event)
  291. if "pos" in event.dict:
  292. if "button" in event.dict:
  293. if event.type == 5:#press
  294. mouse_down = 1
  295. mouse_pos1 = [event.pos[0],event.pos[1]]
  296. if event.type == 6:#release
  297. mouse_down = 0
  298. for btn in mouse_grab:
  299. btn.btn2.val.set(1)
  300. mouse_grab = []
  301. mouse_pos2 = [event.pos[0],event.pos[1]]
  302. if mouse_down:
  303. d1 = mouse_pos1[0]-mouse_pos2[0]
  304. d2 = mouse_pos1[1]-mouse_pos2[1]
  305. pix = 23
  306. #print(d1,d2)
  307. if ( d1 > pix or d1 < -pix) or ( d2 >pix or d2 < -pix):
  308. sdl_elm.draw_mouse_box(window,mouse_pos1,mouse_pos2)
  309. for k in table:
  310. t = table[k]
  311. pos = t.get_rect()
  312. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  313. if sdl_elm.check_area2(pos,mpos):
  314. t._set_mouse_focus(1)
  315. mouse_grab.append(t)
  316. else:
  317. t._set_mouse_focus(0)
  318. if resize_changed:# = True
  319. screen = pygame.display.set_mode(scrsize,pg.RESIZABLE)
  320. clock.tick(10)