| 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() |