Changeset 3247

Show
Ignore:
Timestamp:
07/13/07 05:49:56 (1 year ago)
Author:
ed
Message:

Added the following draw methods:

drawEllipse(xPos, yPos, width, height, ...)
drawArc(xPos, yPos, rad, startAngle, endAngle, ...)
drawEllipticArc(xPos, yPos, width, height, startAngle, endAngle, ...)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dabo/ui/uiwx/dPemMixin.py

    r3244 r3247  
    12421242 
    12431243    def drawCircle(self, xPos, yPos, rad, penColor="black", penWidth=1, 
    1244             fillColor=None, lineStyle=None, hatchStyle=None, mode=None,  
     1244            fillColor=None, lineStyle=None, hatchStyle=None, mode=None, 
    12451245            persist=True): 
    12461246        """Draws a circle of the specified radius around the specified point. 
    12471247 
    1248         You can set the color and thickness of the line, as well as the  
    1249         color and hatching style of the fill. Normally, when persist=True,  
    1250         the circle will be re-drawn on paint events, but if you pass False,  
     1248        You can set the color and thickness of the line, as well as the 
     1249        color and hatching style of the fill. Normally, when persist=True, 
     1250        the circle will be re-drawn on paint events, but if you pass False, 
    12511251        it will be drawn once only. 
    1252          
    1253         A drawing object is returned, or None if persist=False. You can  
    1254         'remove' the drawing by setting the Visible property of the  
     1252 
     1253        A drawing object is returned, or None if persist=False. You can 
     1254        'remove' the drawing by setting the Visible property of the 
    12551255        returned object to False. You can also manipulate the position, size, 
    12561256        color, and fill by changing the various properties of the object. 
     
    12621262        obj = self._addToDrawnObjects(obj, persist) 
    12631263        return obj 
    1264      
    1265      
    1266     def drawRectangle(self, xPos, yPos, width, height, penColor="black",  
     1264 
     1265 
     1266    def drawArc(self, xPos, yPos, rad, startAngle, endAngle, penColor="black", 
    12671267            penWidth=1, fillColor=None, lineStyle=None, hatchStyle=None, 
    12681268            mode=None, persist=True): 
    1269         """Draws a rectangle of the specified size beginning at the specified  
    1270         point.  
     1269        """Draws an arc (pie slice) of a circle centered around the specified point, 
     1270        starting from 'startAngle' degrees, and sweeping counter-clockwise 
     1271        until 'endAngle' is reached. 
    12711272 
    12721273        See the 'drawCircle()' method above for more details. 
    12731274        """ 
    12741275        obj = DrawObject(self, FillColor=fillColor, PenColor=penColor, 
    1275                 PenWidth=penWidth, LineStyle=lineStyle, HatchStyle=hatchStyle,  
    1276                 Shape="rect", Xpos=xPos, Ypos=yPos, Width=width, Height=height,  
     1276                PenWidth=penWidth, Radius=rad, StartAngle=startAngle, 
     1277                EndAngle=endAngle, LineStyle=lineStyle, HatchStyle=hatchStyle, 
     1278                Shape="arc", Xpos=xPos, Ypos=yPos, DrawMode=mode) 
     1279        # Add it to the list of drawing objects 
     1280        obj = self._addToDrawnObjects(obj, persist) 
     1281        return obj 
     1282 
     1283 
     1284    def drawEllipse(self, xPos, yPos, width, height, penColor="black", 
     1285            penWidth=1, fillColor=None, lineStyle=None, hatchStyle=None, 
     1286            mode=None, persist=True): 
     1287        """Draws an ellipse contained within the rectangular space defined by 
     1288        the position and size coordinates 
     1289 
     1290        See the 'drawCircle()' method above for more details. 
     1291        """ 
     1292        obj = DrawObject(self, FillColor=fillColor, PenColor=penColor, 
     1293                PenWidth=penWidth, LineStyle=lineStyle, HatchStyle=hatchStyle, 
     1294                Shape="ellipse", Xpos=xPos, Ypos=yPos, Width=width, Height=height, 
    12771295                DrawMode=mode) 
    12781296        # Add it to the list of drawing objects 
     
    12811299 
    12821300 
    1283     def drawPolygon(self, points, penColor="black", penWidth=1,  
    1284             fillColor=None, lineStyle=None, hatchStyle=None,  
     1301    def drawEllipticArc(self, xPos, yPos, width, height, startAngle, endAngle, 
     1302            penColor="black", penWidth=1, fillColor=None, lineStyle=None, 
     1303            hatchStyle=None, mode=None, persist=True): 
     1304        """Draws an arc (pie slice) of a ellipse contained by the specified 
     1305        dimensions, starting from 'startAngle' degrees, and sweeping 
     1306        counter-clockwise until 'endAngle' is reached. 
     1307 
     1308        See the 'drawCircle()' method above for more details. 
     1309        """ 
     1310        obj = DrawObject(self, FillColor=fillColor, PenColor=penColor, 
     1311                PenWidth=penWidth, StartAngle=startAngle, 
     1312                EndAngle=endAngle, LineStyle=lineStyle, HatchStyle=hatchStyle, 
     1313                Shape="ellipticarc", Xpos=xPos, Ypos=yPos, Width=width, 
     1314                Height=height, DrawMode=mode) 
     1315        # Add it to the list of drawing objects 
     1316        obj = self._addToDrawnObjects(obj, persist) 
     1317        return obj 
     1318 
     1319 
     1320    def drawRectangle(self, xPos, yPos, width, height, penColor="black", 
     1321            penWidth=1, fillColor=None, lineStyle=None, hatchStyle=None, 
     1322            mode=None, persist=True): 
     1323        """Draws a rectangle of the specified size beginning at the specified 
     1324        point. 
     1325 
     1326        See the 'drawCircle()' method above for more details. 
     1327        """ 
     1328        obj = DrawObject(self, FillColor=fillColor, PenColor=penColor, 
     1329                PenWidth=penWidth, LineStyle=lineStyle, HatchStyle=hatchStyle, 
     1330                Shape="rect", Xpos=xPos, Ypos=yPos, Width=width, Height=height, 
     1331                DrawMode=mode) 
     1332        # Add it to the list of drawing objects 
     1333        obj = self._addToDrawnObjects(obj, persist) 
     1334        return obj 
     1335 
     1336 
     1337    def drawPolygon(self, points, penColor="black", penWidth=1, 
     1338            fillColor=None, lineStyle=None, hatchStyle=None, 
    12851339            mode=None, persist=True): 
    12861340        """Draws a polygon defined by the specified points. 
    12871341 
    1288         The 'points' parameter should be a tuple of (x,y) pairs defining the  
     1342        The 'points' parameter should be a tuple of (x,y) pairs defining the 
    12891343        polygon. 
    12901344 
     
    12991353 
    13001354 
    1301     def drawPolyLines(self, points, penColor="black", penWidth=1,  
     1355    def drawPolyLines(self, points, penColor="black", penWidth=1, 
    13021356            lineStyle=None, mode=None, persist=True): 
    13031357        """Draws a series of connected line segments defined by the specified points. 
     
    13051359        The 'points' parameter should be a tuple of (x,y) pairs defining the shape. Lines 
    13061360        are drawn connecting the points sequentially, but a segment from the last 
    1307         point to the first is not drawn, leaving an 'open' polygon. As a result, there is no  
     1361        point to the first is not drawn, leaving an 'open' polygon. As a result, there is no 
    13081362        FillColor or HatchStyle defined for this. 
    13091363 
    13101364        See the 'drawCircle()' method above for more details. 
    13111365        """ 
    1312         obj = DrawObject(self, PenColor=penColor, PenWidth=penWidth, LineStyle=lineStyle,  
     1366        obj = DrawObject(self, PenColor=penColor, PenWidth=penWidth, LineStyle=lineStyle, 
    13131367                Shape="polylines", Points=points, DrawMode=mode) 
    13141368        # Add it to the list of drawing objects 
     
    25812635        self._points = None 
    25822636        self._radius = None 
     2637        self._startAngle = None 
     2638        self._endAngle = None 
    25832639        self._shape = None 
    25842640        self._visible = True 
     
    27152771            dc.DrawCircle(x, y, self.Radius) 
    27162772            self._width = self._height = self.Radius * 2 
    2717         elif self.Shape == "rect": 
     2773        elif self.Shape == "arc": 
     2774            xc, yc = self.Xpos, self.Ypos 
     2775            x1 = xc + (math.cos(math.radians(self.StartAngle)) * self.Radius) 
     2776            y1 = yc - (math.sin(math.radians(self.StartAngle)) * self.Radius) 
     2777            x2 = xc + (math.cos(math.radians(self.EndAngle)) * self.Radius) 
     2778            y2 = yc - (math.sin(math.radians(self.EndAngle)) * self.Radius) 
     2779            dc.DrawArc(x1, y1, x2, y2, xc, yc)           
     2780        elif self.Shape == "ellipticarc": 
     2781            dc.DrawEllipticArc(self.Xpos, self.Ypos, self.Width, self.Height, self.StartAngle, self.EndAngle) 
     2782        elif self.Shape in ("rect", "ellipse"): 
    27182783            w, h = self.Width, self.Height 
    27192784            # If any of these values is -1, use the parent object's size 
     
    27222787            if h < 0: 
    27232788                h = self.Parent.Height 
    2724             dc.DrawRectangle(x, y, w, h) 
     2789            if self.Shape == "rect": 
     2790                dc.DrawRectangle(x, y, w, h) 
     2791            else: 
     2792                dc.DrawEllipse(x, y, w, h) 
    27252793        elif self.Shape in ("polygon", "polylines"): 
    27262794            if self.Shape == "polygon": 
     
    29102978 
    29112979 
     2980    def _getEndAngle(self): 
     2981        return self._endAngle 
     2982 
     2983    def _setEndAngle(self, val): 
     2984        if self._endAngle != val: 
     2985            self._endAngle = val 
     2986            self.update() 
     2987 
     2988 
    29122989    def _getFillColor(self): 
    29132990        return self._fillColor 
     
    31343211         
    31353212         
     3213    def _getStartAngle(self): 
     3214        return self._startAngle 
     3215 
     3216    def _setStartAngle(self, val): 
     3217        if self._startAngle != val: 
     3218            self._startAngle = val 
     3219            self.update() 
     3220 
     3221 
    31363222    def _getText(self): 
    31373223        return self._text 
     
    31853271         
    31863272    Angle = property(_getAngle, _setAngle, None, 
    3187             _("Angle to draw text  (int)")) 
     3273            _("Angle (in degrees) to draw text  (int)")) 
    31883274     
    31893275    BackColor = property(_getBackColor, _setBackColor, None, 
     
    32133299            """)) 
    32143300     
     3301    EndAngle = property(_getEndAngle, _setEndAngle, None, 
     3302            _("Angle (in degrees) used to end drawing a circular arc  (int)")) 
     3303     
    32153304    FillColor = property(_getFillColor, _setFillColor, None, 
    32163305            _("Background color for the shape  (color)")) 
     
    32893378            _("Type of shape to draw  (str)")) 
    32903379 
     3380    StartAngle = property(_getStartAngle, _setStartAngle, None, 
     3381            _("Angle (in degrees) used to start drawing a circular arc  (int)")) 
     3382     
    32913383    Text = property(_getText, _setText, None, 
    32923384            _("Text to be drawn  (str)"))