fix.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  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. BTN_WIDTH = 120
  311. #scroll_bar.btn4.val._max = len(data)-8 #draw()
  312. scroll_max = len(data)-8
  313. scroll_max = len(data.keys())-8
  314. scroll_max = 1
  315. block_wrap = int( (width-200) / BTN_WIDTH)
  316. if block_wrap <= 0:
  317. block_wrap = 1
  318. for k in data.keys():
  319. fix_type = get_fix_type(data[k])
  320. if "ATTRIBUT" in data[k]:
  321. row = data[k]["ATTRIBUT"]
  322. acount = get_attr_count(row)
  323. if fix_type == "DIM":
  324. continue
  325. if acount > block_wrap:
  326. scroll_max += int(acount/block_wrap)
  327. else:
  328. scroll_max += 1
  329. #print()
  330. scroll_bar.btn4.val._max = scroll_max
  331. scroll_bar.increment = (len(data))/100*10 #draw()
  332. #data = add_dmx(data,dmx)
  333. scroll_pos = scroll_bar.btn4.val.get()
  334. scroll_bar.pos[0] = width-scroll_bar.pos[2]-5
  335. scroll_bar.pos[3] = hight-80
  336. #print(scroll_pos)
  337. table_grid_draw=[] #{}
  338. table_draw = []
  339. active_fix = 0
  340. active_attr = 0
  341. i = 0
  342. r=40
  343. if 1:
  344. ch = 141
  345. send = 0
  346. #cmd="stats items"
  347. #if not y:
  348. y=data #mc.get("fix")#cmd)
  349. if y:
  350. iii = 0
  351. key=y.keys()
  352. key = list(key)
  353. key2 = []
  354. for k in key:
  355. #print(k)
  356. try:
  357. key2.append(int(k))
  358. except:
  359. pass
  360. key2.sort()
  361. key = key2 #.sort()
  362. if len(btn1_press) == 0:
  363. btn1_press = [key[0]]
  364. rgb = (0x00,0,0xff,0)
  365. k2 = btn1_press[-1]
  366. #fr = font22.render("SRC:"+str(k2) ,1, rgb) #(200,200,200))
  367. fr = font15.render("FPS:"+str(fps_old) ,1, rgb) #(200,200,200))
  368. window.blit(fr,(600,5))
  369. err_r = 0
  370. if err:
  371. for e in err:
  372. rgb = (255,0,0)
  373. fr = font15.render("err:"+str(e) ,1, rgb) #(200,200,200))
  374. window.blit(fr,(700,5+err_r))
  375. err_r += 20
  376. i4 = 0
  377. for k in key:
  378. k = str(k)
  379. fix_row = y[k]
  380. fix_type = get_fix_type(fix_row)
  381. if fix_type == "DIM":
  382. continue
  383. active_fix += is_active_fix(fix_row)
  384. active_attr += count_active_attr(fix_row)
  385. for k in key:#y.items():
  386. k = str(k)
  387. v = y[k]
  388. fix_row = v
  389. fix_type = get_fix_type(fix_row)
  390. if fix_type == "DIM":
  391. continue
  392. #scroll_max+=1
  393. i4 += 1
  394. if i4 < scroll_pos:
  395. continue
  396. #print(k,v)
  397. x=mc.get(k)
  398. cccount = 0
  399. txt = str([k,v,ch,"=",cccount]) #x[ch-1]])
  400. rgb = (0xaa,0xaa,0xaa,0)
  401. i += 1
  402. if k not in table:
  403. bx = sdl_elm.Button(window,pos=[20+20,r,50,20])
  404. bx.btn1.color_on = [255,255,0]
  405. bx.ID = -1
  406. if "ID" in v:
  407. bx.ID = v["ID"]
  408. if bx.ID == 0:
  409. bx.ID = -2
  410. bx.ATTR = "_ACTIVE"
  411. table[k] = bx
  412. # color box
  413. bxc = sdl_elm.Button(window,pos=[-11+20,r,5,20])
  414. bxc.btn1.color_on = [255,255,0]
  415. table[k+"_color"] = bxc
  416. bx = table[k]
  417. bx.data = v
  418. bxc.data = {}
  419. active = is_active_fix(v)
  420. bx.btn1.val.set(active)
  421. try:
  422. if int(k) % 10 == 0:
  423. #pygame.draw.aaline(window,[255,0,0],[2,r],[800,r],1)
  424. pygame.draw.rect(window,[58,58,58],[2,r,2000,25])
  425. except:pass
  426. bx.text = "ID:"+ k
  427. bx.text += " "+v["NAME"]
  428. bx.font0 = bx_font0
  429. bx.btn1.bg_on = [0,255,255]
  430. bx.btn1.type = "toggle"
  431. bx.pos = [10+10,r,BTN_WIDTH,20]
  432. if "ATTRIBUT" in v:
  433. bcv_r = 0
  434. bcv_g = 0
  435. bcv_b = 0
  436. if "RED" in v["ATTRIBUT"]:
  437. bcv_r = v["ATTRIBUT"]["RED"]["VALUE2"]
  438. if "GREEN" in v["ATTRIBUT"]:
  439. bcv_g = v["ATTRIBUT"]["GREEN"]["VALUE2"]
  440. if "BLUE" in v["ATTRIBUT"]:
  441. bcv_b = v["ATTRIBUT"]["BLUE"]["VALUE2"]
  442. #print("bvc_rgb" [bcv_r,bcv_g,bcv_b])
  443. if bcv_r > 255:
  444. bcv_r=255
  445. if bcv_g > 255:
  446. bcv_g=255
  447. if bcv_b > 255:
  448. bcv_b=255
  449. bxc.btn1.color = [bcv_r,bcv_g,bcv_b]
  450. bxc.btn1.color_on = [bcv_r,bcv_g,bcv_b]
  451. bxc.pos = [140+5,r,20,20]
  452. bxc.text = ""
  453. bx.draw()
  454. bxc.draw()
  455. r_buf=bx.get_rect()[3]+2
  456. iii += 35
  457. rr = 0
  458. acount = 0
  459. if "ATTRIBUT" in v: # and 10:
  460. ATTR = v["ATTRIBUT"]
  461. for k2 in ATTR:
  462. k2_ATTR = ATTR[k2]
  463. if is_hidden_attr(k2):
  464. continue
  465. k3 = k+"-"+k2
  466. val2 = ""
  467. if "VALUE" in k2_ATTR:
  468. val2 = k2_ATTR["VALUE"]
  469. virt = 1
  470. if "NR" in k2_ATTR:
  471. if k2_ATTR["NR"] > 0:
  472. virt = 0
  473. dmx_val = -3
  474. if "VALUE2"in k2_ATTR:
  475. dmx_val = k2_ATTR["VALUE2"]
  476. if k3 not in table_grid:
  477. bx = sdl_elm.Button(window,pos=[600,rr,60,20])
  478. bx.btn1.color_on = [255,255,0]
  479. bx.ID = 0
  480. if "ID" in v:
  481. bx.ID = v["ID"]
  482. bx.ATTR = k2
  483. table_grid[k3] = bx
  484. if "ACTIVE" in k2_ATTR:
  485. if k2_ATTR["ACTIVE"] >=1:
  486. table_grid[k3].btn1.val.set(1)
  487. #active_attr += 1
  488. else:
  489. table_grid[k3].btn1.val.set(0)
  490. bx = table_grid[k3]
  491. bx.data = k2_ATTR
  492. try:val = v
  493. except:pass
  494. bx.text = k2 +" "+str(val2)+" "+str(dmx_val)
  495. bx.font0 = bx_font0
  496. if k2 == "RED":
  497. bx.btn4.color_on = [255,0,0]
  498. elif k2 == "GREEN":
  499. bx.btn4.color_on = [0,255,0]
  500. elif k2 == "BLUE":
  501. bx.btn4.color_on = [0,0,255]
  502. if virt == 1:
  503. bx.btn3.color= [0,0,0]
  504. bx.btn1.type = "toggle"
  505. if type(dmx_val) == int:
  506. bx.btn4.val.set(dmx_val) # "toggle"
  507. bx.pos = [170+rr,r,BTN_WIDTH,20]
  508. bx.draw()
  509. rr+=bx.get_rect()[2]+2
  510. table_grid_draw.append(k3) #table_grid[k3]
  511. if rr > 1000:
  512. break
  513. acount +=1
  514. if acount %block_wrap==0:
  515. r += r_buf
  516. rr = 0
  517. table_draw.append(k)
  518. r += r_buf
  519. if r > hight-30:#/20:
  520. break
  521. active_ratio = 0
  522. if active_fix:
  523. active_ratio = (active_attr/active_fix)
  524. fr = font18.render("ACTIVE:{}:{} ({:0.01f})".format(active_fix,active_attr,active_ratio) ,1, [255,255,0]) #(200,200,200))
  525. window.blit(fr,(300,5))
  526. if SHIFT_FINE:
  527. fr = font18.render("ENCODER:±0.25" ,1, [255,255,0])
  528. else:
  529. fr = font18.render("ENCODER:±5.00" ,1, [255,255,0])
  530. window.blit(fr,(420,5))
  531. if 0: #show line number +scroll_pos
  532. bxc = sdl_elm.Button(window,pos=[-11+10,(0*23),50,10])
  533. bxc.text = "{:0.02f} {}".format(scroll_pos,scroll_max)
  534. ii = int(scroll_pos) #int(scroll_pos/23*29)
  535. bxc.font0 = bx_font0
  536. bxc.draw()
  537. for i in range(40+1):
  538. bxc = sdl_elm.Button(window,pos=[0,40+(i*23),30,10])
  539. bxc.text = "{}".format(1+i+ii)
  540. bxc.btn1.color = [255,200,200]
  541. bxc.btn2.color = [255,200,200]
  542. bxc.btn3.color = [255,200,200]
  543. bxc.font0 = bx_font0
  544. bxc.draw()
  545. resize_changed = 0
  546. for event in pygame.event.get():
  547. if "scancode" in event.dict:
  548. print(event.dict,event.type)
  549. if event.scancode == 50:
  550. if event.type == 2: # press
  551. #pg.display.set_caption(CAPTION+ " SHIFT/FINE")
  552. SHIFT_FINE = 1
  553. if event.type == 3: # release
  554. #pg.display.set_caption(CAPTION)
  555. SHIFT_FINE = 0
  556. if event.scancode == 9:
  557. for k in table_draw:
  558. t = table[k]
  559. #t.btn2.clean()
  560. t.btn1.clean()
  561. for k in table_grid_draw:
  562. t = table_grid[k]
  563. #t.btn2.clean()
  564. t.btn1.clean()
  565. msg=json.dumps([{"event":"CLEAR"}]).encode("utf-8")
  566. print("ESC",msg)
  567. cmd_client.send(msg)
  568. keycode = {27:"REC",39:"SELECT",46:"LABEL",54:"CFG-BTN",56:"BLIND",41:"FLASH",26:"EDIT"}
  569. print( event.scancode in keycode,event.scancode)
  570. if event.scancode in keycode: # r
  571. if event.type == 2: # press
  572. msg=json.dumps([{"event":keycode[event.scancode]}]).encode("utf-8")
  573. print("SPCIAL-KEY",msg)
  574. cmd_client.send(msg)
  575. if event.scancode in range(10,20+1):
  576. if event.type in [2,3]: # press
  577. v = 1-event.type+2
  578. if v:
  579. v=255
  580. else:
  581. v=0
  582. btn_nr = event.scancode-9
  583. btn_nr_raw = btn_nr
  584. btn_nr += 161-1
  585. msg=json.dumps([{"event":"EXEC","EXEC":btn_nr,"VAL":v,"NR-KEY":btn_nr_raw}]).encode("utf-8")
  586. print("SPCIAL-KEY",msg)
  587. cmd_client.send(msg)
  588. #msg=json.dumps({"event":"EXEC","EXEC":btn_nr,"VAL":v,"NR-KEY":btn_nr_raw})#.encode("utf-8")
  589. #cmd = "echo '{}' > ~/backpipe ".format(msg)
  590. #print(":::::::", cmd)
  591. #os.system(cmd)
  592. if event.scancode in range(67,76+1) or event.scancode in [95,96]:
  593. if event.type in [2,3]: # press
  594. v = 1-event.type+2
  595. if v:
  596. v=255
  597. else:
  598. v=0
  599. btn_nr = event.scancode
  600. if btn_nr == 95:
  601. btn_nr = 11
  602. elif btn_nr == 96:
  603. btn_nr = 12
  604. else:
  605. btn_nr = event.scancode-66
  606. btn_nr_raw = btn_nr
  607. btn_nr += 81-1
  608. msg=json.dumps([{"event":"EXEC","EXEC":btn_nr,"VAL":v,"F-KEY":btn_nr_raw}]).encode("utf-8")
  609. print("SPCIAL-KEY",msg)
  610. cmd_client.send(msg)
  611. #msg=json.dumps({"event":"EXEC","EXEC":btn_nr,"VAL":v,"F-KEY":btn_nr_raw})#.encode("utf-8")
  612. #cmd = "echo '{}' > ~/backpipe ".format(msg)
  613. #print(":::::::", cmd)
  614. #os.system(cmd)
  615. if event.type == pygame.QUIT:
  616. #movewin.store_all_sdl()
  617. pygame.quit()
  618. sys.exit(0)
  619. elif event.type == pygame.VIDEORESIZE:
  620. scrsize = event.size
  621. width = event.w
  622. hight = event.h
  623. resize_changed = True
  624. scroll_bar.event(event) #daraw()
  625. scroll_change = 0
  626. if scroll_bar.btn3.val.get(): #scroll_bar focus
  627. spos = scroll_bar.rel_pos[1]
  628. #print("------------------",spos)
  629. if "button" in event.dict:
  630. if event.dict["button"] == 1:
  631. scroll_bar.btn4.val.set(scroll_bar.btn4.val._max*spos)
  632. if "buttons" in event.dict:
  633. if event.dict["buttons"][0]:
  634. scroll_bar.btn4.val.set(scroll_bar.btn4.val._max*spos)
  635. event_lock = scroll_bar.btn3.val.get() #focus on
  636. if not event_lock:
  637. for t in table_draw:
  638. table[t].event(event)
  639. if table[t].btn3.get():
  640. data = table[t].data
  641. if not event_lock:
  642. for k3 in table_draw:
  643. #print(t)
  644. row = table[k3]
  645. change = table[k3].event(event)
  646. if row.btn3.get():
  647. # FIXTURE SELECTOR
  648. data = row.data
  649. FIX = row.ID
  650. ATTR = row.ATTR
  651. key = "BUTTON"
  652. if key in change:
  653. if "press" in change[key]:
  654. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  655. print(" ",msg)
  656. cmd_client.send(msg)
  657. if "release" in change[key]:
  658. pass
  659. if not event_lock:
  660. for k3 in table_grid_draw:
  661. row = table_grid[k3]
  662. change = table_grid[k3].event(event)
  663. if row.btn3.get():
  664. data = row.data
  665. FIX = row.ID
  666. ATTR = row.ATTR
  667. key = "MOUSE ENCODER"
  668. if key in change:
  669. ACC = 2
  670. if SHIFT_FINE:
  671. ACC = 1
  672. VAL = ""
  673. if "press" in change[key]:
  674. VAL = "+"*ACC
  675. if "release" in change[key]:
  676. VAL = "-"*ACC
  677. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":VAL,"ATTR":ATTR}]).encode("utf-8")
  678. print(" ",msg)
  679. cmd_client.send(msg)
  680. key = "BUTTON"
  681. if key in change:
  682. if "press" in change[key]:
  683. #print(" ATTR:",FIX,ATTR,data)
  684. #print(" CHANGE",change)
  685. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  686. print(" ",msg)
  687. cmd_client.send(msg)
  688. if "release" in change[key]:
  689. pass
  690. if "pos" in event.dict:
  691. if "button" in event.dict:
  692. if event.type == 5:#press
  693. mouse_down = 1
  694. mouse_pos1 = [event.pos[0],event.pos[1]]
  695. if event.type == 6:#release
  696. mouse_down = 0
  697. mouse_pos2 = [event.pos[0],event.pos[1]]
  698. if event_lock:
  699. pass
  700. elif "button" in event.dict:
  701. if event.type == 6:
  702. #print("grab DOOOO",event)
  703. #print("grab2", event.dict["button"],len(mouse_grab) )
  704. if event.dict["button"] == 1:
  705. mouse_grab_active = 0
  706. for mg in mouse_grab:
  707. if mg.btn1.val.get():
  708. mouse_grab_active += 1
  709. for mg in mouse_grab:
  710. FIX = str(mg.ID)
  711. ATTR = str(mg.ATTR)
  712. if mouse_grab_active:
  713. if not mg.btn1.val.get():
  714. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  715. cmd_client.send(msg)
  716. else: #no btn is on
  717. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS","FIX":str(FIX),"VAL":"click","ATTR":ATTR}]).encode("utf-8")
  718. cmd_client.send(msg)
  719. mouse_grab = []
  720. if event.dict["button"] == 3:
  721. mouse_grab_active = 0
  722. for mg in mouse_grab:
  723. if mg.btn1.val.get():
  724. mouse_grab_active += 1
  725. for mg in mouse_grab:
  726. FIX = str(mg.ID)
  727. ATTR = str(mg.ATTR)
  728. if mouse_grab_active:
  729. if mg.btn1.val.get():
  730. msg = json.dumps([{"event":"FIXTURES","TYPE":"ENCODERS"
  731. ,"FIX":str(FIX),"VAL":"click"
  732. ,"ATTR":ATTR}]).encode("utf-8")
  733. #print(" mouse_grab ",msg,mg.btn1.val.get())
  734. cmd_client.send(msg)
  735. mouse_grab = []
  736. if mouse_down:
  737. d1 = mouse_pos1[0]-mouse_pos2[0]
  738. d2 = mouse_pos1[1]-mouse_pos2[1]
  739. pix = 10
  740. if ( d1 > pix or d1 < -pix) or ( d2 >pix or d2 < -pix):
  741. sdl_elm.draw_mouse_box(window,mouse_pos1,mouse_pos2)
  742. for k in table_draw: # FIX-ID
  743. t = table[k]
  744. pos = t.get_rect()
  745. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  746. if sdl_elm.check_area2(pos,mpos):
  747. if t not in mouse_grab:
  748. mouse_grab.append(t)
  749. else:
  750. if t in mouse_grab:
  751. mouse_grab.remove(t)
  752. for k3 in table_grid_draw: # FIX-ATTR
  753. t = table_grid[k3]
  754. pos = t.get_rect()
  755. mpos = [mouse_pos1[0],mouse_pos1[1],mouse_pos2[0],mouse_pos2[1]]
  756. if sdl_elm.check_area2(pos,mpos):
  757. if t not in mouse_grab:
  758. mouse_grab.append(t)
  759. else:
  760. if t in mouse_grab:
  761. mouse_grab.remove(t)
  762. for k3 in table_grid:
  763. t = table_grid[k3]
  764. t._set_mouse_focus(0)
  765. i = 1
  766. if mouse_grab:
  767. mouse_grab = reorder_table_by_pos(mouse_grab)
  768. for t in mouse_grab:
  769. t._set_mouse_focus(1)
  770. pos = t.pos[:2]
  771. pos[0] += 100
  772. pos[1] += 8
  773. rgb = (0,255,255)
  774. fr = font15.render(""+str(i) ,1, rgb) #(200,200,200))
  775. #print(pos)
  776. pygame.draw.rect(window,(0,0,0),[pos[0]-2,pos[1]-2,15,13])
  777. window.blit(fr,pos)
  778. i+=1
  779. if resize_changed:# = True
  780. screen = pygame.display.set_mode(scrsize,pg.RESIZABLE)
  781. scroll_bar.draw()
  782. clock.tick(6)
  783. except Exception as e:
  784. err.append([int((time.time()-boot)*100),e])
  785. traceback.print_exc()
  786. print("Exc",e)