示例#1
0
    def __init__(self, viz):
        """!
        Initializer function

        @param self: this object
        @param viz: visualization object
        @return none
        """
        self.viz = viz
        self.color = 0x8080C0FF
        self.hlines = GooCanvas.CanvasPath(parent=viz.canvas.get_root_item(),
                                           stroke_color_rgba=self.color)
        self.hlines.lower(None)
        self.vlines = GooCanvas.CanvasPath(parent=viz.canvas.get_root_item(),
                                           stroke_color_rgba=self.color)
        self.vlines.lower(None)
        self.labels = []
        hadj = self.viz.get_hadjustment()
        vadj = self.viz.get_vadjustment()

        def update(adj):
            if self.visible:
                self.update_view()

        hadj.connect("value-changed", update)
        vadj.connect("value-changed", update)
        hadj.connect("changed", update)
        vadj.connect("changed", update)
        self.visible = True
        self.update_view()
示例#2
0
 def update_notes(self):
     while self.notes.get_n_children() > 0:
         self.notes.remove_child(0)
     for item in self.pattern.items():
         x = self.pulse_to_screen_x(item.pos) - self.instr_width
         y = self.row_to_screen_y(item.row + 0.5)
         if item.channel == self.channel:
             fill_color = 0xC0C0C0 - int(item.vel * 1.5) * 0x000101
             stroke_color = 0x808080
             if item.selected:
                 stroke_color = 0xFF8080
         else:
             fill_color = 0xE0E0E0
             stroke_color = 0xE0E0E0
         if item.len > 1:
             x2 = self.pulse_to_screen_x(item.pos +
                                         item.len) - self.pulse_to_screen_x(
                                             item.pos)
             polygon = [-2, 0, 0, -5, x2 - 5, -5, x2, 0, x2 - 5, 5, 0, 5]
         else:
             polygon = [-5, 0, 0, -5, 5, 0, 0, 5, -5, 0]
         item.item = GooCanvas.CanvasPath(parent=self.notes,
                                          data=polygon_to_path(polygon),
                                          line_width=1,
                                          fill_color=("#%06x" % fill_color),
                                          stroke_color=("#%06x" %
                                                        stroke_color))
         #item.item.set_property('stroke_color_rgba', guint(stroke_color))
         item.item.translate(x, y)
示例#3
0
    def __init__(self, tbox, x, y):
        super(Curve, self).__init__(tbox)
        self.origin = x, y
        self.moved = False
        self.bx = 0
        self.by = 0
        self.marker1 = Marker(self.tbox.layer,
                              x,
                              y,
                              color="Red",
                              callback=self.moveto)

        self.curve = GooCanvas.CanvasPath(
            parent=tbox.layer,
            data="",
            x=x,
            y=y,
            width=0,
            height=0,
            stroke_color_rgba=self.stroke_color,
            fill_color_rgba=self.fill_color,
            line_width=self.line_width,
        )

        self.id_release = tbox.layer.connect("button-release-event",
                                             self.button_released)
        self.id_motion = tbox.layer.connect("motion-notify-event",
                                            self.button_moved)
示例#4
0
    def __draw_grid(self):
        if self.show_grid:
            width = self.main_window.get_size()[0]
            height = self.main_window.get_size()[1]

            i = 0
            while i < height:
                GooCanvas.CanvasPath(parent=self.get_root_item(),
                                     stroke_color="#F9F9F9",
                                     data="M 0 " + str(i) + " L " +
                                     str(width) + " " + str(i) + "")
                i = i + System.properties.grid
            i = 0
            while i < width:
                GooCanvas.CanvasPath(parent=self.get_root_item(),
                                     stroke_color="#F9F9F9",
                                     data="M " + str(i) + " 0 L " + str(i) +
                                     " " + str(height) + "")
                i = i + System.properties.grid
