rendered paste bodyIndex: lib/python/pyvcp_widgets.py
===================================================================
RCS file: /cvs/emc2/lib/python/pyvcp_widgets.py,v
retrieving revision 1.29
diff -u -w -B -b -r1.29 pyvcp_widgets.py
--- lib/python/pyvcp_widgets.py 2 Feb 2007 03:34:02 -0000 1.29
+++ lib/python/pyvcp_widgets.py 2 Feb 2007 22:48:27 -0000
@@ -543,8 +544,8 @@
place widgets here
</vbox>
"""
- def __init__(self,master,pycomp,bd=0,relief=FLAT):
- Frame.__init__(self,master,bd=bd,relief=relief)
+ def __init__(self,master,pycomp,bd=0,relief=FLAT,**kw):
+ Frame.__init__(self,master,bd=bd,relief=relief,**kw)
self.fill = 'x'
self.side = 'top'
self.anchor = 'center'
@@ -563,6 +564,9 @@
if isinstance(widget, pyvcp_boxanchor):
self.anchor = widget.anchor
return
+ if isinstance(widget, pyvcp_boxside):
+ self.side = widget.side
+ return
widget.pack(side=self.side, anchor=self.anchor, fill=self.fill, expand=self.expand)
class pyvcp_boxfill:
@@ -580,6 +584,10 @@
self.expand = expand
def update(self, pycomp): pass
+class pyvcp_boxside:
+ def __init__(self, master, pycomp, side):
+ self.side = side
+ def update(self, pycomp): pass
# -------------------------------------------
class pyvcp_hbox(Frame):
@@ -590,8 +598,8 @@
place widgets here
</vbox>
"""
- def __init__(self,master,pycomp,bd=0,relief=FLAT):
- Frame.__init__(self,master,bd=bd,relief=relief)
+ def __init__(self,master,pycomp,bd=0,relief=FLAT,side=None,**kw):
+ Frame.__init__(self,master,bd=bd,relief=relief,**kw)
self.fill = 'y'
self.side = 'left'
self.anchor = 'center'
@@ -610,7 +618,10 @@
if isinstance(widget, pyvcp_boxanchor):
self.anchor = widget.anchor
return
- widget.pack(side=self.side, anchor=self.anchor, fill=self.fill)
+ if isinstance(widget, pyvcp_boxside):
+ self.side = widget.side
+ return
+ widget.pack(side=self.side, anchor=self.anchor, fill=self.fill, expand=self.expand)
class pyvcp_labelframe(LabelFrame):
"""
@@ -846,24 +857,142 @@
class pyvcp_checkbutton(Checkbutton):
""" (control) a check button
- halpin is 1 when button checked, 0 otherwise
+ halpin is 1 when checkbutton-momentary pressed, 0 otherwise
+ 20070123
+ added parameter 'btnType' to allowed token list
+ allow values "Opin" & "IOpin"
+ this preserves the original checkbutton with an 'o' pin
+ but allows the 'new' IOpin type
+ the IOpin type stays pressed until some xtrnl force releases it
+
+ <checkbutton>
+ <halpin>"mybtn"</halpin>
+ <btnType>"O"</btnType> halpin is ouput only
+ </checkbutton>
+ <checkbutton>
+ <halpin>"mybtn"</halpin> optional default is created from "checkbutton" & a counter
+ <btnType>"IO"</btnType> optional default it O
+ <text>"Flood"</init> optional default is from a counter
+ <init>True</init> optional default is True
+ </checkbutton>
"""
n=0
- def __init__(self,master,pycomp,halpin=None,**kw):
- self.v = BooleanVar(master)
- Checkbutton.__init__(self,master,variable=self.v,onvalue=1, offvalue=0,**kw)
+ def __init__(self,master,pycomp,halpin=None,btnType=None,text=None,init=None, **kw):
+
+ if btnType==None:
+ btnType="Opin"
+ if ((btnType!="Opin")&(btnType!="IOpin")):
+ return
+
+ if init==None:
+ init=True
+ if ((init!=True)&(init!=False)):
+ return
+
+ if text==None:
+ btntxt=str(pyvcp_checkbutton.n)
+ else:
+ btntxt = text
+
+ self.v = BooleanVar(master) #for original 'Opin' type checkbutton
+
+ self.downVal=init # the logic value to emit when pressed
+ self.btntype=btnType # "Opin" or "IOpin"
+
+ #i dont see why this is necc, else update gives
+ # AttributeError: pyvcp_checkbutton instance has no attribute 'newstate'
+ self.newstate=self.oldstate=None
+
+ if btnType=="Opin":
+ Checkbutton.__init__(self,master, \
+ variable=self.v, \
+ text=None, indicatoron=0, \
+ onvalue=1, offvalue=0, \
+ **kw)
+ else:
+ Checkbutton.__init__(self,master, \
+ text=None, indicatoron=0, \
+ **kw)
+
if halpin == None:
halpin = "checkbutton."+str(pyvcp_checkbutton.n)
+
self.halpin=halpin
+
+ if btnType=="Opin":
pycomp.newpin(halpin, HAL_BIT, HAL_OUT)
+ self.configure(text=btntxt)
+ else:
+ pycomp.newpin(halpin, HAL_BIT, HAL_IO)
+ self.configure(text=btntxt)
+
+ #show the color according to <init>, set the pin & history to opposite of presed state ( becuz not pressed yet )
+ if self.downVal==True:
+ colr="red"
+ self.configure(activebackground=colr)
+ self.configure(bg=colr)
+ pycomp[self.halpin]=self.oldstate=self.newstate=False # if init was True, then begin UP, Red, and oldstate = False
+ else:
+ colr="green"
+ self.configure(activebackground=colr)
+ self.configure(selectcolor=colr)
+ self.configure(bg=colr)
+ pycomp[self.halpin]=self.oldstate=self.newstate=True # if init was False, then begin UP, Green & oldstate = True
+ self.bind('<ButtonPress>',self.bdown) # only bind the IOpin vrsn of cbtn chg output state when pressed
+
pyvcp_checkbutton.n += 1
+ self.mirror=None
- def update(self,pycomp):
- pycomp[self.halpin]=self.v.get()
+ # this func requests a change in state
+ def bdown(self,event):
+ if self.btntype=="IOpin":
+ if self.downVal==True:
+ self.newstate=True
+ else:
+ self.newstate=False
+ self.configure(state=DISABLED)
+ #def bup(self)
+ # there is no bup, only external srcs can release the btn, not this widget
+ def update(self,pycomp):
+ if self.btntype=="Opin":
+ pycomp[self.halpin]=self.v.get()
+ else: # btnType = "IO"
+ dirty = False # no need to change appearance till we know theres been a change
+ if self.newstate!=self.oldstate: # detect a change caused by btn press ( an internal change )
+ pycomp[self.halpin]=self.newstate
+ dirty=True # need to chg appearance
+ self.oldstate=self.newstate
+ elif pycomp[self.halpin]!=self.oldstate: # detect a change caused by by external src
+ dirty=True # need to chg appearance
+ self.oldstate=self.newstate=pycomp[self.halpin]
+
+
+ if dirty==True:
+ tmp=pycomp[self.halpin]
+
+ if self.downVal==True: # downVal is True
+ if tmp==True: # halpin is True
+ self.select() # btn looks down looks decided by downVal & halpin
+ colr="green" # colr is green color decided by halpin
+ else: # halpin is False
+ self.deselect() # btn looks up
+ colr="red" # colr is red
+ else: # downVal is False
+ if tmp==True: # halpin is True
+ self.deselect() # btn looks up
+ colr="green" # colr is green
+ else: # halpin is False
+ self.select() # btn looks down
+ colr="red" # colr is red
+
+ self.configure(selectcolor=colr)
+ self.configure(activebackground=colr)
+ self.configure(state=NORMAL)
+ dirty=False
# -------------------------------------------