UN-tabbed
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9804 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -34,8 +34,8 @@ distribution). See the Python site (http://www.python.org) for
|
|||||||
information on downloading source or binaries.""",
|
information on downloading source or binaries.""",
|
||||||
"Numeric not found")
|
"Numeric not found")
|
||||||
if d.ShowModal() == wx.wxID_CANCEL:
|
if d.ShowModal() == wx.wxID_CANCEL:
|
||||||
d = wx.wxMessageDialog(wx.NULL, "I kid you not! Pressing Cancel won't help you!", "Not a joke", wx.wxOK)
|
d = wx.wxMessageDialog(wx.NULL, "I kid you not! Pressing Cancel won't help you!", "Not a joke", wx.wxOK)
|
||||||
d.ShowModal()
|
d.ShowModal()
|
||||||
raise ImportError
|
raise ImportError
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -45,7 +45,7 @@ class PolyPoints:
|
|||||||
|
|
||||||
def __init__(self, points, attr):
|
def __init__(self, points, attr):
|
||||||
self.points = Numeric.array(points)
|
self.points = Numeric.array(points)
|
||||||
self.scaled = self.points
|
self.scaled = self.points
|
||||||
self.attributes = {}
|
self.attributes = {}
|
||||||
for name, value in self._attributes.items():
|
for name, value in self._attributes.items():
|
||||||
try:
|
try:
|
||||||
@@ -70,11 +70,11 @@ class PolyLine(PolyPoints):
|
|||||||
'width': 1}
|
'width': 1}
|
||||||
|
|
||||||
def draw(self, dc):
|
def draw(self, dc):
|
||||||
color = self.attributes['color']
|
color = self.attributes['color']
|
||||||
width = self.attributes['width']
|
width = self.attributes['width']
|
||||||
arguments = []
|
arguments = []
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color), width))
|
dc.SetPen(wx.wxPen(wx.wxNamedColour(color), width))
|
||||||
dc.DrawLines(map(tuple,self.scaled))
|
dc.DrawLines(map(tuple,self.scaled))
|
||||||
|
|
||||||
|
|
||||||
class PolyMarker(PolyPoints):
|
class PolyMarker(PolyPoints):
|
||||||
@@ -92,20 +92,20 @@ class PolyMarker(PolyPoints):
|
|||||||
'marker': 'circle'}
|
'marker': 'circle'}
|
||||||
|
|
||||||
def draw(self, dc):
|
def draw(self, dc):
|
||||||
color = self.attributes['color']
|
color = self.attributes['color']
|
||||||
width = self.attributes['width']
|
width = self.attributes['width']
|
||||||
size = self.attributes['size']
|
size = self.attributes['size']
|
||||||
fillcolor = self.attributes['fillcolor']
|
fillcolor = self.attributes['fillcolor']
|
||||||
fillstyle = self.attributes['fillstyle']
|
fillstyle = self.attributes['fillstyle']
|
||||||
marker = self.attributes['marker']
|
marker = self.attributes['marker']
|
||||||
|
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour(color),width))
|
dc.SetPen(wx.wxPen(wx.wxNamedColour(color),width))
|
||||||
if fillcolor:
|
if fillcolor:
|
||||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour(fillcolor),fillstyle))
|
dc.SetBrush(wx.wxBrush(wx.wxNamedColour(fillcolor),fillstyle))
|
||||||
else:
|
else:
|
||||||
dc.SetBrush(wx.wxBrush(wx.wxNamedColour('black'), wx.wxTRANSPARENT))
|
dc.SetBrush(wx.wxBrush(wx.wxNamedColour('black'), wx.wxTRANSPARENT))
|
||||||
|
|
||||||
self._drawmarkers(dc, self.scaled, marker, size)
|
self._drawmarkers(dc, self.scaled, marker, size)
|
||||||
|
|
||||||
def _drawmarkers(self, dc, coords, marker,size=1):
|
def _drawmarkers(self, dc, coords, marker,size=1):
|
||||||
f = eval('self._' +marker)
|
f = eval('self._' +marker)
|
||||||
@@ -113,31 +113,31 @@ class PolyMarker(PolyPoints):
|
|||||||
f(dc, xc, yc, size)
|
f(dc, xc, yc, size)
|
||||||
|
|
||||||
def _circle(self, dc, xc, yc, size=1):
|
def _circle(self, dc, xc, yc, size=1):
|
||||||
dc.DrawEllipse(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
dc.DrawEllipse(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
||||||
|
|
||||||
def _dot(self, dc, xc, yc, size=1):
|
def _dot(self, dc, xc, yc, size=1):
|
||||||
dc.DrawPoint(xc,yc)
|
dc.DrawPoint(xc,yc)
|
||||||
|
|
||||||
def _square(self, dc, xc, yc, size=1):
|
def _square(self, dc, xc, yc, size=1):
|
||||||
dc.DrawRectangle(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
dc.DrawRectangle(xc-2.5*size,yc-2.5*size,5.*size,5.*size)
|
||||||
|
|
||||||
def _triangle(self, dc, xc, yc, size=1):
|
def _triangle(self, dc, xc, yc, size=1):
|
||||||
dc.DrawPolygon([(-0.5*size*5,0.2886751*size*5),
|
dc.DrawPolygon([(-0.5*size*5,0.2886751*size*5),
|
||||||
(0.5*size*5,0.2886751*size*5),
|
(0.5*size*5,0.2886751*size*5),
|
||||||
(0.0,-0.577350*size*5)],xc,yc)
|
(0.0,-0.577350*size*5)],xc,yc)
|
||||||
|
|
||||||
def _triangle_down(self, dc, xc, yc, size=1):
|
def _triangle_down(self, dc, xc, yc, size=1):
|
||||||
dc.DrawPolygon([(-0.5*size*5,-0.2886751*size*5),
|
dc.DrawPolygon([(-0.5*size*5,-0.2886751*size*5),
|
||||||
(0.5*size*5,-0.2886751*size*5),
|
(0.5*size*5,-0.2886751*size*5),
|
||||||
(0.0,0.577350*size*5)],xc,yc)
|
(0.0,0.577350*size*5)],xc,yc)
|
||||||
|
|
||||||
def _cross(self, dc, xc, yc, size=1):
|
def _cross(self, dc, xc, yc, size=1):
|
||||||
dc.DrawLine(xc-2.5*size,yc-2.5*size,xc+2.5*size,yc+2.5*size)
|
dc.DrawLine(xc-2.5*size,yc-2.5*size,xc+2.5*size,yc+2.5*size)
|
||||||
dc.DrawLine(xc-2.5*size,yc+2.5*size,xc+2.5*size,yc-2.5*size)
|
dc.DrawLine(xc-2.5*size,yc+2.5*size,xc+2.5*size,yc-2.5*size)
|
||||||
|
|
||||||
def _plus(self, dc, xc, yc, size=1):
|
def _plus(self, dc, xc, yc, size=1):
|
||||||
dc.DrawLine(xc-2.5*size,yc,xc+2.5*size,yc)
|
dc.DrawLine(xc-2.5*size,yc,xc+2.5*size,yc)
|
||||||
dc.DrawLine(xc,yc-2.5*size,xc,yc+2.5*size)
|
dc.DrawLine(xc,yc-2.5*size,xc,yc+2.5*size)
|
||||||
|
|
||||||
class PlotGraphics:
|
class PlotGraphics:
|
||||||
|
|
||||||
@@ -145,192 +145,192 @@ class PlotGraphics:
|
|||||||
self.objects = objects
|
self.objects = objects
|
||||||
|
|
||||||
def boundingBox(self):
|
def boundingBox(self):
|
||||||
p1, p2 = self.objects[0].boundingBox()
|
p1, p2 = self.objects[0].boundingBox()
|
||||||
for o in self.objects[1:]:
|
for o in self.objects[1:]:
|
||||||
p1o, p2o = o.boundingBox()
|
p1o, p2o = o.boundingBox()
|
||||||
p1 = Numeric.minimum(p1, p1o)
|
p1 = Numeric.minimum(p1, p1o)
|
||||||
p2 = Numeric.maximum(p2, p2o)
|
p2 = Numeric.maximum(p2, p2o)
|
||||||
return p1, p2
|
return p1, p2
|
||||||
|
|
||||||
def scaleAndShift(self, scale=1, shift=0):
|
def scaleAndShift(self, scale=1, shift=0):
|
||||||
for o in self.objects:
|
for o in self.objects:
|
||||||
o.scaleAndShift(scale, shift)
|
o.scaleAndShift(scale, shift)
|
||||||
|
|
||||||
def draw(self, canvas):
|
def draw(self, canvas):
|
||||||
for o in self.objects:
|
for o in self.objects:
|
||||||
o.draw(canvas)
|
o.draw(canvas)
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return len(self.objects)
|
return len(self.objects)
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return self.objects[item]
|
return self.objects[item]
|
||||||
|
|
||||||
|
|
||||||
class PlotCanvas(wx.wxWindow):
|
class PlotCanvas(wx.wxWindow):
|
||||||
|
|
||||||
def __init__(self, parent, id = -1):
|
def __init__(self, parent, id = -1):
|
||||||
wx.wxWindow.__init__(self, parent, id, wx.wxPyDefaultPosition, wx.wxPyDefaultSize)
|
wx.wxWindow.__init__(self, parent, id, wx.wxPyDefaultPosition, wx.wxPyDefaultSize)
|
||||||
self.border = (1,1)
|
self.border = (1,1)
|
||||||
self.SetClientSizeWH(400,400)
|
self.SetClientSizeWH(400,400)
|
||||||
self.SetBackgroundColour(wx.wxNamedColour("white"))
|
self.SetBackgroundColour(wx.wxNamedColour("white"))
|
||||||
|
|
||||||
wx.EVT_SIZE(self,self.reconfigure)
|
wx.EVT_SIZE(self,self.reconfigure)
|
||||||
wx.EVT_PAINT(self, self.OnPaint)
|
wx.EVT_PAINT(self, self.OnPaint)
|
||||||
self._setsize()
|
self._setsize()
|
||||||
self.last_draw = None
|
self.last_draw = None
|
||||||
# self.font = self._testFont(font)
|
# self.font = self._testFont(font)
|
||||||
|
|
||||||
def OnPaint(self, event):
|
def OnPaint(self, event):
|
||||||
pdc = wx.wxPaintDC(self)
|
pdc = wx.wxPaintDC(self)
|
||||||
if self.last_draw is not None:
|
if self.last_draw is not None:
|
||||||
apply(self.draw, self.last_draw + (pdc,))
|
apply(self.draw, self.last_draw + (pdc,))
|
||||||
|
|
||||||
def reconfigure(self, event):
|
def reconfigure(self, event):
|
||||||
(new_width,new_height) = self.GetClientSizeTuple()
|
(new_width,new_height) = self.GetClientSizeTuple()
|
||||||
if new_width == self.width and new_height == self.height:
|
if new_width == self.width and new_height == self.height:
|
||||||
return
|
return
|
||||||
self._setsize()
|
self._setsize()
|
||||||
# self.redraw()
|
# self.redraw()
|
||||||
|
|
||||||
def _testFont(self, font):
|
def _testFont(self, font):
|
||||||
if font is not None:
|
if font is not None:
|
||||||
bg = self.canvas.cget('background')
|
bg = self.canvas.cget('background')
|
||||||
try:
|
try:
|
||||||
item = CanvasText(self.canvas, 0, 0, anchor=NW,
|
item = CanvasText(self.canvas, 0, 0, anchor=NW,
|
||||||
text='0', fill=bg, font=font)
|
text='0', fill=bg, font=font)
|
||||||
self.canvas.delete(item)
|
self.canvas.delete(item)
|
||||||
except TclError:
|
except TclError:
|
||||||
font = None
|
font = None
|
||||||
return font
|
return font
|
||||||
|
|
||||||
def _setsize(self):
|
def _setsize(self):
|
||||||
(self.width,self.height) = self.GetClientSizeTuple();
|
(self.width,self.height) = self.GetClientSizeTuple();
|
||||||
self.plotbox_size = 0.97*Numeric.array([self.width, -self.height])
|
self.plotbox_size = 0.97*Numeric.array([self.width, -self.height])
|
||||||
xo = 0.5*(self.width-self.plotbox_size[0])
|
xo = 0.5*(self.width-self.plotbox_size[0])
|
||||||
yo = self.height-0.5*(self.height+self.plotbox_size[1])
|
yo = self.height-0.5*(self.height+self.plotbox_size[1])
|
||||||
self.plotbox_origin = Numeric.array([xo, yo])
|
self.plotbox_origin = Numeric.array([xo, yo])
|
||||||
|
|
||||||
def draw(self, graphics, xaxis = None, yaxis = None, dc = None):
|
def draw(self, graphics, xaxis = None, yaxis = None, dc = None):
|
||||||
if dc == None: dc = wx.wxClientDC(self)
|
if dc == None: dc = wx.wxClientDC(self)
|
||||||
dc.BeginDrawing()
|
dc.BeginDrawing()
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
self.last_draw = (graphics, xaxis, yaxis)
|
self.last_draw = (graphics, xaxis, yaxis)
|
||||||
p1, p2 = graphics.boundingBox()
|
p1, p2 = graphics.boundingBox()
|
||||||
xaxis = self._axisInterval(xaxis, p1[0], p2[0])
|
xaxis = self._axisInterval(xaxis, p1[0], p2[0])
|
||||||
yaxis = self._axisInterval(yaxis, p1[1], p2[1])
|
yaxis = self._axisInterval(yaxis, p1[1], p2[1])
|
||||||
text_width = [0., 0.]
|
text_width = [0., 0.]
|
||||||
text_height = [0., 0.]
|
text_height = [0., 0.]
|
||||||
if xaxis is not None:
|
if xaxis is not None:
|
||||||
p1[0] = xaxis[0]
|
p1[0] = xaxis[0]
|
||||||
p2[0] = xaxis[1]
|
p2[0] = xaxis[1]
|
||||||
xticks = self._ticks(xaxis[0], xaxis[1])
|
xticks = self._ticks(xaxis[0], xaxis[1])
|
||||||
bb = dc.GetTextExtent(xticks[0][1])
|
bb = dc.GetTextExtent(xticks[0][1])
|
||||||
text_height[1] = bb[1]
|
text_height[1] = bb[1]
|
||||||
text_width[0] = 0.5*bb[0]
|
text_width[0] = 0.5*bb[0]
|
||||||
bb = dc.GetTextExtent(xticks[-1][1])
|
bb = dc.GetTextExtent(xticks[-1][1])
|
||||||
text_width[1] = 0.5*bb[0]
|
text_width[1] = 0.5*bb[0]
|
||||||
else:
|
else:
|
||||||
xticks = None
|
xticks = None
|
||||||
if yaxis is not None:
|
if yaxis is not None:
|
||||||
p1[1] = yaxis[0]
|
p1[1] = yaxis[0]
|
||||||
p2[1] = yaxis[1]
|
p2[1] = yaxis[1]
|
||||||
yticks = self._ticks(yaxis[0], yaxis[1])
|
yticks = self._ticks(yaxis[0], yaxis[1])
|
||||||
for y in yticks:
|
for y in yticks:
|
||||||
bb = dc.GetTextExtent(y[1])
|
bb = dc.GetTextExtent(y[1])
|
||||||
text_width[0] = max(text_width[0],bb[0])
|
text_width[0] = max(text_width[0],bb[0])
|
||||||
h = 0.5*bb[1]
|
h = 0.5*bb[1]
|
||||||
text_height[0] = h
|
text_height[0] = h
|
||||||
text_height[1] = max(text_height[1], h)
|
text_height[1] = max(text_height[1], h)
|
||||||
else:
|
else:
|
||||||
yticks = None
|
yticks = None
|
||||||
text1 = Numeric.array([text_width[0], -text_height[1]])
|
text1 = Numeric.array([text_width[0], -text_height[1]])
|
||||||
text2 = Numeric.array([text_width[1], -text_height[0]])
|
text2 = Numeric.array([text_width[1], -text_height[0]])
|
||||||
scale = (self.plotbox_size-text1-text2) / (p2-p1)
|
scale = (self.plotbox_size-text1-text2) / (p2-p1)
|
||||||
shift = -p1*scale + self.plotbox_origin + text1
|
shift = -p1*scale + self.plotbox_origin + text1
|
||||||
self._drawAxes(dc, xaxis, yaxis, p1, p2,
|
self._drawAxes(dc, xaxis, yaxis, p1, p2,
|
||||||
scale, shift, xticks, yticks)
|
scale, shift, xticks, yticks)
|
||||||
graphics.scaleAndShift(scale, shift)
|
graphics.scaleAndShift(scale, shift)
|
||||||
graphics.draw(dc)
|
graphics.draw(dc)
|
||||||
dc.EndDrawing()
|
dc.EndDrawing()
|
||||||
|
|
||||||
def _axisInterval(self, spec, lower, upper):
|
def _axisInterval(self, spec, lower, upper):
|
||||||
if spec is None:
|
if spec is None:
|
||||||
return None
|
return None
|
||||||
if spec == 'minimal':
|
if spec == 'minimal':
|
||||||
if lower == upper:
|
if lower == upper:
|
||||||
return lower-0.5, upper+0.5
|
return lower-0.5, upper+0.5
|
||||||
else:
|
else:
|
||||||
return lower, upper
|
return lower, upper
|
||||||
if spec == 'automatic':
|
if spec == 'automatic':
|
||||||
range = upper-lower
|
range = upper-lower
|
||||||
if range == 0.:
|
if range == 0.:
|
||||||
return lower-0.5, upper+0.5
|
return lower-0.5, upper+0.5
|
||||||
log = Numeric.log10(range)
|
log = Numeric.log10(range)
|
||||||
power = Numeric.floor(log)
|
power = Numeric.floor(log)
|
||||||
fraction = log-power
|
fraction = log-power
|
||||||
if fraction <= 0.05:
|
if fraction <= 0.05:
|
||||||
power = power-1
|
power = power-1
|
||||||
grid = 10.**power
|
grid = 10.**power
|
||||||
lower = lower - lower % grid
|
lower = lower - lower % grid
|
||||||
mod = upper % grid
|
mod = upper % grid
|
||||||
if mod != 0:
|
if mod != 0:
|
||||||
upper = upper - mod + grid
|
upper = upper - mod + grid
|
||||||
return lower, upper
|
return lower, upper
|
||||||
if type(spec) == type(()):
|
if type(spec) == type(()):
|
||||||
lower, upper = spec
|
lower, upper = spec
|
||||||
if lower <= upper:
|
if lower <= upper:
|
||||||
return lower, upper
|
return lower, upper
|
||||||
else:
|
else:
|
||||||
return upper, lower
|
return upper, lower
|
||||||
raise ValueError, str(spec) + ': illegal axis specification'
|
raise ValueError, str(spec) + ': illegal axis specification'
|
||||||
|
|
||||||
def _drawAxes(self, dc, xaxis, yaxis,
|
def _drawAxes(self, dc, xaxis, yaxis,
|
||||||
bb1, bb2, scale, shift, xticks, yticks):
|
bb1, bb2, scale, shift, xticks, yticks):
|
||||||
dc.SetPen(wx.wxPen(wx.wxNamedColour('BLACK'),1))
|
dc.SetPen(wx.wxPen(wx.wxNamedColour('BLACK'),1))
|
||||||
if xaxis is not None:
|
if xaxis is not None:
|
||||||
lower, upper = xaxis
|
lower, upper = xaxis
|
||||||
text = 1
|
text = 1
|
||||||
for y, d in [(bb1[1], -3), (bb2[1], 3)]:
|
for y, d in [(bb1[1], -3), (bb2[1], 3)]:
|
||||||
p1 = scale*Numeric.array([lower, y])+shift
|
p1 = scale*Numeric.array([lower, y])+shift
|
||||||
p2 = scale*Numeric.array([upper, y])+shift
|
p2 = scale*Numeric.array([upper, y])+shift
|
||||||
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
||||||
for x, label in xticks:
|
for x, label in xticks:
|
||||||
p = scale*Numeric.array([x, y])+shift
|
p = scale*Numeric.array([x, y])+shift
|
||||||
dc.DrawLine(p[0],p[1],p[0],p[1]+d)
|
dc.DrawLine(p[0],p[1],p[0],p[1]+d)
|
||||||
if text:
|
if text:
|
||||||
dc.DrawText(label,p[0],p[1])
|
dc.DrawText(label,p[0],p[1])
|
||||||
text = 0
|
text = 0
|
||||||
|
|
||||||
if yaxis is not None:
|
if yaxis is not None:
|
||||||
lower, upper = yaxis
|
lower, upper = yaxis
|
||||||
text = 1
|
text = 1
|
||||||
h = dc.GetCharHeight()
|
h = dc.GetCharHeight()
|
||||||
for x, d in [(bb1[0], -3), (bb2[0], 3)]:
|
for x, d in [(bb1[0], -3), (bb2[0], 3)]:
|
||||||
p1 = scale*Numeric.array([x, lower])+shift
|
p1 = scale*Numeric.array([x, lower])+shift
|
||||||
p2 = scale*Numeric.array([x, upper])+shift
|
p2 = scale*Numeric.array([x, upper])+shift
|
||||||
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
dc.DrawLine(p1[0],p1[1],p2[0],p2[1])
|
||||||
for y, label in yticks:
|
for y, label in yticks:
|
||||||
p = scale*Numeric.array([x, y])+shift
|
p = scale*Numeric.array([x, y])+shift
|
||||||
dc.DrawLine(p[0],p[1],p[0]-d,p[1])
|
dc.DrawLine(p[0],p[1],p[0]-d,p[1])
|
||||||
if text:
|
if text:
|
||||||
dc.DrawText(label,p[0]-dc.GetTextExtent(label)[0],
|
dc.DrawText(label,p[0]-dc.GetTextExtent(label)[0],
|
||||||
p[1]-0.5*h)
|
p[1]-0.5*h)
|
||||||
text = 0
|
text = 0
|
||||||
|
|
||||||
def _ticks(self, lower, upper):
|
def _ticks(self, lower, upper):
|
||||||
ideal = (upper-lower)/7.
|
ideal = (upper-lower)/7.
|
||||||
log = Numeric.log10(ideal)
|
log = Numeric.log10(ideal)
|
||||||
power = Numeric.floor(log)
|
power = Numeric.floor(log)
|
||||||
fraction = log-power
|
fraction = log-power
|
||||||
factor = 1.
|
factor = 1.
|
||||||
error = fraction
|
error = fraction
|
||||||
for f, lf in self._multiples:
|
for f, lf in self._multiples:
|
||||||
e = Numeric.fabs(fraction-lf)
|
e = Numeric.fabs(fraction-lf)
|
||||||
if e < error:
|
if e < error:
|
||||||
error = e
|
error = e
|
||||||
factor = f
|
factor = f
|
||||||
grid = factor * 10.**power
|
grid = factor * 10.**power
|
||||||
if power > 3 or power < -3:
|
if power > 3 or power < -3:
|
||||||
format = '%+7.0e'
|
format = '%+7.0e'
|
||||||
elif power >= 0:
|
elif power >= 0:
|
||||||
@@ -339,18 +339,18 @@ class PlotCanvas(wx.wxWindow):
|
|||||||
else:
|
else:
|
||||||
digits = -int(power)
|
digits = -int(power)
|
||||||
format = '%'+`digits+2`+'.'+`digits`+'f'
|
format = '%'+`digits+2`+'.'+`digits`+'f'
|
||||||
ticks = []
|
ticks = []
|
||||||
t = -grid*Numeric.floor(-lower/grid)
|
t = -grid*Numeric.floor(-lower/grid)
|
||||||
while t <= upper:
|
while t <= upper:
|
||||||
ticks.append( (t, format % (t,)) )
|
ticks.append( (t, format % (t,)) )
|
||||||
t = t + grid
|
t = t + grid
|
||||||
return ticks
|
return ticks
|
||||||
|
|
||||||
_multiples = [(2., Numeric.log10(2.)), (5., Numeric.log10(5.))]
|
_multiples = [(2., Numeric.log10(2.)), (5., Numeric.log10(5.))]
|
||||||
|
|
||||||
def redraw(self,dc=None):
|
def redraw(self,dc=None):
|
||||||
if self.last_draw is not None:
|
if self.last_draw is not None:
|
||||||
apply(self.draw, self.last_draw + (dc,))
|
apply(self.draw, self.last_draw + (dc,))
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.canvas.delete('all')
|
self.canvas.delete('all')
|
||||||
@@ -386,75 +386,75 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
|
|
||||||
class AppFrame(wx.wxFrame):
|
class AppFrame(wx.wxFrame):
|
||||||
def __init__(self, parent, id, title):
|
def __init__(self, parent, id, title):
|
||||||
wx.wxFrame.__init__(self, parent, id, title,
|
wx.wxFrame.__init__(self, parent, id, title,
|
||||||
wx.wxPyDefaultPosition, wx.wxSize(400, 400))
|
wx.wxPyDefaultPosition, wx.wxSize(400, 400))
|
||||||
|
|
||||||
# Now Create the menu bar and items
|
# Now Create the menu bar and items
|
||||||
self.mainmenu = wx.wxMenuBar()
|
self.mainmenu = wx.wxMenuBar()
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.wxMenu()
|
||||||
menu.Append(200, '&Print...', 'Print the current plot')
|
menu.Append(200, '&Print...', 'Print the current plot')
|
||||||
wx.EVT_MENU(self, 200, self.OnFilePrint)
|
wx.EVT_MENU(self, 200, self.OnFilePrint)
|
||||||
menu.Append(209, 'E&xit', 'Enough of this already!')
|
menu.Append(209, 'E&xit', 'Enough of this already!')
|
||||||
wx.EVT_MENU(self, 209, self.OnFileExit)
|
wx.EVT_MENU(self, 209, self.OnFileExit)
|
||||||
self.mainmenu.Append(menu, '&File')
|
self.mainmenu.Append(menu, '&File')
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.wxMenu()
|
||||||
menu.Append(210, '&Draw', 'Draw plots')
|
menu.Append(210, '&Draw', 'Draw plots')
|
||||||
wx.EVT_MENU(self,210,self.OnPlotDraw)
|
wx.EVT_MENU(self,210,self.OnPlotDraw)
|
||||||
menu.Append(211, '&Redraw', 'Redraw plots')
|
menu.Append(211, '&Redraw', 'Redraw plots')
|
||||||
wx.EVT_MENU(self,211,self.OnPlotRedraw)
|
wx.EVT_MENU(self,211,self.OnPlotRedraw)
|
||||||
menu.Append(212, '&Clear', 'Clear canvas')
|
menu.Append(212, '&Clear', 'Clear canvas')
|
||||||
wx.EVT_MENU(self,212,self.OnPlotClear)
|
wx.EVT_MENU(self,212,self.OnPlotClear)
|
||||||
self.mainmenu.Append(menu, '&Plot')
|
self.mainmenu.Append(menu, '&Plot')
|
||||||
|
|
||||||
menu = wx.wxMenu()
|
menu = wx.wxMenu()
|
||||||
menu.Append(220, '&About', 'About this thing...')
|
menu.Append(220, '&About', 'About this thing...')
|
||||||
wx.EVT_MENU(self, 220, self.OnHelpAbout)
|
wx.EVT_MENU(self, 220, self.OnHelpAbout)
|
||||||
self.mainmenu.Append(menu, '&Help')
|
self.mainmenu.Append(menu, '&Help')
|
||||||
|
|
||||||
self.SetMenuBar(self.mainmenu)
|
self.SetMenuBar(self.mainmenu)
|
||||||
|
|
||||||
# A status bar to tell people what's happening
|
# A status bar to tell people what's happening
|
||||||
self.CreateStatusBar(1)
|
self.CreateStatusBar(1)
|
||||||
|
|
||||||
self.client = PlotCanvas(self)
|
self.client = PlotCanvas(self)
|
||||||
|
|
||||||
def OnFilePrint(self, event):
|
def OnFilePrint(self, event):
|
||||||
d = wx.wxMessageDialog(self,
|
d = wx.wxMessageDialog(self,
|
||||||
"""As of this writing, printing support in wxPython is shaky at best.
|
"""As of this writing, printing support in wxPython is shaky at best.
|
||||||
Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
Are you sure you want to do this?""", "Danger!", wx.wxYES_NO)
|
||||||
if d.ShowModal() == wx.wxID_YES:
|
if d.ShowModal() == wx.wxID_YES:
|
||||||
psdc = wx.wxPostScriptDC("out.ps", wx.TRUE, self)
|
psdc = wx.wxPostScriptDC("out.ps", wx.TRUE, self)
|
||||||
self.client.redraw(psdc)
|
self.client.redraw(psdc)
|
||||||
|
|
||||||
def OnFileExit(self, event):
|
def OnFileExit(self, event):
|
||||||
self.Close()
|
self.Close()
|
||||||
|
|
||||||
def OnPlotDraw(self, event):
|
def OnPlotDraw(self, event):
|
||||||
self.client.draw(_InitObjects(),'automatic','automatic');
|
self.client.draw(_InitObjects(),'automatic','automatic');
|
||||||
|
|
||||||
def OnPlotRedraw(self,event):
|
def OnPlotRedraw(self,event):
|
||||||
self.client.redraw()
|
self.client.redraw()
|
||||||
|
|
||||||
def OnPlotClear(self,event):
|
def OnPlotClear(self,event):
|
||||||
self.client.last_draw = None
|
self.client.last_draw = None
|
||||||
dc = wx.wxClientDC(self.client)
|
dc = wx.wxClientDC(self.client)
|
||||||
dc.Clear()
|
dc.Clear()
|
||||||
|
|
||||||
def OnHelpAbout(self, event):
|
def OnHelpAbout(self, event):
|
||||||
about = wx.wxMessageDialog(self, __doc__, "About...", wx.wxOK)
|
about = wx.wxMessageDialog(self, __doc__, "About...", wx.wxOK)
|
||||||
about.ShowModal()
|
about.ShowModal()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MyApp(wx.wxApp):
|
class MyApp(wx.wxApp):
|
||||||
def OnInit(self):
|
def OnInit(self):
|
||||||
frame = AppFrame(wx.NULL, -1, "wxPlotCanvas")
|
frame = AppFrame(wx.NULL, -1, "wxPlotCanvas")
|
||||||
frame.Show(wx.TRUE)
|
frame.Show(wx.TRUE)
|
||||||
self.SetTopWindow(frame)
|
self.SetTopWindow(frame)
|
||||||
return wx.TRUE
|
return wx.TRUE
|
||||||
|
|
||||||
|
|
||||||
app = MyApp(0)
|
app = MyApp(0)
|
||||||
|
Reference in New Issue
Block a user