fix.py 32 KB

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