FX3.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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:
  159. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  160. c+=1
  161. if c >=6:
  162. c=0
  163. r+=1
  164. c=0
  165. r+=1
  166. return c,r
  167. def _draw_fx(frame,c,r,gui,mode="FX"):
  168. if mode=="FX-MAIN":
  169. ct = MAIN.meta.fx_main
  170. prm = MAIN.meta.fx_prm_main
  171. elif mode=="FX-MOVE":
  172. ct = MAIN.meta.fx_moves
  173. prm = MAIN.meta.fx_prm_move
  174. elif mode=="FX":
  175. ct = MAIN.meta.fx_cfg
  176. prm = MAIN.meta.fx_prm
  177. elif mode=="FX-GENERIC":
  178. ct = MAIN.meta.fx_generic
  179. prm = MAIN.meta.fx_prm #_generic
  180. elif mode=="FX-COLOR":
  181. ct = MAIN.meta.fx_color
  182. prm = MAIN.meta.fx_color #_generic
  183. else:
  184. ct = Elem_Container()
  185. ct.labels =["err"]
  186. prm = ["err"]
  187. for comm in ct.labels:
  188. if comm == "\n\n":
  189. b = tk.Label(frame,bg="black", text="-",font=space_font)
  190. b.grid(row=r, column=c,pady=0,padx=0, sticky=tk.W+tk.E)
  191. c=0
  192. r+=1
  193. continue
  194. if comm == "\n":
  195. c=0
  196. r+=1
  197. continue
  198. v=0
  199. if "PAN/TILT" in comm:
  200. b = tk.Button(frame,bg="grey", text=str(comm),width=6,height=2)
  201. else:
  202. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  203. if 1:#comm not in ct.elem:
  204. #comm = comm.replace("\n","")
  205. ct.elem[comm] = b
  206. ct.val[comm] = 0
  207. b.bind("<Button>",tkevent.tk_event_fx(fix=0,elem=b,attr=comm,data=gui,mode=mode).cb)
  208. if comm == "REC-FX":
  209. b["bg"] = "grey"
  210. elif comm == "FX OFF":
  211. b["bg"] = "magenta"
  212. elif comm[:3] == "FX:" or comm[:3] == "2D:":
  213. b["text"] = comm
  214. b["bg"] = "#ffbf00"
  215. elif comm[:3] == "MO:":
  216. b["text"] = comm
  217. b["bg"] = "lightgreen"
  218. elif comm.startswith( "SIZE:"):
  219. b["text"] = "SIZE:\n{:0.0f}".format(prm["SIZE"])
  220. b["bg"] = "lightgreen"
  221. elif comm.startswith( "SPEED:"):
  222. b["text"] = "SPEED:\n{:0.0f}".format(prm["SPEED"])
  223. b["bg"] = "lightgreen"
  224. elif comm.startswith("START:"):
  225. b["bg"] = "lightgreen"
  226. b["text"] = "START:\n{:0.0f}".format(prm["START"])
  227. elif comm.startswith( "OFFSET:"):
  228. b["bg"] = "lightgreen"
  229. b["text"] = "OFFSET:\n{:0.0f}".format(prm["OFFSET"])
  230. elif comm[:3] == "BASE:":
  231. b["bg"] = "lightgreen"
  232. b["text"] = "BASE:\n{}".format(prm["BASE"])
  233. elif comm[0] == "M":
  234. b["text"] = comm
  235. b["bg"] = "lightgrey"
  236. if comm:
  237. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  238. c+=1
  239. if c >=6:
  240. c=0
  241. r+=1
  242. c=0
  243. r+=1
  244. return c,r
  245. def draw_fx3(gui,xframe,data=[]):
  246. frame_fx=xframe
  247. i=0
  248. c=0
  249. r=0
  250. frame = tk.Frame(frame_fx,bg="black")
  251. frame.pack(fill=tk.X, side=tk.TOP)
  252. # ------------------------------
  253. b = tk.Button(frame,bg="lightblue", text="FX3",width=6)
  254. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  255. c+=1
  256. thread.start_new_thread(mytklib.tk_btn_bg_loop,(b,))
  257. # ------------------------------
  258. _add_space(frame,r,c)
  259. c,r = _draw_fx(frame,c,r,gui,mode="FX-MAIN")
  260. #r,c=_add_space(frame,r,c)
  261. #c,r = _draw_fx(frame,c,r,gui,mode="FX-COLOR")
  262. r,c=_add_space(frame,r,c)
  263. c,r = _draw_fx3(frame,c,r,gui,mode="FX-3")
  264. import tool.movewin as movewin
  265. #movewin.check_is_started(CAPTION,_file_path)
  266. movewin.check_is_started("FX3","/opt/LibreLight/Xdesk/tkgui/FX3.py")
  267. _global_short_key = 1
  268. root = None
  269. cmd_client = chat.Client(port=30003)
  270. try:
  271. import memcache
  272. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  273. #data = mc.get("MODES")
  274. except:
  275. mc = None
  276. class Refresher(): # DUMMY
  277. def __init__(self,*arg,**args):
  278. print(self,"__init__",arg,args)
  279. def reset(*arg,**args):
  280. print(self,"reset",arg,args)
  281. class Command():
  282. def __init__(self):
  283. self.elem = {}
  284. class MANAGER(): # DUMMY
  285. def __init__(self,*arg,**args):
  286. print(self,"__init__",arg,args)
  287. #self.refresh_fix = Refresher()
  288. #self.commands = Command()
  289. def refresh_fix(self,*arg,**args):# = Refresher()
  290. print(self,"refresh_fix",arg,args)
  291. def exec_go(self,nr,*arg,**args): #val=None,xfade=None,event=None,button="",ptfade=None):
  292. if _global_key_lock:
  293. return
  294. #def exec_go(nr,xfade=None,val=0):
  295. print(self,"MASTER",nr,arg,args)
  296. btn_nr = nr
  297. v = args["val"]
  298. msg=json.dumps([{"event":"EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}]).encode("utf-8")
  299. cprint("SEND MASTER.EXEC_GO:",msg,color="green")
  300. cmd_client.send(msg)
  301. def refresh_fix(*arg,**args): # DUMMY
  302. print("refresh_fix",arg,args)
  303. class Refresher_fix(): # DUMMY
  304. def __init__(self,*arg,**args):
  305. print(self,"init",arg,args)
  306. def reset(self,*arg,**args):
  307. print(self,"reset",arg,args)
  308. refresher_fix = Refresher_fix()
  309. class Modes(): # DUMMY
  310. def __init__(self,*arg,**args):
  311. print("Modes.__init__",arg,args)
  312. self.modes = {}
  313. def val(self,*arg,**args):
  314. #print("Modes.val",arg,args)
  315. pass
  316. manager = MANAGER() # MASTER() #{}
  317. modes = Modes()
  318. import tkinter as tk
  319. class Exec(): # DUMMY
  320. def __init__(self):
  321. self.val_exec = {}
  322. for i in range(512):
  323. k=i #"ABC-{}".format(i+1)
  324. self.val_exec[k] = {"NAME":"XX"}
  325. EXEC = Exec()
  326. class Gui(): # DUMMY
  327. def __init__(self):
  328. self.elem_exec = []
  329. self.elem_meta = [None]*512
  330. self.old_btn_nr = -1
  331. self.METAS = []
  332. for i in range(512):
  333. self.METAS.append({})
  334. def _load_meta(self,nr):
  335. data = {}
  336. try:
  337. data = mc.get("EXEC-META-"+str(nr))
  338. data = json.loads(data)
  339. except Exception as e:
  340. print(" ER1R mc...",e)
  341. return data
  342. def _refresh_exec(self,*arg,**args):
  343. #print("EXEC_Gui._refresh_exec",arg,args)
  344. start = time.time()
  345. METAS = []
  346. for i in range(512):
  347. nr = i #+1
  348. METAS.append( self._load_meta(nr) )
  349. self.METAS = METAS
  350. for nr,b in enumerate( self.elem_exec): #[nr]
  351. self._refresh_exec_single(nr,b,METAS)
  352. #time.sleep(0.001)
  353. print( "refres_exec:",time.time()-start )
  354. def _refresh_exec_single(self,nr,b,METAS=None):
  355. start = time.time()
  356. no_meta = 0
  357. if not METAS:
  358. no_meta = 1
  359. try:
  360. data = mc.get("EXEC-META-"+str(nr)) #,json.dumps(index))
  361. data = json.loads(data)
  362. self.METAS[nr] = data #.append(data)
  363. #print(time.time())
  364. print(" _REFRESH_EXEC_SINGLE",nr,b,data["LABEL"])
  365. except Exception as e:
  366. print(" ER1R mc...",e)
  367. METAS = self.METAS
  368. _bg = "grey"
  369. _ba = "grey"
  370. _bg = "grey"
  371. _fg = "#555" #darkgrey"
  372. _text = "0 N/V 0\n N/V"
  373. txt = "None/nNone"
  374. txt1 = "None/nNone"
  375. out = {} # default
  376. out["fx"] = ""
  377. out["bg"] = _bg # "grey"
  378. out["ba"] = _ba #"grey"
  379. out["fg"] = _fg
  380. out["text"] = _text #"? "+str(nr+1)
  381. META = {'LABEL': 'ERR', 'CFG': {}}
  382. META["CFG"] = {'FADE': 3.0, 'DEALY': 0, 'DELAY': 4.0, 'BUTTON': 'ON', 'HTP-MASTER': 100
  383. ,'SIZE-MASTER': 100, 'SPEED-MASTER': 100, 'OFFSET-MASTER': 100, 'OUT-FADE': 10.0
  384. ,'FIX-COUNT':0 ,'HAVE-FX':0,'HAVE-VAL':0
  385. }
  386. try:
  387. META = METAS[nr]
  388. label = "{} {} {}\n{}".format(nr+1,META["CFG"]["BUTTON"],META["CFG"]["FIX-COUNT"],META["LABEL"])
  389. out["text"] = str(label)
  390. if no_meta:
  391. print(" no_meta:",[label])
  392. except Exception as e:
  393. print(" ER4R",e,nr)
  394. time.sleep(0.001)
  395. try:
  396. txt1 = META["CFG"]["BUTTON"]
  397. except:
  398. pass
  399. if META["CFG"]["FIX-COUNT"]:
  400. _fg = "black"
  401. if META["CFG"]["HAVE-VAL"]:
  402. _fg = "black"
  403. _bg = "yellow"
  404. _ba = "#ffaa55"
  405. if "SEL" in txt1:
  406. #_bg = "blue"
  407. #_fg = "blue"
  408. _bg = "gold"
  409. _bg = "#77f"
  410. elif "ON" in txt1:
  411. _bg = "gold"
  412. _fg = "#040"
  413. _fg = "black"
  414. elif "GO" in txt1:
  415. _bg = "gold"
  416. _fg = "#555"
  417. _fg = "black"
  418. elif "FL" in txt1:
  419. _bg = "gold"
  420. out["fx"] = ""
  421. if META["CFG"]["HAVE-FX"] >= 1:
  422. out["fx"] = META["CFG"]["HAVE-FX"] # show FX on EXEC-BTN
  423. if META["CFG"]["HAVE-FX"] >= 1 and META["CFG"]["HAVE-VAL"] == 0:
  424. _bg = "cyan"
  425. if "FL" in txt1:
  426. _fg = "#00e"
  427. out["fg"] = _fg #= "#00e"
  428. out["bg"] = _bg #= "#00e"
  429. cfg = out
  430. self.elem_meta[nr] = META
  431. #print(" -",nr, round(time.time()-start,4))
  432. b = self.elem_exec[nr]
  433. b.configure(fg=cfg["fg"],bg=cfg["bg"],activebackground=cfg["ba"],text=cfg["text"],fx=cfg["fx"])
  434. #print(" -",nr, round(time.time()-start,4))
  435. def exec_go(self,*arg,**args):
  436. print("Gui.exec_go",arg,args)
  437. btn_nr = arg[0]
  438. v=args["val"]
  439. if "CFG-BTN" in modes.modes:
  440. button = self.elem_exec[btn_nr]
  441. label = str(btn_nr) #self.elem_meta[nr] = META
  442. if v:
  443. META = self.elem_meta[btn_nr]
  444. dialog_cfg_open(btn_nr,META)
  445. return #STOP
  446. if "LABEL" 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_label_open(btn_nr,META)
  452. return #STOP
  453. #REFRESH = 0
  454. #for k in ["REC","COPY","MOVE","DEL","REC-FX","LABEL"]:
  455. # if k in modes.modes:
  456. # REFRESH = 1
  457. print(" ",[arg,args])
  458. edata={}
  459. if "event" in args:
  460. edata = libtk2.serialize_event(args["event"])
  461. print(" ",edata)
  462. num = -1
  463. MOUSE = ""
  464. out={"event": "EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}
  465. if "num" in edata:
  466. num = edata["num"]
  467. if num == 1:
  468. out["MOUSE"]="LEFT"
  469. if num == 3:
  470. out["MOUSE"]="RIGHT"
  471. msg=json.dumps([out]).encode("utf-8")
  472. if not _global_key_lock:
  473. cmd_client.send(msg)
  474. cprint("SEND GUI.EXEC_GO",msg,color="green")
  475. if v == 0: # release btn
  476. thread.start_new_thread(refresh_exec_btn,(btn_nr,))
  477. gui = Gui()
  478. import lib.libwin as libwin
  479. if 0:
  480. name="FX3"
  481. args = {"title":name,"master":0,"width":364,"height":418+30,"left":L1+10+W1,"top":TOP+302,"resize":1}
  482. geo = libwin.filter_window_geo(geo_list,name)
  483. if geo:
  484. args.update(geo)
  485. cls = draw_fx3 #(manager,w.tk)
  486. data = []
  487. cb_ok = None
  488. c = libtk.window_create_buffer(args=args,cls=cls,data=data,cb_ok=cb_ok,gui=manager,scroll=0)
  489. window_manager.new(None,name,wcb=c)
  490. if libwin.split_window_show(geo_list,_filter=name):
  491. window_manager.top(name)
  492. name="EXEC"
  493. pos_list = libwin.read_window_geo()
  494. geo = libwin.filter_window_geo(pos_list,name)
  495. args = {"title":name,"master":0,"width":600,"height":113,"left":30+5,"top":30+5+400*2+10}
  496. if geo:
  497. args.update(geo)
  498. root = tk.Tk()
  499. root.maxsize(830,2000)
  500. win_title="FX3"
  501. store = movewin.load_all_sdl(win_title)
  502. print(store)
  503. W=850
  504. H=460
  505. POS=[10,10]
  506. if store:
  507. W = store[-4]
  508. H = store[-3]
  509. POS=[store[-2],store[-1]]
  510. root.geometry('%dx%d+%d+%d' % (W, H, POS[0],POS[1]))
  511. root.tk_setPalette(background='#bbb', foreground='black', activeBackground='#aaa', activeForeground="black")
  512. defaultFont = tk.font.nametofont("TkDefaultFont")
  513. defaultFont.configure(family="FreeSans",
  514. size=10,
  515. weight="bold")
  516. # MAIN MENUE
  517. try:
  518. ico_path = "/opt/LibreLight/Xdesk/icon/"
  519. root.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png"))
  520. except Exception as e:
  521. print(" Exception GUIWindowContainer.__init__",e)
  522. xframe = libtk.ScrollFrame(root,width=820,height=400,bd=1,bg="black",head=None,foot=None)
  523. #draw_exec(gui,xframe,EXEC)
  524. draw_fx3(gui,xframe,EXEC)
  525. root.title(title) #"TK-EXEC")
  526. root.bind("<Button>",libtk2.tk_event)#
  527. root.bind("<Key>",libtk2.tk_event)#,self.callback)
  528. root.bind("<KeyRelease>",libtk2.tk_event)#,self.callback)
  529. #root.bind("<FocusIn>",libtk2.tk_event)#, on_focus(self.args["title"],"In").cb)
  530. #root.bind("<FocusOut>",libtk2.tk_event)#, on_focus(self.args["title"],"Out").cb)
  531. import os
  532. _global_key_lock = 0
  533. def focus_in(event=None):
  534. _global_short_key = 0 # protect key-press-repeat
  535. cmd = "xset -display :0.0 r off"
  536. print("FOCUS_IN1", cmd)
  537. os.system(cmd)
  538. time.sleep(0.3)
  539. print("FOCUS_IN2", cmd)
  540. os.system(cmd)
  541. _global_short_key = 1 # protect key-press-repeat
  542. time.sleep(0.3)
  543. _global_key_lock = 0
  544. def focus_out(event=None):
  545. _global_key_lock = 1
  546. _global_short_key = 0
  547. cmd="xset -display :0.0 r rate 240 20"
  548. print("FOCUS_OUT", cmd)
  549. #os.system(cmd) # DISABLED
  550. root.bind("<FocusIn>", focus_in)
  551. root.bind("<FocusOut>", focus_out)
  552. def _refr_loop():
  553. time.sleep(3)
  554. while 1:
  555. gui._refresh_exec()
  556. time.sleep(3)
  557. thread.start_new_thread(_refr_loop,())
  558. def _refr_loop2():
  559. time.sleep(3)
  560. while 1:
  561. try:
  562. global root,title
  563. data = mc.get("MODES")
  564. title2 = title +" "+str(data)
  565. data = json.loads(data)
  566. #print("MODES",data)
  567. modes.modes = data
  568. if root:
  569. root.title(title2)
  570. if "S-KEY" in data:
  571. _global_short_key = 0
  572. if data["S-KEY"]:
  573. _global_short_key = 1
  574. for k in data:
  575. #print("title",k)
  576. for kk in ["RESTART","PRO","EASY","EXIT"]:
  577. if kk in str(k):
  578. print("RESTART !!! EXIT !!")
  579. time.sleep(0.1)
  580. root.quit()
  581. #sys.exit()
  582. except Exception as e:
  583. print(" ER7R mc...",e)
  584. time.sleep(3)
  585. time.sleep(0.1)
  586. thread.start_new_thread(_refr_loop2,())
  587. root.mainloop()