def create_toolbar_background(sprite_list, width): # Create the toolbar background for the selectors spr = Sprite(sprite_list, 0, 0, svg_str_to_pixbuf(SVG().toolbar(2 * width, ICON_SIZE))) spr.type = 'toolbar' spr.set_layer(CATEGORY_LAYER) return spr
def _make_background(self, x, y, w, h, regenerate=False): ''' Make the background sprite for the palette. ''' orientation = self._turtle_window.orientation if regenerate and not self.backgrounds[orientation] is None: self.backgrounds[orientation].hide() self.backgrounds[orientation] = None if self.backgrounds[orientation] is None: svg = SVG() self.backgrounds[orientation] = \ Sprite(self._turtle_window.sprite_list, x, y, svg_str_to_pixbuf(svg.palette(w, h))) self.backgrounds[orientation].save_xy = (x, y) self._float_palette(self.backgrounds[orientation]) if orientation == 0 and w > self._turtle_window.width: self.backgrounds[orientation].type = \ 'category-shift-horizontal' elif orientation == 1 and \ h > self._turtle_window.height - ICON_SIZE: self.backgrounds[orientation].type = \ 'category-shift-vertical' else: self.backgrounds[orientation].type = 'category' '''
def __init__(self, tw, width, height): ''' Create a sprite to hold the canvas. ''' self.tw = tw self.width = width self.height = height # Build a cairo.Context from a cairo.XlibSurface self.canvas = cairo.Context(self.tw.turtle_canvas) cr = gtk.gdk.CairoContext(self.canvas) cr.set_line_cap(1) # Set the line cap to be round self.cx = 0 self.cy = 0 self.fgrgb = [255, 0, 0] self.bgrgb = [255, 248, 222] self.textsize = 48 # deprecated self.shade = 0 self.pendown = False self.xcor = 0 self.ycor = 0 self.heading = 0 self.pensize = 5 self.color = 0 self.gray = 100 self.fill = False self.poly_points = [] self.svg = SVG() self.svg.set_fill_color('none') self.tw.svg_string = ''
def layout(self, regenerate=False, show=True): ''' Layout prototypes in a palette. ''' offset = self._turtle_window.toolbar_offset buttons = self._turtle_window.palette_button orientation = self._turtle_window.orientation w = PALETTE_WIDTH h = PALETTE_HEIGHT if orientation == HORIZONTAL_PALETTE: x, y, max_w = self._horizontal_layout(_BUTTON_SIZE, offset + _MARGIN, self.blocks) if self._trash_palette(): blocks = [] # self.blocks[:] for blk in self._turtle_window.trash_stack: blocks.append(blk) x, y, max_w = self._horizontal_layout(x + max_w, y, blocks) w = x + max_w + _BUTTON_SIZE + _MARGIN if show: buttons[2].move((w - _BUTTON_SIZE, offset)) buttons[4].move((_BUTTON_SIZE, offset)) buttons[6].move((_BUTTON_SIZE, offset)) else: x, y, max_h = self._vertical_layout( _MARGIN, offset + _BUTTON_SIZE + _MARGIN, self.blocks) if self._trash_palette(): blocks = [] # self.blocks[:] for blk in self._turtle_window.trash_stack: blocks.append(blk) x, y, max_h = self._vertical_layout(x, y + max_h, blocks) h = y + max_h + _BUTTON_SIZE + _MARGIN - offset if show: buttons[2].move((PALETTE_WIDTH - _BUTTON_SIZE, offset)) buttons[3].move((0, offset + _BUTTON_SIZE)) buttons[5].move((0, offset + _BUTTON_SIZE)) self._make_background(0, offset, w, h, regenerate) if show: for blk in self.blocks: if blk.get_visibility(): blk.spr.set_layer(PROTO_LAYER) else: blk.spr.hide() buttons[2].save_xy = buttons[2].get_xy() self._float_palette(buttons[2]) self.backgrounds[orientation].set_layer(CATEGORY_LAYER) self.display_palette_shift_buttons() if self._trash_palette(): for blk in self._turtle_window.trash_stack: for gblk in find_group(blk): gblk.spr.set_layer(PROTO_LAYER) svg = SVG() self.backgrounds[orientation].set_shape( svg_str_to_pixbuf(svg.palette(w, h)))
def generate_turtle_pixbufs(colors): ''' Generate pixbufs for generic turtles ''' shapes = [] svg = SVG() svg.set_scale(1.0) for i in range(SHAPES): svg.set_orientation(i * 10) shapes.append(svg_str_to_pixbuf(svg.turtle(colors))) return shapes
def _new_block_from_factory(self, sprite_list, x, y, copy_block=None): self.svg = SVG() self.svg.set_scale(self.scale) self.svg.set_innie([False]) self.svg.set_outie(False) self.svg.set_tab(True) self.svg.set_slot(True) if copy_block is not None: self._left = copy_block._left self._top = copy_block._top self._right = copy_block._right self._bottom = copy_block._bottom self.dx = copy_block.dx self.ex = copy_block.ex self.ey = copy_block.ey self.width = copy_block.width self.height = copy_block.height self.shapes[0] = copy_block.shapes[0] if sprite_list is not None: self.spr = sprites.Sprite(sprite_list, x, y, self.shapes[0]) self.spr._margins = copy_block.spr._margins[:] if len(copy_block.shapes) > 1: self.shapes[1] = copy_block.shapes[1] self.docks = copy_block.docks[:] else: if self.expandable() and self.type == 'block': self.svg.set_show(True) self._make_block(self.svg) if sprite_list is not None: self.spr = sprites.Sprite(sprite_list, x, y, self.shapes[0]) self._set_margins() self._set_label_attributes() if (self.name == 'number' or self.name == 'string') and \ len(self.values) > 0: for i, v in enumerate(self.values): if v is not None: if self.name == 'number': self._set_labels( i, str(v).replace('.', self.block_list.decimal_point)) else: self._set_labels(i, str(v)) elif self.type == 'block' and self.name in CONSTANTS: self._set_labels(0, block_names[self.name][0] + ' = ' + \ str(CONSTANTS[self.name])) elif self.name in block_names: for i, n in enumerate(block_names[self.name]): self._set_labels(i, n) if copy_block is None and self.spr is not None: if self.spr.label_width() > self.spr.label_safe_width(): self.resize()