dmx.py 11 KB

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