fix.py 32 KB

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