Пример #1
0
    def _comp_default(self):
        canvas = Canvas(draw_axes=True, bgcolor="gray")
        self.triangle = SierpinskiTriangle(
            position=[0.0, 0.0],
            bounds=[self.base_width, self.base_width * (SQRT3 / 2)],
            iterations=self.iterations,
            max_iters=self.max_iters,
            base_width=self.base_width,
            bgcolor="gray")
        canvas.add(self.triangle)

        self.viewport = Viewport(component=canvas,
                                 enable_zoom=True,
                                 stay_inside=True)
        self.viewport.zoom_tool.min_zoom = 1.0
        self.viewport.tools.append(
            ViewportPanTool(self.viewport, drag_button="right"))

        scrolled = Scrolled(
            canvas,
            inside_padding_width=0,
            mousewheel_scroll=False,
            viewport_component=self.viewport,
            always_show_sb=True,
            continuous_drag_update=True,
        )
        return scrolled
Пример #2
0
 def create_component(self):
     canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)
     from basic_move import Box
     box = Box(color="red", bounds=[50, 50], resizable="")
     box.position = [75, 75]
     canvas.add(box)
     viewport = Viewport(component=canvas)
     viewport.view_position = [0, 0]
     viewport.tools.append(ViewportPanTool(viewport))
     return viewport
Пример #3
0
    def _create_window(self):

        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)
        from basic_move import Box
        box = Box(color="red", bounds=[50,50], resizable="")
        box.position= [75,75]
        canvas.add(box)


        viewport = Viewport(component=canvas)
        viewport.view_position = [0,0]
        viewport.tools.append(ViewportPanTool(viewport))

        return Window(self, -1, component=viewport)
Пример #4
0
    def _create_component(self):
        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)

        boxgridsize = 8
        boxsize = 50

        spacing = boxsize * 2
        offset = spacing / 2

        origin_color = array([0.0, 0.0, 1.0])
        x_color = array([0.0, 1.0, 0.0])
        y_color = array([1.0, 0.0, 0.0])

        for i in range(boxgridsize):
            for j in range(boxgridsize):
                color = tuple(x_color / (boxgridsize - 1) * i + y_color /
                              (boxgridsize - 1) * j + origin_color) + (1.0, )
                box = Box(color=color, bounds=[boxsize, boxsize], resizable="")
                box.position = [
                    i * spacing + offset - boxsize / 2 + 0.5,
                    j * spacing + offset - boxsize / 2 + 0.5,
                ]
                canvas.add(box)

        viewport = Viewport(
            component=canvas,
            enable_zoom=True,
            vertical_anchor="center",
            horizontal_anchor="center",
        )
        # viewport.view_position = [0,0]
        viewport.tools.append(ViewportPanTool(viewport))

        # Uncomment the following to enforce limits on the zoom
        # viewport.min_zoom = 0.1
        # viewport.max_zoom = 3.0

        scrolled = Scrolled(
            canvas,
            fit_window=True,
            inside_padding_width=0,
            mousewheel_scroll=False,
            viewport_component=viewport,
            always_show_sb=True,
            continuous_drag_update=True,
        )

        return scrolled
Пример #5
0
    def _create_window(self):

        canvas = Canvas(bgcolor="lightsteelblue", draw_axes=True)

        boxgridsize = 8
        boxsize = 50

        spacing = boxsize * 2
        offset = spacing / 2

        origin_color = array([0.0, 0.0, 1.0])
        x_color = array([0.0, 1.0, 0.0])
        y_color = array([1.0, 0.0, 0.0])

        for i in range(boxgridsize):
            for j in range(boxgridsize):
                color = tuple(x_color / (boxgridsize - 1) * i + \
                              y_color / (boxgridsize - 1) * j + \
                              origin_color) + (1.0,)
                box = Box(color=color, bounds=[boxsize, boxsize], resizable="")
                box.position= [i*spacing + offset - boxsize/2 + 0.5,
                               j*spacing + offset - boxsize/2 + 0.5]
                canvas.add(box)

        viewport = Viewport(component=canvas, enable_zoom=True,
                            vertical_anchor='center',
                            horizontal_anchor='center')
        #viewport.view_position = [0,0]
        viewport.tools.append(ViewportPanTool(viewport))

        # Uncomment the following to enforce limits on the zoom
        #viewport.min_zoom = 0.1
        #viewport.max_zoom = 3.0

        scrolled = Scrolled(canvas, fit_window = True,
                            inside_padding_width = 0,
                            mousewheel_scroll = False,
                            viewport_component = viewport,
                            always_show_sb = True,
                            continuous_drag_update = True)

        return Window(self, -1, component=scrolled)
Пример #6
0
    def _canvas_default(self):
        """ Trait initialiser.
        """

        logo_path = join(dirname(__file__), "images", "python.png")
        logo = Image(image_file=logo_path, bounds=[100, 196],
            position=[25, 25])

        workbench_path = join(dirname(__file__), "images",
            "workbench.png")
        workbench = RelativeImage(image_file=workbench_path, bounds=[128, 128])
        workbench.on_trait_change(self._on_workbench, "selected")

        app_name = self.window.application.name
        title = RelativeText(text=app_name, font="Sans 72",
            font_color="dark orchid", bounds=[66, 66])

        canvas = Canvas(bgcolor="white")
        canvas.add(logo)
        canvas.add(workbench)
#        canvas.add(title)

        return canvas
