123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #!/usr/bin/python3
- import _thread as thread
- import time
- import copy
- from collections import OrderedDict
- import tkinter
- tk = tkinter
- from idlelib.tooltip import Hovertip
- #import tkgui.dialog as dialoglib
- #dialog = dialoglib.Dialog()
- import __main__ as MAIN
- from lib.cprint import *
- import lib.mytklib as mytklib
- #import lib.fixlib as fixlib
- #import lib.showlib as showlib
- #import lib.libtk as libtk
- #import lib.tkevent as tkevent
- class BEvent():
- def __init__(self,data,cb):
- self._data = data
- self._cb = cb
- def cb(self,event):
- #print(self,event)
- self._cb(event,self._data)
- class GUI_menu():
- def __init__(self,root,frame ,data,title="tilte"):
- global tk
- global INIT_OK
- self.frame = frame
-
- self.data = data
- self.elem = {}
- self.root = root
- self.draw()
- def draw(self):
- cprint("***",self,"draw")
- r=0
- c=0
- i=1
- self.b = tk.Label(self.frame,bg="lightblue", text="MAIN:MENU",width=8,height=1)
- self.TITLE = self.b
- self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
- BUF = []
- for j in range(3):
- BUF.append([""]*40)
- print(BUF)
- r=0
- h = 2
- for row in self.data:
- print(" draw",row)
- text="<TXT>"
- frame = self.frame
- #row = data[i]
- if row["text"] == "---":
- h=1
- if "name" in row:
- text = row["name"]
- else:
- text = row["text"]
- if "- DEMO -" == text:
- c=2
- r=1
- b = tk.Button(frame,bg="lightgrey", text=text,width=8,height=h)
- self.b = b
- if "tip" in row:
- from idlelib.tooltip import Hovertip
- myTip = Hovertip(self.b,row["tip"])
- self.b.bind("<Button>",BEvent({"NR":i,"text":row["text"]},self.on_top).cb)
- BUF[c][r] = b
- #self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
- row["elem"] = self.b
- self.elem[row["text"]] = row
- r+=1
- i+=1
-
- r=1
- c=0
- for rows in BUF:
- h=2
- for b in rows:
- #print("b",type(b))
- text=""
- if r > 6:
- h=1
- if type(b) is str:
- b = tk.Button(self.frame,bg="lightgrey", text=text,width=8,height=h)
- b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
- else:
- b["height"] = h
- b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
- r+=1
- c+=1
- r=1
-
- self.BUF = BUF
- self.frame.pack()
- INIT_OK = 1
- self.start_loop()
- def start_loop(self):
- print(self,"--- start_bg_loop ----- xxxx")
- thread.start_new_thread(mytklib.tk_btn_bg_loop,(self.TITLE,))
- def on_top(self,event,data={}):
- print("menue.on_top",data)
- MAIN.window_manager.top(data["text"])
- def update(self,button,text):
- #print(self,button,text)
- for k in self.elem:
- v=self.elem[k]
- #print(self,k,v)
- if button == k:
- v["elem"]["text"] = k+"\n"+text
- def config(self,button,attr,value):
- #print("config",self,button,attr,value)
- for k in self.elem:
- v=self.elem[k]
- #print(self,k,v)
- if button == k:
- #print(dir(v["elem"]))
- if attr == "bg":
- if value == "":
- value = "lightgrey"
- v["elem"][attr] = str(value)
- if attr == "activebackground":
- if value == "":
- value = "lightgrey"
- v["elem"][attr] = str(value)
|