Thanks. Been meaning to refactor this class for a while...

Nate

Sent from my iPhone

On Nov 24, 2011, at 8:40 PM, Ed Leafe <[email protected]> wrote:

> dabo Commit
> Revision 6978
> Date: 2011-11-24 17:40:02 -0800 (Thu, 24 Nov 2011)
> Author: Ed
> Trac: http://trac.dabodev.com/changeset/6978
> 
> Changed:
> U   trunk/dabo/ui/uiwx/dLinePlot.py
> 
> Log:
> No functional changes; just style standardization.
> 
> I saw the line "if len(self.Traces) != 0:" in the previous changeset, and 
> went to correct it to the more succinct "if self.Traces:". While in the code 
> I noticed a lot of style inconsistencies, so I cleaned up as many as I 
> noticed.
> 
> 
> Diff:
> Modified: trunk/dabo/ui/uiwx/dLinePlot.py
> ===================================================================
> --- trunk/dabo/ui/uiwx/dLinePlot.py    2011-11-25 00:56:11 UTC (rev 6977)
> +++ trunk/dabo/ui/uiwx/dLinePlot.py    2011-11-25 01:40:02 UTC (rev 6978)
> @@ -21,6 +21,7 @@
> from dabo.lib.utils import ustr
> 
> 
> +
> class _TraceMixin(object):
>        #Property Getters and Setters
>    def _getCaption(self):
> @@ -35,7 +36,7 @@
> 
>    def _setPoints(self, val):
>        for point in val:
> -            if not (point is tuple and len(point)==2):
> +            if not ((point is tuple) and (len(point) == 2)):
>                raise ValueError('Points must be tuples of length 2')
> 
> 
> @@ -67,11 +68,13 @@
>            _("The width of the plotted trace (default=1) (int)"))
> 
> 
> -class plotLine(_TraceMixin, plot.PolyLine):
> +
> +class PlotLine(_TraceMixin, plot.PolyLine):
>    def __init__(self, *args, **kwargs):
>        self._lineStyle = "solid"
>        plot.PolyLine.__init__(self, *args, **kwargs)
> 
> +
>    #Property Getters and Setters
>    def _getLineStyle(self):
>        return self._lineStyle
> @@ -89,11 +92,13 @@
>            _("The drawn style of the plotted line (default='solid') ('solid', 
> 'dot', or 'dash')"))
> 
> 
> -class plotMarkers(_TraceMixin, plot.PolyMarker):
> +
> +class PlotMarkers(_TraceMixin, plot.PolyMarker):
>    def __init__(self, *args, **kwargs):
>        self._fillStyle = "solid"
>        plot.PolyMarker.__init__(self, *args, **kwargs)
> 
> +
>    #Property getters and setters
>    def _getFillStyle(self):
>        return self._fillStyle
> @@ -143,6 +148,7 @@
>            _("The size of the marker (default=2) (int)"))
> 
> 
> +
> class dLinePlot(cm.dControlMixin, plot.PlotCanvas):
>    """Creates a panel that can load and display a line graph."""
>    def __init__(self, parent, properties=None, attProperties=None, *args, 
> **kwargs):
> @@ -157,46 +163,42 @@
>                attProperties=attProperties, _explicitName=_explicitName, 
> *args, **kwargs)
> 
>        self.SetPointLabelFunc(self.DrawPointLabel)
> -
>        self.setDefaults()
> -        if len(self.Traces) != 0:
> +        if self.Traces:
>            self.Draw(self._plotManager)
> 
> +
>    def appendLineFromEquation(self, equation, Start, End, points=1000.0, 
> LineColor='black', LineStyle='solid',
> -                               LineWidth=1, Caption=""):
> +                LineWidth=1, Caption=""):
>        spacing = (float(End) - float(Start))/float(points)
> -        pointList = Start+_Numeric.arange(points)*spacing
> +        pointList = Start + (_Numeric.arange(points) * spacing)
>        coordinates = []
> -
>        s = "value = %s" % equation
> -
>        for index in range(len(pointList)):
>            exec(s % pointList[index])
>            coordinates.append((pointList[index], value))
> -
>        self.appendLineFromPoints(coordinates, LineColor, LineStyle, 
> LineWidth, Caption)
> 
> +
>    def appendLineFromPoints(self, points, LineColor='black', 
> LineStyle='solid', LineWidth=1, Caption=""):
>        if Caption == "":
>            Caption = "Line %s" % len(self.Traces)
> -
> -        line = plotLine(points, legend=Caption, colour=LineColor, 
> width=LineWidth)
> +        line = PlotLine(points, legend=Caption, colour=LineColor, 
> width=LineWidth)
>        line.LineStyle = LineStyle
> -
>        self.Traces.append(line)
>        self.Redraw()
> 
> +
>    def appendMarkerFromPoints(self, points, Color='black', 
> MarkerShape='circle', Width=1,
> -                               FillStyle='solid', MarkerSize=2, Caption=""):
> +                FillStyle='solid', MarkerSize=2, Caption=""):
>        if Caption == "":
>            Caption = "Set %s" % len(self.Traces)
> -
> -        marker = plotMarkers(points, legend=Caption, colour=Color, 
> width=Width, marker=MarkerShape, size=MarkerSize)
> +        marker = PlotMarkers(points, legend=Caption, colour=Color, 
> width=Width, marker=MarkerShape, size=MarkerSize)
>        marker.FillStyle = FillStyle
> -
>        self.Traces.append(marker)
>        self.Redraw()
> 
> +
>    def OnSize(self,event):
>        # The Buffer init is done here, to make sure the buffer is always
>        # the same size as the Window
> @@ -209,14 +211,15 @@
>        # a file, or whatever.
>        self._Buffer = wx.EmptyBitmap(Size.width, Size.height)
>        plot.PlotCanvas._setSize(self)
> +        # Reset PointLable
> +        self.last_PointLabel = None
> 
> -        self.last_PointLabel = None        #reset pointLabel
> -
>        if self.last_draw is None:
>            self.Clear()
>        else:
>            self.Draw(self._plotManager)
> 
> +
>    def DrawPointLabel(self, dc, mDataDict):
>        """
>        This is the fuction that defines how the pointLabels are plotted
> @@ -232,17 +235,20 @@
>        dc.SetPen(wx.Pen(wx.BLACK))
>        dc.SetBrush(wx.Brush( wx.BLACK, wx.SOLID ) )
> 
> -        sx, sy = mDataDict["scaledXY"] #scaled x,y of closest point
> -        dc.DrawRectangle( sx-5,sy-5, 10, 10)  #10by10 square centered on 
> point
> +        # scaled x,y of closest point
> +        sx, sy = mDataDict["scaledXY"] 
> +        # 10by10 square centered on point
> +        dc.DrawRectangle(sx-5, sy-5, 10, 10)
>        px,py = mDataDict["pointXY"]
>        cNum = mDataDict["curveNum"]
>        pntIn = mDataDict["pIndex"]
>        legend = mDataDict["legend"]
> -        #make a string to display
> +        # make a string to display
>        s = "Crv# %i, '%s', Pt. (%.2f,%.2f), PtInd %i" %(cNum, legend, px, py, 
> pntIn)
>        dc.DrawText(s, sx , sy+1)
>        # -----------
> 
> +
>    def setDefaults(self):
>        self.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
>        self.SetFontSizeAxis(10)
> @@ -251,6 +257,7 @@
>        self.SetXSpec('auto')
>        self.SetYSpec('auto')
> 
> +
>    #Property getters and setters
>    def _getAxisFontSize(self):
>        return self._fontSizeAxis
> @@ -503,15 +510,17 @@
>        'auto' - rounds axis range to sensible values"""))
> 
> 
> +
> class _dLinePlot_test(dLinePlot):
>    def initProperties(self):
>        self.XAxisLabel = "X Axis"
>        self.YAxisLabel = "Y Axis"
>        self.Caption = "Title of Graph"
> 
> +
>    def afterInit(self):
>        # 1000 points cos function, plotted as blue line
> -        self.appendLineFromEquation("2*_Numeric.cos(%s)", 5, 10, 
> Caption="Blue Line", LineWidth=2, LineColor='blue')
> +        self.appendLineFromEquation("2*_Numeric.cos(%s)", 5, 10, 
> Caption="Blue Line", LineWidth=2, LineColor="blue")
> 
>        line = []
>        for i in range(10):
> @@ -529,7 +538,6 @@
> 
> 
> 
> -
> if __name__ == "__main__":
>    import test
>    test.Test().runTest(_dLinePlot_test)
> 
> 
> 
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: http://leafe.com/archives/search/dabo-dev
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to