FX3.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. #!/usr/bin/python3
  2. import json
  3. import time
  4. import sys
  5. import os
  6. import tkinter as tk
  7. import traceback
  8. import _thread as thread
  9. sys.path.insert(0,"/opt/LibreLight/Xdesk/")
  10. gui=None
  11. INIT_OK = 1
  12. IS_GUI = 0
  13. import __main__ as MAIN
  14. import lib.meta as meta
  15. import tool.git as git
  16. CAPTION = "FX3"
  17. title = CAPTION
  18. title += git.get_all()
  19. from lib.cprint import cprint
  20. import lib.libtk as libtk
  21. import lib.libtk2 as libtk2
  22. import lib.zchat as chat
  23. import lib.mytklib as mytklib
  24. import lib.tkevent as tkevent
  25. #import tkgui.draw as draw
  26. import tool.movewin as movewin
  27. movewin.check_is_started("FX3","/opt/LibreLight/Xdesk/tkgui/FX3.py")
  28. def _add_space(frame,r,c):
  29. b = tk.Canvas(frame,bg="black", height=2,bd=0,width=6,highlightthickness=0) #,bd="black")
  30. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  31. r+=1
  32. c=0
  33. return r,c
  34. def _draw_fx3(frame,c,r,gui,mode="FX"):
  35. ct = MAIN.meta.fx3 #moves
  36. prm = MAIN.meta.fx3_prm
  37. for comm in ct.labels:
  38. if comm == "\n\n":
  39. b = tk.Label(frame,bg="black", text="-",font=space_font)
  40. b.grid(row=r, column=c,pady=0,padx=0, sticky=tk.W+tk.E)
  41. c=0
  42. r+=1
  43. continue
  44. if comm == "\n":
  45. c=0
  46. r+=1
  47. continue
  48. v=0
  49. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=1)
  50. ct.elem[comm] = b
  51. ct.val[comm] = 0
  52. b.bind("<Button>",tkevent.tk_event_fx(fix=0,elem=b,attr=comm,data=gui,mode=mode).cb)
  53. if comm == "xREC-FX":
  54. b["bg"] = "grey"
  55. elif comm == "xFX OFF":
  56. b["bg"] = "magenta"
  57. elif comm[:3] == "xFX:" or comm[:3] == "x2D:":
  58. b["text"] = comm
  59. b["bg"] = "#ffbf00"
  60. if comm in MAIN.meta.fx3_grid:
  61. fx_func = MAIN.meta.fx3_grid[comm]
  62. fx_func.data["wrap"] = 1
  63. #fx_func.inc()
  64. v=fx_func.val()
  65. print(fx_func,v)
  66. b["text"] = v
  67. if comm.startswith("TYPE:"):
  68. b["bg"] = "orange"
  69. b.config(activebackground="#dd0")
  70. for a in ["SPEED:","SIZE:","START:","OFFSET:"]:
  71. if comm.startswith(a):
  72. b["bg"] = "lightgreen"
  73. b.config(activebackground="#0d0")
  74. if comm:
  75. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  76. c+=1
  77. if c >=6:
  78. c=0
  79. r+=1
  80. c=0
  81. r+=1
  82. return c,r
  83. def _draw_fx(frame,c,r,gui,mode="FX"):
  84. ct = None
  85. prm = None
  86. if mode=="FX-MAIN":
  87. ct = MAIN.meta.fx_main
  88. prm = MAIN.meta.fx_prm_main
  89. for comm in ct.labels:
  90. if comm == "\n\n":
  91. b = tk.Label(frame,bg="black", text="-",font=space_font)
  92. b.grid(row=r, column=c,pady=0,padx=0, sticky=tk.W+tk.E)
  93. c=0
  94. r+=1
  95. continue
  96. if comm == "\n":
  97. c=0
  98. r+=1
  99. continue
  100. v=0
  101. b = tk.Button(frame,bg="lightgrey", text=str(comm),width=6,height=2)
  102. ct.elem[comm] = b
  103. ct.val[comm] = 0
  104. b.bind("<Button>",tkevent.tk_event_fx(fix=0,elem=b,attr=comm,data=gui,mode=mode).cb)
  105. if comm == "REC-FX":
  106. b["bg"] = "grey"
  107. elif comm == "FX OFF":
  108. b["bg"] = "magenta"
  109. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  110. c+=1
  111. if c >=6:
  112. c=0
  113. r+=1
  114. c=0
  115. r+=1
  116. return c,r
  117. def draw_fx3(gui,xframe):
  118. frame_fx=xframe
  119. i=0
  120. c=0
  121. r=0
  122. frame = tk.Frame(frame_fx,bg="black")
  123. frame.pack(fill=tk.X, side=tk.TOP)
  124. # ------------------------------
  125. b = tk.Button(frame,bg="lightblue", text="FX3",width=6)
  126. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  127. c+=1
  128. _add_space(frame,r,c)
  129. c,r = _draw_fx(frame,c,r,gui,mode="FX-MAIN")
  130. r,c=_add_space(frame,r,c)
  131. c,r = _draw_fx3(frame,c,r,gui,mode="FX-3")
  132. _global_short_key = 1
  133. root = None
  134. cmd_client = chat.Client(port=30003)
  135. try:
  136. import memcache
  137. mc = memcache.Client(['127.0.0.1:11211'], debug=0)
  138. #data = mc.get("MODES")
  139. except:
  140. mc = None
  141. class MANAGER(): # DUMMY
  142. def __init__(self,*arg,**args):
  143. print(self,"__init__",arg,args)
  144. def _go(self,nr,*arg,**args): #val=None,xfade=None,event=None,button="",ptfade=None):
  145. if _global_key_lock:
  146. return
  147. print(self,"MASTER",nr,arg,args)
  148. btn_nr = nr
  149. v = args["val"]
  150. msg=json.dumps([{"event":"EXEC","EXEC":btn_nr+1,"VAL":v,"NR-KEY":btn_nr}]).encode("utf-8")
  151. cprint("SEND MASTER._GO:",msg,color="green")
  152. cmd_client.send(msg)
  153. class Modes(): # DUMMY
  154. def __init__(self,*arg,**args):
  155. print("Modes.__init__",arg,args)
  156. self.modes = {}
  157. def val(self,*arg,**args):
  158. #print("Modes.val",arg,args)
  159. pass
  160. class Gui(): # DUMMY
  161. def __init__(self):
  162. self.elem_exec = []
  163. self.elem_meta = [None]*512
  164. self.old_btn_nr = -1
  165. self.METAS = []
  166. for i in range(512):
  167. self.METAS.append({})
  168. def _load_meta(self,nr):
  169. data = {}
  170. try:
  171. data = mc.get("EXEC-META-"+str(nr))
  172. data = json.loads(data)
  173. except Exception as e:
  174. print(" ER1R mc...",e)
  175. return data
  176. def _refresh_data(self,*arg,**args):
  177. start = time.time()
  178. METAS = []
  179. for i in range(512):
  180. nr = i #+1
  181. METAS.append( self._load_meta(nr) )
  182. self.METAS = METAS
  183. for nr,b in enumerate( self.elem_exec): #[nr]
  184. self._refresh_data_single(nr,b,METAS)
  185. print(__file__.split("/")[-1], "_refresh_data:",int((time.time()-start)*10)/10 )
  186. def _refresh_data_single(self,nr,b,METAS=None):
  187. start = time.time()
  188. no_meta = 0
  189. if not METAS:
  190. no_meta = 1
  191. try:
  192. data = mc.get("EXEC-META-"+str(nr)) #,json.dumps(index))
  193. data = json.loads(data)
  194. self.METAS[nr] = data #.append(data)
  195. #print(time.time())
  196. print(" _REFRESH_EXEC_SINGLE",nr,b,data["LABEL"])
  197. except Exception as e:
  198. print(" ER1R mc...",e)
  199. METAS = self.METAS
  200. manager = MANAGER()
  201. modes = Modes()
  202. gui = Gui()
  203. <<<<<<< HEAD
  204. =======
  205. >>>>>>> a411153 (test: commit branch:dev)
  206. root = tk.Tk()
  207. root.maxsize(600,800)
  208. win_title="FX3"
  209. store = movewin.load_all_sdl(win_title)
  210. print(store)
  211. W=380
  212. H=500
  213. POS=[800,200]
  214. if store:
  215. W = store[-4]
  216. H = store[-3]
  217. POS=[store[-2],store[-1]]
  218. root.geometry('%dx%d+%d+%d' % (W, H, POS[0],POS[1]))
  219. root.tk_setPalette(background='#bbb', foreground='black', activeBackground='#aaa', activeForeground="black")
  220. defaultFont = tk.font.nametofont("TkDefaultFont")
  221. defaultFont.configure(family="FreeSans", size=10, weight="bold")
  222. # MAIN MENUE
  223. try:
  224. ico_path = "/opt/LibreLight/Xdesk/icon/"
  225. root.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png"))
  226. except Exception as e:
  227. print(" Exception GUIWindowContainer.__init__",e)
  228. xframe = libtk.ScrollFrame(root,width=820,height=400,bd=1,bg="black",head=None,foot=None)
  229. draw_fx3(gui,xframe)
  230. root.title(title)
  231. root.bind("<Button>",libtk2.tk_event)#
  232. root.bind("<Key>",libtk2.tk_event)#,self.callback)
  233. root.bind("<KeyRelease>",libtk2.tk_event)#,self.callback)
  234. #root.bind("<FocusIn>",libtk2.tk_event)#, on_focus(self.args["title"],"In").cb)
  235. #root.bind("<FocusOut>",libtk2.tk_event)#, on_focus(self.args["title"],"Out").cb)
  236. _global_key_lock = 0
  237. def focus_in(event=None):
  238. _global_short_key = 0 # protect key-press-repeat
  239. cmd = "xset -display :0.0 r off"
  240. print("FOCUS_IN1", cmd)
  241. os.system(cmd)
  242. time.sleep(0.3)
  243. print("FOCUS_IN2", cmd)
  244. os.system(cmd)
  245. _global_short_key = 1 # protect key-press-repeat
  246. time.sleep(0.3)
  247. _global_key_lock = 0
  248. def focus_out(event=None):
  249. _global_key_lock = 1
  250. _global_short_key = 0
  251. cmd="xset -display :0.0 r rate 240 20"
  252. print("FOCUS_OUT", cmd)
  253. #os.system(cmd) # DISABLED
  254. root.bind("<FocusIn>", focus_in)
  255. root.bind("<FocusOut>", focus_out)
  256. def _refr_loop():
  257. time.sleep(3)
  258. while 1:
  259. try:
  260. gui._refresh_data()
  261. time.sleep(3)
  262. except Exception as e:
  263. print(" ER5R refr_loop()...",e)
  264. time.sleep(3)
  265. time.sleep(0.1)
  266. def _refr_loop2():
  267. time.sleep(3)
  268. while 1:
  269. try:
  270. global root,title
  271. data = mc.get("MODES")
  272. title2 = title +" "+str(data)
  273. data = json.loads(data)
  274. #print("MODES",data)
  275. modes.modes = data
  276. if root:
  277. root.title(title2)
  278. if "S-KEY" in data:
  279. _global_short_key = 0
  280. if data["S-KEY"]:
  281. _global_short_key = 1
  282. for k in data:
  283. #print("title",k)
  284. for kk in ["RESTART","PRO","EASY","EXIT"]:
  285. if kk in str(k):
  286. print("RESTART !!! EXIT !!")
  287. time.sleep(0.1)
  288. root.quit()
  289. #sys.exit()
  290. except Exception as e:
  291. print(" ER7R mc...",e)
  292. time.sleep(3)
  293. time.sleep(0.1)
  294. thread.start_new_thread(_refr_loop,())
  295. thread.start_new_thread(_refr_loop2,())
  296. root.mainloop()