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

Method mouse_down

imagepy/tools/Draw/magic_tol.py:40–71  ·  view source on GitHub ↗
(self, ips, x, y, btn, **key)

Source from the content-addressed store, hash-verified

38 self.oper = ''
39
40 def mouse_down(self, ips, x, y, btn, **key):
41 lim = 5.0/key['canvas'].get_scale()
42 if btn==1 or btn==3:
43 if ips.roi!= None:
44 self.curobj = ips.roi.pick(x, y, lim)
45 if not self.curobj in (None,True):return
46 if ips.roi == None:
47 msk = floodfill(ips.img, x, y,
48 self.para['tor'], self.para['con']=='8-connect')
49 conts = find_contours(msk, 0, 'high')
50 ips.roi = shape2roi(polygonize(conts, btn==3))
51 elif hasattr(ips.roi, 'topolygon'):
52 shp = roi2shape(ips.roi.topolygon())
53 oper = ''
54 if key['shift']: oper = '+'
55 elif key['ctrl']: oper = '-'
56 elif self.curobj: return
57 else: ips.roi=None
58
59 msk = floodfill(ips.img, x, y,
60 self.para['tor'], self.para['con']=='8-connect')
61 conts = find_contours(msk, 0, 'high')
62 cur = polygonize(conts, btn==3)
63 if oper == '+':
64 ips.roi = shape2roi(shp.union(cur))
65 elif oper == '-':
66 ips.roi = shape2roi(shp.difference(cur))
67 else: ips.roi = shape2roi(cur)
68
69 else: ips.roi = None
70
71 ips.update()
72
73 def mouse_up(self, ips, x, y, btn, **key):
74 ips.update()

Callers

nothing calls this directly

Calls 9

floodfillFunction · 0.90
shape2roiFunction · 0.90
roi2shapeFunction · 0.90
get_scaleMethod · 0.80
unionMethod · 0.80
polygonizeFunction · 0.70
pickMethod · 0.45
topolygonMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected