fix.py 28 KB

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