fix.py 26 KB

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