Esempio n. 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.Path(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.color)
     self.hlines.lower(None)
     self.vlines = goocanvas.Path(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()
    def motion_notify_event(self, widget, event):
        x = event.x
        y = event.y
        state = event.state
        if self.item_temp is not None:
            self.item_temp.remove()

        if self.item_data is not None:
            if self.image.draw_tool == 'brush':
                self.item_data = self.item_data + '%s,%s ' % (x, y)
                self.item_temp = goocanvas.Path(parent=self.root,
                                                data=self.item_data,
                                                line_width=self.line_width,
                                                stroke_color=self.color)
            elif self.image.draw_tool == 'oval':
                self.item_temp = goocanvas.Ellipse(
                    parent=self.root,
                    center_x=self.item_temp_coords[0] +
                    (x - self.item_temp_coords[0]) / 2,
                    center_y=self.item_temp_coords[1] +
                    (y - self.item_temp_coords[1]) / 2,
                    radius_x=abs(x - self.item_temp_coords[0]) / 2,
                    radius_y=abs(y - self.item_temp_coords[1]) / 2,
                    stroke_color=self.color,
                    line_width=self.line_width)
            elif self.image.draw_tool == 'line':
                self.item_data = 'M %s,%s L' % self.item_temp_coords
                self.item_data = self.item_data + ' %s,%s' % (x, y)
                self.item_temp = goocanvas.Path(parent=self.root,
                                                data=self.item_data,
                                                line_width=self.line_width,
                                                stroke_color=self.color)
    def add_recieved(self, parent_rid, new_items):
        ''' adds the path to the items listing, both minidom node and goocanvas
        object in a tuple '''
        node = new_items[parent_rid]['data'][0]

        self.items[parent_rid] = new_items[parent_rid]
        for x in new_items[parent_rid]['children']:
            self.items[x] = new_items[x]

        if node.getName() == 'path':
            goocanvas_obj = goocanvas.Path(parent=self.root,
                                           data=node.getAttr('d'),
                                           line_width=int(
                                               node.getAttr('stroke-width')),
                                           stroke_color=node.getAttr('stroke'))

        if node.getName() == 'ellipse':
            goocanvas_obj = goocanvas.Ellipse(
                parent=self.root,
                center_x=float(node.getAttr('cx')),
                center_y=float(node.getAttr('cy')),
                radius_x=float(node.getAttr('rx')),
                radius_y=float(node.getAttr('ry')),
                stroke_color=node.getAttr('stroke'),
                line_width=float(node.getAttr('stroke-width')))

        self.items[parent_rid]['data'].append(goocanvas_obj)
        goocanvas_obj.connect('button-press-event',
                              self.item_button_press_events)
Esempio n. 4
0
 def __init__(self, src, dest):
     """src is source PortView, dst is destination PortView"""
     self.src = src
     self.dest = dest
     self.mask = goocanvas.Path(parent=src.get_graph().get_root(),
                                line_width=12,
                                stroke_color_rgba=0,
                                pointer_events=goocanvas.EVENTS_ALL)
     self.mask.type = "wire"
     self.mask.object = self
     self.wire = goocanvas.Path(parent=src.get_graph().get_root(),
                                stroke_color_rgba=Colors.connectedWire,
                                pointer_events=0)
     self.wire.type = "wirecore"
     self.wire.object = self
     self.update_shape()
Esempio n. 5
0
 def render(self, ctx, parent, y):
     module = self.module
     (width, margin, spacing) = (module.width, module.margin,
                                 module.spacing)
     al = "left"
     portName = self.model.get_name()
     title = goocanvas.Text(parent=parent,
                            text=portName,
                            font=self.fontName,
                            width=width - 2 * margin,
                            x=margin,
                            y=y,
                            alignment=al,
                            fill_color_rgba=Colors.text,
                            hint_metrics=cairo.HINT_METRICS_ON,
                            pointer_events=False,
                            wrap=False)
     height = 1 + int(title.get_requested_height(ctx, width - 2 * margin))
     title.ensure_updated()
     bnds = title.get_bounds()
     bw = bnds.x2 - bnds.x1 + 2 * margin
     if not self.isInput:
         title.translate(width - bw - 2, 0)
     else:
         title.translate(2, 0)
     bw += 10
     if self.isInput:
         box = goocanvas.Path(parent=parent,
                              data=self.input_arrow(0.5, y - 0.5, bw,
                                                    height + 1))
     else:
         box = goocanvas.Path(parent=parent,
                              data=self.output_arrow(
                                  width - bw, y - 0.5, bw, height + 1))
     box.lower(title)
     y += height + spacing
     box.type = "port"
     box.object = box.module = self
     box.model = self.model
     title.model = self.model
     self.box = box
     self.title = title
     self.update_style()
     return y
Esempio n. 6
0
 def __init__(self, viz):
     self.viz = viz
     self.color = 0x8080C0FF
     self.hlines = goocanvas.Path(parent=viz.canvas.get_root_item(), stroke_color_rgba=self.color)
     self.hlines.lower(None)
     self.vlines = goocanvas.Path(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()
Esempio n. 7
0
 def __init__(self, port_view, x, y):
     self.module = port_view.module
     self.port_view = port_view
     self.x = x
     self.y = y
     self.drag_wire = goocanvas.Path(parent=self.get_graph().get_root(),
                                     stroke_color_rgba=Colors.draggedWire)
     self.drag_wire.type = "tmp wire"
     self.drag_wire.object = None
     self.drag_wire.raise_(None)
     self.connect_candidate = None
     self.update_drag_wire(x, y)
Esempio n. 8
0
    def append(self, x, y):
        self.data += " " + str(x) + " " + str(y)
        return
        #here's how it's going to go:
        #we'll draw segments in sets of 100 to start
        #so, keep drawing and drawing until there are 100 segments
        #then finish that stroke, and start a new stroke, and that one has been drawn 100 times
        self._draw_tick += 1

        if self._temp_path == "":
            self.temp_path = "M " + str(self._end_x) + " " + str(self._end_y)
            self.temp_path += "C" + str(x) + " " + str(y)
        goocanvas.Path(data=path_data, parent=self.goocanvas.get_root_item())
        self._end_x = x
        self._end_y = y
Esempio n. 9
0
    def draw(self, cr):
        x0, y0 = self.points[0]
        data = 'M%d,%d' % (x0, y0)
        for i in xrange(1, len(self.points), 3):
            x1, y1 = self.points[i]
            x2, y2 = self.points[i + 1]
            x3, y3 = self.points[i + 2]
            data += 'C%d,%d %d,%d %d,%d' % (x1, y1, x2, y2, x3, y3)

        path = goocanvas.Path(
            parent=cr.get_root_item(),
            data=data,
            line_width=self.pen.linewidth,
            stroke_color=self.pen.color.to_rgb_hex(),
        )

        #cr.set_dash(pen.dash)

        if self.filled:
            path.props.fill_color = self.pen.fill_color.to_rgb_hex()

        self.path = path
    def add_path(self, data, line_width, color):
        ''' adds the path to the items listing, both minidom node and goocanvas
        object in a tuple '''

        goocanvas_obj = goocanvas.Path(parent=self.root,
                                       data=data,
                                       line_width=line_width,
                                       stroke_color=color)
        goocanvas_obj.connect('button-press-event',
                              self.item_button_press_events)

        node = self.g.addChild(name='path')
        node.setAttr('d', data)
        node.setAttr('stroke-width', str(line_width))
        node.setAttr('stroke', color)
        self.g.addChild(node=node)

        rids = self.session.generate_rids(4)
        self.items[rids[0]] = {
            'type': 'element',
            'data': [node, goocanvas_obj],
            'children': rids[1:]
        }
        self.items[rids[1]] = {'type': 'attr', 'data': 'd', 'parent': node}
        self.items[rids[2]] = {
            'type': 'attr',
            'data': 'stroke-width',
            'parent': node
        }
        self.items[rids[3]] = {
            'type': 'attr',
            'data': 'stroke',
            'parent': node
        }

        self.session.send_items(self.items, rids)
Esempio n. 11
0
class Gcompris_smya:
  """The practice activity"""


  def __init__(self, gcomprisBoard):
    print "smya init"

        # Save the gcomprisBoard, it defines everything we need
    # to know from the core
    self.gcomprisBoard = gcomprisBoard

    # Needed to get key_press
    gcomprisBoard.disable_im_context = True
    self.rootitem = None 

  def start(self):
    print "smya start"
    self.gcomprisBoard.level=1
    self.gcomprisBoard.maxlevel = 2
    self.gcomprisBoard.sublevel = 1
    self.gcomprisBoard.number_of_sublevel=1
    # Set the buttons we want in the bar
    # gcompris.bar_set(gcompris.BAR_LEVEL)
    #gcompris.bar_set_level(self.gcomprisBoard)
    self.backroot = goocanvas.Group(parent = \
        self.gcomprisBoard.canvas.get_root_item())
    gcompris.bar_set(gcompris.BAR_LEVEL)
    gcompris.bar_set_level(self.gcomprisBoard)

    # Set a background image
    #    gcompris.set_default_background(self.gcomprisBoard.canvas.get_root_item())


    # Create our rootitem. We put each canvas item in it so at the end we
    # only have to kill it. The canvas deletes all the items it contains
    # automaticaly.
    
    self.rootitem = goocanvas.Group(parent = self.gcomprisBoard.canvas.get_root_item())
    #svghandle = gcompris.utils.load_svg("/smya/index.jpeg")
    




    pic = goocanvas.Image(
      parent = self.rootitem,
      pixbuf = gcompris.utils.load_pixmap("smya/index.jpeg"),
      x = 475,
      y = 225,
      width = 160,
      height = 160)
  
    pic.connect("button_press_event", self.pic_event) 
    
    
    txt = goocanvas.Text(
      parent = self.rootitem,
      x=400.0,
      y=100.0,
      text=("Welcome dear children\n"
            "This is a trial \n"
            "Click on any object to change the background color"),
      fill_color="white",
      anchor = gtk.ANCHOR_CENTER,
      alignment = pango.ALIGN_CENTER
      )
  
    txt.connect("button_press_event", self.txt_event)    
    
      el = goocanvas.Ellipse(
      parent=self.rootitem,
      center_x=100,
      center_y=100,
      radius_x=50,
      radius_y=30,
      stroke_color="red",
      fill_color="blue",
      line_width=5.0) 

    el.connect("button_press_event", self.el_event)

    rec = goocanvas.Rect(
      parent=self.rootitem,
      x=650,
      y=70,
      height=100,
      width=100,
      stroke_color="black",
      fill_color="green",
      line_width=5.0)
   
    rec.connect("button_press_event", self.rec_event)

    
    path = goocanvas.Path(
      parent=self.rootitem,
      data="M 10 240 L 170 240", 
      stroke_color="orange")
     
    path.connect("button_press_event", self.path_event)   

    item = goocanvas.Rect(
      parent = self.backroot,
      x = 0,
      y = 0,
      width = gcompris.BOARD_WIDTH,
      height = 900,
      fill_color = "pink"
      )
Esempio n. 12
0
def setup_canvas(canvas):
    global master, agent_item_map, client_item_map, point_map

    master = create_focus_image(canvas, CANVAS_WIDTH / 2.0 - 30, 80 - 60,
                                "master.svg", "Master")

    # Get list of agents from master
    agent_map = fetch_agent_data_map()
    total_agents = len(agent_map.keys())

    i = 1
    point_map = {}

    # Align agents, and draw lines between agents and master
    for each in agent_map.keys():
        offset = (CANVAS_WIDTH * 1.0 / (total_agents + 1)) * i
        path = goocanvas.Path(parent=canvas.get_root_item(),
                              data="M %s %s L %s %s" %
                              (CANVAS_WIDTH / 2.0, 80, offset, 200))

        #item = create_focus_elipse (canvas, offset, 200, 30, 30, "red", "agent")
        item = create_focus_image(canvas, offset - 50, 150, "ap.svg", "agent")
        agent_item_map[each] = item

        i += 1
        item.set_data("coords", (offset, 200))
        point_map[each] = [offset, 300]

    # Keep master above the lines
    master.raise_(None)

    # Get list of clients from master
    client_map = fetch_client_data_map()

    # Draw nodes for each client. If a client
    # hasn't received an IP address (didn't follow)
    # through with the connection, then indicate
    # as so.
    for each in client_map.keys():
        if (client_map[each]["ipAddress"] != "0.0.0.0"):
            color = "green"
            if (client_map[each]["agent"] is not None):
                x = point_map["/" + client_map[each]["agent"]][0]
                y = point_map["/" + client_map[each]["agent"]][1]

                item = create_focus_image(canvas, x - 20, y - 20, "client.svg",
                                          "client-" + each)

                agent = agent_item_map["/" + client_map[each]["agent"]]

                if (agent != None):
                    path = goocanvas.Path(parent=canvas.get_root_item(),
                                          data="M %s %s L %s %s" %
                                          (agent.get_data("coords")[0],
                                           agent.get_data("coords")[1], x, y))
                    item.set_data("path_object", path)
                    item.set_data("my_coords", (x, y))
                    path.props.visibility = goocanvas.ITEM_INVISIBLE

                agent.raise_(None)
                item.raise_(None)

                client_item_map[each] = item
                point_map["/" + client_map[each]["agent"]][1] += 60
                update_client_tooltip(item, each, client_map[each])
                #item.connect ("query_tooltip",  on_tooltip)
                item.connect("button_press_event", on_button_press)

    return
Esempio n. 13
0
def setup_canvas(canvas):
    root = canvas.get_root_item()

    path = goocanvas.Path(parent=root, data="M 20 20 L 40 40")

    path = goocanvas.Path(parent=root, data="M30 20 l20, 20")

    path = goocanvas.Path(parent=root, data="M 60 20 H 80")

    path = goocanvas.Path(parent=root, data="M60 40 h20")

    path = goocanvas.Path(parent=root, data="M 100,20 V 40")

    path = goocanvas.Path(parent=root, data="M 120 20 v 20")

    path = goocanvas.Path(parent=root, data="M 140 20 h20 v20 h-20 z")

    path = goocanvas.Path(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)

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

    path = goocanvas.Path(
        parent=root, data="M20,100 C20,50 100,50 100,100 S180,150 180,100")

    path = goocanvas.Path(parent=root,
                          data="M220,100 c0,-50 80,-50 80,0 s80,50 80,0")

    path = goocanvas.Path(parent=root, data="M20,200 Q60,130 100,200 T180,200")

    path = goocanvas.Path(parent=root, data="M220,200 q40,-70 80,0 t80,0")

    path = goocanvas.Path(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)

    path = goocanvas.Path(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)

    path = goocanvas.Path(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)

    path = goocanvas.Path(parent=root,
                          data="M 525,75 a100,50 0 0,0 100,50",
                          stroke_color="red",
                          line_width=5.0)

    path = goocanvas.Path(parent=root,
                          data="M 725,75 a100,50 0 0,1 100,50",
                          stroke_color="red",
                          line_width=5.0)

    path = goocanvas.Path(parent=root,
                          data="M 525,200 a100,50 0 1,0 100,50",
                          stroke_color="red",
                          line_width=5.0)

    path = goocanvas.Path(parent=root,
                          data="M 725,200 a100,50 0 1,1 100,50",
                          stroke_color="red",
                          line_width=5.0)