HistCanvas: diverid from wx.core.Panel
| 6 | if sys.version_info[0]==2:memoryview=np.getbuffer |
| 7 | |
| 8 | class CMapPanel(wx.Panel): |
| 9 | """ HistCanvas: diverid 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(255,30), |
| 13 | style = wx.TAB_TRAVERSAL ) |
| 14 | self.init_buf() |
| 15 | self.offset = (0,0) |
| 16 | self.cmap = np.vstack([np.arange(256)]*3).T.astype(np.uint8) |
| 17 | self.idx = -1 |
| 18 | self.his = None |
| 19 | self.dirty = False |
| 20 | self.pts = [(0,0,0,0), (255,255,255,255)] |
| 21 | self.Bind(wx.EVT_SIZE, self.on_size) |
| 22 | self.Bind(wx.EVT_IDLE, self.on_idle) |
| 23 | self.Bind(wx.EVT_PAINT, self.on_paint) |
| 24 | self.Bind(wx.EVT_LEFT_DOWN, self.on_ld) |
| 25 | self.Bind( wx.EVT_LEFT_UP, self.on_lu ) |
| 26 | self.Bind( wx.EVT_MOTION, self.on_mv ) |
| 27 | self.Bind( wx.EVT_RIGHT_DOWN, self.on_rd ) |
| 28 | self.Bind( wx.EVT_LEFT_DCLICK, self.on_rdc ) |
| 29 | self.handle = self.handle_ |
| 30 | |
| 31 | def update(self): self.dirty = True |
| 32 | |
| 33 | def init_buf(self): |
| 34 | box = self.GetClientSize() |
| 35 | self.buffer = wx.Bitmap(box.width, box.height) |
| 36 | |
| 37 | @classmethod |
| 38 | def linear_color(cls, cs): |
| 39 | cs = sorted(cs) |
| 40 | cmap = np.vstack([np.arange(256)]*3).T |
| 41 | for i in range(1, len(cs)): |
| 42 | c1, c2 = cs[i-1][1:], cs[i][1:] |
| 43 | rs, gs, bs = [np.linspace(c1[j], c2[j], cs[i][0]-cs[i-1][0]+1) for j in (0,1,2)] |
| 44 | cmap[cs[i-1][0]:cs[i][0]+1] = np.array((rs, gs, bs)).T |
| 45 | return cmap.astype(np.uint8) |
| 46 | |
| 47 | def on_size(self, event): |
| 48 | self.init_buf() |
| 49 | self.update() |
| 50 | |
| 51 | def on_idle(self, event): |
| 52 | if self.dirty == True: |
| 53 | self.draw() |
| 54 | self.dirty = False |
| 55 | |
| 56 | def pick(self, x, y): |
| 57 | if abs(y-10)>3:return -1 |
| 58 | dis = np.abs(np.array(self.pts)[:,0]-x) |
| 59 | if dis.min() > 3: return -1 |
| 60 | return np.argmin(dis) |
| 61 | |
| 62 | def on_ld(self, event): |
| 63 | x,y = event.GetX()-self.offset[0], event.GetY()-self.offset[1] |
| 64 | if abs(y-7)>8:return -1 |
| 65 | self.idx = self.pick(x, y) |
no outgoing calls
no test coverage detected