dmx.py 10 KB

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