dmx.py 10 KB

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