#!/usr/bin/python3 import os import time import sys sys.path.insert(0,"/opt/LibreLight/Xdesk/") import tkinter tk = tkinter import __main__ as MAIN from lib.cprint import cprint import lib.libwin as libwin import lib.baselib as baselib import json _config = [] try: h = os.environ["HOME"] lines = [{}] try: f = open(h +"/LibreLight/config.json") lines = f.readlines() except FileNotFoundError as e: #Exception as e: f = open(h +"/LibreLight/config.json","w") f.write('{"POS_TOP":0}\n{"POS_LEFT":0}') f.close() cprint("Exception:",e) cprint("config read") for line in lines: line=line.strip() print(" config:",line) row = json.loads(line) _config.append(row) except Exception as e: cprint("Exception:",e) _POS_LEFT = 0 _POS_TOP = 15 try: for row in _config: #print(" config:",row) if "POS_LEFT" in row: _POS_LEFT = int(row["POS_LEFT"]) if "POS_TOP" in row: _POS_TOP = int(row["POS_TOP"]) except Exception as e: cprint("Exception:",e) def frame_of_show_list(frame,cb=None): c=0 r=0 base = baselib.Base() for i in ["name","stamp"]: #,"create"]: b = tk.Label(frame,bg="grey",text=i) b.grid(row=r, column=c, sticky=tk.W+tk.E) c+=1 r+=1 blist = baselib.list_shows() for i in range(10): blist.append(["",""]) if cb is None: cb = DummyCallback #("load_show_list.cb") for i in blist: #print(i) c=0 for j in i: bg="lightgrey" dbg="lightgrey" if i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*4)): dbg = "lightgreen" elif i[1] > time.strftime("%Y-%m-%d %X", time.localtime(time.time()-3600*24*7)): dbg = "green" if c > 0: b = tk.Button(frame,text=j,anchor="w",bg=dbg,relief="sunken") b.config(activebackground=dbg) b.grid(row=r, column=c, sticky=tk.W+tk.E) else: if base.show_name == i[0]: bg="green" _cb = cb(j) b = tk.Button(frame,text=j,anchor="w",height=1,bg=bg,command=_cb.cb) if base.show_name == i[0]: b.config(activebackground=bg) b.grid(row=r, column=c, sticky=tk.W+tk.E) c+=1 r+=1 class BLINKI(): def __init__(self,e): self.e = e def blink(self): e = self.e e.config(bg='green') duration = 150 for i in range(8): d = i * duration if i % 2 == 0: e.after(d, lambda: e.config(bg='white')) # after 1000ms e.after(d, lambda: e.config(activebackground='white')) # after 1000ms else: e.after(d, lambda: e.config(bg='orange')) # after 1000ms e.after(d, lambda: e.config(activebackground='orange')) # after 1000ms i+=1 duration = 150 e.after(d, lambda: e.config(bg='white')) # after 1000ms e.after(d, lambda: e.config(activebackground='white')) # after 1000ms class on_focus(): def __init__(self,name,mode): self.name = name self.mode = mode def cb(self,event=None): #print("on_focus",event,self.name,self.mode) try: e = MAIN.master.commands.elem["."] except:pass if self.mode == "Out": cmd="xset -display :0.0 r rate 240 20" #print(cmd) os.system(cmd) try: e["bg"] = "#aaa" e["activebackground"] = "#aaa" except:pass if self.mode == "In": cmd = "xset -display :0.0 r off" #print(cmd) os.system(cmd) try: e["bg"] = "#fff" e["activebackground"] = "#fff" except:pass class DummyCallback(): def __init__(self,name="name"): self.name = name def cb(self,event=None): cprint("DummyCallback.cb",[self.name,event]) class Window(): def __init__(self,args): #title="title",master=0,width=100,height=100,left=None,top=None,exit=0,cb=None,resize=1): global MAIN #lf_nr self.args = {"title":"title","master":0,"width":100,"height":100,"left":None,"top":None,"exit":0,"cb":None,"resize":1} self.args.update(args) cprint("Window.init()",self.args["title"],color="yellow") #cprint("Window.init()",id(self.args),color="yellow") #cprint(" ",self.args,color="yellow") ico_path="./icon/" self.cb = MAIN.cb if self.args["master"]: self.tk = tkinter.Tk() self.tk.protocol("WM_DELETE_WINDOW", self.close) self.tk.withdraw() # do not draw self.tk.resizable(self.args["resize"],self.args["resize"]) self.tk.tk_setPalette(background='#bbb', foreground='black', activeBackground='#aaa', activeForeground="black") defaultFont = tkinter.font.nametofont("TkDefaultFont") cprint(defaultFont) defaultFont.configure(family="FreeSans", size=10, weight="bold") # MAIN MENUE try: self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"main.png")) except Exception as e: cprint(" Exception GUIWindow.__init__",e) else: # addtional WINDOW self.tk = tkinter.Toplevel() self.tk.iconify() #self.tk.withdraw() # do not draw self.tk.protocol("WM_DELETE_WINDOW", self.close) self.tk.resizable(self.args["resize"],self.args["resize"]) try: if "COLORPICKER" in self.args["title"]: self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"picker.png")) elif "ENCODER" in self.args["title"]: self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"enc.png")) elif "EXEC" in self.args["title"]: self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"exec.png")) elif "FX" in self.args["title"]: self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"fx.png")) else: self.tk.iconphoto(False, tk.PhotoImage(file=ico_path+"scribble.png")) except Exception as e: cprint(" Exception on load window icon",self.args["title"]) cprint(" Exception:",e) #time.sleep(3) self.tk.deiconify() self.tk["bg"] = "black" self.tk.bind("