dmx.py 10 KB

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