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 _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 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 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)))