LineCanvas: derived from wx.core.Panel
| 6 | from ..core.manager import PlotManager |
| 7 | |
| 8 | class LineCanvas(wx.Panel): |
| 9 | """LineCanvas: derived from wx.core.Panel""" |
| 10 | def __init__(self, parent): |
| 11 | wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, |
| 12 | pos = wx.DefaultPosition, size = wx.Size(256,80), |
| 13 | style = wx.SIMPLE_BORDER|wx.TAB_TRAVERSAL ) |
| 14 | self.init_buf() |
| 15 | self.data, self.extent = [], [0,0,1,1] |
| 16 | self.set_title_label('Graph', 'X-unit', 'Y-unit') |
| 17 | self.dirty = False |
| 18 | |
| 19 | self.SetBackgroundColour( wx.Colour( 255, 255, 255 ) ) |
| 20 | self.Bind(wx.EVT_SIZE, self.on_size) |
| 21 | self.Bind(wx.EVT_PAINT, self.on_paint) |
| 22 | self.Bind(wx.EVT_IDLE, self.on_idle) |
| 23 | self.Bind(wx.EVT_MOTION, self.on_move ) |
| 24 | |
| 25 | def update(self):self.dirty = True |
| 26 | |
| 27 | def init_buf(self): |
| 28 | box = self.GetClientSize() |
| 29 | self.width, self.height = box.width, box.height |
| 30 | self.buffer = wx.Bitmap(self.width, self.height) |
| 31 | |
| 32 | def on_size(self, event): |
| 33 | self.init_buf() |
| 34 | self.draw() |
| 35 | |
| 36 | def on_paint(self, event): |
| 37 | wx.BufferedPaintDC(self, self.buffer) |
| 38 | |
| 39 | def trans(self, x, y): |
| 40 | l, t, r, b = 35,35,15,35 |
| 41 | w = self.width - l - r |
| 42 | h = self.height - t - b |
| 43 | left, low, right, high = self.extent |
| 44 | x = (x-l)*1.0/w*(right-left)+left |
| 45 | y = (t+h-y)*1.0/(h)*(high-low)+low |
| 46 | return x, y |
| 47 | |
| 48 | def clear(self): |
| 49 | del self.data[:] |
| 50 | |
| 51 | def on_move(self, event): |
| 52 | self.handle_move(*self.trans(event.x, event.y)) |
| 53 | |
| 54 | def handle_move(self, x, y):pass |
| 55 | |
| 56 | def on_idle(self, event): |
| 57 | if self.dirty == True: |
| 58 | self.draw() |
| 59 | self.dirty = False |
| 60 | |
| 61 | def set_title_label(self, title, labelx, labely): |
| 62 | self.title, self.labelx, self.labely = title, labelx, labely |
| 63 | |
| 64 | def paint(self): |
| 65 | if len(self.data)==0 : |