diff --git a/SketchWidget.py b/SketchWidget.py index 4e6d923..e992896 100644 --- a/SketchWidget.py +++ b/SketchWidget.py @@ -252,7 +252,7 @@ class SketchWidget: self.view_center[1] - this_pt[1] + start_pt[1]) self.panning_start = (event.x, self.size[1] - event.y) self.queue_redraw() - elif self.drawingShape is not None: + else: if self.mode == 'line': self.do_line_motion(event.x, event.y) elif self.mode == 'circle': @@ -383,31 +383,32 @@ class SketchWidget: self.queue_redraw() def do_line_motion(self, x, y): - this_pt = self.screenPtToPt((x, self.size[1] - y)) - start = self.drawingShape.getPt(0) - angle = math.atan2(this_pt[1] - start[1], this_pt[0] - start[0]) - angle *= 180.0 / math.pi - def within(a, b, d): return abs(a - b) < d - def snaps_to(q): return within(angle, q, self.snap_angle) - hv_snap_dist = self.screenDistToDist(self.hv_snap_dist) - if ((snaps_to(-180) or snaps_to(180) or snaps_to(0)) - and within(start[1], this_pt[1], hv_snap_dist)): - this_pt = (this_pt[0], start[1]) - if not (len(self.drawingConstraints) > 0 - and isinstance(self.drawingConstraints[0], Horizontal)): - c = Horizontal(self.drawingShape, 0, self.drawingShape, 1) - self.drawingConstraints = [c] - elif ((snaps_to(-90) or snaps_to(90)) - and within(start[0], this_pt[0], hv_snap_dist)): - this_pt = (start[0], this_pt[1]) - if not (len(self.drawingConstraints) > 0 - and isinstance(self.drawingConstraints[0], Vertical)): - c = Vertical(self.drawingShape, 0, self.drawingShape, 1) - self.drawingConstraints = [c] - else: - self.drawingConstraints = [] - self.drawingShape.setPt(1, this_pt) - self.queue_redraw() + if self.drawingShape is not None: + this_pt = self.screenPtToPt((x, self.size[1] - y)) + start = self.drawingShape.getPt(0) + angle = math.atan2(this_pt[1] - start[1], this_pt[0] - start[0]) + angle *= 180.0 / math.pi + def within(a, b, d): return abs(a - b) < d + def snaps_to(q): return within(angle, q, self.snap_angle) + hv_snap_dist = self.screenDistToDist(self.hv_snap_dist) + if ((snaps_to(-180) or snaps_to(180) or snaps_to(0)) + and within(start[1], this_pt[1], hv_snap_dist)): + this_pt = (this_pt[0], start[1]) + if not (len(self.drawingConstraints) > 0 + and isinstance(self.drawingConstraints[0], Horizontal)): + c = Horizontal(self.drawingShape, 0, self.drawingShape, 1) + self.drawingConstraints = [c] + elif ((snaps_to(-90) or snaps_to(90)) + and within(start[0], this_pt[0], hv_snap_dist)): + this_pt = (start[0], this_pt[1]) + if not (len(self.drawingConstraints) > 0 + and isinstance(self.drawingConstraints[0], Vertical)): + c = Vertical(self.drawingShape, 0, self.drawingShape, 1) + self.drawingConstraints = [c] + else: + self.drawingConstraints = [] + self.drawingShape.setPt(1, this_pt) + self.queue_redraw() def do_circle_left_click(self, x, y): pt = self.screenPtToPt((x, self.size[1] - y)) @@ -423,10 +424,11 @@ class SketchWidget: self.queue_redraw() def do_circle_motion(self, x, y): - pt = self.screenPtToPt((x, self.size[1] - y)) - r = self.dist_bw(self.drawingShape.getPt(0), pt) - self.drawingShape.setRadius(r) - self.queue_redraw() + if self.drawingShape is not None: + pt = self.screenPtToPt((x, self.size[1] - y)) + r = self.dist_bw(self.drawingShape.getPt(0), pt) + self.drawingShape.setRadius(r) + self.queue_redraw() def cancel_drawing_shape(self): self.drawingShape = None