fix.py 25 KB

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