fix.py 27 KB

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