MENUE.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #!/usr/bin/python3
  2. import _thread as thread
  3. import time
  4. import copy
  5. from collections import OrderedDict
  6. import tkinter
  7. tk = tkinter
  8. from idlelib.tooltip import Hovertip
  9. import tkgui.dialog as dialoglib
  10. dialog = dialoglib.Dialog()
  11. import __main__ as MAIN
  12. from lib.cprint import *
  13. import lib.mytklib as mytklib
  14. import lib.fixlib as fixlib
  15. import lib.showlib as showlib
  16. import lib.libtk as libtk
  17. import lib.tkevent as tkevent
  18. class BEvent():
  19. def __init__(self,data,cb):
  20. self._data = data
  21. self._cb = cb
  22. def cb(self,event):
  23. #print(self,event)
  24. self._cb(event,self._data)
  25. class GUI_menu():
  26. def __init__(self,root,frame ,data,title="tilte"):
  27. global tk
  28. global INIT_OK
  29. self.frame = frame
  30. self.data = data
  31. self.elem = {}
  32. self.root = root
  33. self.draw()
  34. def draw(self):
  35. cprint("***",self,"draw")
  36. r=0
  37. c=0
  38. i=1
  39. self.b = tk.Label(self.frame,bg="lightblue", text="MAIN:MENU",width=8,height=1)
  40. self.TITLE = self.b
  41. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  42. BUF = []
  43. for j in range(3):
  44. BUF.append([""]*40)
  45. print(BUF)
  46. r=0
  47. h = 2
  48. for row in self.data:
  49. print(" draw",row)
  50. text="<TXT>"
  51. #row = data[i]
  52. if row["text"] == "---":
  53. h=1
  54. if "name" in row:
  55. text = row["name"]
  56. else:
  57. text = row["text"]
  58. if "- DEMO -" == text:
  59. c=2
  60. r=1
  61. b = tk.Button(self.frame,bg="lightgrey", text=text,width=8,height=h)
  62. self.b = b
  63. if "tip" in row:
  64. from idlelib.tooltip import Hovertip
  65. myTip = Hovertip(self.b,row["tip"])
  66. self.b.bind("<Button>",BEvent({"NR":i,"text":row["text"]},self.on_top).cb)
  67. BUF[c][r] = b
  68. #self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  69. row["elem"] = self.b
  70. self.elem[row["text"]] = row
  71. r+=1
  72. i+=1
  73. r=1
  74. c=0
  75. for rows in BUF:
  76. h=2
  77. for b in rows:
  78. #print("b",type(b))
  79. text=""
  80. if r > 6:
  81. h=1
  82. if type(b) is str:
  83. b = tk.Button(self.frame,bg="lightgrey", text=text,width=8,height=h)
  84. b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  85. else:
  86. b["height"] = h
  87. b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  88. r+=1
  89. c+=1
  90. r=1
  91. self.BUF = BUF
  92. self.frame.pack()
  93. INIT_OK = 1
  94. self.start_loop()
  95. def start_loop(self):
  96. print(self,"--- start_bg_loop ----- xxxx")
  97. thread.start_new_thread(mytklib.tk_btn_bg_loop,(self.TITLE,))
  98. def on_top(self,event,data={}):
  99. print("menue.on_top",data)
  100. MAIN.window_manager.top(data["text"])
  101. def update(self,button,text):
  102. #print(self,button,text)
  103. for k in self.elem:
  104. v=self.elem[k]
  105. #print(self,k,v)
  106. if button == k:
  107. v["elem"]["text"] = k+"\n"+text
  108. def config(self,button,attr,value):
  109. #print("config",self,button,attr,value)
  110. for k in self.elem:
  111. v=self.elem[k]
  112. #print(self,k,v)
  113. if button == k:
  114. #print(dir(v["elem"]))
  115. if attr == "bg":
  116. if value == "":
  117. value = "lightgrey"
  118. v["elem"][attr] = str(value)
  119. if attr == "activebackground":
  120. if value == "":
  121. value = "lightgrey"
  122. v["elem"][attr] = str(value)