GUI.py 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  1. import _thread as thread
  2. import time
  3. import copy
  4. from collections import OrderedDict
  5. import tkinter
  6. tk = tkinter
  7. from idlelib.tooltip import Hovertip
  8. import tkgui.dialog as dialoglib
  9. dialog = dialoglib.Dialog()
  10. import __main__ as MAIN
  11. from lib.cprint import *
  12. import lib.mytklib as mytklib
  13. import lib.fixlib as fixlib
  14. import lib.showlib as showlib
  15. import lib.libtk as libtk
  16. import lib.tkevent as tkevent
  17. class LOAD_FIXTURE():
  18. def __init__(self,parent=None,name="<name>"):
  19. self.name=name
  20. self.master = None
  21. self.parent=parent
  22. #self.x = _LOAD_FIXTURE(parent,name)
  23. #self.cb = self.x.cb
  24. def cb(self,event=None,fixture={}):
  25. print("LOAD_FIXTURE",self.name,event)
  26. print(self,"cb")
  27. self.parent.clear()
  28. if fixture:
  29. print(len(fixture))
  30. self.parent.load(fixture)
  31. class TableFrame():
  32. def __init__(self,root, width=50,height=100,bd=1):
  33. self.root=root
  34. self.a = _TableFrame(self.root)
  35. f=self.a.HFrame()
  36. f=self.a.Sframe(f, width=width,height=height,bd=bd)
  37. self.a.draw([["A","11"],["B",4],["E",""],["R","R"],["Z","Z"],["U","U"]])
  38. self.b = _TableFrame(self.root) #äself.root)
  39. b=self.b.HFrame()
  40. b=self.b.Sframe(b, width=width,height=height,bd=bd)
  41. self.b.draw([["AA","1a1"],["BBB",114],["EE","22"],["RRR","RRR"],["TTZ","TTZ"],["ZZU","ZZU"]])
  42. self.c = _TableFrame(self.root)
  43. c=self.c.HFrame()
  44. c=self.c.Sframe(c, width=width,height=height,bd=bd)
  45. self.c.draw([["A","11"],["B",4],["E",""],["R","R"],["Z","Z"],["U","U"]][::-1])
  46. self.bframe=None
  47. def draw(self,data=[1,2],head=[],config=[]):
  48. pass
  49. class _TableFrame():
  50. def __init__(self,main):
  51. self.main = main
  52. self.frame=tk.Frame(self.main,relief=tk.GROOVE,bg="yellow")#,width=width,height=height,bd=bd)
  53. self.frame.pack(side="top",fill="x",expand=1) #x=0,y=0)
  54. self.hframe=tk.Frame(self.frame,relief=tk.GROOVE,bg="yellow")#,width=width,height=height,bd=bd)
  55. self.hframe.pack(side="top",fill="x",expand=0) #x=0,y=0)
  56. self.aframe=tk.Frame(self.main,relief=tk.GROOVE)#,width=width,height=height,bd=bd)
  57. #aframe.place(x=0,y=0)
  58. self.aframe.pack(side="top",fill="both",expand=1) #x=0,y=0)
  59. self.canvas=tk.Canvas(self.aframe,width=100-24,height=150)
  60. self.canvas["bg"] = "blue" #black" #"green"
  61. self.bframe=tk.Frame(self.canvas)#,width=width,height=height)
  62. self.bframe["bg"] = "blue"
  63. self.scrollbar=tk.Scrollbar(self.aframe,orient="vertical",command=self.canvas.yview,width=20)
  64. self.canvas.configure(yscrollcommand=self.scrollbar.set)
  65. self.scrollbar.pack(side="right",fill="y")
  66. self.canvas.pack(side="left",expand=1,fill="both")
  67. self.canvas.create_window((0,0),window=self.bframe,anchor='nw')
  68. self.bframe.bind("<Configure>",scroll(self.canvas).config)
  69. self.canvas.bind("<Button>",libtk.Event("XXX").event)
  70. self.canvas.bind("<Key>",libtk.Event("XXX").event)
  71. self.canvas.bind("<KeyRelease>",libtk.Event("XXX").event)
  72. #self.bframe=tk.Frame(self.frame,relief=tk.GROOVE,bg="magenta")#,width=width,height=height,bd=bd)
  73. #self.bframe.pack(side="top",fill="both",expand=1) #x=0,y=0)
  74. #self.HFrame()
  75. def event(self,event,**args):
  76. input_event_blocker.set( self.e , self.e_txt)
  77. input_event_blocker.event(event) #,args)
  78. def HFrame(self,main=None):
  79. self.el = tk.Label(self.hframe,text="Filter:")
  80. self.el.pack(side="left")
  81. self.e_txt = tk.StringVar()
  82. #self.e = tk.Entry(self.hframe,state="readonly",textvariable=self.e_txt)
  83. self.e = tk.Entry(self.hframe,textvariable=self.e_txt)
  84. #self.e = tk.Button(self.hframe,textvariable=self.e_txt,relief="sunken",width=20)
  85. self.e["bg"] = "#fff"
  86. self.e.config(highlightthickness=2)
  87. self.e.config(highlightcolor= "red")
  88. #self.e_txt.set(self.e_txt.get()+"<")
  89. self.e.bind("<Key>",self.event)
  90. self.e.bind("<Button>",self.event)
  91. self.e.pack(side="left")
  92. def Sframe(self,main=None, **args):
  93. pass
  94. def draw(self,data=[1,2],head=[],config=[]):
  95. yframe = self.bframe
  96. if 1:
  97. xframe = tk.Frame(yframe,bg="black")
  98. xframe.pack(side="top", expand=1,fill="both")
  99. def yview(event):
  100. print("yevent",event)
  101. yyy=20.1
  102. xframe.yview_moveto(yyy)
  103. i=0
  104. c=0
  105. r=0
  106. b = tk.Button(xframe,bg="lightblue", text="ID",width=6,anchor="e")
  107. #b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b).cb)
  108. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  109. c+=1
  110. b = tk.Button(xframe,bg="lightblue", text="NAME",width=14,anchor="w")
  111. #b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b).cb)
  112. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  113. c+=1
  114. b = tk.Button(xframe,bg="#ddd", text="TYPE",width=3)
  115. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  116. c+=1
  117. b = tk.Button(xframe,bg="#ddd", text="Uni",width=1)
  118. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  119. c+=1
  120. b = tk.Button(xframe,bg="#ddd", text="DMX",width=1)
  121. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  122. c+=1
  123. b = tk.Button(xframe,bg="#ddd", text="CH's",width=1)
  124. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  125. c+=1
  126. c=0
  127. r+=1
  128. for i,p in enumerate(data):
  129. for j in data[i]:
  130. b = tk.Button(xframe,bg="lightblue", text=""+str(j),width=6,anchor="e")
  131. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  132. c+=1
  133. c=0
  134. r+=1
  135. return self.bframe
  136. class GUIHandler():
  137. def __init__(self):
  138. pass
  139. def update(self,fix,attr,args={}):
  140. print("GUIHandler.update()",fix,attr,args)
  141. for i,k in enumerate(args):
  142. v = args[k]
  143. #print("GUI-H", i,k,v)
  144. class X_CLOCK():
  145. def __init__(self):
  146. self._last_label_id = 1
  147. self._label_ring = [ "labelA","labelB"]
  148. self.b = tk.Canvas()
  149. self.bb = tk.Canvas()
  150. self.xfont = tk.font.Font(family="FreeSans", size=65, weight="bold")
  151. self.xfont1 = tk.font.Font(family="FreeSans", size=25, weight="bold")
  152. self.write_text(text1="text1",text2="text2")
  153. def write_text(self,text1="text1",text2="text2"):
  154. tag = self._label_ring[self._last_label_id]
  155. self.bb.create_text(170,41,text=text1,fill="#aa0" ,font=self.xfont,tag=tag)
  156. self.bb.create_text(160,91,text=text2,fill="#aa0" ,font=self.xfont1,tag=tag)
  157. self.delete_tag()
  158. time.sleep(0.2)
  159. def loop_clock(self,b=None):
  160. while 1:
  161. #print("x",self.bb,dir(self.bb))
  162. #print(self,"x")
  163. s = time.strftime("%X")
  164. d = time.strftime("%Y-%m-%d")
  165. try:
  166. self.write_text(text1=s,text2=d)
  167. except:
  168. break
  169. cprint("CLOSE XCLOCK",self)
  170. def delete_tag(self):
  171. self._last_label_id += 1
  172. if self._last_label_id >=len(self._label_ring ):
  173. self._last_label_id = 0
  174. tag = self._label_ring[self._last_label_id]
  175. self.bb.delete(tag)
  176. def draw_clock(self,gui,xframe,data=[]):
  177. #print("draw_clock",self)
  178. xframe.pack(fill="both",expand=1)
  179. frame = tk.Frame(xframe,bg="black")
  180. frame.pack(fill=tk.X, side=tk.TOP)
  181. self.bb = tk.Canvas(frame,bg="black", height=105,bd=0,width=6,highlightthickness=0)
  182. self.bb.pack(fill="both",expand=1)
  183. thread.start_new_thread(self.loop_clock,())
  184. return self.bb
  185. def draw_sub_dim(gui,fix,data,c=0,r=0,frame=None):
  186. i=0
  187. if frame is None:
  188. frame = tk.Frame(root,bg="black")
  189. frame.pack(fill=tk.X, side=tk.TOP)
  190. if fix not in gui.elem_attr:
  191. gui.elem_attr[fix] = {}
  192. attr_list = []
  193. for attr in data["ATTRIBUT"]:
  194. if attr not in gui.all_attr:
  195. gui.all_attr.append(attr)
  196. if attr not in gui.elem_attr[fix]:
  197. gui.elem_attr[fix][attr] = []
  198. if attr.endswith("-FINE"):
  199. continue
  200. if attr.startswith("_"):
  201. continue
  202. attr_list.append(attr)
  203. for attr in attr_list:#data["ATTRIBUT"]:
  204. v= data["ATTRIBUT"][attr]["VALUE"]
  205. b = tk.Button(frame,bg="lightblue", text=""+str(fix),width=3,anchor="w")
  206. b.config(padx=1)
  207. b.bind("<Button>",tkevent.tk_event(fix=fix,mode="D-SELECT",elem=b).cb)
  208. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  209. c+=1
  210. b = tk.Button(frame,bg="lightblue", text=data["NAME"],width=10,anchor="w")
  211. b.config(padx=1)
  212. b.bind("<Button>",tkevent.tk_event(fix=fix,mode="D-SELECT",elem=b).cb)
  213. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  214. c+=1
  215. b = tk.Button(frame,bg="grey", text="S",width=2,anchor="c")
  216. b.config(padx=1)
  217. myTip = Hovertip(b,'SELECT')
  218. b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b,attr="_ACTIVE",mode="ENCODER",data=data).cb)
  219. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  220. gui.elem_attr[fix]["S"] = b
  221. c+=1
  222. b = tk.Button(frame,bg="grey", text=str(round(v,2)),width=10,anchor="w")
  223. b.config(padx=1)
  224. gui.elem_attr[fix][attr] = b
  225. b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b,attr=attr,mode="ENCODER",data=data).cb)
  226. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  227. c+=1
  228. if c >=12:
  229. c=0
  230. r+=1
  231. return c,r
  232. class GUI_DIM():
  233. def __init__(self,gui,xframe,data):
  234. self.gui = gui
  235. self.data = data
  236. self.xframe = xframe
  237. self.draw()
  238. def draw(self):
  239. FIXTURES = self.data
  240. gui=self.gui
  241. xframe=self.xframe
  242. r=0
  243. c=0
  244. frame_dim=xframe
  245. for widget in xframe.winfo_children():
  246. widget.destroy()
  247. root = frame_dim
  248. dim_frame = tk.Frame(root,bg="black")
  249. dim_frame.pack(fill=tk.X, side=tk.TOP)
  250. i=0
  251. c=0
  252. r=0
  253. dim_end=0
  254. for fix in FIXTURES.fixtures:
  255. i+=1
  256. data = FIXTURES.fixtures[fix]
  257. #print("DIMMER----",data)
  258. if fix not in gui.elem_attr:
  259. gui.elem_attr[fix] = {}
  260. kix = []
  261. for ix in data["ATTRIBUT"].keys():
  262. #print("DIMMER----",ix)
  263. if not ix.startswith("_") and not ix.endswith("-FINE"):
  264. kix.append(ix)
  265. if "DIM" in kix and len(kix) == 1:
  266. c,r=draw_sub_dim(gui,fix,data,c=c,r=r,frame=dim_frame)
  267. class GUI_FIX():
  268. def __init__(self,gui,xframe,data):
  269. self.gui = gui
  270. self.data = data
  271. self.xframe = xframe
  272. self.draw()
  273. def draw(self):
  274. FIXTURES = self.data
  275. gui=self.gui
  276. xframe=self.xframe
  277. r=0
  278. c=0
  279. frame_dim=xframe
  280. frame_fix=xframe
  281. for widget in xframe.winfo_children():
  282. widget.destroy()
  283. root = frame_dim
  284. root = frame_fix
  285. fix_frame = tk.Frame(root,bg="black")
  286. fix_frame.pack(fill=tk.X, side=tk.TOP)
  287. i=0
  288. c=0
  289. r=0
  290. dim_end=0
  291. for fix in FIXTURES.fixtures:
  292. i+=1
  293. data = FIXTURES.fixtures[fix]
  294. if fix not in gui.elem_attr:
  295. gui.elem_attr[fix] = {}
  296. kix = []
  297. for ix in data["ATTRIBUT"].keys():
  298. if not ix.startswith("_") and not ix.endswith("-FINE"):
  299. kix.append(ix)
  300. if "DIM" in kix and len(kix) == 1:
  301. continue
  302. if not dim_end:
  303. dim_end=1
  304. c=0
  305. r=0
  306. #gui._draw_fix(fix,data,root=fix_frame)
  307. frame = fix_frame
  308. b = tk.Button(frame,bg="lightblue", text="ID:"+str(fix),width=6,anchor="w")
  309. b.bind("<Button>",tkevent.tk_event(fix=fix,mode="SELECT",elem=b).cb)
  310. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  311. c+=1
  312. b = tk.Button(frame,bg="#55f", text=data["NAME"],width=10,anchor="w")
  313. b.bind("<Button>",tkevent.tk_event(fix=fix,attr="ALL",mode="ENCODER",elem=b).cb)
  314. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  315. c+=1
  316. b = tk.Button(frame,bg="grey", text="S",width=2,anchor="c")
  317. b.config(padx=1)
  318. myTip = Hovertip(b,'SELECT')
  319. b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b,attr="_ACTIVE",mode="ENCODER",data=data).cb)
  320. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  321. gui.elem_attr[fix]["S"] = b
  322. c+=1
  323. #r+=1
  324. start_c=3
  325. c=start_c
  326. attr_list = []
  327. for attr in data["ATTRIBUT"]:
  328. if attr == "END":
  329. continue
  330. if attr.endswith("-FINE"):
  331. continue
  332. #if attr.startswith("_"):
  333. # continue
  334. attr_list.append(attr)
  335. for attr in attr_list:#data["ATTRIBUT"]:
  336. virtual = 0
  337. if attr not in gui.all_attr:
  338. gui.all_attr.append(attr)
  339. if attr not in gui.elem_attr[fix]:
  340. gui.elem_attr[fix][attr] = ["line1348",fix,attr]
  341. v= data["ATTRIBUT"][attr]["VALUE"]
  342. if data["ATTRIBUT"][attr]["NR"] <= 0:
  343. virtual = 1
  344. if attr.startswith("_"):
  345. continue
  346. if virtual:
  347. b = tk.Button(frame,bg="darkgrey", text=str(attr)+' '+str(round(v,2)),relief="solid",width=12, anchor="w")
  348. else:
  349. b = tk.Button(frame,bg="grey", text=str(attr)+' '+str(round(v,2)),width=12, anchor="w")
  350. gui.elem_attr[fix][attr] = b
  351. b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b,attr=attr,mode="ENCODER",data=data).cb)
  352. b.grid(row=r, column=c, sticky=tk.W+tk.E,ipadx=0,ipady=0,padx=0,pady=0)
  353. c+=1
  354. if c >=8:
  355. c=start_c
  356. r+=1
  357. c=0
  358. r+=1
  359. #master._refresh_exec()
  360. #master.refresh_exec()
  361. class _SET_PATCH():
  362. def __init__(self,k,v,fix,data,_cb=None):
  363. self._cb = _cb
  364. self.v = v
  365. self.button = None
  366. self.k = k
  367. self.fix = fix
  368. self.data = data
  369. def attr(self,_event=None):
  370. k = self.k
  371. data = self.data
  372. fix = self.fix
  373. txt = "k={} v={}".format(self.k,self.v)
  374. print(txt)
  375. print( "fix", self.fix )
  376. print( "row data",self.data)
  377. val = ""
  378. if k in self.data:
  379. val = self.data[k]
  380. #txt = dialog.askstring("SET","SET: {}={}".format(self.k,self.v),initialvalue=val)
  381. def _cb(data):
  382. if not data:
  383. print("err443",self,"_cb",data)
  384. return None
  385. txt = data["Value"]
  386. print("_SET.attr",txt)
  387. v = txt
  388. if v is not None:
  389. err = 1
  390. if k in self.data:
  391. if k == "NAME":
  392. self.data[k] = v
  393. err = 0
  394. if k == "DMX":
  395. v = int(v)
  396. if v <= 512 and v >= 0:
  397. self.data[k] = v
  398. err = 0
  399. if k == "UNIVERS":
  400. v = int(v)
  401. if v > 15:
  402. v=15
  403. if v < 0:
  404. v=0
  405. self.data[k] = v
  406. err = 0
  407. if self.button:
  408. if err:
  409. self.button["bg"] = "red"
  410. else:
  411. self.button["bg"] = "#fff"
  412. self.button["text"] = "{}".format(v)
  413. if self._cb:
  414. self._cb()
  415. print( "row data",self.data)
  416. dialog._cb = _cb
  417. dialog.askstring("SET","SET: {}={}".format(self.k,self.v),initialvalue=val)
  418. def set_button(self,button):
  419. self.button = button
  420. class GUI_PATCH():
  421. #def __init__(self,gui,yframe):
  422. def __init__(self,gui,yframe,data,head=None,foot=None):
  423. self.gui = gui
  424. self.yframe = yframe
  425. self.data = data
  426. self._head = head
  427. self._foot = foot
  428. self.fader_elem = []
  429. self.draw()
  430. def draw(self): #,gui,yframe):
  431. FIXTURES = self.data
  432. gui = self.gui
  433. yframe = self.yframe
  434. #print(dir(yframe))
  435. #yframe.clear()
  436. for widget in yframe.winfo_children():
  437. widget.destroy()
  438. xframe = tk.Frame(yframe,bg="black")
  439. xframe.pack()
  440. def yview(event):
  441. print("yevent",event)
  442. yyy=20.1
  443. xframe.yview_moveto(yyy)
  444. i=0
  445. c=0
  446. r=0
  447. def head(i,c,r,xframe=None):
  448. b = tk.Button(xframe,bg="grey", text="Z:{} ID".format(z+1),width=6,anchor="e")
  449. #b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b).cb)
  450. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  451. c+=1
  452. b = tk.Button(xframe,bg="grey", text="NAME",width=14,anchor="w")
  453. #b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b).cb)
  454. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  455. c+=1
  456. rgb = "#aaa"
  457. b = tk.Button(xframe,bg=rgb, text="TYPE",width=8)
  458. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  459. c+=1
  460. b = tk.Button(xframe,bg=rgb, text="Uni",width=3)
  461. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  462. c+=1
  463. b = tk.Button(xframe,bg=rgb, text="DMX",width=2)
  464. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  465. c+=1
  466. b = tk.Button(xframe,bg=rgb, text="CH's",width=4)
  467. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  468. c+=1
  469. b = tk.Button(xframe,bg=rgb, text="from - to",width=8)
  470. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  471. c+=1
  472. b = tk.Button(xframe,bg=rgb, text="DMX-SUM",width=6)
  473. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  474. c+=1
  475. b = tk.Button(xframe,bg=rgb, text="TEST",width=4)
  476. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  477. c+=1
  478. b = tk.Button(xframe,bg=rgb, text="DMX Collision!",width=15)
  479. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  480. c+=1
  481. b = tk.Button(xframe,bg="orange", text="DELETE",width=15)
  482. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  483. c+=1
  484. c=0
  485. r+=1
  486. return i,c,r
  487. #i,c,r = head(i,c,r)
  488. dmx_ch_sum = 0
  489. dmx_collision = {}
  490. for fix in FIXTURES.fixtures:
  491. data = FIXTURES.fixtures[fix]
  492. max_dmx = FIXTURES.get_max_dmx_nr(fix)
  493. for i in range(data["DMX"],data["DMX"]+max_dmx[1]):
  494. k = "{}.{}".format(data["UNIVERS"],i)
  495. if k in dmx_collision:
  496. dmx_collision[k] += 1
  497. else:
  498. dmx_collision[k] = 0
  499. z=0
  500. print("F:H:",self._head,self._foot)
  501. if self._head:
  502. #l = tk.Label(self._head,text="llklk")
  503. #l.pack()
  504. head(0,0,0,xframe=self._head)
  505. for fix in FIXTURES.fixtures:
  506. #if z % 20 == 0:
  507. # i,c,r = head(i,c,r,xframe=xframe)
  508. z+=1
  509. collision = []
  510. i+=1
  511. data = FIXTURES.fixtures[fix]
  512. b = tk.Button(xframe,bg="lightblue", text=""+str(fix),width=6,anchor="e")
  513. #b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b).cb)
  514. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  515. c+=1
  516. command = _SET_PATCH("NAME",data["NAME"],fix,data)
  517. b = tk.Button(xframe,bg="grey", text=data["NAME"],width=14,anchor="w",command=command.attr)
  518. command.set_button(b)
  519. #b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b).cb)
  520. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  521. c+=1
  522. LABEL = ""
  523. if len(data["ATTRIBUT"]) == 1:
  524. LABEL = "DIMMER"
  525. elif "PAN" in data["ATTRIBUT"] or "TILT" in data["ATTRIBUT"] :
  526. LABEL = "MOVER"
  527. else:
  528. LABEL = {}
  529. for a in data["ATTRIBUT"]:
  530. nr = data["ATTRIBUT"][a]["NR"]
  531. if a[0] != "_":
  532. LABEL[nr] = a[0]
  533. keys = list(LABEL.keys())
  534. keys.sort()
  535. L2 =""
  536. for k in keys:
  537. L2 += LABEL[k]
  538. LABEL = L2
  539. b = tk.Button(xframe,bg="#aaa", text=LABEL,width=8,anchor="w")
  540. #b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b).cb)
  541. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  542. b["activebackground"] = "#aaa"
  543. c+=1
  544. b = tk.Button(xframe,bg="#ddd", text="EDIT",width=3)
  545. b.bind("<Button>",tkevent.tk_event(fix=fix,mode="SELECT",elem=b).cb)
  546. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  547. c+=1
  548. b = tk.Button(xframe,bg="#ddd", text="[ ][x]",width=1)
  549. b.bind("<Button>",tkevent.tk_event(fix=fix,mode="SELECT",elem=b).cb)
  550. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  551. c+=1
  552. #r+=1
  553. start_c=3
  554. c=start_c
  555. if fix not in gui.elem_attr:
  556. gui.elem_attr[fix] = {}
  557. patch = ["UNIVERS","DMX"]
  558. for k in patch:
  559. v=data[k]
  560. #b = tk.Button(xframe,bg="grey", text=str(k)+' '+str(v),width=8)
  561. command = _SET_PATCH(k,v,fix,data) #,_cb=highlight2(fix) ) #,_cb=self.draw)
  562. b = tk.Button(xframe,bg="grey", text=str(v),width=2,command=command.attr)
  563. command.set_button(b)
  564. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  565. c+=1
  566. if c >=8:
  567. c=start_c
  568. r+=1
  569. max_dmx = FIXTURES.get_max_dmx_nr(fix)
  570. dmx_ch_sum += max_dmx[1]
  571. for i in range(data["DMX"],data["DMX"]+max_dmx[1]):
  572. k = "{}.{}".format(data["UNIVERS"],i)
  573. if k in dmx_collision:
  574. if dmx_collision[k]:
  575. collision.append(k)
  576. # CH's
  577. b = tk.Button(xframe,bg="#aaa", text="{:3} ({})".format(max_dmx[1] , max_dmx[0]),width=4) #a,anchor="w")
  578. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  579. b["activebackground"] = "#aaa"
  580. c+=1
  581. # from - to
  582. b = tk.Button(xframe,bg="#aaa", text="{:03} - {:03}".format(data["DMX"],max_dmx[1]+(data["DMX"]-1)),width=8,anchor="w")
  583. b["activebackground"] = "#aaa"
  584. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  585. c+=1
  586. b = tk.Button(xframe,bg="#aaa",fg="#225", text="{} : {:03}".format(z,dmx_ch_sum),width=6,anchor="w")
  587. b["activebackground"] = "#aaa"
  588. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  589. c+=1
  590. def x(fix):
  591. def xx():
  592. print("TEST",fix)
  593. if fix in FIXTURES.fixtures:
  594. data = FIXTURES.fixtures[fix]
  595. # print(data)
  596. MAIN.highlight(fix)
  597. return xx
  598. #print(fix)
  599. #TEST BTN
  600. b = tk.Button(xframe,bg="grey",fg="#000", text="TEST",width=4,anchor="w",command=x(fix))
  601. myTip = Hovertip(b,'BLINK DIMMER')
  602. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  603. #b.command = x
  604. #exit()
  605. c+=1
  606. bg = "#252"
  607. if collision:
  608. bg = "#f22"
  609. else:
  610. collision = ""
  611. b = tk.Button(xframe,bg=bg, text="{}".format(",".join(collision)),width=14,anchor="w")
  612. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  613. b["activebackground"] = bg
  614. c+=1
  615. def x_del(fix):
  616. def xx():
  617. print( "DELETE FIXTURE !!!",fix)
  618. if str(fix) in FIXTURES.fixtures:
  619. del FIXTURES.fixtures[fix]
  620. return xx
  621. b = tk.Button(xframe,bg="orange",fg="#000", text="DELETE",width=12,anchor="w")
  622. b["command"] = x_del(fix)
  623. myTip = Hovertip(b,'DELETE FIXTURE')
  624. b.grid(row=r, column=c, sticky=tk.W+tk.E)
  625. c=0
  626. r+=1
  627. class GUI_grid():
  628. def __init__(self,root,data,title="tilte",width=800):
  629. self.data = data
  630. self.frame = tk.Frame(root,bg="black",width=width)
  631. self.frame.pack(fill=tk.BOTH, side=tk.LEFT)
  632. r=0
  633. c=0
  634. i=1
  635. for row in data:
  636. self.b = tk.Button(self.frame,bg="lightblue", text=row["text"],width=11,height=4)
  637. #self.b.bind("<Button>",tkevent.tk_event(fix=fix,elem=b).cb)
  638. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  639. c+=1
  640. if c % 8 == 0:
  641. r+=1
  642. c=0
  643. i+=1
  644. self.frame.pack()
  645. class EXEC_FADER():
  646. def __init__(self,frame,nr,cb=None,fader_cb=None,**args):
  647. self.frame = frame
  648. self.nr= nr
  649. self.id=nr
  650. self.elem = []
  651. self._cb = cb
  652. self._fader_cb = fader_cb
  653. width=11
  654. frameS = tk.Frame(self.frame,bg="#005",width=width)
  655. frameS.pack(fill=tk.Y, side=tk.LEFT)
  656. self.frame=frameS
  657. def fader_event(self,a1="",a2=""):
  658. print(" EXEC_FADER.fader_event",[self.nr,a1,a2],self.label["text"],self.attr["text"])
  659. if self._fader_cb:
  660. self._fader_cb(a1,a2,nr=self.nr)
  661. def event(self,a1="",a2=""):
  662. print(" EXEC_FADER.event",[self.nr,a1,a2],self.label["text"],self.attr["text"])
  663. if self._cb:
  664. self._cb(a1,a2,nr=self.nr)
  665. def set_attr(self,_event=None):
  666. txt= self.attr["text"]
  667. def _cb(data):
  668. if not data:
  669. print("err443",self,"_cb",data)
  670. return None
  671. print(self,"set_attr._cb()",data)
  672. if "Value" in data and type( data["Value"]) is str:
  673. txt = data["Value"]
  674. self._set_attr(txt)
  675. dialog._cb = _cb
  676. dialog.askstring("ATTR","set attr:",initialvalue=txt)
  677. def _set_attr(self,txt=""):
  678. if type(txt) is str:
  679. self.attr["text"] = "{}".format(txt)
  680. #print("_set_attr",[self])
  681. def set_label(self,name=""):
  682. #print("set_label",self.b,name)
  683. self.label["text"] = name
  684. def set_mode(self,_event=None):
  685. txt= self.mode["text"]
  686. def _cb(data):
  687. if not data:
  688. print("err443",self,"_cb",data)
  689. return None
  690. txt = data["Value"]
  691. print(self,"set_mode._cb()",txt)
  692. #w = MAIN.WindowContainer("config",master=1,width=200,height=140,left=L1,top=TOP)
  693. #w.pack()
  694. self._set_mode(txt)
  695. #w.show()
  696. dialog._cb = _cb
  697. dialog.askstring("MODE S/F:","SWITCH or FADE",initialvalue=txt)
  698. def _set_mode(self,txt=""):
  699. print("_set_mode",txt)
  700. if type(txt) is str:
  701. self.mode["text"] = "{}".format(txt[0].upper())
  702. #print("_set_mode",[self])
  703. def _refresh(self):
  704. pass
  705. def go(self,event=None,X=None,Y=None):
  706. print(self,"go()",event,self.attr["text"])
  707. #print(dir(event))
  708. print(event.num,event.state,event.type)
  709. nr = self.id+80
  710. if event.state > 0:
  711. value = 0
  712. MAIN.master.exec_go(nr-1,xfade=None,val=value)
  713. else:
  714. value = 1
  715. MAIN.master.exec_go(nr-1,xfade=None,val=value)
  716. def pack(self,init=None,from_=255,to=0,**args):
  717. width=11
  718. r=0
  719. c=0
  720. j=0
  721. self.font8 = ("FreeSans",8)
  722. frameS=self.frame
  723. self.b = tk.Scale(frameS,bg="lightblue", width=28,from_=from_,to=to,command=self.fader_event)
  724. self.b.pack(fill=tk.Y, side=tk.TOP)
  725. if init is not None:
  726. self.b.set(init)
  727. self.elem.append(self.b)
  728. self.b = tk.Button(frameS,bg="lightblue",text="{}".format(self.nr), width=5,command=libtk.test_command,font=self.font8 )
  729. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  730. self.label = self.b
  731. if 1: #self.nr <= 10:
  732. self.elem.append(self.b)
  733. self.b = tk.Button(frameS,bg="lightblue",text="", width=5,font=self.font8 )
  734. self.b.bind("<Button>",self.go) #BEvent({"NR":self.id+80,"text":""},self.go).cb)
  735. self.b.bind("<ButtonRelease>",self.go) #BEvent({"NR":self.id+80,"text":""},self.go).cb)
  736. #b = self.b
  737. #k = ""
  738. #gui = MAIN.master
  739. #self.b.bind("<Button>",tkevent.tk_event(fix=0,elem=b,attr=k,data=gui,mode="EXEC").cb)
  740. #self.b.bind("<ButtonRelease>",tkevent.tk_event(fix=0,elem=b,attr=k,data=gui,mode="EXEC").cb)
  741. self.attr=self.b
  742. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  743. self.elem.append(self.b)
  744. f = tk.Frame(frameS)
  745. ##f.pack()
  746. #self.b = tk.Button(f,bg="lightblue",text="<+", width=1,command=self.set_mode,font=self.font8 )
  747. #self.mode=self.b
  748. ##self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  749. #self.elem.append(self.b)
  750. #self.b = tk.Button(frameS,bg="lightblue",text="F", width=4,command=self.set_mode,font=self.font8 )
  751. #self.mode=self.b
  752. #self.b.pack(fill=tk.BOTH, side=tk.TOP)
  753. ##self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  754. #self.elem.append(self.b)
  755. #self.b = tk.Button(f,bg="lightblue",text="+>", width=1,command=self.set_mode,font=self.font8 )
  756. #self.mode=self.b
  757. ##self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  758. #self.elem.append(self.b)
  759. self.b = tk.Label(frameS,bg="black",text="", width=4,font=self.font8 )
  760. self.b.pack(fill=tk.BOTH, side=tk.TOP)
  761. self.elem.append(self.b)
  762. class GUI_ExecWingLayout():
  763. def __init__(self,root,frame,data,title="tilte",width=800,start=81):
  764. self.font8 = ("FreeSans",8)
  765. self.dmx=1
  766. self.univ=0
  767. self.start=start-1
  768. r=0
  769. c=0
  770. i=1
  771. self.elem=[]
  772. self.fader_elem = []
  773. self.header=[]
  774. self.data = data
  775. self.frame = tk.Frame(frame,bg="#000",width=width,border=2)
  776. self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  777. r=0
  778. c=0
  779. pb=10
  780. self.pb=pb
  781. for j,row in enumerate(data):
  782. if c % pb == 0 or c==0:
  783. h=hex(j*10)[2:].rjust(2,"0")
  784. frameS = tk.Frame(self.frame,bg="#000",width=width,border=2)
  785. frameS.pack(fill=tk.BOTH, side=tk.TOP)
  786. p=j//pb+1
  787. if j < 10:
  788. txt="x-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  789. else:
  790. txt="x-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  791. self.b = tk.Label(frameS,bg="lightblue",text=txt,width=25,font=self.font8 )
  792. self.header.append(self.b)
  793. self.b.pack(fill=None, side=tk.LEFT)
  794. self.b = tk.Label(frameS,bg="black",text="" ,width=11,font=self.font8 )
  795. self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  796. try:
  797. frameS = tk.Frame(self.frame,bg="#a000{}".format(h),width=width,border=2)
  798. except:
  799. frameS = tk.Frame(self.frame,bg="#a0aadd",width=width,border=2)
  800. c=0
  801. #print(frameS)
  802. #e= libtk.ELEM_FADER(frameS,nr=j+1,cb=self.event_cb)
  803. e= EXEC_FADER(frameS,nr=j+1,fader_cb=self.event_cb)
  804. if j >= 10:
  805. e.pack(from_=400,to=0,init=100)
  806. else:
  807. e.pack(from_=200,to=0,init=100)
  808. self.elem.append(e)
  809. self.fader_elem.append(e)
  810. frameS.pack(fill=tk.X, side=tk.TOP)
  811. c+=1
  812. i+=1
  813. self.frame.pack()
  814. self._event_redraw()
  815. def set_fader(self,nr,val,color="",info="info",change=0):
  816. mute = 1
  817. if nr == 2:
  818. mute = 1
  819. if info != "dmx_in":
  820. mute=1
  821. if not mute:print("set_fader",nr,val,info)
  822. if nr < len(self.elem):
  823. try:
  824. ee = self.elem[nr].elem[0]
  825. ee.set(val)
  826. if color:
  827. ee["bg"] = color
  828. except Exception as e:
  829. if change:
  830. self.event_cb(a1=val,nr=nr)
  831. #cprint("set_fader",e,color="red")
  832. #raise e
  833. #self.frame.update_idle_task()
  834. if not mute:print("set_fader",nr,val,info)
  835. return # STOP
  836. def event_cb(self,a1="",a2="",nr=None,**args):
  837. #print(" ExecWing.event_cb:",nr,a1,a2,args)
  838. nr += 1
  839. jdata= {"CMD":"X-MASTER","NR":nr,"VALUE":int(a1)}
  840. if nr >= 1 and nr <= 10:
  841. jdata["CMD"] = "EXEC-SIZE-MASTER"
  842. jdata["NR"] = nr +self.start
  843. if nr >= 11 and nr <= 20:
  844. jdata["CMD"] = "EXEC-SPEED-MASTER"
  845. jdata["NR"] = nr-10 +self.start
  846. if nr >= 21 and nr <= 30:
  847. jdata["CMD"] = "EXEC-OFFSET-MASTER"
  848. jdata["NR"] = nr-20 +self.start
  849. #print(" ExecWing.event_cb",jdata)
  850. j = [jdata]
  851. MAIN.jclient_send(j)
  852. def set_name(self,_event=None):
  853. txt = self.name["text"]
  854. def _cb(data):
  855. if not data:
  856. print("err443",self,"_cb",data)
  857. return None
  858. txt = data["Value"]
  859. print(self,"._cb()",txt)
  860. self.name["text"] = "{}".format(txt)
  861. print("change_dmx",[_event,self])
  862. dialog._cb = _cb
  863. dialog.askstring("FIXTURE NAME:","NAME:",initialvalue=txt)
  864. def event_value(self,_event=None):
  865. nr=self.dmx
  866. txt= self.entry_dmx["text"]
  867. def _event_redraw(self,_event=None):
  868. nr = 0
  869. print("change_dmx",[_event,self])
  870. for i,btn in enumerate(self.elem):
  871. btn.set_label("{} D:{}".format(i+1,nr))
  872. btn.nr = nr+i
  873. pb=self.pb
  874. for j,e in enumerate(self.header):
  875. p=j+1
  876. #p=nr/pb
  877. if p == 1:
  878. txt="SIZE-MASTER:{} {}-{}".format(p,1+self.start,10+self.start)#p*pb-pb+1,p*pb)
  879. elif p == 2:
  880. txt="SPEED-MASTER:{} {}-{}".format(p,1+self.start,10+self.start)#p*pb-pb+1,p*pb)
  881. elif p == 3:
  882. txt="OFFSET-MASTER:{} {}-{}".format(p,1+self.start,10+self.start)#p*pb-pb+1,p*pb)
  883. else:
  884. txt="X-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  885. #txt="BANK:{} {}-{}".format(p,p*pb-pb+nr,p*pb+nr)
  886. print("---",j,txt,e)
  887. e["text"] = txt
  888. class GUI_MasterWingLayout():
  889. def __init__(self,root,frame,data,title="tilte",width=800):
  890. #xfont = tk.font.Font(family="FreeSans", size=5, weight="bold")
  891. self.font8 = ("FreeSans",8)
  892. self.dmx=1
  893. self.univ=0
  894. r=0
  895. c=0
  896. i=1
  897. self.elem=[]
  898. self.header=[]
  899. self.data = data
  900. #self.frame = tk.Frame(root,bg="black",width=width)
  901. #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  902. #self.b = tk.Label(self.frame,bg="#fff",text="Master Wing") #,font=font8 )
  903. #self.b.pack(fill=None, side=tk.LEFT)
  904. #self.frame = tk.Frame(root,bg="black",width=width)
  905. #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  906. #self.b = tk.Label(self.frame,bg="black",text="") # spacer
  907. #self.b.pack(fill=tk.Y, side=tk.LEFT)
  908. #self.frame = tk.Frame(root,bg="magenta",width=width,border=2) # fader frame
  909. #self.frame.pack(fill=tk.BOTH, side=tk.TOP)
  910. self.frame=frame
  911. r=0
  912. c=0
  913. pb=1
  914. self.pb=pb
  915. for j,row in enumerate(data):
  916. if c % pb == 0 or c==0:
  917. h=hex(j*10)[2:].rjust(2,"0")
  918. frameS = tk.Frame(self.frame,bg="#000",width=width,border=2)
  919. frameS.pack(fill=tk.BOTH, side=tk.TOP)
  920. p=j//pb+1
  921. if j < 1:
  922. txt="x-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  923. else:
  924. txt="x-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  925. self.b = tk.Label(frameS,bg="lightblue",text=txt,width=25,font=self.font8 )
  926. self.header.append(self.b)
  927. self.b.pack(fill=None, side=tk.LEFT)
  928. self.b = tk.Label(frameS,bg="black",text="" ,width=11,font=self.font8 )
  929. self.b.pack(fill=tk.BOTH, side=tk.LEFT)
  930. try:
  931. frameS = tk.Frame(self.frame,bg="#a000{}".format(h),width=width,border=2)
  932. except:
  933. frameS = tk.Frame(self.frame,bg="#a0aadd",width=width,border=2)
  934. c=0
  935. #print(frameS)
  936. e= libtk.ELEM_FADER(frameS,nr=j+1,fader_cb=self.event_cb)
  937. if j >= 2:
  938. e.pack(from_=400,to=0,init=100)
  939. else:
  940. e.pack(from_=200,to=0,init=100)
  941. self.elem.append(e)
  942. frameS.pack(fill=tk.X, side=tk.TOP)
  943. c+=1
  944. i+=1
  945. self.frame.pack()
  946. self._event_redraw()
  947. def event_cb(self,a1="",a2="",nr=None,**args):
  948. print(" MasterWing.event_cb:",nr,a1,a2,args)
  949. nr += 1
  950. jdata= {"CMD":"X-MASTER","NR":nr,"VALUE":int(a1)}
  951. if nr == 1:
  952. jdata["CMD"] = "SIZE-MASTER"
  953. jdata["NR"] = 1 #nr
  954. if nr == 2:
  955. jdata["CMD"] = "SPEED-MASTER"
  956. jdata["NR"] = 1 #nr
  957. print(" MasterWing.event_cb",jdata)
  958. j = [jdata]
  959. MAIN.jclient_send(j)
  960. def set_name(self,_event=None):
  961. txt = self.name["text"]
  962. def _cb(data):
  963. if not data:
  964. print("err443",self,"_cb",data)
  965. return None
  966. txt = data["Value"]
  967. print(self,"._cb()",txt)
  968. self.name["text"] = "{}".format(txt)
  969. print("set_name",[_event,self])
  970. dialog._cb = _cb
  971. dialog.askstring("FIXTURE NAME:","NAME:",initialvalue=txt)
  972. def event_value(self,_event=None):
  973. nr=self.dmx
  974. txt= self.entry_dmx["text"]
  975. def _event_redraw(self,_event=None):
  976. nr = 0
  977. print("_event_redraw",[_event,self])
  978. for i,btn in enumerate(self.elem):
  979. btn.set_label("{} D:{}".format(i+1,nr))
  980. btn.nr = nr+i
  981. pb=self.pb
  982. for j,e in enumerate(self.header):
  983. p=j+1
  984. #p=nr/pb
  985. if p == 1:
  986. txt="SIZE-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  987. else:
  988. txt="SPEED-MASTER:{} {}-{}".format(p,p*pb-pb+1,p*pb)
  989. #txt="BANK:{} {}-{}".format(p,p*pb-pb+nr,p*pb+nr)
  990. print("---",j,txt,e)
  991. e["text"] = txt
  992. class BEvent():
  993. def __init__(self,data,cb):
  994. self._data = data
  995. self._cb = cb
  996. def cb(self,event):
  997. #print(self,event)
  998. self._cb(event,self._data)
  999. class GUI_menu():
  1000. def __init__(self,root,frame ,data,title="tilte"):
  1001. global tk
  1002. global INIT_OK
  1003. self.frame = frame
  1004. self.data = data
  1005. self.elem = {}
  1006. self.draw()
  1007. def draw(self):
  1008. cprint("***",self,"draw")
  1009. r=0
  1010. c=0
  1011. i=1
  1012. self.b = tk.Label(self.frame,bg="lightblue", text="MAIN:MENU",width=8,height=1)
  1013. self.TITLE = self.b
  1014. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  1015. r+=1
  1016. h = 2
  1017. for row in self.data:
  1018. print(" draw",row)
  1019. #row = data[i]
  1020. if row["text"] == "---":
  1021. h=1
  1022. if "name" in row:
  1023. self.b = tk.Button(self.frame,bg="lightgrey", text=row["name"],width=8,height=h)
  1024. else:
  1025. self.b = tk.Button(self.frame,bg="lightgrey", text=row["text"],width=8,height=h)
  1026. if "tip" in row:
  1027. from idlelib.tooltip import Hovertip
  1028. myTip = Hovertip(self.b,row["tip"])
  1029. self.b.bind("<Button>",BEvent({"NR":i,"text":row["text"]},self.on_top).cb)
  1030. self.b.grid(row=r, column=c, sticky=tk.W+tk.E)#,anchor="w")
  1031. row["elem"] = self.b
  1032. self.elem[row["text"]] = row
  1033. r+=1
  1034. i+=1
  1035. self.frame.pack()
  1036. INIT_OK = 1
  1037. self.start_loop()
  1038. def start_loop(self):
  1039. print(self,"--- start_bg_loop ----- xxxx")
  1040. thread.start_new_thread(mytklib.tk_btn_bg_loop,(self.TITLE,))
  1041. def on_top(self,event,data={}):
  1042. print("menue.on_top",data)
  1043. MAIN.window_manager.top(data["text"])
  1044. def update(self,button,text):
  1045. #print(self,button,text)
  1046. for k in self.elem:
  1047. v=self.elem[k]
  1048. #print(self,k,v)
  1049. if button == k:
  1050. v["elem"]["text"] = k+"\n"+text
  1051. def config(self,button,attr,value):
  1052. #print("config",self,button,attr,value)
  1053. for k in self.elem:
  1054. v=self.elem[k]
  1055. #print(self,k,v)
  1056. if button == k:
  1057. #print(dir(v["elem"]))
  1058. if attr == "bg":
  1059. if value == "":
  1060. value = "lightgrey"
  1061. v["elem"][attr] = str(value)
  1062. if attr == "activebackground":
  1063. if value == "":
  1064. value = "lightgrey"
  1065. v["elem"][attr] = str(value)