Thanks, works like a charm.
This caching should be included directly within pyglet Label class.


Here is a modified version with static attributes instead of global
variables:


class Label(pyglet.text.Label):
    _cached_groups = {}
    def _init_groups(self, group):
        if not group:
            return
        if group not in self.__class__._cached_groups.keys():
            top = pyglet.text.layout.TextLayoutGroup(group)
            bg = pyglet.graphics.OrderedGroup(0,top)
            fg = pyglet.text.layout.TextLayoutForegroundGroup(1,top)
            fg2 =
pyglet.text.layout.TextLayoutForegroundDecorationGroup (2,top)
            self.__class__._cached_groups[group] = [top,bg,fg,fg2,0]
        groups = self.__class__._cached_groups[group]
        self.top_group= groups[0]
        self.background_group = groups[1]
        self.foreground_group = groups[2]
        self.foreground_decoration_group = groups[3]
        groups[4] += 1

    def delete(self):
        pyglet.text.Label.delete(self)
        group = self.top_group.parent
        if group is not None:
            groups = self.__class__._cached_groups[group]
            groups[4] -= 1
            if not groups[4]:
                del self.__class__._cached_groups[group]
            self.top_group = None
            self.background_self = None
            self.foreground_group = None
            self.foreground_decoration_group = None




Nicolas


On Jun 24, 7:44 am, Lynx <[email protected]> wrote:
> Oops, made a mistake - replace self.top_group with top_group in the
> following lines!
>
> On Jun 23, 10:41 pm, Lynx <[email protected]> wrote:
>
> >             top_group = pyglet.text.layout.TextLayoutGroup(group)
> >             background_group = pyglet.graphics.OrderedGroup(0,
> > self.top_group)
> >             foreground_group = \
> >                 pyglet.text.layout.TextLayoutForegroundGroup(1,
> > self.top_group)
> >             foreground_decoration_group = \
> >                 pyglet.text.layout.TextLayoutForegroundDecorationGroup
> > (
> >                     2, self.top_group)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to