Currently, if you set pyglet.resource.path to ["foo"] and load "abc.png"
(foo/abc.png), and then change pyglet.resource.path to ["bar"] and try to
load "abc.png", you still get foo/abc.png, since the caching looks at the
name of the image file only.
This simple patch makes it so that the images are cached per specific
setting of pyglet.resource.path. I included the patch as an attachment and
inline below since it's so tiny.
# HG changeset patch
# User Nathan Stocks <nathan.sto...@gmail.com>
# Date 1349326606 21600
# Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
# Parent bf7f6c05275664ed76aab926944fe3a6a74ff022
Made it so that once you load an image, you can still load more images of
the same name by changing pyglet.resource.path.
On Thu, Oct 4, 2012 at 12:58 AM, Nathan <nathan.sto...@gmail.com> wrote:
> Currently, if you set pyglet.resource.path to ["foo"] and load "abc.png"
> (foo/abc.png), and then change pyglet.resource.path to ["bar"] and try to
> load "abc.png", you still get foo/abc.png, since the caching looks at the
> name of the image file only.
> This simple patch makes it so that the images are cached per specific
> setting of pyglet.resource.path. I included the patch as an attachment and
> inline below since it's so tiny.
> # HG changeset patch
> # User Nathan Stocks <nathan.sto...@gmail.com>
> # Date 1349326606 21600
> # Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
> # Parent bf7f6c05275664ed76aab926944fe3a6a74ff022
> Made it so that once you load an image, you can still load more images of
> the same name by changing pyglet.resource.path.
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
Andre, I'm not combining paths. I'm using the string representation of the
current state of the list of paths to add a unique prefix to the key used
to cache the image.
For example, if pyglet.resource.path is ['my_sad_theme', 'my_happy_theme'],
...then the key will end up being the string "['my_sad_theme',
'my_happy_theme']imagename"
If you change the path in any way, then the string representation of the
entire path list changes, which results in a different unique key, and a
new image searched for and cached using the new string representation of
the list as a prefix to the key.
Not quite as elegant as making a hash of the path state and using that as a
shorter prefix, but it definitely works.
On Thu, Oct 4, 2012 at 5:35 AM, Andre D <an...@andred.ca> wrote:
> Please use os.path.join to combine paths
> On Thu, Oct 4, 2012 at 12:58 AM, Nathan <nathan.sto...@gmail.com> wrote:
> > Currently, if you set pyglet.resource.path to ["foo"] and load "abc.png"
> > (foo/abc.png), and then change pyglet.resource.path to ["bar"] and try to
> > load "abc.png", you still get foo/abc.png, since the caching looks at the
> > name of the image file only.
> > This simple patch makes it so that the images are cached per specific
> > setting of pyglet.resource.path. I included the patch as an attachment
> and
> > inline below since it's so tiny.
> > # HG changeset patch
> > # User Nathan Stocks <nathan.sto...@gmail.com>
> > # Date 1349326606 21600
> > # Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
> > # Parent bf7f6c05275664ed76aab926944fe3a6a74ff022
> > Made it so that once you load an image, you can still load more images of
> > the same name by changing pyglet.resource.path.
> > --
> > You received this message because you are subscribed to the Google Groups
> > "pyglet-users" group.
> > To post to this group, send email to pyglet-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > pyglet-users+unsubscribe@googlegroups.com.
> > For more options, visit this group at
> > http://groups.google.com/group/pyglet-users?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
On Thu, Oct 4, 2012 at 9:36 AM, Nathan <nathan.sto...@gmail.com> wrote:
> Andre, I'm not combining paths. I'm using the string representation of
> the current state of the list of paths to add a unique prefix to the key
> used to cache the image.
> For example, if pyglet.resource.path is ['my_sad_theme', 'my_happy_theme'],
> ...then the key will end up being the string "['my_sad_theme',
> 'my_happy_theme']imagename"
> If you change the path in any way, then the string representation of the
> entire path list changes, which results in a different unique key, and a
> new image searched for and cached using the new string representation of
> the list as a prefix to the key.
> Not quite as elegant as making a hash of the path state and using that as
> a shorter prefix, but it definitely works.
> ~ Nathan
> On Thu, Oct 4, 2012 at 5:35 AM, Andre D <an...@andred.ca> wrote:
>> Please use os.path.join to combine paths
>> On Thu, Oct 4, 2012 at 12:58 AM, Nathan <nathan.sto...@gmail.com> wrote:
>> > Currently, if you set pyglet.resource.path to ["foo"] and load "abc.png"
>> > (foo/abc.png), and then change pyglet.resource.path to ["bar"] and try
>> to
>> > load "abc.png", you still get foo/abc.png, since the caching looks at
>> the
>> > name of the image file only.
>> > This simple patch makes it so that the images are cached per specific
>> > setting of pyglet.resource.path. I included the patch as an attachment
>> and
>> > inline below since it's so tiny.
>> > # HG changeset patch
>> > # User Nathan Stocks <nathan.sto...@gmail.com>
>> > # Date 1349326606 21600
>> > # Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
>> > # Parent bf7f6c05275664ed76aab926944fe3a6a74ff022
>> > Made it so that once you load an image, you can still load more images
>> of
>> > the same name by changing pyglet.resource.path.
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups
>> > "pyglet-users" group.
>> > To post to this group, send email to pyglet-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > pyglet-users+unsubscribe@googlegroups.com.
>> > For more options, visit this group at
>> > http://groups.google.com/group/pyglet-users?hl=en.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pyglet-users" group.
>> To post to this group, send email to pyglet-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> pyglet-users+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/pyglet-users?hl=en.
I should have some time to check it over tonight. Is there an issue for
this in the tracker?
On Oct 9, 2012 4:03 AM, "Nathan" <nathan.sto...@gmail.com> wrote:
> Sooo, would anyone be willing to commit this? Or...?
> ~ Nathan
> On Thu, Oct 4, 2012 at 9:36 AM, Nathan <nathan.sto...@gmail.com> wrote:
>> Andre, I'm not combining paths. I'm using the string representation of
>> the current state of the list of paths to add a unique prefix to the key
>> used to cache the image.
>> For example, if pyglet.resource.path is ['my_sad_theme',
>> 'my_happy_theme'],
>> ...then the key will end up being the string "['my_sad_theme',
>> 'my_happy_theme']imagename"
>> If you change the path in any way, then the string representation of the
>> entire path list changes, which results in a different unique key, and a
>> new image searched for and cached using the new string representation of
>> the list as a prefix to the key.
>> Not quite as elegant as making a hash of the path state and using that as
>> a shorter prefix, but it definitely works.
>> ~ Nathan
>> On Thu, Oct 4, 2012 at 5:35 AM, Andre D <an...@andred.ca> wrote:
>>> Please use os.path.join to combine paths
>>> On Thu, Oct 4, 2012 at 12:58 AM, Nathan <nathan.sto...@gmail.com> wrote:
>>> > Currently, if you set pyglet.resource.path to ["foo"] and load
>>> "abc.png"
>>> > (foo/abc.png), and then change pyglet.resource.path to ["bar"] and try
>>> to
>>> > load "abc.png", you still get foo/abc.png, since the caching looks at
>>> the
>>> > name of the image file only.
>>> > This simple patch makes it so that the images are cached per specific
>>> > setting of pyglet.resource.path. I included the patch as an
>>> attachment and
>>> > inline below since it's so tiny.
>>> > # HG changeset patch
>>> > # User Nathan Stocks <nathan.sto...@gmail.com>
>>> > # Date 1349326606 21600
>>> > # Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
>>> > # Parent bf7f6c05275664ed76aab926944fe3a6a74ff022
>>> > Made it so that once you load an image, you can still load more images
>>> of
>>> > the same name by changing pyglet.resource.path.
>>> > if not rotate and not flip_x and not flip_y:
>>> > Works great for me!
>>> > Thoughts?
>>> > ~ Nathan
>>> > --
>>> > You received this message because you are subscribed to the Google
>>> Groups
>>> > "pyglet-users" group.
>>> > To post to this group, send email to pyglet-users@googlegroups.com.
>>> > To unsubscribe from this group, send email to
>>> > pyglet-users+unsubscribe@googlegroups.com.
>>> > For more options, visit this group at
>>> > http://groups.google.com/group/pyglet-users?hl=en.
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "pyglet-users" group.
>>> To post to this group, send email to pyglet-users@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> pyglet-users+unsubscribe@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/pyglet-users?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
I just noticed a small bug in this patch that causes it to never
actually use the cached images. The condition for testing if a cached
version is available still looks for "name" in the dict.
So the line
if name in self._cached_images:
should of course read
if str(self.path)+name in self._cached_images:
With that change, it might be desirable to put the value of
"str(self.path)+name" into a variable before the "if", instead of
computing it twice (for checking and then getting/setting the cached
image).
Additionally, for consistency reasons, I think we should add similar
changes to the texture() and animation() functions too, which also use
a cache.
On Tue, Oct 9, 2012 at 11:00 AM, Adam Bark <adam.jt...@gmail.com> wrote:
> I should have some time to check it over tonight. Is there an issue for this
> in the tracker?
> On Oct 9, 2012 4:03 AM, "Nathan" <nathan.sto...@gmail.com> wrote:
>> Sooo, would anyone be willing to commit this? Or...?
>> ~ Nathan
>> On Thu, Oct 4, 2012 at 9:36 AM, Nathan <nathan.sto...@gmail.com> wrote:
>>> Andre, I'm not combining paths. I'm using the string representation of
>>> the current state of the list of paths to add a unique prefix to the key
>>> used to cache the image.
>>> For example, if pyglet.resource.path is ['my_sad_theme',
>>> 'my_happy_theme'],
>>> ...then the key will end up being the string "['my_sad_theme',
>>> 'my_happy_theme']imagename"
>>> If you change the path in any way, then the string representation of the
>>> entire path list changes, which results in a different unique key, and a new
>>> image searched for and cached using the new string representation of the
>>> list as a prefix to the key.
>>> Not quite as elegant as making a hash of the path state and using that as
>>> a shorter prefix, but it definitely works.
>>> ~ Nathan
>>> On Thu, Oct 4, 2012 at 5:35 AM, Andre D <an...@andred.ca> wrote:
>>>> Please use os.path.join to combine paths
>>>> On Thu, Oct 4, 2012 at 12:58 AM, Nathan <nathan.sto...@gmail.com> wrote:
>>>> > Currently, if you set pyglet.resource.path to ["foo"] and load
>>>> > "abc.png"
>>>> > (foo/abc.png), and then change pyglet.resource.path to ["bar"] and try
>>>> > to
>>>> > load "abc.png", you still get foo/abc.png, since the caching looks at
>>>> > the
>>>> > name of the image file only.
>>>> > This simple patch makes it so that the images are cached per specific
>>>> > setting of pyglet.resource.path. I included the patch as an
>>>> > attachment and
>>>> > inline below since it's so tiny.
>>>> > # HG changeset patch
>>>> > # User Nathan Stocks <nathan.sto...@gmail.com>
>>>> > # Date 1349326606 21600
>>>> > # Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
>>>> > # Parent bf7f6c05275664ed76aab926944fe3a6a74ff022
>>>> > Made it so that once you load an image, you can still load more images
>>>> > of
>>>> > the same name by changing pyglet.resource.path.
>>>> > if not rotate and not flip_x and not flip_y:
>>>> > Works great for me!
>>>> > Thoughts?
>>>> > ~ Nathan
>>>> > --
>>>> > You received this message because you are subscribed to the Google
>>>> > Groups
>>>> > "pyglet-users" group.
>>>> > To post to this group, send email to pyglet-users@googlegroups.com.
>>>> > To unsubscribe from this group, send email to
>>>> > pyglet-users+unsubscribe@googlegroups.com.
>>>> > For more options, visit this group at
>>>> > http://groups.google.com/group/pyglet-users?hl=en.
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "pyglet-users" group.
>>>> To post to this group, send email to pyglet-users@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> pyglet-users+unsubscribe@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/pyglet-users?hl=en.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pyglet-users" group.
>> To post to this group, send email to pyglet-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> pyglet-users+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/pyglet-users?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
On Tue, Oct 9, 2012 at 3:00 AM, Adam Bark <adam.jt...@gmail.com> wrote:
> I should have some time to check it over tonight. Is there an issue for
> this in the tracker?
> On Oct 9, 2012 4:03 AM, "Nathan" <nathan.sto...@gmail.com> wrote:
>> Sooo, would anyone be willing to commit this? Or...?
>> ~ Nathan
>> On Thu, Oct 4, 2012 at 9:36 AM, Nathan <nathan.sto...@gmail.com> wrote:
>>> Andre, I'm not combining paths. I'm using the string representation of
>>> the current state of the list of paths to add a unique prefix to the key
>>> used to cache the image.
>>> For example, if pyglet.resource.path is ['my_sad_theme',
>>> 'my_happy_theme'],
>>> ...then the key will end up being the string "['my_sad_theme',
>>> 'my_happy_theme']imagename"
>>> If you change the path in any way, then the string representation of the
>>> entire path list changes, which results in a different unique key, and a
>>> new image searched for and cached using the new string representation of
>>> the list as a prefix to the key.
>>> Not quite as elegant as making a hash of the path state and using that
>>> as a shorter prefix, but it definitely works.
>>> ~ Nathan
>>> On Thu, Oct 4, 2012 at 5:35 AM, Andre D <an...@andred.ca> wrote:
>>>> Please use os.path.join to combine paths
>>>> On Thu, Oct 4, 2012 at 12:58 AM, Nathan <nathan.sto...@gmail.com>
>>>> wrote:
>>>> > Currently, if you set pyglet.resource.path to ["foo"] and load
>>>> "abc.png"
>>>> > (foo/abc.png), and then change pyglet.resource.path to ["bar"] and
>>>> try to
>>>> > load "abc.png", you still get foo/abc.png, since the caching looks at
>>>> the
>>>> > name of the image file only.
>>>> > This simple patch makes it so that the images are cached per specific
>>>> > setting of pyglet.resource.path. I included the patch as an
>>>> attachment and
>>>> > inline below since it's so tiny.
>>>> > # HG changeset patch
>>>> > # User Nathan Stocks <nathan.sto...@gmail.com>
>>>> > # Date 1349326606 21600
>>>> > # Node ID f8102f9ee5b19c43c6129dac070bf393f82e3ef7
>>>> > # Parent bf7f6c05275664ed76aab926944fe3a6a74ff022
>>>> > Made it so that once you load an image, you can still load more
>>>> images of
>>>> > the same name by changing pyglet.resource.path.
>>>> > if not rotate and not flip_x and not flip_y:
>>>> > Works great for me!
>>>> > Thoughts?
>>>> > ~ Nathan
>>>> > --
>>>> > You received this message because you are subscribed to the Google
>>>> Groups
>>>> > "pyglet-users" group.
>>>> > To post to this group, send email to pyglet-users@googlegroups.com.
>>>> > To unsubscribe from this group, send email to
>>>> > pyglet-users+unsubscribe@googlegroups.com.
>>>> > For more options, visit this group at
>>>> > http://groups.google.com/group/pyglet-users?hl=en.
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "pyglet-users" group.
>>>> To post to this group, send email to pyglet-users@googlegroups.com.
>>>> To unsubscribe from this group, send email to
>>>> pyglet-users+unsubscribe@googlegroups.com.
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/pyglet-users?hl=en.
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pyglet-users" group.
>> To post to this group, send email to pyglet-users@googlegroups.com.
>> To unsubscribe from this group, send email to
>> pyglet-users+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/pyglet-users?hl=en.
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
> wrote:
> I just noticed a small bug in this patch that causes it to never
> actually use the cached images. The condition for testing if a cached
> version is available still looks for "name" in the dict.
> So the line
> if name in self._cached_images:
> should of course read
> if str(self.path)+name in self._cached_images:
> With that change, it might be desirable to put the value of
> "str(self.path)+name" into a variable before the "if", instead of
> computing it twice (for checking and then getting/setting the cached
> image).
> Additionally, for consistency reasons, I think we should add similar
> changes to the texture() and animation() functions too, which also use
> a cache.
On Tue, Oct 9, 2012 at 1:03 PM, Adam Bark <adam.jt...@gmail.com> wrote:
> It might be good to document it if you can be bothered.
> On Oct 9, 2012 3:54 PM, "Nathan" <nathan.sto...@gmail.com> wrote:
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
> On Tue, Oct 9, 2012 at 1:03 PM, Adam Bark <adam.jt...@gmail.com> wrote:
>> It might be good to document it if you can be bothered.
> Thanks. I've posted a couple of things including a work around that I
> would like opinions on.
> Cheers,
> Adam.
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet-users@googlegroups.com.
> To unsubscribe from this group, send email to
> pyglet-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.
>> I tested it, and it works great for me. It's also a much more elegant
>> (and functional) solution than my quick-n-dirty attempt.
>> ~ Nathan
>> I can commit it later, I was just waiting for confirmation that it works.
> Thanks,
> Adam.
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To post to this group, send email to pyglet-users@googlegroups.com.
> To unsubscribe from this group, send email to pyglet-users+unsubscribe@**
> googlegroups.com <pyglet-users%2Bunsubscribe@googlegroups.com>.
> For more options, visit this group at http://groups.google.com/** > group/pyglet-users?hl=en<http://groups.google.com/group/pyglet-users?hl=en>
> .