dmx.py 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. while 1:
  132. fps +=1
  133. t = time.time()
  134. if t-fps_t >= 1:
  135. #print("FPS:",fps)
  136. fps_old = fps
  137. fps=0
  138. fps_t =t
  139. pygame.display.flip()
  140. pos = [160,10,70,60]
  141. rgb = (0xdd,0xdd,0xdd,0)
  142. rgb = (0xaa,0xaa,0xaa,0)
  143. window.fill((5,5,5))
  144. pygame.draw.rect(window,(0,0,0),[0,0,main_size[0],main_size[1]])
  145. fr = font22.render("FPS:"+str(fps_old) +" RAW DMX DATA" ,1, (200,200,200))
  146. window.blit(fr,(3,10 ))
  147. fr = font22.render("DEMO / TEST - MODE ! " ,1, (200,200,200))
  148. #window.blit(fr,(10,30 ))
  149. pos = [160,110,70+80,20]
  150. #pygame.draw.rect(window,rgb,pos)
  151. t=(time.time()-start)
  152. if t > 15:
  153. start = time.time()
  154. b= 80-int(t*10)
  155. pos = [160,110,70+(b),20]
  156. rgb = (0x00,0xff,0xff,0)
  157. #pygame.draw.rect(window,rgb,pos)
  158. rgb = (0x00,0x00,0x00,0)
  159. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  160. #window.blit(fr,pos[:2])
  161. pos = [160,200,80,20]
  162. #fd = sdl_elm.Fader(window,pos)
  163. #fd.draw()
  164. pos = [160,90,70+80,20]
  165. #pygame.draw.rect(window,rgb,pos)
  166. b= int(t*10)
  167. pos = [160,90,0+(b),20]
  168. rgb = (0x00,0xff,0xff,0)
  169. #pygame.draw.rect(window,rgb,pos)
  170. rgb = (0x00,0x00,0x00,0)
  171. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  172. # window.blit(fr,pos[:2])
  173. rgb = (0xaa,0xaa,0xaa,0)
  174. fr = font22.render(str(round(t,1)) ,1, rgb) #(200,200,200))
  175. #window.blit(fr,(500,500))
  176. rgb = (0xff,0,0xaa,0)
  177. #for t in table:
  178. # t.draw()
  179. jjjj=330
  180. iiii=25
  181. for i in range(20):
  182. fr = font15.render(str(i+1) ,1, rgb) #(200,200,200))
  183. window.blit(fr,(jjjj,10+iiii))
  184. jjjj+=25
  185. jjjj=300
  186. iiii=40
  187. for i in range(26):
  188. fr = font15.render(str(i*20+1) ,1, rgb) #(200,200,200))
  189. window.blit(fr,(jjjj,10+iiii))
  190. iiii+=15
  191. r=40
  192. if 1:
  193. ch = 141
  194. send = 0
  195. #cmd="stats items"
  196. y=mc.get("index")#cmd)
  197. if y:
  198. #print(x)
  199. #print()
  200. iii = 0
  201. key=y.keys()
  202. key = list(key)
  203. key.sort()
  204. if len(btn1_press) == 0:
  205. btn1_press = [key[0]]
  206. rgb = (0x00,0,0xff,0)
  207. k2 = btn1_press[-1]
  208. fr = font22.render("SRC:"+str(k2) ,1, rgb) #(200,200,200))
  209. window.blit(fr,(300,1))
  210. #fr = font22.render("FPS:"+str(fps_old) ,1, rgb) #(200,200,200))
  211. #window.blit(fr,(600,1))
  212. for k in key:#y.items():
  213. v = y[k]
  214. #print(k,v)
  215. x=mc.get(k)
  216. cccount = 0
  217. for ch in x:
  218. try:
  219. if ch > 0:
  220. cccount +=1
  221. except:pass
  222. txt = str([k,v,ch,"=",cccount]) #x[ch-1]])
  223. #print(txt )#k,v,ch,"=",x[ch-1])
  224. rgb = (0xaa,0xaa,0xaa,0)
  225. fr = font22.render(str(txt) ,1, rgb) #(200,200,200))
  226. #window.blit(fr,(30,40+iii))
  227. i += 1
  228. if k not in table:
  229. bx = sdl_elm.Button(window,pos=[20,r,230,20])
  230. bx.btn1.color_on = [255,255,0]
  231. table[k] = bx
  232. bx = table[k]
  233. bx.text = str(txt) #+"\n<val>\n" #.format(i+1)
  234. bx.font0 = pygame.font.SysFont("freesans-bold",15)
  235. bx.btn1.bg_on = [0,255,255]
  236. #bx.dbg = 1
  237. #bx.btn4.val.set( 100)
  238. bx.btn1.type = "toggle"
  239. #bx.fader = 0
  240. #table.append(bx)
  241. bx.pos = [20,r,230,20]
  242. bx.draw()
  243. r+=bx.get_rect()[3]+2
  244. iii += 35
  245. iiii=40
  246. jjjj=330
  247. k2 = ""
  248. try:
  249. k2 = btn1_press[-1]
  250. except:pass
  251. if k2 == k:
  252. for l,m in enumerate(x):
  253. #fr = font15.render(str([l,m]) ,1, rgb) #(200,200,200))
  254. fr = font16.render(str(m) ,1, rgb) #(200,200,200))
  255. window.blit(fr,(jjjj,10+iiii))
  256. jjjj+=25
  257. if (l+1) % 20 == 0:
  258. iiii+=15
  259. jjjj=330
  260. #time.sleep(.13)
  261. last_k = ""
  262. for k in table:
  263. t = table[k]
  264. if t.btn1.val.get():
  265. if k not in btn1_press:
  266. btn1_press.append(k)
  267. #print(btn1_press)
  268. if len(btn1_press) > 1:
  269. for k in table:
  270. table[k].btn1.val.set(0)
  271. k = btn1_press[-1]
  272. if k in table:
  273. btn1_press = [k]
  274. try:
  275. k = btn1_press[-1]
  276. table[k].btn1.val.set(1)
  277. except:pass
  278. resize_changed = 0
  279. for event in pygame.event.get():
  280. if "scancode" in event.dict:
  281. if event.scancode == 9:
  282. for k in table:
  283. t = table[k]
  284. t.btn2.clean()
  285. print("event",event)
  286. if event.type == pygame.QUIT:
  287. pygame.quit()
  288. sys.exit(0)
  289. elif event.type == pygame.VIDEORESIZE:
  290. scrsize = event.size
  291. width = event.w
  292. hight = event.h
  293. resize_changed = True
  294. for t in table:
  295. print(t)
  296. table[t].event(event)
  297. if "pos" in event.dict:
  298. if "button" in event.dict:
  299. if event.type == 5:#press
  300. mouse_down = 1
  301. mouse_pos1 = [event.pos[0],event.pos[1]]
  302. if event.type == 6:#release
  303. mouse_down = 0
  304. for btn in mouse_grab:
  305. btn.btn2.val.set(1)
  306. mouse_grab = []
  307. mouse_pos2 = [event.pos[0],event.pos[1]]
  308. if mouse_down:
  309. d1 = mouse_pos1[0]-mouse_pos2[0]
  310. d2 = mouse_pos1[1]-mouse_pos2[1]
  311. pix = 23
  312. #print(d1,d2)
  313. if ( d1 > pix or d1 < -pix) or ( d2 >pix or d2 < -pix):
  314. sdl_elm.draw_mouse_box(window,mouse_pos1,mouse_pos2)
  315. for k in table:
  316. t = table[k]
  317. pos = t.get_rect()
  318. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  319. if sdl_elm.check_area2(pos,mpos):
  320. t._set_mouse_focus(1)
  321. mouse_grab.append(t)
  322. else:
  323. t._set_mouse_focus(0)
  324. if resize_changed:# = True
  325. screen = pygame.display.set_mode(scrsize,pg.RESIZABLE)
  326. clock.tick(10)