def setup_ellipses(self, root): ellipse1 = goocanvas.Ellipse(parent=root, center_x=245, center_y=45, radius_x=25, radius_y=15, stroke_color="goldenrod", line_width=8.0) self.setup_item_signals(ellipse1) self.ellipse2 = goocanvas.Ellipse(parent=root, center_x=335, center_y=70, radius_x=45, radius_y=30, fill_color="wheat", stroke_color="midnightblue", line_width=4.0, title="An ellipse") self.setup_item_signals(self.ellipse2) pattern = self.create_stipple("cadetblue") ellipse3 = goocanvas.Ellipse(parent=root, center_x=245, center_y=110, radius_x=35, radius_y=30, fill_pattern=pattern, stroke_color="black", line_width=1.0) self.setup_item_signals(ellipse3)
def setup_canvas(canvas): global ellipse1, ellipse2, rect1, rect2, rect3, rect4 root = canvas.get_root_item() # Absolute. ellipse1 = goocanvas.Ellipse(parent=root, center_x=0, center_y=0, radius_x=25, radius_y=15, fill_color="blue") ellipse1.translate(100, 100) rect1 = goocanvas.Rect(parent=root, x=-10, y=-10, width=20, height=20, fill_color="blue") rect1.translate(100, 200) rect3 = goocanvas.Rect(parent=root, x=-10, y=-10, width=20, height=20, fill_color="blue") rect3.translate(200, 200) # Relative. ellipse2 = goocanvas.Ellipse(parent=root, center_x=0, center_y=0, radius_x=25, radius_y=15, fill_color="red") ellipse2.translate(100, 400) rect2 = goocanvas.Rect(parent=root, x=-10, y=-10, width=20, height=20, fill_color="red") rect2.translate(100, 500) rect4 = goocanvas.Rect(parent=root, x=-10, y=-10, width=20, height=20, fill_color="red") rect4.translate(200, 500)
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)
def construct(self, posx, posy): # fretboard for string in xrange(len(self.strings)): semitone = self.strings[string] for fret in xrange(self.frets + 1): x = posx + fret * self.rectwidth y = posy + self.rectheight * string rect = Semitone(self.control, semitone=semitone + fret, method=self.method, parent=self, x=x, y=y, width=self.rectwidth, height=self.rectheight) rect.connect("button_press_event", self.press_semitone, string, fret) rect.connect("button_release_event", self.release_semitone) y = posy + self.rectheight * (len(self.strings) + 0.5) for fret in self.markers: x = posx + self.rectwidth * (fret + 0.5) circle = goocanvas.Ellipse(parent=self, center_x=x, center_y=y, radius_x=self.markers_radius, radius_y=self.markers_radius) circle.props.fill_color_rgba = 0x333333ff circle.props.line_width = 0 if self.capo: x = posx + self.rectwidth * (self.capo + .3) y1 = posy y2 = posy + self.rectheight * len(self.strings) width = self.rectwidth / 3 goocanvas.polyline_new_line(self, x, y1, x, y2, width=line_width, stroke_color_rgba=0x660000cc, pointer_events=0) # draw nut x = posx + self.rectwidth * .3 y1 = posy y2 = posy + self.rectheight * len(self.strings) width = self.rectwidth / 3 goocanvas.polyline_new_line(self, x, y1, x, y2, line_width=width, stroke_color_rgba=0xcc0000cc, pointer_events=0)
def restore(self, anim_): AnimItem.restore(self, anim_) self.item = \ goocanvas.Ellipse( parent = self.rootitem ) AnimItem.init_item(self)
def button_release_event(self, widget, event): x = event.x y = event.y state = event.state if self.image.draw_tool == 'brush': self.item_data = self.item_data + '%s,%s' % (x, y) if x == self.item_temp_coords[0] and y == self.item_temp_coords[1]: goocanvas.Ellipse(parent=self.root, center_x=x, center_y=y, radius_x=1, radius_y=1, stroke_color=self.color, fill_color=self.color, line_width=self.line_width) self.image.add_path(self.item_data, self.line_width, self.color) if self.image.draw_tool == 'oval': cx = self.item_temp_coords[0] + (x - self.item_temp_coords[0]) / 2 cy = self.item_temp_coords[1] + (y - self.item_temp_coords[1]) / 2 rx = abs(x - self.item_temp_coords[0]) / 2 ry = abs(y - self.item_temp_coords[1]) / 2 self.image.add_ellipse(cx, cy, rx, ry, self.line_width, self.color) if 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) if x == self.item_temp_coords[0] and y == self.item_temp_coords[1]: goocanvas.Ellipse(parent=self.root, center_x=x, center_y=y, radius_x=1, radius_y=1, stroke_color='black', fill_color='black', line_width=self.line_width) self.image.add_path(self.item_data, self.line_width, self.color) if self.image.draw_tool == 'delete': pass self.item_data = None if self.item_temp is not None: self.item_temp.remove() self.item_temp = None
def draw(self, cr): ellipse = goocanvas.Ellipse( parent=cr.get_root_item(), center_x=self.x0, center_y=self.y0, radius_x=self.w, radius_y=self.h, stroke_color=self.pen.color.to_rgb_hex(), #line_dash = pen.dash, line_width=self.pen.linewidth, ) if self.filled: ellipse.props.fill_color = self.pen.fill_color.to_rgb_hex()
def point(self, x, y, d=30): """Setting point from his x and y location""" rond = goocanvas.Ellipse( parent=self.ROOT, center_x=x, center_y=y, radius_x=d / 2, radius_y=d / 2, fill_color_rgba= 0x3DF500D0, # default color is green and outline in black stroke_color="black", line_width=1.5) rond.x, rond.y = x, y return rond
def add_ellipse(self, cx, cy, rx, ry, line_width, stroke_color): ''' adds the ellipse to the items listing, both minidom node and goocanvas object in a tuple ''' goocanvas_obj = goocanvas.Ellipse(parent=self.root, center_x=cx, center_y=cy, radius_x=rx, radius_y=ry, stroke_color=stroke_color, line_width=line_width) goocanvas_obj.connect('button-press-event', self.item_button_press_events) node = self.g.addChild(name='ellipse') node.setAttr('cx', str(cx)) node.setAttr('cy', str(cy)) node.setAttr('rx', str(rx)) node.setAttr('ry', str(ry)) node.setAttr('stroke-width', str(line_width)) node.setAttr('stroke', stroke_color) self.g.addChild(node=node) rids = self.session.generate_rids(7) self.items[rids[0]] = { 'type': 'element', 'data': [node, goocanvas_obj], 'children': rids[1:] } self.items[rids[1]] = {'type': 'attr', 'data': 'cx', 'parent': node} self.items[rids[2]] = {'type': 'attr', 'data': 'cy', 'parent': node} self.items[rids[3]] = {'type': 'attr', 'data': 'rx', 'parent': node} self.items[rids[4]] = {'type': 'attr', 'data': 'ry', 'parent': node} self.items[rids[5]] = { 'type': 'attr', 'data': 'stroke-width', 'parent': node } self.items[rids[6]] = { 'type': 'attr', 'data': 'stroke', 'parent': node } self.session.send_items(self.items, rids)
def create_demo_table(root, x, y, width, height): table = goocanvas.Table(parent=root, row_spacing=4.0, column_spacing=4.0, width=width, height=height) table.translate(x, y) square = goocanvas.Rect(parent=table, x=0.0, y=0.0, width=50.0, height=50.0, fill_color="red") table.set_child_properties(square, row=0, column=0, x_shrink=True) square.set_data("id", "Red square") square.connect("button_press_event", on_button_press) circle = goocanvas.Ellipse(parent=table, center_x=0, center_y=0, radius_x=25, radius_y=25, fill_color="blue") table.set_child_properties(circle, row=0, column=1, x_shrink=True) circle.set_data("id", "Blue circle") circle.connect("button_press_event", on_button_press) p = goocanvas.Points([(25, 0), (0, 50), (50, 50)]) triangle = goocanvas.Polyline(parent=table, close_path=True, points=p, fill_color="yellow") table.set_child_properties(triangle, row=0, column=2, x_shrink=True) triangle.set_data("id", "Yellow triangle") triangle.connect("button_press_event", on_button_press)
def record_location(self, widget=None, target=None, event=None): ''' method generates output to content.desktop.in according to the specified format. Method called if RECORD_LOCATIONS = True and developer clicks map. Merhod record the location of the click, and writes a template of the section to content.desktop.in to be filled in later by the developer. ''' self.numLocations += 1 self.data.add_section(str(self.numLocations)) x = event.x y = event.y self.data.set(str(self.numLocations), 'x', int(x)) self.data.set(str(self.numLocations), 'y', int(y)) self.data.set(str(self.numLocations), '_title', 'Location Title Here') self.data.set(str(self.numLocations), '_text', 'location text here') self.data.set( str(self.numLocations), 'image', 'image filepath here, located in resources/name_of_activity/') self.data.set(str(self.numLocations), 'music', 'music file name here') self.data.set(str(self.numLocations), '_shortPrompt', 'enter text for child to match to the location') # draw small elipse on screen to show developer where they clicked goocanvas.Ellipse(parent=self.rootitem, center_x=x, center_y=y, radius_x=5, radius_y=5, fill_color='white', stroke_color='white', line_width=1.0) # write a small number ontop of the ellipse so developer can record # which numbers (sections) correspond to which locations goocanvas.Text( parent=self.rootitem, x=x, y=y, text=str(self.numLocations), anchor=gtk.ANCHOR_CENTER, alignment=pango.ALIGN_CENTER, )
def __init__(self, anim, center_x, center_y, color_fill, color_stroke, line_width): AnimItem.__init__(self, anim) center_x, center_y = self.snap_to_grid(center_x, center_y) self.item = \ goocanvas.Ellipse( parent = self.rootitem, center_x = center_x, center_y = center_y, radius_x = 0, radius_y = 0, stroke_color_rgba = color_stroke, line_width = line_width) if color_fill: self.filled = True self.item.set_properties(fill_color_rgba = color_fill) AnimItem.init_item(self)
def button_press_event(self, widget, event): x = event.x y = event.y state = event.state self.item_temp_coords = (x, y) if self.image.draw_tool == 'brush': self.item_temp = goocanvas.Ellipse(parent=self.root, center_x=x, center_y=y, radius_x=1, radius_y=1, stroke_color=self.color, fill_color=self.color, line_width=self.line_width) self.item_data = 'M %s,%s L ' % (x, y) elif self.image.draw_tool == 'oval': self.item_data = True if self.image.draw_tool == 'line': self.item_data = 'M %s,%s L' % (x, y)
def create_item(self, x, y): self.item_id = str(uuid.uuid4()) self.item_orig_x = x self.item_orig_y = y self.item_width = DEFAULT_WIDTH self.item_height = DEFAULT_HEIGHT if self.tool == 'circle': self.item = goocanvas.Ellipse(parent=self._root, center_x=x, \ center_y=y, radius_x = DEFAULT_WIDTH/2, \ radius_y = DEFAULT_HEIGHT/2, title=self.item_id, \ fill_color_rgba = self._fill_color, \ stroke_color_rgba = self._stroke_color) elif self.tool == 'rect': self.item = goocanvas.Rect(parent=self._root, x=x, y=y, \ width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT, \ fill_color_rgba = self._fill_color, \ stroke_color_rgba = self._stroke_color, title=self.item_id) elif self.tool == 'pencil': self.line_points = [] #Reset self.line_points.append((x, y)) self.item = goocanvas.Polyline(parent=self._root, \ points=goocanvas.Points(self.line_points), \ stroke_color_rgba = self._stroke_color, title=self.item_id) elif self.tool == 'poly': self.line_points = [] #Reset self.line_points.append((x, y)) self.item = goocanvas.Polyline(parent=self._root, \ points=goocanvas.Points(self.line_points), \ stroke_color_rgba = self._stroke_color, \ fill_color_rgba = self._fill_color, title=self.item_id) elif self.tool == 'eraser': self.item = self.get_item_at(x, y, True) else: pass
def make_ellipse_item(self, **kwargs): item = goocanvas.Ellipse(**kwargs) return item
def start(self): self.gcomprisBoard.level = 1 self.gcomprisBoard.maxlevel = 9 self.gcomprisBoard.sublevel = 1 self.gcomprisBoard.number_of_sublevel = 1 gcompris.bar_set(gcompris.BAR_LEVEL) gcompris.set_background(self.gcomprisBoard.canvas.get_root_item(), "ballcatch/beach1.svgz") gcompris.bar_set_level(self.gcomprisBoard) gcompris.bar_location(gcompris.BOARD_WIDTH - 190, -1, 0.7) self.ballinc = 20 # Event loop timer for the ball move self.timer_diff = 0 # Store the time diff between left and right key # 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()) # The instructions self.instruction = goocanvas.Text( parent=self.rootitem, x=600.0, y=300.0, width=250, text=_("Press the two shift keys at the same time," " to make the ball go in a straight line."), fill_color="black", font=gcompris.skin.get_font("gcompris/board/medium"), anchor=gtk.ANCHOR_CENTER, alignment=pango.ALIGN_CENTER) # Tux goocanvas.Image(parent=self.rootitem, pixbuf=gcompris.utils.load_pixmap("ballcatch/tux.svg"), x=gcompris.BOARD_WIDTH / 2 - 60, y=135.0) # Balloon self.balloon_item = goocanvas.Ellipse(parent=self.rootitem, ) self.init_balloon() # The Left Hand goocanvas.Image( parent=self.rootitem, pixbuf=gcompris.utils.load_pixmap("ballcatch/hand.svg"), x=gcompris.BOARD_WIDTH / 2 - 150.0, y=gcompris.BOARD_HEIGHT - 150) # The Right Hand (invert the left hand) item = goocanvas.Image( parent=self.rootitem, pixbuf=gcompris.utils.load_pixmap("ballcatch/hand.svg"), ) item.set_transform( cairo.Matrix(-1, 0, 0, 1, gcompris.BOARD_WIDTH / 2 + 100.0, gcompris.BOARD_HEIGHT - 150)) # The Left Shift KEY self.leftkey = goocanvas.Image( parent=self.rootitem, pixbuf=gcompris.utils.load_pixmap("ballcatch/shift_key.svg"), x=gcompris.BOARD_WIDTH / 2 - 240.0, y=gcompris.BOARD_HEIGHT - 80) # The Right Shift KEY self.rightkey = goocanvas.Image( parent=self.rootitem, pixbuf=gcompris.utils.load_pixmap("ballcatch/shift_key.svg"), x=gcompris.BOARD_WIDTH / 2 + 100.0, y=gcompris.BOARD_HEIGHT - 80) # The basic tick for object moves self.timerinc = 1000 self.left_continue = True self.right_continue = True self.counter_left = 0 self.counter_right = 0 self.timer_inc = gobject.timeout_add(self.timerinc, self.timer_inc_display)
def create_canvas_features(): vb = gtk.VBox(False, 4) vb.set_border_width(4) label = gtk.Label( "Reparent test: click on the items to switch them between parents") alignment = gtk.Alignment(0.5, 0.5, 0.0, 0.0) frame = gtk.Frame() frame.set_shadow_type(gtk.SHADOW_IN) alignment.add(frame) vb.pack_start(label, False, False, 0) vb.pack_start(alignment, False, False, 0) canvas = goocanvas.Canvas() root = canvas.get_root_item() canvas.set_size_request(400, 200) canvas.set_bounds(0, 0, 300, 200) frame.add(canvas) parent1 = goocanvas.Group(parent=root) rect = goocanvas.Rect(parent=parent1, x=0, y=0, width=200, height=200, fill_color="tan") parent2 = goocanvas.Group(parent=root) parent2.translate(200, 0) rect = goocanvas.Rect(parent=parent2, x=0, y=0, width=200, height=200, fill_color="#204060") ellipse = goocanvas.Ellipse(parent=parent1, center_x=100, center_y=100, radius_x=90, radius_y=90, stroke_color="black", fill_color="mediumseagreen", line_width=3.0) ellipse.set_data("parent1", parent1) ellipse.set_data("parent2", parent2) ellipse.connect("button-press-event", on_button_press) group = goocanvas.Group(parent=parent2) group.translate(100, 100) ellipse = goocanvas.Ellipse(parent=group, center_x=0, center_y=0, radius_x=50, radius_y=50, stroke_color="black", fill_color="wheat", line_width=3.0) ellipse = goocanvas.Ellipse(parent=group, center_x=0, center_y=0, radius_x=25, radius_y=25, fill_color="steelblue") group.set_data("parent1", parent1) group.set_data("parent2", parent2) group.connect("button-press-event", on_button_press) return vb
def __init__(self, rootitem, x, y, width, letter, dot_on, dot_off, fill_color, stroke_color, display_letter, clickable, rectangle, callback, braille_letter="alphabet"): self.letter = letter self.callback = callback self.display_letter = display_letter self.clickable = clickable self.dot_on = dot_on self.dot_off = dot_off self.fill_color = fill_color self.stroke_color = stroke_color self.rectangle = rectangle self.braille_letter = braille_letter height = width * 1.33 self.rootitem = goocanvas.Group(parent=rootitem) if (rectangle): self.item = goocanvas.Rect(parent=self.rootitem, x=x, y=y, width=width, height=height, stroke_color=self.stroke_color, fill_color=self.fill_color, line_width=2.0) self.text = goocanvas.Text(parent=self.rootitem, x=x + (width / 2.0), y=y + height + 15, text=str(letter), fill_color=self.stroke_color, alignment=pango.ALIGN_CENTER, anchor=gtk.ANCHOR_CENTER, font='Sans BOLD') if not display_letter: self.text.props.visibility = goocanvas.ITEM_INVISIBLE dot = 1 self.dot_items = [] self.cell_array = [] cell_radius = (width / 6.3) for u in range(2): for v in range(3): xx = x + width / 3.0 * (u + 1) - width / 20 yy = y + height / 4.0 * (v + 1) - height / 20 if u: xx = x + width / 3.0 * (u + 1) + width / 20 if v == 1: yy = y + height / 4.0 * (v + 1) if v == 2: yy = y + height / 4.0 * (v + 1) + height / 20 self.cell = \ goocanvas.Ellipse(parent = self.rootitem, center_x = xx, center_y = yy, radius_x = cell_radius, radius_y = cell_radius, stroke_color = self.stroke_color, fill_color = self.fill_color, line_width = width/25) self.cell_array.append(self.cell) # To fill the circles in lower board with red color if (clickable == True): self.cell.connect("button_press_event", self.dot_event) gcompris.utils.item_focus_init(self.cell, None) if isinstance(letter, int): fillings = BRAILLE_LETTERS.get(letter) else: fillings = BRAILLE_LETTERS.get(letter.upper()) if fillings == None: """only braille self.cell""" elif dot in fillings: self.cell.set_property("fill_color_rgba", self.dot_on) else: self.cell.set_property("fill_color_rgba", self.dot_off) self.dot_items.append(self.cell) dot += 1
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)
def __init__(self, game, rootitem, level, initial_color): self.game = game self.rootitem = rootitem self.initial_color = initial_color if initial_color == 0: self.color_1 = [ _("Not enough red"), _("Too much red")] self.color_2 = [ _("Not enough green"), _("Too much green")] self.color_3 = [ _("Not enough blue"), _("Too much blue")] else: self.color_1 = [ _("Not enough cyan"), _("Too much cyan")] self.color_2 = [ _("Not enough magenta"), _("Too much magenta")] self.color_3 = [ _("Not enough yellow"), _("Too much yellow")] self.color_rgb = [initial_color, initial_color, initial_color] self.color1 = self.color2 = self.color3 = self.initial_color self.color_cmy = [255 - self.color_rgb[0], 255 - self.color_rgb[1], 255 - self.color_rgb[2]] init_color = self.hex_code(initial_color, initial_color, initial_color) self.color_image = goocanvas.Ellipse( parent = rootitem, center_x = 395, center_y = 230, radius_y = 60, radius_x = 75, stroke_color = "black", fill_color_rgba = long(init_color,16), line_width = 1) # Random color to be matched self.increment = int(255/ (level * 2 + 1)) rand_r = random.randrange(0, 2 * level + 1) rand_g = random.randrange(0, 2 * level + 1) rand_b = random.randrange(0, 2 * level + 1) self.r_random = rand_r * self.increment self.g_random = rand_g * self.increment self.b_random = rand_b * self.increment self.required_color_cmy = [255 - self.r_random, 255 - self.g_random, 255 - self.b_random] code = self.hex_code(self.r_random, self.g_random, self.b_random) random_color = goocanvas.Rect( parent = rootitem, radius_x = 6, radius_y = 6, x = 350, y = 50, width = 100, height = 70, stroke_color = "black", line_width = 1, fill_color_rgba = long(code, 16)) # OK Button ok = goocanvas.Svg(parent = rootitem, svg_handle = gcompris.skin.svg_get(), svg_id = "#OK" ) ok.translate(0, -130) ok.connect("button_press_event", self.ok_event) gcompris.utils.item_focus_init(ok, None)
def start(self): self.gcomprisBoard.level = 1 self.gcomprisBoard.maxlevel = 1 self.gcomprisBoard.sublevel = 1 self.gcomprisBoard.number_of_sublevel = 1 # The basic duration factor for object animations # Higher is longer animation (slower) self.timerinc = 20 self.step_time = 100 # Need to manage the timers to quit properly self.waterlevel_timer = 0 # Used to display the bonus a single time self.you_won = False gcompris.sound.play_ogg("sounds/Harbor1.wav", "sounds/Harbor3.wav") # 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("watercycle/watercycle.svgz") goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#BACKGROUND", pointer_events=goocanvas.EVENTS_NONE) # Take care, the items are stacked on each other in the order you add them. # If you need, you can reorder them later with raise and lower functions. # The River self.riveritem = goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#RIVERWATER", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) self.riverfull = False # The dirty water self.dirtywater = goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#DIRTYWATER", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) # The clean water self.cleanwateritem = goocanvas.Svg( parent=self.rootitem, svg_handle=svghandle, svg_id="#CLEANWATER", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) # The Sun self.sunitem = goocanvas.Svg( parent = self.rootitem, svg_handle = svghandle, svg_id = "#SUN", tooltip = "\n\n\n" + \ _("The sun heats the water and creates water vapor. " "Water vapor combines into small water droplets which " "becomes clouds.") ) self.sunitem.connect("button_press_event", self.sun_item_event) # This item is clickeable and it must be seen gcompris.utils.item_focus_init(self.sunitem, None) self.sun_on = 0 self.sunitem_orig_y1 = self.sunitem.get_bounds().y1 self.sunitem_target_y1 = 10 self.sun_connect_handler = 0 # The Snow self.snowitem = goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#SNOW", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) # The rain self.rainitem = goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#RAIN", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) # The cloud self.clouditem = goocanvas.Svg( parent = self.rootitem, svg_handle = svghandle, svg_id = "#CLOUD", visibility = goocanvas.ITEM_INVISIBLE, tooltip = "\n\n\n" + \ _("As a cloud matures, the dense water droplets may combine " "to produce larger droplets, which may combine to form " "droplets large enough to fall as rain") ) self.clouditem.props.visibility = goocanvas.ITEM_INVISIBLE self.clouditem.connect("animation-finished", self.cloud_arrived) self.cloud_on = False self.cloud_is_arrived = False self.clouditem_bounds = self.clouditem.get_bounds() # The vapor self.vaporitem = goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#VAPOR", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) self.vaporitem.connect("animation-finished", self.vapor_arrived) # The Waterpump self.waterpumpitem = goocanvas.Svg( parent = self.rootitem, svg_handle = svghandle, svg_id = "#PUMPSTATION", tooltip = "\n\n\n" + \ _("This is a water pump station.") ) self.waterpumpitem.connect("button_press_event", self.waterpump_item_event) # This item is clickeable and it must be seen gcompris.utils.item_focus_init(self.waterpumpitem, None) self.waterpump_on = 0 # The WaterCleaning self.watercleaningitem = goocanvas.Svg( parent = self.rootitem, svg_handle = svghandle, svg_id = "#CLEANSTATION", tooltip = "\n\n\n" + \ _("This is a water cleanup station.") ) self.watercleaningitem.connect("button_press_event", self.watercleaning_item_event) # This item is clickeable and it must be seen gcompris.utils.item_focus_init(self.watercleaningitem, None) self.watercleaning_on = 0 # The tuxboat self.boatitem = goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#BOAT", pointer_events=goocanvas.EVENTS_NONE) self.boatitem.translate(-100, 0) self.boatitem_parked = goocanvas.Svg( parent=self.rootitem, svg_handle=svghandle, svg_id="#BOAT_PARKED", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) # Tux in the shower (without water) self.tuxshoweritem = goocanvas.Svg( parent=self.rootitem, svg_handle=svghandle, svg_id="#SHOWER", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) self.shower_tux = goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#SHOWER_TUX", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) # Tux in the shower with the water self.tuxshowerwateritem = goocanvas.Svg( parent=self.rootitem, svg_handle=svghandle, svg_id="#SHOWER_ON", pointer_events=goocanvas.EVENTS_NONE, visibility=goocanvas.ITEM_INVISIBLE) # The shower on/off button (I need to get the 2 buttons to manage the focus) self.showerbuttonitem_on = goocanvas.Svg( parent=self.rootitem, svg_handle=svghandle, svg_id="#SHOWER_BUTTON_ON", visibility=goocanvas.ITEM_INVISIBLE) self.showerbuttonitem_on.connect("button_press_event", self.showerbutton_item_event, True) # This item is clickeable and it must be seen gcompris.utils.item_focus_init(self.showerbuttonitem_on, None) self.showerbutton = False self.showerbuttonitem_off = goocanvas.Svg( parent=self.rootitem, svg_handle=svghandle, svg_id="#SHOWER_BUTTON_OFF", visibility=goocanvas.ITEM_INVISIBLE) self.showerbuttonitem_off.connect("button_press_event", self.showerbutton_item_event, False) # This item is clickeable and it must be seen gcompris.utils.item_focus_init(self.showerbuttonitem_off, None) goocanvas.Svg(parent=self.rootitem, svg_handle=svghandle, svg_id="#FOREGROUND", pointer_events=goocanvas.EVENTS_NONE) goocanvas.Svg( parent = self.rootitem, svg_handle = svghandle, svg_id = "#WATER_TOWER", tooltip = "\n\n\n" + \ _("A water tower or elevated water tower is a large elevated water storage container constructed to hold a water supply at a height sufficient to pressurize a water distribution system.") ) # The level of water in the tower self.waterlevel_max = 12 self.waterlevel_min = 1 self.waterlevel_x_ratio = 1.3 self.waterlevel = 1 self.waterlevel_item = goocanvas.Ellipse(parent=self.rootitem, center_x=635, center_y=142, radius_x=1, radius_y=1, fill_color_rgba=0x0033FFC0L, line_width=0) self.waterlevel_timer = gobject.timeout_add(1000, self.update_waterlevel) # Some item ordering self.rainitem.raise_(None) self.clouditem.raise_(None) self.vaporitem.raise_(None) # Ready GO target_x = 700 trip_x = int(target_x - self.boatitem.get_bounds().x1) self.boatitem.connect("animation-finished", self.boat_arrived) self.boatitem.animate(target_x, 0, 1, 1, True, self.timerinc * trip_x, self.step_time, goocanvas.ANIMATE_FREEZE) gcompris.bar_set(0) gcompris.bar_location(5, -1, 0.6) gcompris.bar_set_level(self.gcomprisBoard)
def buildBox(self, obj_evt, level): if level < 0: print('refresh trace') else: ### FIXME : this code should be factorized with the ### similar one in tracetimeline (addOperation) ev_time = time.strftime("%H:%M:%S", time.localtime(obj_evt.time)) corpsstr = '' entetestr = '' if obj_evt.name not in self.incomplete_operations_names: if ECACatalog.event_names[obj_evt.name]: entetestr = "%s : %s" % ( ev_time, ECACatalog.event_names[obj_evt.name]) else: entetestr = "%s : %s" % (ev_time, "Event not described") if obj_evt.concerned_object['id']: entetestr = entetestr + ' (%s)' % obj_evt.concerned_object[ 'id'] elif obj_evt.name.find('Player') >= 0: txt = obj_evt.content if txt != None: # content should be of the form pos_bef \n pos #but if it is an old trace, we only got pos poss = txt.split('\n') if len(poss) > 1 and obj_evt.name.find('PlayerSeek') >= 0: txt = poss[1] else: txt = poss[0] else: txt = time.strftime("%H:%M:%S", time.gmtime(obj_evt.movietime / 1000)) entetestr = "%s : %s %s" % ( ev_time, self.incomplete_operations_names[obj_evt.name], txt) else: comp = '' if obj_evt.concerned_object['type'] == Annotation: comp = _('of an annotation (%s)' ) % obj_evt.concerned_object['id'] elif obj_evt.concerned_object['type'] == Relation: comp = _( 'of a relation (%s)') % obj_evt.concerned_object['id'] elif obj_evt.concerned_object['type'] == AnnotationType: comp = _('of an annotation type (%s)' ) % obj_evt.concerned_object['id'] elif obj_evt.concerned_object['type'] == RelationType: comp = _('of a relation type (%s)' ) % obj_evt.concerned_object['id'] elif obj_evt.concerned_object['type'] == Schema: comp = _( 'of a schema (%s)') % obj_evt.concerned_object['id'] elif obj_evt.concerned_object['type'] == View: comp = _('of a view (%s)') % obj_evt.concerned_object['id'] elif obj_evt.concerned_object['type'] == Package: comp = _( 'of a package (%s)') % obj_evt.concerned_object['id'] else: comp = _('of an unknown item (%s)' ) % obj_evt.concerned_object['id'] #print "%s" % ob entetestr = "%s : %s %s" % ( ev_time, self.incomplete_operations_names[obj_evt.name], comp) if obj_evt.content is not None: corpsstr = urllib.parse.unquote( obj_evt.content.encode('utf-8')) entete = Gtk.Label(label=ev_time.encode("UTF-8")) hb = Gtk.HBox() hb.pack_start(entete, False, True, 0) objcanvas = goocanvas.Canvas() objcanvas.set_bounds(0, 0, 60, 20) hb.pack_end(objcanvas, False, True, 0) #BIG HACK to display icon te = obj_evt.name if te.find('Edit') >= 0: if te.find('Start') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file( config.data.advenefile( ('pixmaps', 'traces', 'edition.png'))) elif te.find('End') >= 0 or te.find('Destroy') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file( config.data.advenefile( ('pixmaps', 'traces', 'finedition.png'))) elif te.find('Creat') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file( config.data.advenefile(('pixmaps', 'traces', 'plus.png'))) elif te.find('Delet') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file( config.data.advenefile(('pixmaps', 'traces', 'moins.png'))) elif te.find('Set') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file( config.data.advenefile( ('pixmaps', 'traces', 'allera.png'))) elif te.find('Start') >= 0 or te.find('Resume') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file( config.data.advenefile( ('pixmaps', 'traces', 'lecture.png'))) elif te.find('Pause') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file( config.data.advenefile(('pixmaps', 'traces', 'pause.png'))) elif te.find('Stop') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file( config.data.advenefile(('pixmaps', 'traces', 'stop.png'))) elif te.find('Activation') >= 0: pb = GdkPixbuf.Pixbuf.new_from_file_at_size( config.data.advenefile(('pixmaps', 'traces', 'web.png')), 20, 20) else: pb = GdkPixbuf.Pixbuf.new_from_file_at_size( config.data.advenefile(('pixmaps', 'traces', 'error.png')), 20, 20) print('No icon for %s' % te) goocanvas.Image(parent=objcanvas.get_root_item(), width=20, height=20, x=0, y=0, pixbuf=pb) # object icon objg = Group(parent=objcanvas.get_root_item()) if obj_evt.concerned_object['id']: ob = self.controller.package.get_element_by_id( obj_evt.concerned_object['id']) temp_c = self.controller.get_element_color(ob) if temp_c is not None: temp_c = gdk2intrgba(Gdk.color_parse(temp_c)) else: temp_c = 0xFFFFFFFF goocanvas.Ellipse(parent=objg, center_x=40, center_y=10, radius_x=9, radius_y=9, stroke_color='black', fill_color_rgba=temp_c, line_width=1.0) if obj_evt.concerned_object['type'] == Annotation: #draw a A txt = 'A' elif obj_evt.concerned_object['type'] == Relation: #draw a R txt = 'R' elif obj_evt.concerned_object['type'] == AnnotationType: #draw a AT txt = 'AT' elif obj_evt.concerned_object['type'] == RelationType: #draw a RT txt = 'RT' elif obj_evt.concerned_object['type'] == Schema: #draw a S txt = 'S' elif obj_evt.concerned_object['type'] == View: #draw a V txt = 'V' else: #draw a U txt = 'U' goocanvas.Text(parent=objg, text=txt, x=40, y=10, width=-1, anchor=Gtk.ANCHOR_CENTER, font="Sans 5") else: # no concerned object, we are in an action of navigation txt = obj_evt.content if txt != None: # content should be of the form pos_bef \n pos #but if it is an old trace, we only got pos poss = txt.split('\n') if len(poss) > 1 and obj_evt.name.find('PlayerSeek') >= 0: txt = poss[1] else: txt = poss[0] else: txt = time.strftime("%H:%M:%S", time.gmtime(obj_evt.movietime / 1000)) goocanvas.Text(parent=objg, text=txt, x=40, y=10, width=-1, anchor=Gtk.ANCHOR_CENTER, font="Sans 7") cm = objcanvas.get_colormap() color = cm.alloc_color('#FFFFFF') if obj_evt.name in self.tracer.colormodel[level]: color = Gdk.color_parse(self.tracer.colormodel[level]) elif self.tracer.modelmapping[level]: for k in self.tracer.modelmapping[level]: if obj_evt.name in self.tracer.modelmapping[level][k]: x = self.tracer.modelmapping[level][k][obj_evt.name] if x >= 0: kn = self.tracer.tracemodel[k][x] if kn in self.tracer.colormodel[k]: color = Gdk.color_parse( self.tracer.colormodel[k][kn]) break else: #BIG HACK, FIXME #should do nothing but for incomplete operations we need to do something... if obj_evt.name in self.incomplete_operations_names: if obj_evt.concerned_object['id']: ob = self.controller.package.get_element_by_id( obj_evt.concerned_object['id']) if isinstance( ob, advene.model.annotation.Annotation ) or isinstance( ob, advene.model.annotation.Relation): x = 1 elif isinstance( ob, advene.model.schema.AnnotationType ) or isinstance( ob, advene.model.schema. RelationType) or isinstance( ob, advene.model.schema.Schema): x = 3 elif isinstance(ob, advene.model.view.View): x = 4 else: x = -1 if x >= 0: kn = self.tracer.tracemodel[k][x] if kn in self.tracer.colormodel[k]: color = Gdk.color_parse( self.tracer.colormodel[k][kn]) break objcanvas.modify_base(Gtk.StateType.NORMAL, color) objcanvas.set_size_request(60, 20) if corpsstr != "": objcanvas.set_tooltip_text(corpsstr) if entetestr != "": entete.set_tooltip_text(entetestr) return hb
def setup_canvas (canvas): root = canvas.get_root_item () #Plain items without clip path. item = goocanvas.Ellipse (parent = root, center_x = 0, center_y = 0, radius_x = 50, radius_y = 30, fill_color = "blue") item.translate (100, 100) item.rotate (30, 0, 0) item.connect ("button_press_event", on_button_press, "Blue ellipse (unclipped)") item = goocanvas.Rect (parent = root, x = 200, y = 50, width = 100, height = 100, fill_color = "red", clip_fill_rule = cairo.FILL_RULE_EVEN_ODD) item.connect ("button_press_event", on_button_press, "Red rectangle (unclipped)") item = goocanvas.Rect (parent = root, x = 380, y = 50, width = 100, height = 100, fill_color = "yellow") item.connect ("button_press_event", on_button_press, "Yellow rectangle (unclipped)") # Clipped items. item = goocanvas.Ellipse (parent = root, center_x = 0, center_y = 0, radius_x = 50, radius_y = 30, fill_color = "blue", clip_path = "M 0 0 h 100 v 100 h -100 Z") item.translate (100, 300) item.rotate (30, 0, 0) item.connect ("button_press_event", on_button_press, "Blue ellipse") item = goocanvas.Rect (parent = root, x = 200, y = 250, width = 100, height = 100, fill_color = "red", clip_path = "M 250 300 h 100 v 100 h -100 Z", clip_fill_rule = cairo.FILL_RULE_EVEN_ODD) item.connect ("button_press_event", on_button_press, "Red rectangle") item = goocanvas.Rect (parent = root, x = 380, y = 250, width = 100, height = 100, fill_color = "yellow", clip_path = "M480,230 l40,100 l-80 0 z") item.connect ("button_press_event", on_button_press, "Yellow rectangle") # Table with clipped items. table = goocanvas.Table (parent = root) table.translate (200, 400) table.rotate (30, 0, 0) item = goocanvas.Ellipse (parent = table, center_x = 0, center_y = 0, radius_x = 50, radius_y = 30, fill_color = "blue", clip_path = "M 0 0 h 100 v 100 h -100 Z") item.translate (100, 300) item.rotate (30, 0, 0) item.connect ("button_press_event", on_button_press, "Blue ellipse") item = goocanvas.Rect (parent = table, x = 200, y = 250, width = 100, height = 100, fill_color = "red", clip_path = "M 250 300 h 100 v 100 h -100 Z", clip_fill_rule = cairo.FILL_RULE_EVEN_ODD) item.connect ("button_press_event", on_button_press, "Red rectangle") table.set_child_properties (item, column = 1) item = goocanvas.Rect (parent = table, x = 380, y = 250, width = 100, height = 100, fill_color = "yellow", clip_path = "M480,230 l40,100 l-80 0 z") item.connect ("button_press_event", on_button_press, "Yellow rectangle") table.set_child_properties (item, column = 2)