fix.py 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  1. #!/usr/bin/python3
  2. import time
  3. import traceback
  4. boot = time.time()
  5. from collections import OrderedDict
  6. import random
  7. import os
  8. import sys
  9. #sys.path.insert(0,os.path.realpath(os.getcwd() + '/..'))
  10. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  11. print(sys.path)
  12. print()
  13. CAPTION = 'LibreLight SDL-FIX-LIST '
  14. SHIFT_FINE = 0
  15. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  16. import tool.movewin as movewin
  17. import tool.git as git
  18. #CAPTION += git.get_all()
  19. win_title =CAPTION.strip().split()[-1]
  20. store = movewin.load_all_sdl(win_title)
  21. print(store)
  22. W=850
  23. H=460
  24. POS=[20,20]
  25. if store:
  26. W = store[-4]
  27. H = store[-3]
  28. POS=[store[-2],store[-1]]
  29. #exit()
  30. #CAPTION += ':{}'.format(random.randint(100,999))
  31. CAPTION += git.get_all()
  32. import pathlib
  33. _file_path=pathlib.Path(__file__)
  34. print("file:",_file_path)
  35. #_id = movewin.winfo(CAPTION)
  36. #c1 = movewin.movewin(_id,200,50)
  37. #os.system(c1)
  38. #c1 = movewin.activate(_id)
  39. #os.system(c1)
  40. movewin.check_is_started(CAPTION,_file_path)
  41. # ===== GUI =========
  42. import pygame
  43. import pygame.gfxdraw
  44. import pygame.font
  45. pg = pygame
  46. main_size=(W,H)#850,460)
  47. window = pygame.display.set_mode(main_size,pg.RESIZABLE,32)
  48. pg = pygame
  49. pygame.init()
  50. pygame.mixer.quit()
  51. clock = pygame.time.Clock()
  52. try:
  53. icon = pygame.image.load('icon/scribble.png')
  54. pygame.display.set_icon(icon)
  55. except Exception as e:
  56. print(" ERROR:",os.getcwd())
  57. print(" ERROR:set_icon ",e) #,color="red")
  58. import tool.movewin as movewin
  59. import tool.sdl_elm as sdl_elm
  60. pg.display.set_caption(CAPTION)
  61. font0 = pygame.font.SysFont("freesans",10)
  62. font0b = pygame.font.SysFont("freesansbold",10)
  63. font = pygame.font.SysFont("freemonobold",22)
  64. font10 = pygame.font.SysFont("freemonobold",10)
  65. font12 = pygame.font.SysFont("freemonobold",12)
  66. font15 = pygame.font.SysFont("freemonobold",15)
  67. font16 = pygame.font.SysFont("freemonobold",16)
  68. font18 = pygame.font.SysFont("freemonobold",18)
  69. font22 = pygame.font.SysFont("FreeSans",22)
  70. #font = pygame.font.SysFont(None,30)
  71. fr = font.render("hallo" ,1, (200,0,255))
  72. mouse_down = 0
  73. mouse_pos1 = [0,0]
  74. mouse_pos2 = [0,0]
  75. mouse_grab = []
  76. print(int((time.time()-boot)*10),"loop...")
  77. fps_t = time.time()
  78. fps = 0
  79. fps_old = 0
  80. import memcache
  81. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  82. mc.set("some_key", "Some value")
  83. value = mc.get("some_key")
  84. mc.set("another_key", 3)
  85. mc.delete("another_key")
  86. import time
  87. import json
  88. data = {}
  89. start = time.time()
  90. delta = start
  91. #for i in dir(mc):
  92. # print(i)#,[i.__doc__])
  93. # print()
  94. #for i in mc.get_stats():
  95. # print("keys",i)
  96. #fps_btn = []
  97. #fps_btn_press = []
  98. #i += 1
  99. #bx = sdl_elm.Button(window,pos=[30,r,190,60])
  100. #bx.text = "FIX:{}\n<val>\nx".format(i+1)
  101. #bx.font0 = pygame.font.SysFont("freesans-bold",20)
  102. #bx.btn1['type'] = "flash"
  103. #fps_btn.append(bx)
  104. #r+=bx.get_rect()[3]
  105. def read_dmx():
  106. dmx = {} #univ
  107. iii = 0
  108. y=mc.get("index")
  109. if y:
  110. key=y.keys()
  111. key = list(key)
  112. key.sort()
  113. for k in key:
  114. if k.startswith("ltp-out"):
  115. #v = y[k]
  116. u = k.split(":")[-1]
  117. x=mc.get(k)
  118. dmx[u] = x
  119. return dmx
  120. def read_fix(dmx):
  121. global mc
  122. y=mc.get("fix")#cmd)
  123. if y is None:
  124. print("==== "*10)
  125. print("error -- read_fix(dmx) mc.get('fix') return",y)
  126. print()
  127. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  128. return {}
  129. key=y.keys()
  130. key = list(key)
  131. key.sort()
  132. for k in key:#y.items():
  133. v = y[k]
  134. #print(k,v)
  135. x=mc.get(k)
  136. dmx_start = 0
  137. if "DMX" in v:
  138. dmx_start = v["DMX"]
  139. univ_start = 0
  140. if "UNIVERS" in v:
  141. univ_start = v["UNIVERS"]
  142. if "ATTRIBUT" in v: # and 10:
  143. ATTR = v["ATTRIBUT"]
  144. for k2 in ATTR:
  145. k2_ATTR = ATTR[k2]
  146. k2_ATTR["VALUE2"] = -2
  147. if is_hidden_attr(k2):
  148. #if k2.startswith("_"):
  149. continue
  150. k3 = k+"-"+k2
  151. dmx_nr = 0
  152. if "NR" in k2_ATTR:
  153. if k2_ATTR["NR"] >= 1:
  154. dmx_nr = k2_ATTR["NR"]+1
  155. val2 = ""
  156. if "VALUE" in k2_ATTR:
  157. val2 = k2_ATTR["VALUE"]
  158. dmx_val=-1
  159. dmx_x=-1
  160. if dmx_nr > 0 and dmx_start > 0:
  161. try:
  162. dmx_x = dmx_start-1+dmx_nr-1
  163. dmx_val = dmx[str(univ_start)][dmx_x-1]
  164. except:pass
  165. if type(dmx_val) in [int,float]:
  166. k2_ATTR["VALUE2"] = dmx_val
  167. else:
  168. k2_ATTR["VALUE2"] = 0
  169. return y
  170. def add_dmx(data,dmx):
  171. pass
  172. def reorder_table_by_pos(table_grid):
  173. if type(table_grid) in (dict,OrderedDict):
  174. # order table of type dict by pos [x,y]
  175. table_grid5 = {}
  176. for t5 in table_grid:
  177. t5_row = table_grid[t5]
  178. #print(t5,t5_row.pos)
  179. k5 = "{:010}-{:010}".format(t5_row.pos[0],t5_row.pos[1])
  180. table_grid5[k5] = [t5,t5_row]
  181. ordered = list(table_grid5.keys())
  182. ordered.sort()
  183. table_grid2 = OrderedDict()
  184. for k5 in ordered: #table_grid5:
  185. k5_row = table_grid5[k5]
  186. table_grid2[k5_row[0]] = k5_row[1]
  187. return table_grid2
  188. if type(table_grid) is list:
  189. # order table of type list by pos [x,y]
  190. table_grid5 = {}
  191. for t5 in table_grid:
  192. t5_row = t5 #table_grid[t5]
  193. #print(t5)#,t5_row.pos)
  194. k5 = "{:010}-{:010}".format(t5_row.pos[1],t5_row.pos[0])
  195. table_grid5[k5] = [t5,t5_row]
  196. ordered = list(table_grid5.keys())
  197. ordered.sort()
  198. table_grid2 = [] #OrderedDict()
  199. for k5 in ordered: #table_grid5:
  200. k5_row = table_grid5[k5]
  201. table_grid2.append( k5_row[1] )
  202. return table_grid2
  203. return table_grid
  204. def is_active_fix(v):
  205. if "ATTRIBUT" in v:
  206. if "_ACTIVE" in v["ATTRIBUT"]:
  207. if "ACTIVE" in v["ATTRIBUT"]["_ACTIVE"]:
  208. if v["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] >=1:
  209. return 1
  210. return 0
  211. def is_hidden_attr(attr_name):
  212. if attr_name.endswith("-FINE"):
  213. return 1
  214. if attr_name.startswith("_"):
  215. return 1
  216. return 0
  217. def count_active_attr(fix_row):
  218. return len(get_active_attr(fix_row))
  219. def get_active_attr(fix_row):
  220. # fix_row = {ID:"12"NAME:"xyz",ATTRIBUTE:{"RED":{"VALUE":0}}}
  221. active_attr = []
  222. if "ATTRIBUT" in fix_row:
  223. attr_row = fix_row["ATTRIBUT"]
  224. for attr_name in attr_row:
  225. if is_hidden_attr(attr_name):
  226. continue
  227. attr_data = attr_row[attr_name]
  228. if "ACTIVE" in attr_data:
  229. if attr_data["ACTIVE"] >=1:
  230. active_attr.append(attr_name)
  231. return active_attr
  232. def get_attr_count(attr_row):
  233. acount = 0
  234. for attr in attr_row:
  235. if is_hidden_attr(attr):
  236. continue
  237. acount+=1
  238. return acount
  239. def get_fix_type(fix_row):
  240. attr2 = []
  241. if "ATTRIBUT" in fix_row:
  242. attr_row = fix_row["ATTRIBUT"]
  243. for attr in attr_row:
  244. if is_hidden_attr(attr):
  245. continue
  246. attr2.append(attr)
  247. if "PAN" in attr2 and "TILT" in attr2:
  248. return "MOVER"
  249. if "RED" in attr2 and "GREEN" in attr2 and "BLUE" in attr2:
  250. return "RGB"
  251. if len(attr2) == 1 and "DIM" in attr2:
  252. return "DIM"
  253. return "UNKNOWN"
  254. win_con = movewin.Control()
  255. win_con.title = win_title
  256. win_con.winfo()
  257. if POS:
  258. win_con.move(POS[0],POS[1])
  259. print(POS,win_con.title)
  260. table={}
  261. table_grid={}
  262. btn1_press = [] #["10.10.10.13:0"]
  263. y=[]
  264. bx_font0 = pygame.font.SysFont("freesans-bold",20)
  265. import lib.zchat as chat
  266. cmd_client = chat.Client(port=30003)
  267. err = []
  268. #err.append([time.time(),"init"])
  269. scroll_bar = sdl_elm.Button(window,pos=[640,40,40,400])
  270. scroll_bar.btn1.color_on = [255,255,0]
  271. scroll_bar.dbg = 0
  272. scroll_bar.btn4.color_on=[0,0,0]
  273. scroll_bar.btn4.color_off=[0,0,0]
  274. scroll_bar.fader = "v"
  275. scroll_bar.text="\n"*10+"<ival%>%"
  276. scroll_bar.text=" "
  277. scroll_bar.btn4.nr_on = [5]
  278. scroll_bar.btn4.nr_off = [4]
  279. scroll_bar.draw()
  280. width,hight = main_size #[1]
  281. scroll_max = 100
  282. def draw_frame(window):
  283. fr = font22.render("FIXTURE LIST " ,1, (200,200,200))
  284. window.blit(fr,(20,5 ))
  285. fr = font22.render("DEMO / TEST - MODE ! " ,1, (200,200,200))
  286. #window.blit(fr,(10,30 ))
  287. # -------------------
  288. x=200
  289. y=5
  290. bx = sdl_elm.Button(window,pos=[x,y,50,20])
  291. bx.text = " HELP "
  292. import lib.libtk as libtk
  293. def xhelp(event=None):
  294. #print(event)
  295. libtk.online_help("librelight:20-exec")()
  296. bx.btn1.cb_on.set(xhelp)
  297. #bx.draw()
  298. btn_help=bx
  299. # -------------------
  300. while 1:
  301. try:
  302. fps +=1
  303. t = time.time()
  304. if t-fps_t >= 1:
  305. #print("FPS:",fps)
  306. fps_old = fps
  307. fps=0
  308. fps_t =t
  309. pygame.display.flip()
  310. pos = [160,10,70,60]
  311. rgb = (0xdd,0xdd,0xdd,0)
  312. rgb = (0xaa,0xaa,0xaa,0)
  313. #window.fill((2,2,2))
  314. window.fill((0,0,0))
  315. pygame.draw.rect(window,(0,0,0),[0,0,main_size[0],main_size[1]])
  316. draw_frame(window)
  317. pos = [160,110,70+80,20]
  318. #pygame.draw.rect(window,rgb,pos)
  319. t=(time.time()-start)
  320. if t > 15:
  321. start = time.time()
  322. b= 80-int(t*10)
  323. pos = [160,110,70+(b),20]
  324. rgb = (0x00,0xff,0xff,0)
  325. dmx = read_dmx()
  326. rgb = (0xff,0,0xaa,0)
  327. data = read_fix(dmx)
  328. BTN_WIDTH = 120
  329. #scroll_bar.btn4.val._max = len(data)-8 #draw()
  330. scroll_max = len(data)-8
  331. scroll_max = len(data.keys())-8
  332. scroll_max = 1
  333. block_wrap = int( (width-200) / BTN_WIDTH)
  334. if block_wrap <= 0:
  335. block_wrap = 1
  336. for k in data.keys():
  337. fix_type = get_fix_type(data[k])
  338. if "ATTRIBUT" in data[k]:
  339. row = data[k]["ATTRIBUT"]
  340. acount = get_attr_count(row)
  341. if fix_type == "DIM":
  342. continue
  343. if acount > block_wrap:
  344. scroll_max += int(acount/block_wrap)
  345. else:
  346. scroll_max += 1
  347. #print()
  348. scroll_bar.btn4.val._max = scroll_max
  349. scroll_bar.increment = (len(data))/100*10 #draw()
  350. #data = add_dmx(data,dmx)
  351. scroll_pos = scroll_bar.btn4.val.get()
  352. scroll_bar.pos[0] = width-scroll_bar.pos[2]-5
  353. scroll_bar.pos[3] = hight-80
  354. #print(scroll_pos)
  355. table_grid_draw=[] #{}
  356. table_draw = []
  357. active_fix = 0
  358. active_attr = 0
  359. i = 0
  360. r=40
  361. if 1:
  362. ch = 141
  363. send = 0
  364. #cmd="stats items"
  365. #if not y:
  366. y=data #mc.get("fix")#cmd)
  367. if y:
  368. iii = 0
  369. key=y.keys()
  370. key = list(key)
  371. key2 = []
  372. for k in key:
  373. #print(k)
  374. try:
  375. key2.append(int(k))
  376. except:
  377. pass
  378. key2.sort()
  379. key = key2 #.sort()
  380. if len(btn1_press) == 0:
  381. btn1_press = [key[0]]
  382. rgb = (0x00,0,0xff,0)
  383. k2 = btn1_press[-1]
  384. #fr = font22.render("SRC:"+str(k2) ,1, rgb) #(200,200,200))
  385. fr = font15.render("FPS:"+str(fps_old) ,1, rgb) #(200,200,200))
  386. window.blit(fr,(600,5))
  387. err_r = 0
  388. if err:
  389. for e in err:
  390. rgb = (255,0,0)
  391. fr = font15.render("err:"+str(e) ,1, rgb) #(200,200,200))
  392. window.blit(fr,(700,5+err_r))
  393. err_r += 20
  394. i4 = 0
  395. for k in key:
  396. k = str(k)
  397. fix_row = y[k]
  398. fix_type = get_fix_type(fix_row)
  399. if fix_type == "DIM":
  400. continue
  401. active_fix += is_active_fix(fix_row)
  402. active_attr += count_active_attr(fix_row)
  403. for k in key:#y.items():
  404. k = str(k)
  405. v = y[k]
  406. fix_row = v
  407. fix_type = get_fix_type(fix_row)
  408. if fix_type == "DIM":
  409. continue
  410. #scroll_max+=1
  411. i4 += 1
  412. if i4 < scroll_pos:
  413. continue
  414. #print(k,v)
  415. x=mc.get(k)
  416. cccount = 0
  417. txt = str([k,v,ch,"=",cccount]) #x[ch-1]])
  418. rgb = (0xaa,0xaa,0xaa,0)
  419. i += 1
  420. if k not in table:
  421. bx = sdl_elm.Button(window,pos=[20+20,r,50,20])
  422. bx.btn1.color_on = [255,255,0]
  423. bx.ID = -1
  424. if "ID" in v:
  425. bx.ID = v["ID"]
  426. if bx.ID == 0:
  427. bx.ID = -2
  428. bx.ATTR = "_ACTIVE"
  429. table[k] = bx
  430. # color box
  431. bxc = sdl_elm.Button(window,pos=[-11+20,r,5,20])
  432. bxc.btn1.color_on = [255,255,0]
  433. table[k+"_color"] = bxc
  434. bx = table[k]
  435. bx.data = v
  436. bxc.data = {}
  437. active = is_active_fix(v)
  438. bx.btn1.val.set(active)
  439. try:
  440. if int(k) % 10 == 0:
  441. #pygame.draw.aaline(window,[255,0,0],[2,r],[800,r],1)
  442. pygame.draw.rect(window,[58,58,58],[2,r,2000,25])
  443. except:pass
  444. bx.text = "ID:"+ k
  445. bx.text += " "+v["NAME"]
  446. bx.font0 = bx_font0
  447. bx.btn1.bg_on = [0,255,255]
  448. bx.btn1.type = "toggle"
  449. bx.pos = [10+10,r,BTN_WIDTH,20]
  450. if "ATTRIBUT" in v:
  451. try: # info
  452. if int(k) == 12001:
  453. #print(" ",k,k2,k2_ATTR)
  454. print("-",v["ATTRIBUT"].keys())
  455. except: pass
  456. bcv_r = 0
  457. bcv_g = 0
  458. bcv_b = 0
  459. if "RED" in v["ATTRIBUT"]:
  460. bcv_r = v["ATTRIBUT"]["RED"]["VALUE2"]
  461. if "GREEN" in v["ATTRIBUT"]:
  462. bcv_g = v["ATTRIBUT"]["GREEN"]["VALUE2"]
  463. if "BLUE" in v["ATTRIBUT"]:
  464. bcv_b = v["ATTRIBUT"]["BLUE"]["VALUE2"]
  465. #print("bvc_rgb" [bcv_r,bcv_g,bcv_b])
  466. if bcv_r > 255:
  467. bcv_r=255
  468. if bcv_g > 255:
  469. bcv_g=255
  470. if bcv_b > 255:
  471. bcv_b=255
  472. bxc.btn1.color = [bcv_r,bcv_g,bcv_b]
  473. bxc.btn1.color_on = [bcv_r,bcv_g,bcv_b]
  474. bxc.pos = [140+5,r,20,20]
  475. bxc.text = ""
  476. bx.draw()
  477. bxc.draw()
  478. r_buf=bx.get_rect()[3]+2
  479. iii += 35
  480. rr = 0
  481. acount = 0
  482. if "ATTRIBUT" in v: # and 10:
  483. ATTR = v["ATTRIBUT"]
  484. for k2 in ATTR:
  485. k2_ATTR = ATTR[k2]
  486. if is_hidden_attr(k2):
  487. continue
  488. k3 = k+"-"+k2
  489. val2 = ""
  490. if "VALUE" in k2_ATTR:
  491. val2 = k2_ATTR["VALUE"]
  492. virt = 1
  493. if "NR" in k2_ATTR:
  494. if k2_ATTR["NR"] > 0:
  495. virt = 0
  496. dmx_val = -3
  497. if "VALUE2"in k2_ATTR:
  498. dmx_val = k2_ATTR["VALUE2"]
  499. if k3 not in table_grid:
  500. bx = sdl_elm.Button(window,pos=[600,rr,60,20])
  501. bx.btn1.color_on = [255,255,0]
  502. bx.ID = 0
  503. if "ID" in v:
  504. bx.ID = v["ID"]
  505. bx.ATTR = k2
  506. table_grid[k3] = bx
  507. if "ACTIVE" in k2_ATTR:
  508. if k2_ATTR["ACTIVE"] >=1:
  509. table_grid[k3].btn1.val.set(1)
  510. #active_attr += 1
  511. else:
  512. table_grid[k3].btn1.val.set(0)
  513. bx = table_grid[k3]
  514. bx.data = k2_ATTR
  515. try:val = v
  516. except:pass
  517. bx.text = k2 +" "+str(val2)+" "+str(dmx_val)
  518. bx.font0 = bx_font0
  519. if k2 == "RED":
  520. bx.btn4.color_on = [255,0,0]
  521. elif k2 == "GREEN":
  522. bx.btn4.color_on = [0,255,0]
  523. elif k2 == "BLUE":
  524. bx.btn4.color_on = [0,0,255]
  525. if virt == 1:
  526. bx.btn3.color= [0,0,0]
  527. bx.btn1.type = "toggle"
  528. if type(dmx_val) == int:
  529. bx.btn4.val.set(dmx_val) # "toggle"
  530. bx.pos = [170+rr,r,BTN_WIDTH,20]
  531. bx.draw()
  532. rr+=bx.get_rect()[2]+2
  533. table_grid_draw.append(k3) #table_grid[k3]
  534. acount +=1
  535. if acount %block_wrap==0:
  536. r += r_buf
  537. rr = 0
  538. table_draw.append(k)
  539. r += r_buf
  540. if r > hight-30:#/20:
  541. break
  542. active_ratio = 0
  543. if active_fix:
  544. active_ratio = (active_attr/active_fix)
  545. fr = font18.render("ACTIVE:{}:{} ({:0.01f})".format(active_fix,active_attr,active_ratio) ,1, [255,255,0]) #(200,200,200))
  546. window.blit(fr,(300,5))
  547. if SHIFT_FINE:
  548. fr = font18.render("ENCODER:±0.25" ,1, [255,255,0])
  549. else:
  550. fr = font18.render("ENCODER:±5.00" ,1, [255,255,0])
  551. window.blit(fr,(420,5))
  552. if 0: #show line number +scroll_pos
  553. bxc = sdl_elm.Button(window,pos=[-11+10,(0*23),50,10])
  554. bxc.text = "{:0.02f} {}".format(scroll_pos,scroll_max)
  555. ii = int(scroll_pos) #int(scroll_pos/23*29)
  556. bxc.font0 = bx_font0
  557. bxc.draw()
  558. for i in range(40+1):
  559. bxc = sdl_elm.Button(window,pos=[0,40+(i*23),30,10])
  560. bxc.text = "{}".format(1+i+ii)
  561. bxc.btn1.color = [255,200,200]
  562. bxc.btn2.color = [255,200,200]
  563. bxc.btn3.color = [255,200,200]
  564. bxc.font0 = bx_font0
  565. bxc.draw()
  566. btn_help.draw()
  567. resize_changed = 0
  568. for raw_event in pygame.event.get():
  569. x_change=btn_help.event(raw_event)
  570. event = {'unicode': '', 'key': 0, 'mod': 0, 'scancode': 0, 'window': None,'type':'','button':''}
  571. event['type'] = raw_event.type
  572. event.update( raw_event.dict)
  573. if event['button'] and event["type"] in [1025,1026]:
  574. event["type"] -= 1020
  575. if event["button"] or event['scancode']:
  576. print(" event:",event)
  577. if "scancode" in event:
  578. #print(" ",event)
  579. if event['scancode'] in [50,225]: # shift old/new
  580. if event['type'] in [2,768]: # press
  581. #pg.display.set_caption(CAPTION+ " SHIFT/FINE")
  582. SHIFT_FINE = 1
  583. if event['type'] in [3,769]: # release
  584. #pg.display.set_caption(CAPTION)
  585. SHIFT_FINE = 0
  586. if event['scancode'] in [9,41]:
  587. for k in table_draw:
  588. t = table[k]
  589. t.btn1.clean()
  590. for k in table_grid_draw:
  591. t = table_grid[k]
  592. t.btn1.clean()
  593. msg=json.dumps([{"event":"ESC"}]).encode("utf-8")
  594. print("ESC",msg)
  595. cmd_client.send(msg)
  596. if event['mod'] == 0:
  597. keycode = {27:"REC",39:"SELECT",46:"LABEL",54:"CFG-BTN",56:"BLIND",41:"FLASH",26:"EDIT"}
  598. #print(" 45:", event['scancode'] in keycode,event['scancode'])
  599. if event['scancode'] in keycode: # r
  600. if event['type'] == 2: # press
  601. msg=json.dumps([{"event":keycode[event['scancode']]}]).encode("utf-8")
  602. print("SPCIAL-KEY",msg)
  603. cmd_client.send(msg)
  604. if event['mod'] == 64:
  605. keycode = {39:"SAVE\nSHOW",54:"RESTART"}
  606. print( " 56:",event['scancode'] in keycode,event['scancode'])
  607. if event['scancode'] in keycode: # r
  608. if event['type'] == 2: # press
  609. msg=json.dumps([{"event":keycode[event['scancode']]}]).encode("utf-8")
  610. print("SPCIAL-KEY",msg)
  611. cmd_client.send(msg)
  612. if event['scancode'] in range(10,20+1) or event['scancode'] in range(30,39+1):
  613. if event['type'] in [2,3,768,769]: # press
  614. if event['type'] in [2,769]:
  615. v=0
  616. if event['type'] in [3,768]:
  617. v=255
  618. btn_nr=-3000
  619. if event['scancode'] in range(10,20+1):
  620. btn_nr = event['scancode']-10+1
  621. if event['scancode'] in range(30,39+1):
  622. btn_nr = event['scancode']-30+1
  623. btn_nr_raw = btn_nr
  624. btn_nr += 161-1
  625. msg=json.dumps([{"event":"EXEC","EXEC":btn_nr,"VAL":v,"NR-KEY":btn_nr_raw}]).encode("utf-8")
  626. print("SPCIAL-KEY",msg)
  627. cmd_client.send(msg)
  628. def f1_bis_f12_alt(scancode,_type):
  629. if scancode in range(67,76+1) and _type in [2,3]: # F1-F12 OLD
  630. return 1
  631. def f1_bis_f12_neu(scancode,_type):
  632. if scancode in range(58,92+1) and _type in [768,769]: # F1-F12 NEW
  633. return 1
  634. if f1_bis_f12_alt(event['scancode'], event['type']) or f1_bis_f12_neu(event['scancode'], event['type']) or event['scancode'] in [95,96]:
  635. if event['type'] in [2,3,768,769]: # press
  636. if event['type'] in [2,769]:
  637. v=0
  638. if event['type'] in [3,768]:
  639. v=255
  640. btn_nr = event['scancode']
  641. if btn_nr == 95:
  642. btn_nr = 11
  643. elif btn_nr == 96:
  644. btn_nr = 12
  645. else:
  646. if event['type'] in [768,769]:
  647. btn_nr = event['scancode']-57
  648. else:
  649. btn_nr = event['scancode']-66
  650. btn_nr_raw = btn_nr
  651. if f1_bis_f12_alt(event['scancode'], event['type']):
  652. btn_nr_raw = str(btn_nr) +"-ALT"
  653. if f1_bis_f12_neu(event['scancode'], event['type']):
  654. btn_nr_raw = str(btn_nr) +"-NEU"
  655. btn_nr += 81-1
  656. msg=json.dumps([{"event":"EXEC","EXEC":btn_nr,"VAL":v,"F-KEY":btn_nr_raw}]).encode("utf-8")
  657. print("SPCIAL-KEY",msg)
  658. cmd_client.send(msg)
  659. if event['type'] == pygame.QUIT:
  660. print()
  661. print("quit",event)
  662. pygame.quit()
  663. sys.exit(0)
  664. elif event['type'] == pygame.VIDEORESIZE:
  665. print()
  666. print("resize",event)
  667. scrsize = event['size']
  668. width = event['w']
  669. hight = event['h']
  670. resize_changed = True
  671. scroll_bar.event(raw_event) #daraw()
  672. scroll_change = 0
  673. if scroll_bar.btn3.val.get(): #scroll_bar focus
  674. spos = scroll_bar.rel_pos[1]
  675. #print("------------------",spos)
  676. if "button" in event:
  677. if event["button"] == 1:
  678. scroll_bar.btn4.val.set(scroll_bar.btn4.val._max*spos)
  679. if "buttons" in event:
  680. if event["buttons"][0]:
  681. scroll_bar.btn4.val.set(scroll_bar.btn4.val._max*spos)
  682. event_lock = scroll_bar.btn3.val.get() #focus on
  683. if not event_lock:
  684. for t in table_draw:
  685. table[t].event(raw_event)
  686. if table[t].btn3.get():
  687. data = table[t].data
  688. if not event_lock:
  689. for k3 in table_draw:
  690. #print(t)
  691. row = table[k3]
  692. change = table[k3].event(raw_event)
  693. if row.btn3.get():
  694. # FIXTURE SELECTOR
  695. data = row.data
  696. FIX = row.ID
  697. ATTR = row.ATTR
  698. key = "BUTTON"
  699. if key in change:
  700. if "press" in change[key]:
  701. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  702. print(" msg:",msg)
  703. cmd_client.send(msg)
  704. if "release" in change[key]:
  705. pass
  706. if not event_lock:
  707. for k3 in table_grid_draw:
  708. row = table_grid[k3]
  709. change = table_grid[k3].event(raw_event)
  710. if row.btn3.get():
  711. data = row.data
  712. FIX = row.ID
  713. ATTR = row.ATTR
  714. key = "MOUSE ENCODER"
  715. if key in change:
  716. ACC = 2
  717. if SHIFT_FINE:
  718. ACC = 1
  719. VAL = ""
  720. if "press" in change[key]:
  721. VAL = "+"*ACC
  722. if "release" in change[key]:
  723. VAL = "-"*ACC
  724. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":VAL,"ATTR":ATTR}]).encode("utf-8")
  725. print(" ",msg)
  726. cmd_client.send(msg)
  727. key = "BUTTON"
  728. if key in change:
  729. if "press" in change[key]:
  730. #print(" ATTR:",FIX,ATTR,data)
  731. #print(" CHANGE",change)
  732. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  733. print(" ",msg)
  734. cmd_client.send(msg)
  735. if "release" in change[key]:
  736. pass
  737. if "pos" in event:
  738. if "button" in event:
  739. if event['type'] in [5,1025]:#press
  740. mouse_down = 1
  741. mouse_pos1 = [event['pos'][0],event['pos'][1]]
  742. if event['type'] in [6,1026]:#release
  743. mouse_down = 0
  744. mouse_pos2 = [event['pos'][0],event['pos'][1]]
  745. if event_lock:
  746. pass
  747. elif "button" in event:
  748. if event['type'] in [6,1026]:
  749. if event["button"] == 1:
  750. mouse_grab_active = 0
  751. for mg in mouse_grab:
  752. if mg.btn1.val.get():
  753. mouse_grab_active += 1
  754. for mg in mouse_grab:
  755. FIX = str(mg.ID)
  756. ATTR = str(mg.ATTR)
  757. if mouse_grab_active:
  758. if not mg.btn1.val.get():
  759. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  760. print(" send:",msg)
  761. cmd_client.send(msg)
  762. else: #no btn is on
  763. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  764. print(" send:",msg)
  765. cmd_client.send(msg)
  766. mouse_grab = []
  767. if event["button"] == 3:
  768. mouse_grab_active = 0
  769. for mg in mouse_grab:
  770. if mg.btn1.val.get():
  771. mouse_grab_active += 1
  772. for mg in mouse_grab:
  773. FIX = str(mg.ID)
  774. ATTR = str(mg.ATTR)
  775. if mouse_grab_active:
  776. if mg.btn1.val.get():
  777. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS"
  778. ,"FIX":str(FIX),"VAL":"click"
  779. ,"ATTR":ATTR}]).encode("utf-8")
  780. #print(" mouse_grab ",msg,mg.btn1.val.get())
  781. cmd_client.send(msg)
  782. mouse_grab = []
  783. if mouse_down:
  784. d1 = mouse_pos1[0]-mouse_pos2[0]
  785. d2 = mouse_pos1[1]-mouse_pos2[1]
  786. pix = 10
  787. if ( d1 > pix or d1 < -pix) or ( d2 >pix or d2 < -pix):
  788. sdl_elm.draw_mouse_box(window,mouse_pos1,mouse_pos2)
  789. for k in table_draw: # FIX-ID
  790. t = table[k]
  791. pos = t.get_rect()
  792. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  793. if sdl_elm.check_area2(pos,mpos):
  794. if t not in mouse_grab:
  795. mouse_grab.append(t)
  796. else:
  797. if t in mouse_grab:
  798. mouse_grab.remove(t)
  799. for k3 in table_grid_draw: # FIX-ATTR
  800. t = table_grid[k3]
  801. pos = t.get_rect()
  802. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  803. if sdl_elm.check_area2(pos,mpos):
  804. if t not in mouse_grab:
  805. mouse_grab.append(t)
  806. else:
  807. if t in mouse_grab:
  808. mouse_grab.remove(t)
  809. for k3 in table_grid:
  810. t = table_grid[k3]
  811. t._set_mouse_focus(0)
  812. i = 1
  813. if mouse_grab:
  814. mouse_grab = reorder_table_by_pos(mouse_grab)
  815. for t in mouse_grab:
  816. t._set_mouse_focus(1)
  817. pos = t.pos[:2]
  818. pos[0] += 100
  819. pos[1] += 8
  820. rgb = (0,255,255)
  821. fr = font15.render(""+str(i) ,1, rgb) #(200,200,200))
  822. #print(pos)
  823. pygame.draw.rect(window,(0,0,0),[pos[0]-2,pos[1]-2,15,13])
  824. window.blit(fr,pos)
  825. i+=1
  826. if resize_changed:# = True
  827. screen = pygame.display.set_mode(scrsize,pg.RESIZABLE)
  828. scroll_bar.draw()
  829. clock.tick(6)
  830. except Exception as e:
  831. err.append([int((time.time()-boot)*100),e])
  832. traceback.print_exc()
  833. print("Exc",e)