Пример #7
0
    def _create_window(self):
        self.canvas = Canvas(bgcolor='lightgrey',
                             draw_axes=True,
                             fit_window = True)


        sys,cat = load_system("datsun truck.repo")
        #        sys,cat = load_system()
#        find_technologies(sys)
        self.make_components(sys)


        viewport = Viewport(component=self.canvas,enable_zoom=True)

        max_x = 0
        max_y = 0
        for art in sys.artifacts:
            try:
                if art.drawable.x2 > max_x:
                    max_x = art.drawable.x2
                if art.drawable.y2 > max_y:
                    max_y = art.drawable.y2
            except AttributeError:
                pass

#        max_x = max([art.drawable.x2 for art in sys.artifacts])
#        max_y = max([art.drawable.y2 for art in sys.artifacts])

        viewport.view_position = [max_x/2,max_y/2]

        viewport.view_bounds = self.canvas.bounds
        viewport.zoom = 0.3
        viewport.zoom_tool.wheel_zoom_step = 1
        viewport.tools.append(ViewportPanTool(viewport))

        self.viewport = viewport
        self.fit_window()

        return Window(self, -1, component=viewport)
Пример #8
0
class GraphFrame(DemoFrame):
    drawables = List(Instance(Drawable))
    canvas = Instance(Canvas)

    def _create_window(self):
        self.canvas = Canvas(bgcolor='lightgrey',
                             draw_axes=True,
                             fit_window = True)


        sys,cat = load_system("datsun truck.repo")
        #        sys,cat = load_system()
#        find_technologies(sys)
        self.make_components(sys)


        viewport = Viewport(component=self.canvas,enable_zoom=True)

        max_x = 0
        max_y = 0
        for art in sys.artifacts:
            try:
                if art.drawable.x2 > max_x:
                    max_x = art.drawable.x2
                if art.drawable.y2 > max_y:
                    max_y = art.drawable.y2
            except AttributeError:
                pass

#        max_x = max([art.drawable.x2 for art in sys.artifacts])
#        max_y = max([art.drawable.y2 for art in sys.artifacts])

        viewport.view_position = [max_x/2,max_y/2]

        viewport.view_bounds = self.canvas.bounds
        viewport.zoom = 0.3
        viewport.zoom_tool.wheel_zoom_step = 1
        viewport.tools.append(ViewportPanTool(viewport))

        self.viewport = viewport
        self.fit_window()

        return Window(self, -1, component=viewport)

    def make_components(self,sys):
        do_layout(sys)

        for artifact in sys.connected_artifacts:
                self.add_node(artifact)
                for subfunction in artifact.subfunctions:
                    for in_port in subfunction.in_ports:
                        for out_port in subfunction.out_ports:
                            self.add_edge(in_port.drawable,
                                          out_port.drawable,
                                          None)

        for flow in sys.flows:
            self.add_edge(flow.source.drawable,flow.sink.drawable,flow)

    def add_node(self,artifact):
        node = ArtifactNode(element=artifact)
        artifact.drawable = node
        self.plot_drawable(node)

        # Create ports to act as connection points for flows
        for port in artifact.in_ports:
            pn = PortNode(element=port,
                          parent=node)
            port.drawable = pn
            node.in_ports.append(pn)
            self.plot_drawable(pn)
        for port in artifact.out_ports:
            pn = PortNode(element=port,
                          parent=node)
            port.drawable = pn
            node.out_ports.append(pn)
            self.plot_drawable(pn)

        #Arrange internal ports
        for port in artifact.internal_out_ports:
            pn = PortNode(element=port,
                          parent=node,
                          height=2)
            port.drawable = pn
            node.internal_out_ports.append(pn)
            self.plot_drawable(pn)
        for port in artifact.internal_in_ports:
            pn = PortNode(element=port,
                          parent=node,
                          height=2)
            port.drawable = pn
            node.internal_in_ports.append(pn)
            self.plot_drawable(pn)

        node.arrange_ports()

        for flow in artifact.internal_flows:
#            flow.source.dir = 'out'
#            flow.sink.dir = 'in'
            self.add_edge(flow.source.drawable,flow.sink.drawable,flow)

    def add_port(self,port_elem,node_elem):
        pn = PortNode(element=port_elem,
                      parent=node_elem)
        port_elem.drawable = pn
        node_elem.in_ports.append(pn)
        self.plot_drawable(pn)

    def add_edge(self,source_port,sink_port,flow_element):
        edge = FlowEdge(source_port=source_port,
                              sink_port=sink_port,
                              element=flow_element)
        source_port.edges.append(edge)
        sink_port.edges.append(edge)
        if flow_element is not None:
            flow_element.drawable = edge
        self.plot_drawable(edge)

    def plot_drawable(self,drawable):
        self.canvas.add(drawable)

    def fit_window(self):
        min_x = min([c.x for c in self.canvas.components])
        max_x = max([c.x2 for c in self.canvas.components])

        min_y = min([c.y for c in self.canvas.components])
        max_y = max([c.y2 for c in self.canvas.components])
        print max_x,max_y

        self.viewport.view_bounds = (640,480)
        print self.viewport.get_preferred_size()
Пример #9
0
 def _dispatch_draw(self, layer, gc, view_bounds, mode):
     Canvas._dispatch_draw(self, layer, gc, view_bounds, mode)
Пример #10
0
 def _dispatch_draw(self, layer, gc, view_bounds, mode):
     Canvas._dispatch_draw(self, layer, gc, view_bounds, mode)