fix.py 29 KB

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