fix.py 34 KB

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