[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- From: René Dudfield <renesd@xxxxxxxxx>
- Date: Wed, 17 Jun 2009 16:41:52 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Wed, 17 Jun 2009 02:41:55 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=1bQ1yGawsemAm/bbEB2+hQVDea2WqLKjLNqzniiUCE0=; b=lcu0mK6MA382+qWNFPnMOuMYghwViHzHeeJlnPMctRcU0jI4xW+IlYXongfbYdK1Pl 12LbByZJQBuUF49urk6oewgJtOjDikf0xQa5TWWkOioSMq4OjscDK8uT/tIGyvGWEDD7 5aHTkJYfXfb5ZcX+vodPSOtsDepfLfU/VCDdM=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=GJDiDp18HGs3+HYskYoyG3PVHmobO4bioIVgATxuKDOzDznAkVNORucHRDIl91+Fmq f1VgU/c8sWNY3uDHmKoTDpmaj3n5MmEADZo1RA/2Mox+6/HsXnNmcW/lfP4/pFlTfVFE MWPH1Vqit2fR0MWas0a6L/fSU5paKaOou7Z1c=
- In-reply-to: <4A388D38.5040304@xxxxxxxxx>
- References: <64ddb72c0906162202r432887e5l760c6bb2cca8660f@xxxxxxxxxxxxxx> <4A388D38.5040304@xxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
On Wed, Jun 17, 2009 at 4:29 PM, Lenard Lindstrom<len-l@xxxxxxxxx> wrote:
> René Dudfield wrote:
>>
>> Hi,
>>
>> one issue with the new Color type is unpacking to r,g,b or r,g,b,a.
>>
>> In some places Color is assumed to return (r,g,b) and others
>> (r,g,b,a), and now many things return a Color rather than a tuple.
>>
>> So I want to change Color to unpack to r,g,b,a or r,g,b.
>>
>> r,g,b = pygame.Color(1,2,3,4)
>> r,g,b,a = pygame.Color(1,2,3,4)
>>
>> Anyone have an idea how this can work? Either in C or python?
>>
>> This is to keep backwards compatibility.
>>
>>
>> cheers,
>>
>
> Hi René,
>
> Are there cases where this is breaking code? For the most part I believe
> Pygame functions returned 4-tuples. So Color is just pretty much a drop-in
> replacement. If a program is using tuples to declare color values then the
> size is already known and unpacking is not a problem. It is
> Surface.get_palette and get_palette_at, which originally returned 3-tuples,
> where we run into problems. So here are the choices I see. One, just accept
> that the new get_palette and get_palette_at will break things, just as any
> program that tries to use a color return value as a dictionary key will now
> break. How many programs actually use color palettes anyway? Two, give Color
> a size property. If alpha is set None it becomes length 3. But then how does
> one represent this internally without adding another field to the Color C
> structure? Declare the color component values as C ints? Three, create a new
> Color subtype of length 3 having a fixed alpha of 255. I'm not happy with
> any of the choices but prefer three. Any other ideas?
>
> Lenard
>
>
hi,
yeah for example in solarwolf:
File "solarwolf-1.5/code/gamemenu.py", line 70, in load_game_resources
pal = [(g,g,b) for (r,g,b) in origpal]
File "solarwolf-1.5/code/objshot.py", line 28, in load_game_resources
for (r,g,b) in origpal]
hrmm. I think a 3 element Color subtype might be the way to go.
Maybe we don't even need a subtype, but just a length property that
can be 1,2,3, or 4? As you say get_palette(_at) could return len 3
Colors.
If it could unpack to 3, or 4 depending on the number of elements on
the left, I think I'd prefer that though.
cheers,
- Follow-Ups:
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- References:
- [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Prev by Author:
[pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Next by Author:
Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Previous by thread:
Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Next by thread:
Re: [pygame] Color, unpacking to r,g,b and r,g,b,a - ValueError: too many values to unpack
- Index(es):