def __init__(self, turtle_window, n):
        '''This class handles the display of palette selectors (Only relevant
        to GNOME version and very old versions of Sugar).
        '''

        self.shapes = []
        self.spr = None
        self._turtle_window = turtle_window
        self._index = n

        if not n < len(palette_names):
            # Shouldn't happen, but hey...
            debug_output('palette index %d is out of range' % n,
                         self._turtle_window.running_sugar)
            self._name = 'extras'
        else:
            self._name = palette_names[n]

        icon_pathname = None
        for path in self._turtle_window.icon_paths:
            if os.path.exists(os.path.join(path, '%soff.svg' % (self._name))):
                icon_pathname = os.path.join(path, '%soff.svg' % (self._name))
                break

        if icon_pathname is not None:
            off_shape = svg_str_to_pixbuf(svg_from_file(icon_pathname))
        else:
            off_shape = svg_str_to_pixbuf(
                svg_from_file(
                    os.path.join(self._turtle_window.icon_paths[0],
                                 'extrasoff.svg')))
            error_output('Unable to open %soff.svg' % (self._name),
                         self._turtle_window.running_sugar)

        icon_pathname = None
        for path in self._turtle_window.icon_paths:
            if os.path.exists(os.path.join(path, '%son.svg' % (self._name))):
                icon_pathname = os.path.join(path, '%son.svg' % (self._name))
                break

        if icon_pathname is not None:
            on_shape = svg_str_to_pixbuf(svg_from_file(icon_pathname))
        else:
            on_shape = svg_str_to_pixbuf(
                svg_from_file(
                    os.path.join(self._turtle_window.icon_paths[0],
                                 'extrason.svg')))
            error_output('Unable to open %son.svg' % (self._name),
                         self._turtle_window.running_sugar)

        self.shapes.append(off_shape)
        self.shapes.append(on_shape)

        x = int(ICON_SIZE * self._index)
        self.spr = Sprite(self._turtle_window.sprite_list, x, 0, off_shape)
        self.spr.type = 'selector'
        self.spr.name = self._name
        self.set_layer()
Example #2
0
    def __init__(self, turtle_window, n):
        '''This class handles the display of palette selectors (Only relevant
        to GNOME version and very old versions of Sugar).
        '''

        self.shapes = []
        self.spr = None
        self._turtle_window = turtle_window
        self._index = n

        if not n < len(palette_names):
            # Shouldn't happen, but hey...
            debug_output('palette index %d is out of range' % n,
                         self._turtle_window.running_sugar)
            self._name = 'extras'
        else:
            self._name = palette_names[n]

        icon_pathname = None
        for path in self._turtle_window.icon_paths:
            if os.path.exists(os.path.join(path, '%soff.svg' % (self._name))):
                icon_pathname = os.path.join(path, '%soff.svg' % (self._name))
                break

        if icon_pathname is not None:
            off_shape = svg_str_to_pixbuf(svg_from_file(icon_pathname))
        else:
            off_shape = svg_str_to_pixbuf(svg_from_file(os.path.join(
                self._turtle_window.icon_paths[0], 'extrasoff.svg')))
            error_output('Unable to open %soff.svg' % (self._name),
                         self._turtle_window.running_sugar)

        icon_pathname = None
        for path in self._turtle_window.icon_paths:
            if os.path.exists(os.path.join(path, '%son.svg' % (self._name))):
                icon_pathname = os.path.join(path, '%son.svg' % (self._name))
                break

        if icon_pathname is not None:
            on_shape = svg_str_to_pixbuf(svg_from_file(icon_pathname))
        else:
            on_shape = svg_str_to_pixbuf(svg_from_file(os.path.join(
                self._turtle_window.icon_paths[0], 'extrason.svg')))
            error_output('Unable to open %son.svg' % (self._name),
                         self._turtle_window.running_sugar)

        self.shapes.append(off_shape)
        self.shapes.append(on_shape)

        x = int(ICON_SIZE * self._index)
        self.spr = Sprite(self._turtle_window.sprite_list, x, 0, off_shape)
        self.spr.type = 'selector'
        self.spr.name = self._name
        self.set_layer()
Example #3
0
 def _make_block_graphics(self, svg, function, arg=None):
     if arg is None:
         self.shapes[0] = svg_str_to_pixbuf(function())
     else:
         self.shapes[0] = svg_str_to_pixbuf(function(arg))
     self.width = self.svg.get_width()
     self.height = self.svg.get_height()
     self.svg.set_stroke_width(SELECTED_STROKE_WIDTH)
     self.svg.set_stroke_color(SELECTED_COLOR)
     if arg is None:
         self.shapes[1] = svg_str_to_pixbuf(function())
     else:
         self.shapes[1] = svg_str_to_pixbuf(function(arg))
Example #4
0
 def _make_block_graphics(self, svg, function, arg=None):
     self._set_colors(svg)
     self.svg.set_gradient(True, GRADIENT_COLOR)
     if arg is None:
         self.shapes[0] = svg_str_to_pixbuf(function())
     else:
         self.shapes[0] = svg_str_to_pixbuf(function(arg))
     self.width = self.svg.get_width()
     self.height = self.svg.get_height()
     self.svg.set_gradient(False)
     if arg is None:
         self.shapes[1] = svg_str_to_pixbuf(function())
     else:
         self.shapes[1] = svg_str_to_pixbuf(function(arg))
Example #5
0
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
Example #6
0
    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'

            '''
Example #7
0
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 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)))
Example #10
0
    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 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 _make_block_graphics(self, svg, function, arg=None):
     self._set_colors(svg)
     self.svg.set_gradient(True, GRADIENT_COLOR)
     if arg is None:
         pixbuf = svg_str_to_pixbuf(function())
     else:
         pixbuf = svg_str_to_pixbuf(function(arg))
     self.width = self.svg.get_width()
     self.height = self.svg.get_height()
     self.shapes[0] = _pixbuf_to_cairo_surface(pixbuf,
                                               self.width, self.height)
     self.svg.set_gradient(False)
     if arg is None:
         pixbuf = svg_str_to_pixbuf(function())
     else:
         pixbuf = svg_str_to_pixbuf(function(arg))
     self.shapes[1] = _pixbuf_to_cairo_surface(pixbuf,
                                               self.width, self.height)