示例#5
0
 def update_grid(self):
     for i in self.grid.items:
         i.destroy()
     bg = GooCanvas.CanvasRect(parent=self.grid,
                               x=0,
                               y=0,
                               width=self.pattern.get_length() *
                               self.zoom_in,
                               height=self.rows * self.row_height,
                               fill_color="white")
     bar_fg = "blue"
     beat_fg = "darkgray"
     grid_fg = "lightgray"
     row_grid_fg = "lightgray"
     row_ext_fg = "black"
     for i in range(0, self.rows + 1):
         color = row_ext_fg if (i == 0 or i == self.rows) else row_grid_fg
         GooCanvas.CanvasPath(
             parent=self.grid,
             data="M %s %s L %s %s" %
             (0, i * self.row_height, self.pattern.get_length() *
              self.zoom_in, i * self.row_height),
             stroke_color=color,
             line_width=1)
     for i in range(0, self.pattern.get_length() + 1, int(self.grid_unit)):
         color = grid_fg
         if i % self.pattern.ppqn == 0:
             color = beat_fg
         if (i % (self.pattern.ppqn * self.pattern.beats)) == 0:
             color = bar_fg
         GooCanvas.CanvasPath(parent=self.grid,
                              data="M %s %s L %s %s" %
                              (i * self.zoom_in, 1, i * self.zoom_in,
                               self.rows * self.row_height - 1),
                              stroke_color=color,
                              line_width=1)
示例#6
0
    def __update_draw(self):
        """
        This method update draw.
        """
        # svg M L bezier curve
        path = ""
        x0 = self.__from_point[0]
        y0 = self.__from_point[1]
        x1 = self.__to_point[0]
        y1 = self.__to_point[1]

        path += "M " + str(x0) + " " + str(y0)

        path += " L " + str(x0 + 25) + " " + str(y0)
        path += " L " + str(x0 + 25) + " " + str((y0 + y1) / 2)
        if x1 < x0 + 50:
            path += " L " + str((x1 + x0) / 2) + " " + str((y0 + y1) / 2)
            path += " L " + str(x1 - 25) + " " + str((y0 + y1) / 2)
        else:
            path += " L " + str(x0 + 25) + " " + str(y1)
        path += " L " + str(x1 - 25) + " " + str(y1)
        path += " L " + str(x1) + " " + str(y1)

        path += " L " + str(x1 - 4) + " " + str(y1 - 4)
        path += " L " + str(x1 - 4) + " " + str(y1 + 4)
        path += " L " + str(x1) + " " + str(y1)

        color = 'black'
        if self.conn_type in System.ports:
            color = System.ports[self.conn_type].color

        if "Line" not in self.__widgets:
            widget = GooCanvas.CanvasPath(parent=self,
                                          stroke_color=color,
                                          data=path)
            self.__widgets["Line"] = widget
        else:
            self.__widgets["Line"].set_property("data", path)

        self.__update_state()
示例#7
0
    def __update_draw(self):
        """
        This method update draw.
        """
        path = ""
        x0 = self.__from_point[0]
        y0 = self.__from_point[1]
        x1 = self.__to_point[0]
        y1 = self.__to_point[1]

        if System.properties.connection == "Curve":
            c1x = x1
            c1y = y0
            c2x = x0
            c2y = y1
            path += "M " + str(x0) + " " + str(y0)
            path += " C"
            if x0 + 25 > x1:
                c1x = x0 + x0 - x1
                c2x = x1 - x0 + x1
            path += " " + str(c1x) + " " + str(c1y)
            path += " " + str(c2x) + " " + str(c2y)
            path += " " + str(x1) + " " + str(y1)

        elif System.properties.connection == "Line":
            path += "M " + str(x0) + " " + str(y0)
            path += " L " + str(x1) + " " + str(y1)

        else:  # System.properties.connection == "Square":
            x0_shift = (self.output_port.type_index * 4)
            x1_shift = 0
            if self.input_port is not None:
                x1_shift = self.input_port.type_index * 4

            # svg M L bezier curve
            # Move to output port starting point / first horizontal line
            path += "M " + str(x0) + " " + str(y0)
            # Line to start point + 25 on x + output type index --
            path += " L " + str(x0 + 25 + x0_shift) + " " + str(y0)
            # First vertical line
            path += " L " + str(x0 + 25 + x0_shift) + " " + str((y0 + y1) / 2)

            # Middle horizontal line if second block is on the left
            if x1 - 25 - x1_shift < x0 + 25 + x0_shift:
                path += " L " + str((x1 + x0) / 2 - x1_shift) + " " + str(
                    (y0 + y1) / 2)
                path += " L " + str(x1 - 25 - x1_shift) + " " + str(
                    (y0 + y1) / 2)
            else:
                path += " L " + str(x0 + 25 + x0_shift) + " " + str(y1)

            path += " L " + str(x1 - 25 - x1_shift) + " " + str(y1)
            # End Point
            path += " L " + str(x1) + " " + str(y1)

        if "Line" not in self.__widgets:
            color = self.output_port.color
            widget = GooCanvas.CanvasPath(parent=self,
                                          stroke_color=color,
                                          data=path)
            self.__widgets["Line"] = widget
        else:
            self.__widgets["Line"].set_property("data", path)

        self.__update_state()
