def _get_button_region(self): """Return our region, in global coordinates, if we are active""" # XXXX Only rectangulars for now if not self._sensitive: return None if not self._insidetemporal(): return None rgn = Qd.NewRgn() if self._shape == 'rect': x0, y0 = self._convert_point(self._coordinates[0:2]) x1, y1 = self._convert_point(self._coordinates[2:4]) box = x0, y0, x1, y1 Qd.RectRgn(rgn, box) elif self._shape == 'poly': Qd.OpenRgn() xl, yl = self._convert_point(self._coordinates[-2:]) Qd.MoveTo(xl, yl) for i in range(0, len(self._coordinates), 2): x, y = self._convert_point(self._coordinates[i:i + 2]) Qd.LineTo(x, y) Qd.CloseRgn(rgn) elif self._shape == 'circle': print 'Circle not supported yet' elif self._shape == 'ellipse': # Note: rx/ry are width/height, not points x, y, rx, ry = self._dispobj._window._convert_coordinates( self._coordinates) Qd.OpenRgn() Qd.FrameOval((x - rx, y - ry, x + rx, y + ry)) Qd.CloseRgn(rgn) else: print 'Invalid shape type', self._shape return rgn
def _mkpolyrgn(pointlist): rgn = Qd.NewRgn() Qd.OpenRgn() apply(Qd.MoveTo, pointlist[-1]) for x, y in pointlist: Qd.LineTo(x, y) Qd.CloseRgn(rgn) return rgn