import W import Ctl import Controls import Qd from Wbase import _darkencolor class NormalBevelButton(W.Button): procID = Controls.kControlBevelButtonNormalBevelProc def __init__(self, possize, title = "BevelButton", callback = None): W.ControlWidget.__init__(self, possize, title, self.procID, callback, 0, 0, 1) self._isdefault = 0 def enable(self, onoff): if self._control and self._enabled <> onoff: self._enabled = onoff if self._isdefault and self._visible: self.SetPort() self.drawfatframe(onoff) self._control.HiliteControl((not onoff) and 255) def activate(self, onoff): self._activated = onoff if self._enabled: if self._isdefault and self._visible: self.SetPort() self.drawfatframe(onoff) self._control.HiliteControl((not onoff) and 255) def draw(self, visRgn = None): if self._visible: if self._isdefault and self._activated: self.drawfatframe(self._enabled) self._control.Draw1Control() def drawfatframe(self, onoff): # draw a platinum appearance default box color = (0xe000, 0xe000, 0xe000) (l, t, r, b) = Qd.InsetRect(self._bounds, -4, -4) if onoff: Qd.FrameRect((l, t, r, b)) Qd.RGBForeColor(color) Qd.PaintRect((l+1, t+1, r-1, b-1)) Qd.RGBForeColor(_darkencolor(color)) Qd.MoveTo(l+2, b-2) Qd.LineTo(r-2, b-2) Qd.LineTo(r-2, t+2) Qd.RGBForeColor(_darkencolor(color)) (l, t, r, b) = Qd.InsetRect(self._bounds, -1, -1) Qd.PaintRect((l, t, r, b)) Qd.RGBForeColor((0, 0, 0)) Qd.RGBForeColor(_darkencolor(color)) Qd.MoveTo(l, b-1) Qd.LineTo(r-1, b-1) Qd.LineTo(r-1, t) else: Qd.RGBForeColor((0xffff, 0xffff, 0xffff)) Qd.PaintRect((l, t, r, b)) Qd.RGBForeColor((0, 0, 0)) def _setdefault(self, onoff): self._isdefault = onoff if self._control and self._enabled: self.SetPort() self.drawfatframe(onoff) self.draw() class SmallBevelButton(NormalBevelButton): ProcID = Controls.kControlBevelButtonSmallBevelProc class LargeBevelButton(NormalBevelButton): ProcID = Controls.kControlBevelButtonLargeBevelProc if __name__ == "__main__": def callback(): w.setdefaultbutton(w.bevel) print "Bevel" def defaultcallback(): print "Default Bevel" w = W.Window((200,200),"Bevel Test") w.bevel = SmallBevelButton((20,20,100,50), "Bevel Button", callback) w.defaultbevel = LargeBevelButton((20,100,100,50), "OK", defaultcallback) w.setdefaultbutton(w.defaultbevel) w.open()