| 107 | |
| 108 | |
| 109 | class SvgDraggablePoint(gui.SvgRectangle, DraggableItem): |
| 110 | def __init__(self, app_instance, name_coord_x, name_coord_y, compatibility_iterable, **kwargs): |
| 111 | self.w = 15 |
| 112 | self.h = 15 |
| 113 | super(SvgDraggablePoint, self).__init__(0, 0, self.w, self.h, **kwargs) |
| 114 | DraggableItem.__init__(self, app_instance, **kwargs) |
| 115 | self.attributes['stroke-dasharray'] = "2,2" |
| 116 | self.name_coord_x = name_coord_x |
| 117 | self.name_coord_y = name_coord_y |
| 118 | self.set_stroke(1, 'black') |
| 119 | self.set_fill('#ffcc00') |
| 120 | self.compatibility_iterable = compatibility_iterable |
| 121 | self.onmousedown.do(self.start_drag) |
| 122 | |
| 123 | def setup(self, refWidget, newParent): |
| 124 | if type(refWidget) in self.compatibility_iterable or refWidget == None: |
| 125 | DraggableItem.setup(self, refWidget, newParent) |
| 126 | |
| 127 | def on_drag(self, emitter, x, y): |
| 128 | if self.active: |
| 129 | if self.origin_x == -1: |
| 130 | self.origin_x = float(x) |
| 131 | self.origin_y = float(y) |
| 132 | self.refWidget_origin_x = float( |
| 133 | self.refWidget.attributes[self.name_coord_x]) |
| 134 | self.refWidget_origin_y = float( |
| 135 | self.refWidget.attributes[self.name_coord_y]) |
| 136 | else: |
| 137 | self.refWidget.attributes[self.name_coord_x] = self.round_grid( |
| 138 | self.refWidget_origin_x + float(x) - self.origin_x) |
| 139 | self.refWidget.attributes[self.name_coord_y] = self.round_grid( |
| 140 | self.refWidget_origin_y + float(y) - self.origin_y) |
| 141 | self.update_position() |
| 142 | |
| 143 | def update_position(self): |
| 144 | if self.refWidget: |
| 145 | self.set_position(float(self.refWidget.attributes[self.name_coord_x])-self.w/2, float( |
| 146 | self.refWidget.attributes[self.name_coord_y])-self.h/2) |
| 147 | |
| 148 | |
| 149 | class SvgDraggableRectangleResizePoint(gui.SvgRectangle, DraggableItem): |