fix.py 29 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. 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. 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 LIST " ,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. bx.ID = -1
  372. if "ID" in v:
  373. bx.ID = v["ID"]
  374. if bx.ID == 0:
  375. bx.ID = -2
  376. bx.ATTR = "_ACTIVE"
  377. table[k] = bx
  378. # color box
  379. bxc = sdl_elm.Button(window,pos=[-11,r,5,20])
  380. bxc.btn1.color_on = [255,255,0]
  381. table[k+"_color"] = bxc
  382. bx = table[k]
  383. bx.data = v
  384. bxc.data = {}
  385. active = 0
  386. if "ATTRIBUT" in v:
  387. if "_ACTIVE" in v["ATTRIBUT"]:
  388. if "ACTIVE" in v["ATTRIBUT"]["_ACTIVE"]:
  389. if v["ATTRIBUT"]["_ACTIVE"]["ACTIVE"] >=1:
  390. active = 1
  391. #aactive_fix +=1
  392. bx.btn1.val.set(active)
  393. bx.text = "ID:"+ k #str(txt) #+"\n<val>\n" #.format(i+1)
  394. bx.text += " "+v["NAME"]
  395. bx.font0 = bx_font0 #pygame.font.SysFont("freesans-bold",20)
  396. bx.btn1.bg_on = [0,255,255]
  397. bx.btn1.type = "toggle"
  398. bx.pos = [10,r,120,20]
  399. if "ATTRIBUT" in v:
  400. bcv_r = 0
  401. bcv_g = 0
  402. bcv_b = 0
  403. if "RED" in v["ATTRIBUT"]:
  404. bcv_r = v["ATTRIBUT"]["RED"]["VALUE2"]
  405. if "GREEN" in v["ATTRIBUT"]:
  406. bcv_g = v["ATTRIBUT"]["GREEN"]["VALUE2"]
  407. if "BLUE" in v["ATTRIBUT"]:
  408. bcv_b = v["ATTRIBUT"]["BLUE"]["VALUE2"]
  409. #print("bvc_rgb" [bcv_r,bcv_g,bcv_b])
  410. if bcv_r > 255:
  411. bcv_r=255
  412. if bcv_g > 255:
  413. bcv_g=255
  414. if bcv_b > 255:
  415. bcv_b=255
  416. bxc.btn1.color = [bcv_r,bcv_g,bcv_b]
  417. bxc.btn1.color_on = [bcv_r,bcv_g,bcv_b]
  418. bxc.pos = [140,r,20,20]
  419. bxc.text = ""
  420. bx.draw()
  421. bxc.draw()
  422. r_buf=bx.get_rect()[3]+2
  423. iii += 35
  424. rr = 0
  425. acount = 0
  426. if "ATTRIBUT" in v: # and 10:
  427. ATTR = v["ATTRIBUT"]
  428. for k2 in ATTR:
  429. k2_ATTR = ATTR[k2]
  430. if k2.endswith("-FINE"):
  431. continue
  432. if k2.startswith("_"):
  433. continue
  434. k3 = k+"-"+k2
  435. val2 = ""
  436. if "VALUE" in k2_ATTR:
  437. val2 = k2_ATTR["VALUE"]
  438. virt = 1
  439. if "NR" in k2_ATTR:
  440. if k2_ATTR["NR"] > 0:
  441. virt = 0
  442. dmx_val = -3
  443. if "VALUE2"in k2_ATTR:
  444. dmx_val = k2_ATTR["VALUE2"]
  445. if k3 not in table_grid:
  446. bx = sdl_elm.Button(window,pos=[600,rr,60,20])
  447. bx.btn1.color_on = [255,255,0]
  448. bx.ID = 0
  449. if "ID" in v:
  450. bx.ID = v["ID"]
  451. bx.ATTR = k2
  452. table_grid[k3] = bx
  453. #table_grid = reorder_table_by_pos(table_grid)
  454. if "ACTIVE" in k2_ATTR:
  455. if k2_ATTR["ACTIVE"] >=1:
  456. table_grid[k3].btn1.val.set(1)
  457. #active_attr += 1
  458. else:
  459. table_grid[k3].btn1.val.set(0)
  460. bx = table_grid[k3]
  461. bx.data = k2_ATTR
  462. try:val = v
  463. except:pass
  464. bx.text = k2 +" "+str(val2)+" "+str(dmx_val)
  465. bx.font0 = bx_font0
  466. if k2 == "RED":
  467. bx.btn4.color_on = [255,0,0]
  468. elif k2 == "GREEN":
  469. bx.btn4.color_on = [0,255,0]
  470. elif k2 == "BLUE":
  471. bx.btn4.color_on = [0,0,255]
  472. if virt == 1:
  473. bx.btn3.color= [0,0,0]
  474. bx.btn1.type = "toggle"
  475. if type(dmx_val) == int:
  476. bx.btn4.val.set(dmx_val) # "toggle"
  477. bx.pos = [170+rr,r,120,20]
  478. bx.draw()
  479. rr+=bx.get_rect()[2]+2
  480. table_grid_draw.append(k3) #table_grid[k3]
  481. if rr > 1000:
  482. break
  483. acount +=1
  484. if acount %block_wrap==0:
  485. r += r_buf
  486. rr = 0
  487. table_draw.append(k)
  488. r += r_buf
  489. if r > hight-30:#/20:
  490. break
  491. #width = event.w
  492. #hight = event.h
  493. #fr = font22.render("L:{} {}:{}".format(scroll_max,active_fix,active_attr) ,1, rgb) #(200,200,200))
  494. active_ratio = 0
  495. if active_fix:
  496. active_ratio = (active_attr/active_fix)
  497. fr = font18.render("ACTIVE:{}:{} ({:0.01f})".format(active_fix,active_attr,active_ratio) ,1, [255,255,0]) #(200,200,200))
  498. window.blit(fr,(300,5))
  499. resize_changed = 0
  500. for event in pygame.event.get():
  501. #print(event.dict)
  502. #print(event.type)
  503. if "scancode" in event.dict:
  504. if event.scancode == 9:
  505. for k in table_draw:
  506. t = table[k]
  507. #t.btn2.clean()
  508. t.btn1.clean()
  509. for k in table_grid_draw:
  510. t = table_grid[k]
  511. #t.btn2.clean()
  512. t.btn1.clean()
  513. msg=json.dumps([{"event":"CLEAR"}]).encode("utf-8")
  514. print("ESC",msg)
  515. cmd_client.send(msg)
  516. #print("event",event)
  517. #print("event",event.dict)
  518. if event.type == pygame.QUIT:
  519. pygame.quit()
  520. sys.exit(0)
  521. elif event.type == pygame.VIDEORESIZE:
  522. scrsize = event.size
  523. width = event.w
  524. hight = event.h
  525. resize_changed = True
  526. scroll_bar.event(event) #daraw()
  527. scroll_change = 0
  528. if scroll_bar.btn3.val.get(): #scroll_bar focus
  529. spos = scroll_bar.rel_pos[1]
  530. #print("------------------",spos)
  531. if "button" in event.dict:
  532. if event.dict["button"] == 1:
  533. scroll_bar.btn4.val.set(scroll_bar.btn4.val._max*spos)
  534. if "buttons" in event.dict:
  535. if event.dict["buttons"][0]:
  536. #print(" ",(scroll_change))
  537. #print(" ",spos)
  538. scroll_bar.btn4.val.set(scroll_bar.btn4.val._max*spos)
  539. event_lock = scroll_bar.btn3.val.get() #focus on
  540. #if event_lock:
  541. # print("event_lock",event_lock)
  542. if not event_lock:
  543. for t in table_draw:
  544. #print(t)
  545. table[t].event(event)
  546. if table[t].btn3.get():
  547. data = table[t].data
  548. #print("FIX:",data)
  549. if not event_lock:
  550. for k3 in table_draw:
  551. #print(t)
  552. row = table[k3]
  553. change = table[k3].event(event)
  554. if row.btn3.get():
  555. # FIXTURE SELECTOR
  556. data = row.data
  557. FIX = row.ID
  558. ATTR = row.ATTR
  559. #key = "MOUSE ENCODER"
  560. #if key in change:
  561. # if "press" in change[key]:
  562. # msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"++","ATTR":ATTR}]).encode("utf-8")
  563. # if "release" in change[key]:
  564. # msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"--","ATTR":ATTR}]).encode("utf-8")
  565. # print(" ",msg)
  566. # cmd_client.send(msg)
  567. key = "BUTTON"
  568. if key in change:
  569. if "press" in change[key]:
  570. #print(" ATTR:",FIX,ATTR,data)
  571. #print(" CHANGE",change)
  572. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  573. print(" ",msg)
  574. cmd_client.send(msg)
  575. if "release" in change[key]:
  576. pass
  577. if not event_lock:
  578. for k3 in table_grid_draw:
  579. #print(t)
  580. row = table_grid[k3]
  581. change = table_grid[k3].event(event)
  582. if row.btn3.get():
  583. data = row.data
  584. FIX = row.ID
  585. ATTR = row.ATTR
  586. #print("change",change)
  587. key = "MOUSE ENCODER"
  588. if key in change:
  589. if "press" in change[key]:
  590. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"++","ATTR":ATTR}]).encode("utf-8")
  591. if "release" in change[key]:
  592. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"--","ATTR":ATTR}]).encode("utf-8")
  593. print(" ",msg)
  594. cmd_client.send(msg)
  595. key = "BUTTON"
  596. if key in change:
  597. if "press" in change[key]:
  598. #print(" ATTR:",FIX,ATTR,data)
  599. #print(" CHANGE",change)
  600. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  601. print(" ",msg)
  602. cmd_client.send(msg)
  603. if "release" in change[key]:
  604. pass
  605. if "pos" in event.dict:
  606. if "button" in event.dict:
  607. if event.type == 5:#press
  608. mouse_down = 1
  609. mouse_pos1 = [event.pos[0],event.pos[1]]
  610. if event.type == 6:#release
  611. mouse_down = 0
  612. #for btn in mouse_grab:
  613. # btn.btn1.val.set(1)
  614. mouse_pos2 = [event.pos[0],event.pos[1]]
  615. if event_lock:
  616. pass
  617. elif "button" in event.dict:
  618. if event.type == 6:
  619. #print("grab DOOOO",event)
  620. #print("grab2", event.dict["button"],len(mouse_grab) )
  621. if event.dict["button"] == 1:
  622. mouse_grab_active = 0
  623. for mg in mouse_grab:
  624. if mg.btn1.val.get():
  625. mouse_grab_active += 1
  626. for mg in mouse_grab:
  627. FIX = str(mg.ID)
  628. ATTR = str(mg.ATTR)
  629. if mouse_grab_active:
  630. if not mg.btn1.val.get():
  631. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  632. #print(" mouse_grab ",msg,mg.btn1.val.get())
  633. cmd_client.send(msg)
  634. else: #no btn is on
  635. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  636. #amsg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  637. #print(" mouse_grab OFF ",msg,mg.btn1.val.get())
  638. cmd_client.send(msg)
  639. mouse_grab = []
  640. if event.dict["button"] == 3:
  641. mouse_grab_active = 0
  642. for mg in mouse_grab:
  643. if mg.btn1.val.get():
  644. mouse_grab_active += 1
  645. for mg in mouse_grab:
  646. FIX = str(mg.ID)
  647. ATTR = str(mg.ATTR)
  648. if mouse_grab_active:
  649. if mg.btn1.val.get():
  650. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  651. #print(" mouse_grab ",msg,mg.btn1.val.get())
  652. cmd_client.send(msg)
  653. mouse_grab = []
  654. if mouse_down:
  655. d1 = mouse_pos1[0]-mouse_pos2[0]
  656. d2 = mouse_pos1[1]-mouse_pos2[1]
  657. pix = 10
  658. #print(d1,d2)
  659. if ( d1 > pix or d1 < -pix) or ( d2 >pix or d2 < -pix):
  660. sdl_elm.draw_mouse_box(window,mouse_pos1,mouse_pos2)
  661. for k in table_draw: # FIX-ID
  662. t = table[k]
  663. pos = t.get_rect()
  664. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  665. if sdl_elm.check_area2(pos,mpos):
  666. #t._set_mouse_focus(1)
  667. if t not in mouse_grab:
  668. mouse_grab.append(t)
  669. #print("mouse_grab.append",t)
  670. #mouse_grab = reorder_table_by_pos(mouse_grab)
  671. else:
  672. #t._set_mouse_focus(0)
  673. if t in mouse_grab:
  674. mouse_grab.remove(t)
  675. #print("mouse_grab.remove",t)
  676. for k3 in table_grid_draw: # FIX-ATTR
  677. t = table_grid[k3]
  678. pos = t.get_rect()
  679. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  680. if sdl_elm.check_area2(pos,mpos):
  681. #t._set_mouse_focus(1)
  682. if t not in mouse_grab:
  683. mouse_grab.append(t)
  684. #print("mouse_grab.append",t)
  685. #mouse_grab = reorder_table_by_pos(mouse_grab)
  686. else:
  687. #t._set_mouse_focus(0)
  688. if t in mouse_grab:
  689. mouse_grab.remove(t)
  690. #print("mouse_grab.remove",t)
  691. for k3 in table_grid:
  692. t = table_grid[k3]
  693. t._set_mouse_focus(0)
  694. i = 1
  695. if mouse_grab:
  696. mouse_grab = reorder_table_by_pos(mouse_grab)
  697. for t in mouse_grab:
  698. t._set_mouse_focus(1)
  699. pos = t.pos[:2]
  700. pos[0] += 100
  701. pos[1] += 8
  702. rgb = (0,255,255)
  703. fr = font15.render(""+str(i) ,1, rgb) #(200,200,200))
  704. #print(pos)
  705. pygame.draw.rect(window,(0,0,0),[pos[0]-2,pos[1]-2,15,13])
  706. window.blit(fr,pos)
  707. i+=1
  708. if resize_changed:# = True
  709. screen = pygame.display.set_mode(scrsize,pg.RESIZABLE)
  710. scroll_bar.draw()
  711. clock.tick(6)
  712. except Exception as e:
  713. err.append([int((time.time()-boot)*100),e])
  714. traceback.print_exc()
  715. print("Exc",e)