egrid.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/python3
  2. import sys
  3. import os
  4. print( os.getcwd())
  5. try:
  6. import lib.zchat as chat
  7. print(sys.path)
  8. except ModuleNotFoundError:
  9. sys.path.insert(0,os.path.dirname(__file__)+"/.." )
  10. print(sys.path)
  11. import lib.zchat as chat
  12. import tkinter as tk
  13. value = 1
  14. data = []
  15. class Event():
  16. def __init__(self,name):
  17. self.name=name
  18. print("init",self)
  19. def event(self,event):
  20. global value
  21. print(self.name,event)
  22. print("event:",[int(event.type),event.num])
  23. if int(event.type) == 4:
  24. if event.num == 4:
  25. value +=1
  26. if event.num == 5:
  27. value -=1
  28. print(value)
  29. for e in data:
  30. t = e["text"]
  31. if ":" in t:
  32. t = t.split(":")[0]
  33. e["text"] = t +": "+ str(value)
  34. class scroll():
  35. def __init__(self,canvas):
  36. self.canvas=canvas
  37. def config(self,event):
  38. canvas = self.canvas
  39. canvas.configure(scrollregion=canvas.bbox("all"))#,width=400,height=200)
  40. def ScrollFrame(root,width=50,height=100,bd=1,bg="black",scrollbar="xy"):
  41. _scrollbar = scrollbar
  42. #print("ScrollFrame init",width,height)
  43. aframe=tk.Frame(root,relief=tk.GROOVE)#,width=width,height=height,bd=bd)
  44. #aframe.place(x=0,y=0)
  45. aframe.pack(side="top",fill="both",expand=1) #x=0,y=0)
  46. canvas=tk.Canvas(aframe,width=width-24,height=10)#height)
  47. if bg == "":
  48. bg="orange"
  49. canvas["bg"] = bg # "black" #"green"
  50. bframe=tk.Frame(canvas,width=width,height=height)
  51. bframe["bg"] = "blue"
  52. scrollbar_y=tk.Scrollbar(aframe,orient="vertical",command=canvas.yview,width=20)
  53. canvas.configure(yscrollcommand=scrollbar_y.set)
  54. scrollbar_x=tk.Scrollbar(aframe,orient="horizontal",command=canvas.xview,width=20)
  55. canvas.configure(xscrollcommand=scrollbar_x.set)
  56. if "x" in _scrollbar:
  57. scrollbar_x.pack(side="bottom",fill="x")
  58. if "y" in _scrollbar:
  59. scrollbar_y.pack(side="right",fill="y")
  60. canvas.pack(side="left",expand=1,fill="both")
  61. canvas.create_window((0,0),window=bframe,anchor='nw')
  62. bframe.bind("<Configure>",scroll(canvas).config)
  63. canvas.bind("<Button>",Event("XXX").event)
  64. canvas.bind("<Key>",Event("XXX").event)
  65. canvas.bind("<KeyRelease>",Event("XXX").event)
  66. return bframe
  67. #frame = ScrollFrame(root)
  68. root = tk.Tk()
  69. # set window title
  70. root.wm_title("Fixture Editor")
  71. i=0
  72. #root.bind("<Button>",Event("M:{}".format(i)).event)
  73. #root.bind("<Key>" ,Event("M:{}".format(i)).event)
  74. #root.bind("<KeyRelease>",Event("M:{}".format(i)).event)
  75. aframe = tk.Frame(root,height=10) #,bg="#fff")
  76. aframe.pack(side="top",expand=0,fill="both")
  77. aframe.bind("<Button>",Event("H:{}".format(i)).event)
  78. aframe.bind("<Key>" ,Event("H:{}".format(i)).event)
  79. aframe.bind("<KeyRelease>",Event("H:{}".format(i)).event)
  80. i=0
  81. l = tk.Button(aframe,text="MENUE ".format(i+1))
  82. l.grid(row=i,column=0)
  83. aframe = tk.Frame(root,height=5,bg="#333")
  84. aframe.pack(side="top",expand=0,fill="x")
  85. #xframe = ScrollFrame(root,width=300,height=300)
  86. xframe = ScrollFrame(root,width=300,height=300,scrollbar="xy")
  87. i=0
  88. for x in range(40):
  89. for y in range(10):
  90. l = tk.Button(xframe,text="Eintrag {}: 0".format(i+1),width=12)
  91. l.bind("<Button>",Event(" B1:{}".format(i)).event)
  92. #l.bind("<Key>",Event("B2:{}".format(i)).event)
  93. #l.bind("<KeyRelease>",Event("B3:{}".format(i)).event)
  94. data.append(l)
  95. l.grid(row=x,column=y)
  96. i+=1
  97. aframe = tk.Frame(root,height=5,bg="#333")
  98. aframe.pack(side="top",expand=0,fill="x")
  99. bframe = tk.Frame(root ) #,bg="#fff")
  100. bframe.pack(side="top",expand=0,fill="both")
  101. bframe.bind("<Button>",Event("B:{}".format(i)).event)
  102. bframe.bind("<Key>" ,Event("B:{}".format(i)).event)
  103. bframe.bind("<KeyRelease>",Event("B:{}".format(i)).event)
  104. i=1
  105. l = tk.Button(bframe,text="STATUS BAR {}".format(i+1))
  106. l.grid(row=i,column=0)
  107. import _thread as thread
  108. import time
  109. def loop():
  110. time.sleep(3)
  111. c = chat.Client(port=51111)
  112. i=0
  113. while 1:
  114. s = "hi {}".format(i)
  115. print(s)
  116. c.send(s.encode("ascii"))
  117. i+=1
  118. time.sleep(1)
  119. #r=c.read()
  120. #print(r)
  121. thread.start_new_thread(loop,())
  122. # show window
  123. root.geometry("400x500")
  124. #root.width=400
  125. #root.config({"height":400})
  126. #root.config(width=360, height=315)
  127. #root.itemconfigure(height=400)
  128. #root["height"] = 400
  129. root.mainloop()