FX3.py 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. import json
  2. import time
  3. import sys
  4. import tkinter as tk
  5. from tkinter import font
  6. import traceback
  7. import _thread as thread
  8. import dialog
  9. DIALOG = dialog.Dialog()
  10. GLOBAL_old_btn_nr = -1
  11. GLOBAL_mode_on = -1
  12. def refresh_exec_btn(btn_nr):
  13. global GLOBAL_old_btn_nr
  14. nr2= GLOBAL_old_btn_nr
  15. print()
  16. print(" refresh_exec_btn:",btn_nr)
  17. time.sleep(0.5)
  18. nr = btn_nr #+1 #-1
  19. b = gui.elem_exec[nr]
  20. print("---")
  21. gui._refresh_exec_single(nr,b) #,METAS):
  22. if nr2 >= 0 and nr2 != nr:
  23. b = gui.elem_exec[nr2]
  24. gui._refresh_exec_single(nr2,b) #,METAS):
  25. GLOBAL_old_btn_nr = nr
  26. gui=None
  27. def dialog_cfg_open(btn_nr,META):
  28. print("META",META)
  29. cfg = META["CFG"]
  30. label = META["LABEL"]
  31. button = cfg["BUTTON"]
  32. DIALOG._cb = dialog_cb_cfg(btn_nr+1)
  33. DIALOG.ask_exec_config(str(btn_nr+1),button=button,label=label,cfg=cfg)
  34. #print("INFO",master.commands.elem)
  35. def dialog_label_open(btn_nr,META):
  36. print("META",META)
  37. cfg = META["CFG"]
  38. label = META["LABEL"]
  39. button = cfg["BUTTON"]
  40. DIALOG._cb = dialog_cb_label(btn_nr+1)
  41. #DIALOG.ask_exec_config(str(btn_nr+1),button=button,label=label,cfg=cfg)
  42. DIALOG.askstring("LABEL","LABEL EXE:"+str(btn_nr+1),initialvalue=label)
  43. #print("INFO",master.commands.elem)
  44. def dialog_cb_cfg(exec_nr): #DAILOG CONFIG CALLBACK
  45. def _Dcb(*args):
  46. print("dialog_cb_cfg:",args)
  47. msg=json.dumps([{"event":"EXEC-CFG","EXEC":exec_nr,"VALUE":255,"DATA":args[0]}]).encode("utf-8")
  48. cprint(" SEND DIALOG.cb",msg,color="green")
  49. cmd_client.send(msg)
  50. thread.start_new_thread(refresh_exec_btn,(exec_nr,))
  51. return _Dcb
  52. def dialog_cb_label(exec_nr): #DAILOG CONFIG CALLBACK
  53. def _Dcb(*args):
  54. cprint("dialog_cb_label:",args,"EXEC_NR:",exec_nr)
  55. if not args:
  56. cprint(" dialog_cb args_error !",color="red")
  57. return
  58. if args[0] is None:
  59. cprint(" dialog_cb cancel !",color="red")
  60. return
  61. if "Value" in args[0]:
  62. DATA = {"Label":args[0]["Value"]}
  63. msg=json.dumps([{"event":"EXEC-LABEL","EXEC":exec_nr,"VALUE":255,"DATA":DATA}]).encode("utf-8")
  64. cprint(" SEND DIALOG.cb",msg,color="green")
  65. cmd_client.send(msg) # send new meta-data
  66. msg=json.dumps([{"event":"LABEL","EXEC":exec_nr,"VALUE":255,"DATA":{}}]).encode("utf-8")
  67. cmd_client.send(msg) # diable LABEL mode
  68. thread.start_new_thread(refresh_exec_btn,(exec_nr,))
  69. return _Dcb
  70. DIALOG._cb = dialog_cb_cfg(-3)
  71. #d = dialog.Dialog()
  72. #d.ask_exec_config(str(nr+1),button=button,label=label,cfg=cfg)
  73. import __main__ as MAIN
  74. _file_path = "/opt/LibreLight/Xdesk/"
  75. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  76. import tool.git as git
  77. #CAPTION += git.get_all()
  78. CAPTION = "EXEC-BTN"
  79. title = CAPTION
  80. title += git.get_all()
  81. INIT_OK = 1
  82. IS_GUI = 0
  83. from lib.cprint import cprint
  84. import lib.libtk as libtk
  85. import lib.libtk2 as libtk2
  86. import lib.zchat as chat
  87. import lib.mytklib as mytklib
  88. import lib.tkevent as tkevent
  89. #import tkgui.draw as draw
  90. def draw_exec(gui,xframe,EXEC):
  91. i=0
  92. c=0
  93. r=0
  94. root = xframe
  95. frame = tk.Frame(root,bg="black")
  96. frame.pack(fill=tk.X, side=tk.TOP)
  97. gui.elem_exec = {}
  98. i=0
  99. for k in EXEC.val_exec:
  100. if i%(10*8)==0 or i ==0:
  101. c=0
  102. b = tk.Canvas(frame,bg="black", height=4,bd=0,width=6,highlightthickness=0) #,bd="black")
  103. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  104. r+=1
  105. c=0
  106. b = tk.Button(frame,bg="lightblue", text="EXEC " )
  107. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  108. c+=1
  109. b = tk.Button(frame,bg="lightblue", text="BANK " + str(int(i/(8*8))+1) )
  110. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  111. c+=1
  112. b = tk.Button(frame,bg="lightblue", text="NAME" )
  113. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  114. c+=7
  115. if i == 0:
  116. b = tk.Button(frame,bg="darkgrey", text="HELP",command=libtk.online_help("librelight:20-exec")) #"0&do=index"))
  117. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  118. r+=1
  119. c=0
  120. i+=1
  121. v=0
  122. label = ""
  123. sdata=EXEC.val_exec[k]
  124. BTN="go"
  125. if "CFG" in sdata:#["BUTTON"] = "GO"
  126. if "BUTTON" in sdata["CFG"]:
  127. BTN = sdata["CFG"]["BUTTON"]
  128. txt=str(k+1)+":"+str(BTN)+":"+str(len(sdata)-1)+"\n"+label
  129. b = mytklib.ExecButton(frame,text=txt)
  130. b.bind("<Button>", tkevent.tk_event(fix=0,elem=b,attr=k,data=gui,mode="EXEC").cb)
  131. b.bind("<ButtonRelease>",tkevent.tk_event(fix=0,elem=b,attr=k,data=gui,mode="EXEC").cb)
  132. if k not in gui.elem_exec:
  133. gui.elem_exec[k] = b
  134. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  135. b.config(text="xx"+str(i))
  136. c+=1
  137. if c >=10:
  138. c=0
  139. r+=1
  140. time.sleep(0.1)
  141. gui._refresh_exec()
  142. print("##################################")
  143. def _add_space(frame,r,c):
  144. b = tk.Canvas(frame,bg="black", height=2,bd=0,width=6,highlightthickness=0) #,bd="black")
  145. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  146. r+=1
  147. c=0
  148. return r,c
  149. def _draw_fx_3(frame,c,r,gui,mode="FX"):
  150. ct = gui.fx_3 #moves
  151. prm = MAIN.fx_prm_3
  152. for comm in ct.commands:
  153. if comm == "\n\n":
  154. b = tk.Label(frame,bg="black", text="-",font=space_font)
  155. b.grid(row=r, column=c,pady=0,padx=0, sticky=tk.W+tk.E)
  156. c=0
  157. r+=1
  158. continue
  159. if comm == "\n":
  160. c=0
  161. r+=1
  162. continue
  163. v=0
  164. if "PAN/TILT" in comm:
  165. b = tk.Button(frame,bg="grey", text=str(comm),width=6,height=1)
  166. else:
  167. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=1)
  168. if 1:#comm not in ct.elem:
  169. #comm = comm.replace("\n","")
  170. ct.elem[comm] = b
  171. ct.val[comm] = 0
  172. b.bind("<Button>",tkevent.tk_event_fx(fix=0,elem=b,attr=comm,data=gui,mode=mode).cb)
  173. if comm == "xREC-FX":
  174. b["bg"] = "grey"
  175. elif comm == "xFX OFF":
  176. b["bg"] = "magenta"
  177. elif comm[:3] == "xFX:" or comm[:3] == "x2D:":
  178. b["text"] = comm
  179. b["bg"] = "#ffbf00"
  180. elif comm[:3] == "xMO:":
  181. b["text"] = comm
  182. b["bg"] = "lightgreen"
  183. elif comm.startswith( "xSIZE:"):
  184. b["text"] = "SIZE:\n{:0.0f}".format(prm["SIZE"])
  185. b["bg"] = "lightgreen"
  186. elif comm.startswith( "xSPEED:"):
  187. b["text"] = "SPEED:\n{:0.0f}".format(prm["SPEED"])
  188. b["bg"] = "lightgreen"
  189. elif comm.startswith("xSTART:"):
  190. b["bg"] = "lightgreen"
  191. b["text"] = "START:\n{:0.0f}".format(prm["START"])
  192. elif comm.startswith( "xOFFSET:"):
  193. b["bg"] = "lightgreen"
  194. b["text"] = "OFFSET:\n{:0.0f}".format(prm["OFFSET"])
  195. elif comm[:3] == "xBASE:":
  196. b["bg"] = "lightgreen"
  197. b["text"] = "BASE:\n{}".format(prm["BASE"])
  198. elif comm[0] == "M":
  199. b["text"] = comm
  200. b["bg"] = "lightgrey"
  201. if comm:
  202. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  203. c+=1
  204. if c >=6:
  205. c=0
  206. r+=1
  207. c=0
  208. r+=1
  209. return c,r
  210. def _draw_fx(frame,c,r,gui,mode="FX"):
  211. if mode=="FX-MAIN":
  212. ct = gui.fx_main
  213. prm = MAIN.fx_prm_main
  214. elif mode=="FX-MOVE":
  215. ct = gui.fx_moves
  216. prm = MAIN.fx_prm_move
  217. elif mode=="FX":
  218. ct = gui.fx
  219. prm = MAIN.fx_prm
  220. elif mode=="FX-GENERIC":
  221. ct = gui.fx_generic
  222. prm = MAIN.fx_prm #_generic
  223. elif mode=="FX-COLOR":
  224. ct = gui.fx_color
  225. prm = MAIN.fx_color #_generic
  226. else:
  227. ct = Elem_Container()
  228. ct.commands =["err"]
  229. prm = ["err"]
  230. for comm in ct.commands:
  231. if comm == "\n\n":
  232. b = tk.Label(frame,bg="black", text="-",font=space_font)
  233. b.grid(row=r, column=c,pady=0,padx=0, sticky=tk.W+tk.E)
  234. c=0
  235. r+=1
  236. continue
  237. if comm == "\n":
  238. c=0
  239. r+=1
  240. continue
  241. v=0
  242. if "PAN/TILT" in comm:
  243. b = tk.Button(frame,bg="grey", text=str(comm),width=6,height=2)
  244. else:
  245. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  246. if 1:#comm not in ct.elem:
  247. #comm = comm.replace("\n","")
  248. ct.elem[comm] = b
  249. ct.val[comm] = 0
  250. b.bind("<Button>",tkevent.tk_event_fx(fix=0,elem=b,attr=comm,data=gui,mode=mode).cb)
  251. if comm == "REC-FX":
  252. b["bg"] = "grey"
  253. elif comm == "FX OFF":
  254. b["bg"] = "magenta"
  255. elif comm[:3] == "FX:" or comm[:3] == "2D:":
  256. b["text"] = comm
  257. b["bg"] = "#ffbf00"
  258. elif comm[:3] == "MO:":
  259. b["text"] = comm
  260. b["bg"] = "lightgreen"
  261. elif comm.startswith( "SIZE:"):
  262. b["text"] = "SIZE:\n{:0.0f}".format(prm["SIZE"])
  263. b["bg"] = "lightgreen"
  264. elif comm.startswith( "SPEED:"):
  265. b["text"] = "SPEED:\n{:0.0f}".format(prm["SPEED"])
  266. b["bg"] = "lightgreen"
  267. elif comm.startswith("START:"):
  268. b["bg"] = "lightgreen"
  269. b["text"] = "START:\n{:0.0f}".format(prm["START"])
  270. elif comm.startswith( "OFFSET:"):
  271. b["bg"] = "lightgreen"
  272. b["text"] = "OFFSET:\n{:0.0f}".format(prm["OFFSET"])
  273. elif comm[:3] == "BASE:":
  274. b["bg"] = "lightgreen"
  275. b["text"] = "BASE:\n{}".format(prm["BASE"])
  276. elif comm[0] == "M":
  277. b["text"] = comm
  278. b["bg"] = "lightgrey"
  279. if comm:
  280. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  281. c+=1
  282. if c >=6:
  283. c=0
  284. r+=1
  285. c=0
  286. r+=1
  287. return c,r
  288. def draw_fx_3(gui,xframe,data=[]):
  289. frame_fx=xframe
  290. i=0
  291. c=0
  292. r=0
  293. frame = tk.Frame(frame_fx,bg="black")
  294. frame.pack(fill=tk.X, side=tk.TOP)
  295. # ------------------------------
  296. b = tk.Button(frame,bg="lightblue", text="FX3",width=6)
  297. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  298. c+=1
  299. thread.start_new_thread(mytklib.tk_btn_bg_loop,(b,))
  300. # ------------------------------
  301. _add_space(frame,r,c)
  302. c,r = _draw_fx(frame,c,r,gui,mode="FX-MAIN")
  303. #r,c=_add_space(frame,r,c)
  304. #c,r = _draw_fx(frame,c,r,gui,mode="FX-COLOR")
  305. r,c=_add_space(frame,r,c)
  306. c,r = _draw_fx_3(frame,c,r,gui,mode="FX-3")
  307. import tool.movewin as movewin
  308. #movewin.check_is_started(CAPTION,_file_path)
  309. movewin.check_is_started("EXEC-BTN","/opt/LibreLight/Xdesk/tkgui/EXEC-BTN.py")
  310. _global_short_key = 1
  311. root = None
  312. cmd_client = chat.Client(port=30003)
  313. try:
  314. import memcache
  315. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  316. #data = mc.get("MODES")
  317. except:
  318. mc = None
  319. class Refresher(): # DUMMY
  320. def __init__(self,*arg,**args):
  321. print(self,"__init__",arg,args)
  322. def reset(*arg,**args):
  323. print(self,"reset",arg,args)
  324. class Command():
  325. def __init__(self):
  326. self.elem = {}
  327. class MASTER(): # DUMMY
  328. def __init__(self,*arg,**args):
  329. print(self,"__init__",arg,args)
  330. #self.refresh_fix = Refresher()
  331. self.commands = Command()
  332. def refresh_fix(self,*arg,**args):# = Refresher()
  333. print(self,"refresh_fix",arg,args)
  334. def exec_go(self,nr,*arg,**args): #val=None,xfade=None,event=None,button="",ptfade=None):
  335. if _global_key_lock:
  336. return
  337. #def exec_go(nr,xfade=None,val=0):
  338. print(self,"MASTER",nr,arg,args)
  339. btn_nr = nr
  340. v = args["val"]
  341. msg=json.dumps([{"event":"EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}]).encode("utf-8")
  342. cprint("SEND MASTER.EXEC_GO:",msg,color="green")
  343. cmd_client.send(msg)
  344. def refresh_fix(*arg,**args): # DUMMY
  345. print("refresh_fix",arg,args)
  346. class Refresher_fix(): # DUMMY
  347. def __init__(self,*arg,**args):
  348. print(self,"init",arg,args)
  349. def reset(self,*arg,**args):
  350. print(self,"reset",arg,args)
  351. refresher_fix = Refresher_fix()
  352. class Modes(): # DUMMY
  353. def __init__(self,*arg,**args):
  354. print("Modes.__init__",arg,args)
  355. self.modes = {}
  356. def val(self,*arg,**args):
  357. #print("Modes.val",arg,args)
  358. pass
  359. master = MASTER() #{}
  360. modes = Modes()
  361. import tkinter as tk
  362. class Exec(): # DUMMY
  363. def __init__(self):
  364. self.val_exec = {}
  365. for i in range(512):
  366. k=i #"ABC-{}".format(i+1)
  367. self.val_exec[k] = {"NAME":"XX"}
  368. EXEC = Exec()
  369. class Gui(): # DUMMY
  370. def __init__(self):
  371. self.elem_exec = []
  372. self.elem_meta = [None]*512
  373. self.old_btn_nr = -1
  374. self.METAS = []
  375. for i in range(512):
  376. self.METAS.append({})
  377. def _load_meta(self,nr):
  378. data = {}
  379. try:
  380. data = mc.get("EXEC-META-"+str(nr))
  381. data = json.loads(data)
  382. except Exception as e:
  383. print(" ER1R mc...",e)
  384. return data
  385. def _refresh_exec(self,*arg,**args):
  386. #print("EXEC_Gui._refresh_exec",arg,args)
  387. start = time.time()
  388. METAS = []
  389. for i in range(512):
  390. nr = i #+1
  391. METAS.append( self._load_meta(nr) )
  392. self.METAS = METAS
  393. for nr,b in enumerate( self.elem_exec): #[nr]
  394. self._refresh_exec_single(nr,b,METAS)
  395. #time.sleep(0.001)
  396. print( "refres_exec:",time.time()-start )
  397. def _refresh_exec_single(self,nr,b,METAS=None):
  398. start = time.time()
  399. no_meta = 0
  400. if not METAS:
  401. no_meta = 1
  402. try:
  403. data = mc.get("EXEC-META-"+str(nr)) #,json.dumps(index))
  404. data = json.loads(data)
  405. self.METAS[nr] = data #.append(data)
  406. #print(time.time())
  407. print(" _REFRESH_EXEC_SINGLE",nr,b,data["LABEL"])
  408. except Exception as e:
  409. print(" ER1R mc...",e)
  410. METAS = self.METAS
  411. _bg = "grey"
  412. _ba = "grey"
  413. _bg = "grey"
  414. _fg = "#555" #darkgrey"
  415. _text = "0 N/V 0\n N/V"
  416. txt = "None/nNone"
  417. txt1 = "None/nNone"
  418. out = {} # default
  419. out["fx"] = ""
  420. out["bg"] = _bg # "grey"
  421. out["ba"] = _ba #"grey"
  422. out["fg"] = _fg
  423. out["text"] = _text #"? "+str(nr+1)
  424. META = {'LABEL': 'ERR', 'CFG': {}}
  425. META["CFG"] = {'FADE': 3.0, 'DEALY': 0, 'DELAY': 4.0, 'BUTTON': 'ON', 'HTP-MASTER': 100
  426. ,'SIZE-MASTER': 100, 'SPEED-MASTER': 100, 'OFFSET-MASTER': 100, 'OUT-FADE': 10.0
  427. ,'FIX-COUNT':0 ,'HAVE-FX':0,'HAVE-VAL':0
  428. }
  429. try:
  430. META = METAS[nr]
  431. label = "{} {} {}\n{}".format(nr+1,META["CFG"]["BUTTON"],META["CFG"]["FIX-COUNT"],META["LABEL"])
  432. out["text"] = str(label)
  433. if no_meta:
  434. print(" no_meta:",[label])
  435. except Exception as e:
  436. print(" ER4R",e,nr)
  437. time.sleep(0.001)
  438. try:
  439. txt1 = META["CFG"]["BUTTON"]
  440. except:
  441. pass
  442. if META["CFG"]["FIX-COUNT"]:
  443. _fg = "black"
  444. if META["CFG"]["HAVE-VAL"]:
  445. _fg = "black"
  446. _bg = "yellow"
  447. _ba = "#ffaa55"
  448. if "SEL" in txt1:
  449. #_bg = "blue"
  450. #_fg = "blue"
  451. _bg = "gold"
  452. _bg = "#77f"
  453. elif "ON" in txt1:
  454. _bg = "gold"
  455. _fg = "#040"
  456. _fg = "black"
  457. elif "GO" in txt1:
  458. _bg = "gold"
  459. _fg = "#555"
  460. _fg = "black"
  461. elif "FL" in txt1:
  462. _bg = "gold"
  463. out["fx"] = ""
  464. if META["CFG"]["HAVE-FX"] >= 1:
  465. out["fx"] = META["CFG"]["HAVE-FX"] # show FX on EXEC-BTN
  466. if META["CFG"]["HAVE-FX"] >= 1 and META["CFG"]["HAVE-VAL"] == 0:
  467. _bg = "cyan"
  468. if "FL" in txt1:
  469. _fg = "#00e"
  470. out["fg"] = _fg #= "#00e"
  471. out["bg"] = _bg #= "#00e"
  472. cfg = out
  473. self.elem_meta[nr] = META
  474. #print(" -",nr, round(time.time()-start,4))
  475. b = self.elem_exec[nr]
  476. b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"],fx=cfg["fx"])
  477. #print(" -",nr, round(time.time()-start,4))
  478. def exec_go(self,*arg,**args):
  479. print("Gui.exec_go",arg,args)
  480. btn_nr = arg[0]
  481. v=args["val"]
  482. if "CFG-BTN" in modes.modes:
  483. button = self.elem_exec[btn_nr]
  484. label = str(btn_nr) #self.elem_meta[nr] = META
  485. if v:
  486. META = self.elem_meta[btn_nr]
  487. dialog_cfg_open(btn_nr,META)
  488. return #STOP
  489. if "LABEL" in modes.modes:
  490. button = self.elem_exec[btn_nr]
  491. label = str(btn_nr) #self.elem_meta[nr] = META
  492. if v:
  493. META = self.elem_meta[btn_nr]
  494. dialog_label_open(btn_nr,META)
  495. return #STOP
  496. #REFRESH = 0
  497. #for k in ["REC","COPY","MOVE","DEL","REC-FX","LABEL"]:
  498. # if k in modes.modes:
  499. # REFRESH = 1
  500. print(" ",[arg,args])
  501. edata={}
  502. if "event" in args:
  503. edata = libtk2.serialize_event(args["event"])
  504. print(" ",edata)
  505. num = -1
  506. MOUSE = ""
  507. out={"event": "EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}
  508. if "num" in edata:
  509. num = edata["num"]
  510. if num == 1:
  511. out["MOUSE"]="LEFT"
  512. if num == 3:
  513. out["MOUSE"]="RIGHT"
  514. msg=json.dumps([out]).encode("utf-8")
  515. if not _global_key_lock:
  516. cmd_client.send(msg)
  517. cprint("SEND GUI.EXEC_GO",msg,color="green")
  518. if v == 0: # release btn
  519. thread.start_new_thread(refresh_exec_btn,(btn_nr,))
  520. gui = Gui()
  521. import lib.libwin as libwin
  522. if 0:
  523. name="FX3"
  524. args = {"title":name,"master":0,"width":364,"height":418+30,"left":L1+10+W1,"top":TOP+302,"resize":1}
  525. geo = libwin.filter_window_geo(geo_list,name)
  526. if geo:
  527. args.update(geo)
  528. cls = draw_fx_3 #(master,w.tk)
  529. data = []
  530. cb_ok = None
  531. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=master,scroll=0)
  532. window_manager.new(None,name,wcb=c)
  533. if libwin.split_window_show(geo_list,_filter=name):
  534. window_manager.top(name)
  535. name="EXEC"
  536. pos_list = libwin.read_window_geo()
  537. geo = libwin.filter_window_geo(pos_list,name)
  538. args = {"title":name,"master":0,"width":600,"height":113,"left":30+5,"top":30+5+400*2+10}
  539. if geo:
  540. args.update(geo)
  541. root = tk.Tk()
  542. root.maxsize(830,2000)
  543. win_title="EXEC-BTN"
  544. store = movewin.load_all_sdl(win_title)
  545. print(store)
  546. W=850
  547. H=460
  548. POS=[10,10]
  549. if store:
  550. W = store[-4]
  551. H = store[-3]
  552. POS=[store[-2],store[-1]]
  553. root.geometry('%dx%d+%d+%d' % (W, H, POS[0],POS[1]))
  554. root.tk_setPalette(background='#bbb', foreground='black', activeBackground='#aaa', activeForeground="black")
  555. defaultFont = tk.font.nametofont("TkDefaultFont")
  556. defaultFont.configure(family="FreeSans",
  557. size=10,
  558. weight="bold")
  559. # MAIN MENUE
  560. try:
  561. ico_path = "/opt/LibreLight/Xdesk/icon/"
  562. root.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  563. except Exception as e:
  564. print(" Exception GUIWindowContainer.__init__",e)
  565. xframe = libtk.ScrollFrame(root,width=820,height=400,bd=1,bg="black",head=None,foot=None)
  566. draw_exec(gui,xframe,EXEC)
  567. draw_fx_3(gui,xframe,EXEC)
  568. root.title(title) #"TK-EXEC")
  569. root.bind("<Button>",libtk2.tk_event)#
  570. root.bind("<Key>",libtk2.tk_event)#,self.callback)
  571. root.bind("<KeyRelease>",libtk2.tk_event)#,self.callback)
  572. #root.bind("<FocusIn>",libtk2.tk_event)#, on_focus(self.args["title"],"In").cb)
  573. #root.bind("<FocusOut>",libtk2.tk_event)#, on_focus(self.args["title"],"Out").cb)
  574. import os
  575. _global_key_lock = 0
  576. def focus_in(event=None):
  577. _global_short_key = 0 # protect key-press-repeat
  578. cmd = "xset -display :0.0 r off"
  579. print("FOCUS_IN1", cmd)
  580. os.system(cmd)
  581. time.sleep(0.3)
  582. print("FOCUS_IN2", cmd)
  583. os.system(cmd)
  584. _global_short_key = 1 # protect key-press-repeat
  585. time.sleep(0.3)
  586. _global_key_lock = 0
  587. def focus_out(event=None):
  588. _global_key_lock = 1
  589. _global_short_key = 0
  590. cmd="xset -display :0.0 r rate 240 20"
  591. print("FOCUS_OUT", cmd)
  592. #os.system(cmd) # DISABLED
  593. root.bind("<FocusIn>", focus_in)
  594. root.bind("<FocusOut>", focus_out)
  595. def _refr_loop():
  596. time.sleep(3)
  597. while 1:
  598. gui._refresh_exec()
  599. time.sleep(3)
  600. thread.start_new_thread(_refr_loop,())
  601. def _refr_loop2():
  602. time.sleep(3)
  603. while 1:
  604. try:
  605. global root,title
  606. data = mc.get("MODES")
  607. title2 = title +" "+str(data)
  608. data = json.loads(data)
  609. #print("MODES",data)
  610. modes.modes = data
  611. if root:
  612. root.title(title2)
  613. if "S-KEY" in data:
  614. _global_short_key = 0
  615. if data["S-KEY"]:
  616. _global_short_key = 1
  617. for k in data:
  618. #print("title",k)
  619. for kk in ["RESTART","PRO","EASY","EXIT"]:
  620. if kk in str(k):
  621. print("RESTART !!! EXIT !!")
  622. time.sleep(0.1)
  623. root.quit()
  624. #sys.exit()
  625. except Exception as e:
  626. print(" ER7R mc...",e)
  627. time.sleep(3)
  628. time.sleep(0.1)
  629. thread.start_new_thread(_refr_loop2,())
  630. root.mainloop()