fix.py 27 KB

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