Exemplo n.º 1
0
class PolygonDrawer(EditorActor):
    def __init__(self, editor, bundle, polygon_receiver, field = QQ):
        EditorActor.__init__(self, editor)        
        self.polygon_receiver=polygon_receiver
        self._pc=PolygonCreator(field)
        self._v=[]
        self._bundle=bundle
    def on_activate(self):
        self._editor.set_text("Left click to start drawing a polygon.")
    def on_deactivate(self):
        self._editor.get_canvas().delete("PolygonDrawer")

    def single_left_click(self, event):
        x = self._editor.get_canvas().canvasx(event.x)
        y = self._editor.get_canvas().canvasy(event.y)
        newv=self._bundle.screen_to_math_coordinates(x,y)
        if self._pc.add_vertex(newv):
            self._v.append(x)
            self._v.append(y)
            self._editor.get_canvas().delete("PolygonDrawer")
            if (len(self._v)==2):
                self._editor.get_canvas().create_oval(x-2,y-2,x+2,y+2,outline="",fill="#f70",tags="PolygonDrawer")
            else:
                self._editor.get_canvas().create_line(self._v,fill="#f70",tags="PolygonDrawer")
            if (len(self._v)<=4):
                self._editor.set_text("Left click again to choose a new vertex.")
            else:
                self._editor.set_text("Click again, or press return to stop.")
        else:
            self._editor.set_text("That point would make the polygon non-convex.")

    def key_press(self, event):
        if event.keycode==36:
            self.polygon_receiver(self._pc.get_polygon(),self._v[0],self._v[1])
            self._editor.get_canvas().delete("PolygonDrawer")
            self._editor.set_actor(None)
Exemplo n.º 2
0
class PolygonDrawer(EditorActor):
    def __init__(self, editor, bundle, polygon_receiver, field = QQ):
        EditorActor.__init__(self, editor)        
        self.polygon_receiver=polygon_receiver
        self._pc=PolygonCreator(field)
        self._v=[]
        self._bundle=bundle
    def on_activate(self):
        self._editor.set_text("Left click to start drawing a polygon.")
    def on_deactivate(self):
        self._editor.get_canvas().delete("PolygonDrawer")

    def single_left_click(self, event):
        x = self._editor.get_canvas().canvasx(event.x)
        y = self._editor.get_canvas().canvasy(event.y)
        newv=self._bundle.screen_to_math_coordinates(x,y)
        if self._pc.add_vertex(newv):
            self._v.append(x)
            self._v.append(y)
            self._editor.get_canvas().delete("PolygonDrawer")
            if (len(self._v)==2):
                self._editor.get_canvas().create_oval(x-2,y-2,x+2,y+2,outline="",fill="#f70",tags="PolygonDrawer")
            else:
                self._editor.get_canvas().create_line(self._v,fill="#f70",tags="PolygonDrawer")
            if (len(self._v)<=4):
                self._editor.set_text("Left click again to choose a new vertex.")
            else:
                self._editor.set_text("Click again, or press return to stop.")
        else:
            self._editor.set_text("That point would make the polygon non-convex.")

    def key_press(self, event):
        if event.keycode==36:
            self.polygon_receiver(self._pc.get_polygon(),self._v[0],self._v[1])
            self._editor.get_canvas().delete("PolygonDrawer")
            self._editor.set_actor(None)
Exemplo n.º 3
0
 def __init__(self, editor, bundle, polygon_receiver, field = QQ):
     EditorActor.__init__(self, editor)        
     self.polygon_receiver=polygon_receiver
     self._pc=PolygonCreator(field)
     self._v=[]
     self._bundle=bundle
Exemplo n.º 4
0
 def __init__(self, editor, bundle, polygon_receiver, field = QQ):
     EditorActor.__init__(self, editor)        
     self.polygon_receiver=polygon_receiver
     self._pc=PolygonCreator(field)
     self._v=[]
     self._bundle=bundle