示例#8
0
文件: demo.py 项目: zmughal/goocanvas
def setup_canvas(c):
    root = c.get_root_item()

    #Test the simple commands like moveto and lineto: MmZzLlHhVv. */
    GooCanvas.CanvasPath (parent=root, data="M 20 20 L 40 40")
    GooCanvas.CanvasPath (parent=root, data="M30 20 l20, 20")
    GooCanvas.CanvasPath (parent=root, data="M 60 20 H 80")
    GooCanvas.CanvasPath (parent=root, data="M60 40 h20")
    GooCanvas.CanvasPath (parent=root, data="M 100,20 V 40")

    #test empty    
    p = GooCanvas.CanvasPath (parent=root, data="")
    p.props.data = "M 120 20 v 20"

    GooCanvas.CanvasPath (parent=root,
                  data="M 180 20 h20 v20 h-20 z m 5,5 h10 v10 h-10 z",
                  fill_color="red",
    #              "fill_rule", CAIRO_FILL_RULE_EVEN_ODD,
                  )

    GooCanvas.CanvasPath (parent=root,
                  data="M 220 20 L 260 20 L 240 40 z",
                  fill_color="red",
                  stroke_color="blue",
                  line_width=3.0,
                  )

    #Test the bezier curve commands: CcSsQqTt. */
    GooCanvas.CanvasPath (parent=root,
                  data="M20,100 C20,50 100,50 100,100 S180,150 180,100",
                  line_dash=GooCanvas.CanvasLineDash.newv((10.0, 10.0)),
                  )

    GooCanvas.CanvasPath (parent=root,
                  data="M220,100 c0,-50 80,-50 80,0 s80,50 80,0",
                  )

    GooCanvas.CanvasPath (parent=root,
                  data="M20,200 Q60,130 100,200 T180,200",
                  )

    GooCanvas.CanvasPath (parent=root,
                  data="M220,200 q40,-70 80,0 t80,0",
                  )

    # Test the elliptical arc commands: Aa. */
    GooCanvas.CanvasPath (parent=root,
                  data="M200,500 h-150 a150,150 0 1,0 150,-150 z",
                  fill_color="red",
                  stroke_color="blue",
                  line_width=5.0,
                  )

    GooCanvas.CanvasPath (parent=root,
                  data="M175,475 v-150 a150,150 0 0,0 -150,150 z",
                  fill_color="yellow",
                  stroke_color="blue",
                  line_width=5.0,
                  )

    GooCanvas.CanvasPath (parent=root,
                  data="""M400,600 l 50,-25
                  a25,25 -30 0,1 50,-25 l 50,-25
                  a25,50 -30 0,1 50,-25 l 50,-25
                  a25,75 -30 0,1 50,-25 l 50,-25
                  a25,100 -30 0,1 50,-25 l 50,-25""",
                  stroke_color="red",
                  line_width=5.0,
                  )

    GooCanvas.CanvasPath (parent=root,
                  data="M 525,75 a100,50 0 0,0 100,50",
                  stroke_color="red",
                  line_width=5.0,
                  )
    GooCanvas.CanvasPath (parent=root,
                  data="M 725,75 a100,50 0 0,1 100,50",
                  stroke_color="red",
                  line_width=5.0,
                  )
    GooCanvas.CanvasPath (parent=root,
                  data="M 525,200 a100,50 0 1,0 100,50",
                  stroke_color="red",
                  line_width=5.0,
                  )
    GooCanvas.CanvasPath (parent=root,
                  data="M 725,200 a100,50 0 1,1 100,50",
                  stroke_color="red",
                  line_width=5.0,
                  )