MCPcopy Create free account
hub / github.com/Image-Py/imagepy / Canvas

Class Canvas

imagepy/ui/canvas.py:53–289  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 output[r,c] = output[r,c]*(1-k)+img[rr,cc]*k
52
53class Canvas (wx.Panel):
54 scales = [0.03125, 0.0625, 0.125, 0.25, 0.5, 0.75, 1, 1.5, 2, 3, 4, 5, 8, 10]
55 def __init__(self, parent ):
56 wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size(300,300), style = wx.TAB_TRAVERSAL )
57 self.initBuffer()
58 self.bindEvents()
59 self.scaleidx = 4
60 self.oldscale = 1
61 self.o = (0, 0)
62 self.reInitBuffer = True
63 self.resized = True
64 self.ips = None
65 self.scrsize = wx.DisplaySize()
66 self.s = 0
67 self.handle = None
68 self.imgbox = [0,0,0,0]
69 self.imgsize = (0,0)
70
71 def set_handler(self, handle=None):
72 self.handle = handle
73
74 def on_mouseevent(self, me):
75 tool = self.ips.tool
76 if tool == None : tool = ToolsManager.curtool
77 x,y = self.to_data_coor(me.GetX(), me.GetY())
78 if me.Moving() and not me.LeftIsDown() and not me.RightIsDown() and not me.MiddleIsDown():
79 xx,yy = int(round(x)), int(round(y))
80 k, unit = self.ips.unit
81 if xx>=0 and xx<self.ips.img.shape[1] and yy>=0 and yy<self.ips.img.shape[0]:
82 IPy.set_info('Location:%.1f %.1f Value:%s'%(x*k, y*k, self.ips.img[yy,xx]))
83 if tool==None:return
84
85 sta = [me.AltDown(), me.ControlDown(), me.ShiftDown()]
86 if me.ButtonDown():tool.mouse_down(self.ips, x, y, me.GetButton(), alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
87 if me.ButtonUp():tool.mouse_up(self.ips, x, y, me.GetButton(), alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
88 if me.Moving():tool.mouse_move(self.ips, x, y, None, alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
89 btn = [me.LeftIsDown(), me.MiddleIsDown(), me.RightIsDown(),True].index(True)
90 if me.Dragging():tool.mouse_move(self.ips, x, y, 0 if btn==3 else btn+1, alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
91 wheel = np.sign(me.GetWheelRotation())
92 if wheel!=0:tool.mouse_wheel(self.ips, x, y, wheel, alt=sta[0], ctrl=sta[1], shift=sta[2], canvas=self)
93 if hasattr(tool, 'cursor'):
94 self.SetCursor(wx.Cursor(tool.cursor))
95 else : self.SetCursor(wx.Cursor(wx.CURSOR_ARROW))
96
97 def bindEvents(self):
98 for event, handler in [ \
99 (wx.EVT_SIZE, self.on_size),
100 (wx.EVT_MOUSE_EVENTS, self.on_mouseevent), # Draw
101 (wx.EVT_IDLE, self.on_idle),
102 (wx.EVT_PAINT, self.on_paint)]: # Start drawing]:
103 self.Bind(event, handler)
104
105 def initBuffer(self):
106 box = self.GetClientSize()
107 #print(self.GetChientSize())
108 self.buffer = wx.Bitmap(box.width, box.height)
109 self.box = [0,0,box[0],box[1]]
110

Callers 1

canvas.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected