fix.py 26 KB

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