FX3.py 20 KB

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