MENUE.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. frame = self.frame
  52. #row = data[i]
  53. if row["text"] == "---":
  54. h=1
  55. if "name" in row:
  56. text = row["name"]
  57. else:
  58. text = row["text"]
  59. if "- DEMO -" == text:
  60. c=2
  61. r=1
  62. b = tk.Button(frame,bg="lightgrey", text=text,width=8,height=h)
  63. self.b = b
  64. if "tip" in row:
  65. from idlelib.tooltip import Hovertip
  66. myTip = Hovertip(self.b,row["tip"])
  67. self.b.bind("<Button>",BEvent({"NR":i,"text":row["text"]},self.on_top).cb)
  68. BUF[c][r] = b
  69. #self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  70. row["elem"] = self.b
  71. self.elem[row["text"]] = row
  72. r+=1
  73. i+=1
  74. r=1
  75. c=0
  76. for rows in BUF:
  77. h=2
  78. for b in rows:
  79. #print("b",type(b))
  80. text=""
  81. if r > 6:
  82. h=1
  83. if type(b) is str:
  84. b = tk.Button(self.frame,bg="lightgrey", text=text,width=8,height=h)
  85. b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  86. else:
  87. b["height"] = h
  88. b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  89. r+=1
  90. c+=1
  91. r=1
  92. self.BUF = BUF
  93. self.frame.pack()
  94. INIT_OK = 1
  95. self.start_loop()
  96. def start_loop(self):
  97. print(self,"--- start_bg_loop ----- xxxx")
  98. thread.start_new_thread(mytklib.tk_btn_bg_loop,(self.TITLE,))
  99. def on_top(self,event,data={}):
  100. print("menue.on_top",data)
  101. MAIN.window_manager.top(data["text"])
  102. def update(self,button,text):
  103. #print(self,button,text)
  104. for k in self.elem:
  105. v=self.elem[k]
  106. #print(self,k,v)
  107. if button == k:
  108. v["elem"]["text"] = k+"\n"+text
  109. def config(self,button,attr,value):
  110. #print("config",self,button,attr,value)
  111. for k in self.elem:
  112. v=self.elem[k]
  113. #print(self,k,v)
  114. if button == k:
  115. #print(dir(v["elem"]))
  116. if attr == "bg":
  117. if value == "":
  118. value = "lightgrey"
  119. v["elem"][attr] = str(value)
  120. if attr == "activebackground":
  121. if value == "":
  122. value = "lightgrey"
  123. v["elem"][attr] = str(value)