Re: [pygame] Good code for text wrapping?

2008-10-18 Thread Charlie Nolan
Yes, yes, I know, it's Wednesday and then some.  My laptop's display
decided to die on Tuesday and it's in for repairs.  Linux decided to
run fsck on the reboot as it was failing, and since then, I've got no
idea what it's up to, so I couldn't even bring it up to get files off.
 Drive's sitting in front of me, but I don't have any way to connect
it to a different machine.

I'll get on this once Murphy leaves me alone again.

-FM

On Fri, Oct 10, 2008 at 3:12 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
> cool.  There's no rush :)  I haven't gotten back into the text
> wrapping mood yet either.
>
> I saw your mock font, for testing.  That's a good idea.
>
> cu,
>
> On Fri, Oct 10, 2008 at 6:13 PM, Charlie Nolan <[EMAIL PROTECTED]> wrote:
>> Just posting to say that no, I haven't forgotten about this.  I'd just
>> forgotten how many things I have to work on.  Anybody got a cloning
>> device handy?
>>
>> Failing that, give me a prod if there isn't a basic working version up
>> by Wednesday.  It'll only take a couple hours, I just need to find a
>> couple hours when I'm alert, not doing something else, and interested
>> in coding.
>>
>> -FM
>>
>


Re: [pygame] Good code for text wrapping?

2008-10-10 Thread René Dudfield
cool.  There's no rush :)  I haven't gotten back into the text
wrapping mood yet either.

I saw your mock font, for testing.  That's a good idea.

cu,

On Fri, Oct 10, 2008 at 6:13 PM, Charlie Nolan <[EMAIL PROTECTED]> wrote:
> Just posting to say that no, I haven't forgotten about this.  I'd just
> forgotten how many things I have to work on.  Anybody got a cloning
> device handy?
>
> Failing that, give me a prod if there isn't a basic working version up
> by Wednesday.  It'll only take a couple hours, I just need to find a
> couple hours when I'm alert, not doing something else, and interested
> in coding.
>
> -FM
>


Re: [pygame] Good code for text wrapping?

2008-10-10 Thread Charlie Nolan
Just posting to say that no, I haven't forgotten about this.  I'd just
forgotten how many things I have to work on.  Anybody got a cloning
device handy?

Failing that, give me a prod if there isn't a basic working version up
by Wednesday.  It'll only take a couple hours, I just need to find a
couple hours when I'm alert, not doing something else, and interested
in coding.

-FM


Re: [pygame] Good code for text wrapping?

2008-09-25 Thread Charlie Nolan
I like Greg's suggestion, it sounds like the sanest way to handle
this.  I'll go ahead and rough out a skeleton system.

René - Yeah, I'm thinking we'll just use a bare class, since it's got
somewhat nicer syntax than a dict.  (style.bold instead of
style["bold"])  As far as inheritance goes, the default should
probably be to clobber everything, but it might be nice to allow
bleed-through too.  Useful, for instance, if you wanted to set the
entire passage bold but it already had individual
colors/italics/underline in place.

-FM

On 9/25/08, René Dudfield <[EMAIL PROTECTED]> wrote:
> hey,
>
> I like the idea of doing it as a separate module.
>
> 
> let's work on it here...
> http://code.google.com/p/pygame/
>
> branches/text/
>
> I've added you to the project... (if anyone else wants to help with
> it, please send me your email off list).
> 
>
>
> A simple style dict/class which goes along with each part of text
> would work fine I think.  This method seems to work ok for html/css
> etc.
>
> We need to make sure that styles can be applied inside of styles.  I
> guess a simple inheritance would work there?
>
> Either:
> - child styles inherit from the top, over riding what they declare?
> - child styles are completely new, inheriting nothing?
>
> I think the simplest implementation would to make the style be applied
> as is... with nothing inherited from the parent.  Then we can mess
> with inheritance of child styles separately.
>
>
> cheers,
>
>
>
>
>
> On Thu, Sep 25, 2008 at 4:16 PM, Charlie Nolan <[EMAIL PROTECTED]>
> wrote:
>> Sure, I'm always happy to help.  I guess the first issue to look at is
>> where to put this.
>>
>> One possibility would be methods on the font.Font class.
>> Pro:
>> * Right next to the normal render method and hence an obvious place to
>> look.
>> * We might even be able to fold it into the main render function.
>> Con:
>> * Forces us to stick with a single font for the entire text.
>> * Clutters up that class.  If we merge with render instead, we make it
>> much more complicated.
>> * Forced to use C, since we're working in a C class.  (AFAIK, there's
>> no way to mix like that without monkeypatching.)
>>
>> Another possibility would be in its own module, just as naked functions.
>> Pro:
>> * Simple to use.
>> * Everything's grouped together and easy to scan through.
>> Con:
>> * When we start incorporating styles, naked functions get clumsy (as
>> my example already shows).  There's just too much extra data that has
>> to be shoved into the function call.
>>
>> And the third that comes to mind is building a class that represents a
>> block of text with various properties and giving it a render method.
>> Pro:
>> * Styles, especially, benefit from the complexity segmentation this
>> provides.  The final attributes can be built piecemeal and in a
>> sensible order, instead of trying to shove everything into one
>> function call.
>> * This gives us an easy place to store glyph position data for
>> handling click/drag.
>> Con:
>> * Not as easy to use as naked functions, as creating an ordinary block
>> of wrapped text is now a two-step process.
>>
>> My preference would be either the class or a hybrid of class and naked
>> functions.  The hybrid would put the functionality into the naked
>> functions, with the class essentially acting as a "make this sane"
>> wrapper around the complex parts of the naked functions.
>>
>> -FM
>>
>> On 9/24/08, René Dudfield <[EMAIL PROTECTED]> wrote:
>>> hey,
>>>
>>> would you like to work with me in creating something for inclusion in
>>> pygame?
>>>
>>> This would mean working out a simple api, making docs, examples, and
>>> unittests.
>>>
>>> Something basic that we can have a look at, for adding the most easy
>>> and useful features.  We can try and avoid most of the tricky issues
>>> for now.
>>>
>>>
>>>
>>> If anyone else is interested, we can set up a google host page or
>>> something to work on it?
>>>
>>> cheers,
>>>
>>>
>>>
>>>
>>> On Tue, Sep 23, 2008 at 10:11 PM, Charlie Nolan <[EMAIL PROTECTED]>
>>> wrote:
 A fair amount of this is already in that file, down in print_string
 and print_line.  (You're welcome to as much of the file as you like,
 but I'd strongly suggest you look into refactoring it.  It's good
 enough for one isolated project, but probably not up to library
 quality.)

> - aligning text, left, right, center etc.
> - vertical alignment... top, bottom, center.
> - text color
 Check.

> - each part of text having a separate font/attributes.  So you can
> then do words with bold, italics etc.
 Everything but the font is easy to extend (the font's ugly to do, and
 probably overkill).  I've already got underline in there.  Might want
 to swap the style list for a style dict/object, though, to avoid
 degenerating into positional hell.

> - selecting text.  Based on mouse click, which letter and word does it
> collide with?
 I've alread

Re: [pygame] Good code for text wrapping?

2008-09-25 Thread René Dudfield
hey,

I like the idea of doing it as a separate module.


let's work on it here...
http://code.google.com/p/pygame/

branches/text/

I've added you to the project... (if anyone else wants to help with
it, please send me your email off list).



A simple style dict/class which goes along with each part of text
would work fine I think.  This method seems to work ok for html/css
etc.

We need to make sure that styles can be applied inside of styles.  I
guess a simple inheritance would work there?

Either:
- child styles inherit from the top, over riding what they declare?
- child styles are completely new, inheriting nothing?

I think the simplest implementation would to make the style be applied
as is... with nothing inherited from the parent.  Then we can mess
with inheritance of child styles separately.


cheers,





On Thu, Sep 25, 2008 at 4:16 PM, Charlie Nolan <[EMAIL PROTECTED]> wrote:
> Sure, I'm always happy to help.  I guess the first issue to look at is
> where to put this.
>
> One possibility would be methods on the font.Font class.
> Pro:
> * Right next to the normal render method and hence an obvious place to look.
> * We might even be able to fold it into the main render function.
> Con:
> * Forces us to stick with a single font for the entire text.
> * Clutters up that class.  If we merge with render instead, we make it
> much more complicated.
> * Forced to use C, since we're working in a C class.  (AFAIK, there's
> no way to mix like that without monkeypatching.)
>
> Another possibility would be in its own module, just as naked functions.
> Pro:
> * Simple to use.
> * Everything's grouped together and easy to scan through.
> Con:
> * When we start incorporating styles, naked functions get clumsy (as
> my example already shows).  There's just too much extra data that has
> to be shoved into the function call.
>
> And the third that comes to mind is building a class that represents a
> block of text with various properties and giving it a render method.
> Pro:
> * Styles, especially, benefit from the complexity segmentation this
> provides.  The final attributes can be built piecemeal and in a
> sensible order, instead of trying to shove everything into one
> function call.
> * This gives us an easy place to store glyph position data for
> handling click/drag.
> Con:
> * Not as easy to use as naked functions, as creating an ordinary block
> of wrapped text is now a two-step process.
>
> My preference would be either the class or a hybrid of class and naked
> functions.  The hybrid would put the functionality into the naked
> functions, with the class essentially acting as a "make this sane"
> wrapper around the complex parts of the naked functions.
>
> -FM
>
> On 9/24/08, René Dudfield <[EMAIL PROTECTED]> wrote:
>> hey,
>>
>> would you like to work with me in creating something for inclusion in
>> pygame?
>>
>> This would mean working out a simple api, making docs, examples, and
>> unittests.
>>
>> Something basic that we can have a look at, for adding the most easy
>> and useful features.  We can try and avoid most of the tricky issues
>> for now.
>>
>>
>>
>> If anyone else is interested, we can set up a google host page or
>> something to work on it?
>>
>> cheers,
>>
>>
>>
>>
>> On Tue, Sep 23, 2008 at 10:11 PM, Charlie Nolan <[EMAIL PROTECTED]>
>> wrote:
>>> A fair amount of this is already in that file, down in print_string
>>> and print_line.  (You're welcome to as much of the file as you like,
>>> but I'd strongly suggest you look into refactoring it.  It's good
>>> enough for one isolated project, but probably not up to library
>>> quality.)
>>>
 - aligning text, left, right, center etc.
 - vertical alignment... top, bottom, center.
 - text color
>>> Check.
>>>
 - each part of text having a separate font/attributes.  So you can
 then do words with bold, italics etc.
>>> Everything but the font is easy to extend (the font's ugly to do, and
>>> probably overkill).  I've already got underline in there.  Might want
>>> to swap the style list for a style dict/object, though, to avoid
>>> degenerating into positional hell.
>>>
 - selecting text.  Based on mouse click, which letter and word does it
 collide with?
>>> I've already got the baseline in for this, by way of EditableText's
>>> handle_click function.
>>>
 - breaking words (word-break), so it can add a long word like
 "complexifcation" as "complexif-\ncation"
>>>
>>> More-or-less present.  Right now, it'll break on any character,
>>> without adding a hyphen, but extending it shouldn't be hard.  Of
>>> course, if you want intelligent hyphenation, that's an icky can of
>>> worms all by itself.
>>>
 - justify text.
 - letter spacing
 - line spacing
 - word spacing
 - indenting
 - padding around text.
>>> Somewhat annoying, mostly because they affect selecting text.  With
>>> this many weird things, it might be a good idea to look for a way to
>>> merge the layout and se

Re: [pygame] Good code for text wrapping?

2008-09-25 Thread Greg Ewing

Charlie Nolan wrote:


The hybrid would put the functionality into the naked
functions, with the class essentially acting as a "make this sane"
wrapper around the complex parts of the naked functions.


Or the other way around -- implement the functionality as
a class, and provide one or more naked functions to make
it easier to use in the simple cases. This is the approach
used in various places in the stdlib, e.g. re and pickle.

--
Greg


Re: [pygame] Good code for text wrapping?

2008-09-24 Thread Charlie Nolan
Sure, I'm always happy to help.  I guess the first issue to look at is
where to put this.

One possibility would be methods on the font.Font class.
Pro:
* Right next to the normal render method and hence an obvious place to look.
* We might even be able to fold it into the main render function.
Con:
* Forces us to stick with a single font for the entire text.
* Clutters up that class.  If we merge with render instead, we make it
much more complicated.
* Forced to use C, since we're working in a C class.  (AFAIK, there's
no way to mix like that without monkeypatching.)

Another possibility would be in its own module, just as naked functions.
Pro:
* Simple to use.
* Everything's grouped together and easy to scan through.
Con:
* When we start incorporating styles, naked functions get clumsy (as
my example already shows).  There's just too much extra data that has
to be shoved into the function call.

And the third that comes to mind is building a class that represents a
block of text with various properties and giving it a render method.
Pro:
* Styles, especially, benefit from the complexity segmentation this
provides.  The final attributes can be built piecemeal and in a
sensible order, instead of trying to shove everything into one
function call.
* This gives us an easy place to store glyph position data for
handling click/drag.
Con:
* Not as easy to use as naked functions, as creating an ordinary block
of wrapped text is now a two-step process.

My preference would be either the class or a hybrid of class and naked
functions.  The hybrid would put the functionality into the naked
functions, with the class essentially acting as a "make this sane"
wrapper around the complex parts of the naked functions.

-FM

On 9/24/08, René Dudfield <[EMAIL PROTECTED]> wrote:
> hey,
>
> would you like to work with me in creating something for inclusion in
> pygame?
>
> This would mean working out a simple api, making docs, examples, and
> unittests.
>
> Something basic that we can have a look at, for adding the most easy
> and useful features.  We can try and avoid most of the tricky issues
> for now.
>
>
>
> If anyone else is interested, we can set up a google host page or
> something to work on it?
>
> cheers,
>
>
>
>
> On Tue, Sep 23, 2008 at 10:11 PM, Charlie Nolan <[EMAIL PROTECTED]>
> wrote:
>> A fair amount of this is already in that file, down in print_string
>> and print_line.  (You're welcome to as much of the file as you like,
>> but I'd strongly suggest you look into refactoring it.  It's good
>> enough for one isolated project, but probably not up to library
>> quality.)
>>
>>> - aligning text, left, right, center etc.
>>> - vertical alignment... top, bottom, center.
>>> - text color
>> Check.
>>
>>> - each part of text having a separate font/attributes.  So you can
>>> then do words with bold, italics etc.
>> Everything but the font is easy to extend (the font's ugly to do, and
>> probably overkill).  I've already got underline in there.  Might want
>> to swap the style list for a style dict/object, though, to avoid
>> degenerating into positional hell.
>>
>>> - selecting text.  Based on mouse click, which letter and word does it
>>> collide with?
>> I've already got the baseline in for this, by way of EditableText's
>> handle_click function.
>>
>>> - breaking words (word-break), so it can add a long word like
>>> "complexifcation" as "complexif-\ncation"
>>
>> More-or-less present.  Right now, it'll break on any character,
>> without adding a hyphen, but extending it shouldn't be hard.  Of
>> course, if you want intelligent hyphenation, that's an icky can of
>> worms all by itself.
>>
>>> - justify text.
>>> - letter spacing
>>> - line spacing
>>> - word spacing
>>> - indenting
>>> - padding around text.
>> Somewhat annoying, mostly because they affect selecting text.  With
>> this many weird things, it might be a good idea to look for a way to
>> merge the layout and select code, possibly by storing a map as you lay
>> things out.
>>
>>> - flowing around areas...
>>> - eg( place an image, and the text flows around it)
>>> - example here:  http://www.csstextwrap.com/example_for_demo.php
>> This one gets a bit ugly, and also runs into the layout/select
>> duplication mentioned above.
>>
>>> - splitting text up into 'pages',
>>> - different sized pages or Rects could be useful too.
>> Not too hard.  When the printing clips off the end of the available
>> area, you move on to the next one.
>>
>>> - scrolling text.
>> Are you thinking marquee or scrollbar?  Either one seems out of scope.
>>
>>> - text render method.
>> Not sure we need/want this, but it would be easy enough to add.  You'd
>> also want to add a way to replace the related methods (metrics,
>> get_linesize, etc.).  My main worry here is scope creep.  Actually, if
>> you're going into this much depth, wouldn't you just subclass
>> pygame.Font?
>>
>> ---
>>
>>>  - text flow other than left->right (right->left, mixed, top->down)
>> I think

Re: [pygame] Good code for text wrapping?

2008-09-24 Thread René Dudfield
hey,

would you like to work with me in creating something for inclusion in pygame?

This would mean working out a simple api, making docs, examples, and unittests.

Something basic that we can have a look at, for adding the most easy
and useful features.  We can try and avoid most of the tricky issues
for now.



If anyone else is interested, we can set up a google host page or
something to work on it?

cheers,




On Tue, Sep 23, 2008 at 10:11 PM, Charlie Nolan <[EMAIL PROTECTED]> wrote:
> A fair amount of this is already in that file, down in print_string
> and print_line.  (You're welcome to as much of the file as you like,
> but I'd strongly suggest you look into refactoring it.  It's good
> enough for one isolated project, but probably not up to library
> quality.)
>
>> - aligning text, left, right, center etc.
>> - vertical alignment... top, bottom, center.
>> - text color
> Check.
>
>> - each part of text having a separate font/attributes.  So you can
>> then do words with bold, italics etc.
> Everything but the font is easy to extend (the font's ugly to do, and
> probably overkill).  I've already got underline in there.  Might want
> to swap the style list for a style dict/object, though, to avoid
> degenerating into positional hell.
>
>> - selecting text.  Based on mouse click, which letter and word does it
>> collide with?
> I've already got the baseline in for this, by way of EditableText's
> handle_click function.
>
>> - breaking words (word-break), so it can add a long word like
>> "complexifcation" as "complexif-\ncation"
>
> More-or-less present.  Right now, it'll break on any character,
> without adding a hyphen, but extending it shouldn't be hard.  Of
> course, if you want intelligent hyphenation, that's an icky can of
> worms all by itself.
>
>> - justify text.
>> - letter spacing
>> - line spacing
>> - word spacing
>> - indenting
>> - padding around text.
> Somewhat annoying, mostly because they affect selecting text.  With
> this many weird things, it might be a good idea to look for a way to
> merge the layout and select code, possibly by storing a map as you lay
> things out.
>
>> - flowing around areas...
>> - eg( place an image, and the text flows around it)
>> - example here:  http://www.csstextwrap.com/example_for_demo.php
> This one gets a bit ugly, and also runs into the layout/select
> duplication mentioned above.
>
>> - splitting text up into 'pages',
>> - different sized pages or Rects could be useful too.
> Not too hard.  When the printing clips off the end of the available
> area, you move on to the next one.
>
>> - scrolling text.
> Are you thinking marquee or scrollbar?  Either one seems out of scope.
>
>> - text render method.
> Not sure we need/want this, but it would be easy enough to add.  You'd
> also want to add a way to replace the related methods (metrics,
> get_linesize, etc.).  My main worry here is scope creep.  Actually, if
> you're going into this much depth, wouldn't you just subclass
> pygame.Font?
>
> ---
>
>>  - text flow other than left->right (right->left, mixed, top->down)
> I think this really belongs upstream in SDL, assuming it's not there
> already.  Once it renders a string correctly, this is just another
> easy layout/select issue.
>
>>  - support for non-letter fonts (e.g. button glyphs for help text) --
>>  although I suppose you could handle it by something you described,
>>  flowing text around images, if the images could be floated as well
> I'm pretty sure you can do this already.  As long as you have the
> font, you can render whatever you like in it.
>
>>  - support for non-breaking spaces and hyphens
> NBSP is handled correctly.  Hyphens fall under breaking words properly.
>
>>  - proper handling of line-breaking in different languages (e.g.,
>>  French inserts a space or two between the last letter of a sentence
>>  and a final exclamation point, don't want to break there, some
>>  languages consider certain combinations of letters to really be only
>>  one, can't break in between them, etc.)
> Most of this falls under word breaks again.  French's pre-! space is
> kinda annoying, unless they already use an NBSP.
>
>>  - proper support for full Unicode fonts
> I haven't run into anything broken here.  DejaVu seems to render
> perfectly well.  Most of this is up to SDL, though we'd have to pay
> attention to control characters (switching RTL/LTR without warning
> does ugly things).
>
> ---
>
> Most of this isn't too bad to add to what I've already got, but you'd
> want to be really careful with adding them one-by-one.  It'd be really
> easy to get scope creep or just turn the entire thing into hacks of
> hacks.
>
> In some ways, I'd be relieved if you didn't use my code, because it's
> already held together with duct tape and baling wire.  Unfortunately,
> I'm not sure there *is* a sane way to handle this stuff, there are
> just too many special cases.
>
> I think the important thing is to get something in soonish that
> hand

Re: [pygame] Good code for text wrapping?

2008-09-23 Thread Charlie Nolan
A fair amount of this is already in that file, down in print_string
and print_line.  (You're welcome to as much of the file as you like,
but I'd strongly suggest you look into refactoring it.  It's good
enough for one isolated project, but probably not up to library
quality.)

> - aligning text, left, right, center etc.
> - vertical alignment... top, bottom, center.
> - text color
Check.

> - each part of text having a separate font/attributes.  So you can
> then do words with bold, italics etc.
Everything but the font is easy to extend (the font's ugly to do, and
probably overkill).  I've already got underline in there.  Might want
to swap the style list for a style dict/object, though, to avoid
degenerating into positional hell.

> - selecting text.  Based on mouse click, which letter and word does it
> collide with?
I've already got the baseline in for this, by way of EditableText's
handle_click function.

> - breaking words (word-break), so it can add a long word like
> "complexifcation" as "complexif-\ncation"

More-or-less present.  Right now, it'll break on any character,
without adding a hyphen, but extending it shouldn't be hard.  Of
course, if you want intelligent hyphenation, that's an icky can of
worms all by itself.

> - justify text.
> - letter spacing
> - line spacing
> - word spacing
> - indenting
> - padding around text.
Somewhat annoying, mostly because they affect selecting text.  With
this many weird things, it might be a good idea to look for a way to
merge the layout and select code, possibly by storing a map as you lay
things out.

> - flowing around areas...
> - eg( place an image, and the text flows around it)
> - example here:  http://www.csstextwrap.com/example_for_demo.php
This one gets a bit ugly, and also runs into the layout/select
duplication mentioned above.

> - splitting text up into 'pages',
> - different sized pages or Rects could be useful too.
Not too hard.  When the printing clips off the end of the available
area, you move on to the next one.

> - scrolling text.
Are you thinking marquee or scrollbar?  Either one seems out of scope.

> - text render method.
Not sure we need/want this, but it would be easy enough to add.  You'd
also want to add a way to replace the related methods (metrics,
get_linesize, etc.).  My main worry here is scope creep.  Actually, if
you're going into this much depth, wouldn't you just subclass
pygame.Font?

---

>  - text flow other than left->right (right->left, mixed, top->down)
I think this really belongs upstream in SDL, assuming it's not there
already.  Once it renders a string correctly, this is just another
easy layout/select issue.

>  - support for non-letter fonts (e.g. button glyphs for help text) --
>  although I suppose you could handle it by something you described,
>  flowing text around images, if the images could be floated as well
I'm pretty sure you can do this already.  As long as you have the
font, you can render whatever you like in it.

>  - support for non-breaking spaces and hyphens
NBSP is handled correctly.  Hyphens fall under breaking words properly.

>  - proper handling of line-breaking in different languages (e.g.,
>  French inserts a space or two between the last letter of a sentence
>  and a final exclamation point, don't want to break there, some
>  languages consider certain combinations of letters to really be only
>  one, can't break in between them, etc.)
Most of this falls under word breaks again.  French's pre-! space is
kinda annoying, unless they already use an NBSP.

>  - proper support for full Unicode fonts
I haven't run into anything broken here.  DejaVu seems to render
perfectly well.  Most of this is up to SDL, though we'd have to pay
attention to control characters (switching RTL/LTR without warning
does ugly things).

---

Most of this isn't too bad to add to what I've already got, but you'd
want to be really careful with adding them one-by-one.  It'd be really
easy to get scope creep or just turn the entire thing into hacks of
hacks.

In some ways, I'd be relieved if you didn't use my code, because it's
already held together with duct tape and baling wire.  Unfortunately,
I'm not sure there *is* a sane way to handle this stuff, there are
just too many special cases.

I think the important thing is to get something in soonish that
handles as many of the common cases as we can.  We don't want this
degenerating into something that will come out shortly after Duke
Nukem Forever.

-FM


Re: [pygame] Good code for text wrapping?

2008-09-21 Thread Willy Lee
"René Dudfield" <[EMAIL PROTECTED]> writes:

> Shall we start by making an ultimate list of features, or use cases...

> Anything else?

Eventually, you'll want:
 - text flow other than left->right (right->left, mixed, top->down)
 - support for non-letter fonts (e.g. button glyphs for help text) --
 although I suppose you could handle it by something you described,
 flowing text around images, if the images could be floated as well
 - support for non-breaking spaces and hyphens
 - proper handling of line-breaking in different languages (e.g.,
 French inserts a space or two between the last letter of a sentence
 and a final exclamation point, don't want to break there, some
 languages consider certain combinations of letters to really be only
 one, can't break in between them, etc.)
 - proper support for full Unicode fonts

But this is a bit pie-in-the-sky, it can wait until the basics are in,
I just have text processing on the brain a bit lately :)

=wl
-- 
"The whole fist fight is over who gets locked up and thrown rudely to the
ground and tied into little greasy knots." -- Chas Clements


Re: [pygame] Good code for text wrapping?

2008-09-21 Thread René Dudfield
On Mon, Sep 22, 2008 at 3:06 PM, Marius Gedminas <[EMAIL PROTECTED]> wrote:
> On Mon, Sep 22, 2008 at 02:41:28PM +1000, René Dudfield wrote:
>> oops, I also forgot...
>> - CSS3 and CSS4 support.
>> - a pony.
>
> I'm sure the last one could be implemented easily, if you had SVG support
> and Javascript.
>

Cool.  I'll add x86 emulator onto the list.  So we can get
SVG+javascript by installing linux + firefox.


Re: [pygame] Good code for text wrapping?

2008-09-21 Thread Marius Gedminas
On Mon, Sep 22, 2008 at 02:41:28PM +1000, René Dudfield wrote:
> oops, I also forgot...
> - CSS3 and CSS4 support.
> - a pony.

I'm sure the last one could be implemented easily, if you had SVG support
and Javascript.

Marius Gedminas
-- 
In short, at least give the penguin a fair viewing. If you still don't
like it, that's ok: that's why I'm boss. I simply know better than you
do.
-- Linus "what, me arrogant?" Torvalds, on c.o.l.advocacy


signature.asc
Description: Digital signature


Re: [pygame] Good code for text wrapping?

2008-09-21 Thread René Dudfield
oops, I also forgot...
- CSS3 and CSS4 support.
- a pony.


On Mon, Sep 22, 2008 at 2:32 PM, Hugo Arts <[EMAIL PROTECTED]> wrote:
> LaTeX support ;-)
>
> On Sun, Sep 21, 2008 at 9:18 PM, René Dudfield <[EMAIL PROTECTED]> wrote:
>>
>> awesome :)
>>
>>
>> yeah, maybe some text layout code would be a useful addition to
>> pygame.font ?  Or even as a separate download.
>>
>>
>>
>> Shall we start by making an ultimate list of features, or use cases...
>>
>> - aligning text, left, right, center etc.
>> - vertical alignment... top, bottom, center.
>> - justify text.
>> - breaking words (word-break), so it can add a long word like
>> "complexifcation" as "complexif-\ncation"
>> - splitting text up into 'pages',
>>- different sized pages or Rects could be useful too.
>> - scrolling text.
>> - selecting text.  Based on mouse click, which letter and word does it
>> collide with?
>> - each part of text having a separate font/attributes.  So you can
>> then do words with bold, italics etc.
>> - letter spacing
>> - line spacing
>> - word spacing
>> - flowing around areas...
>>- eg( place an image, and the text flows around it)
>>- example here:  http://www.csstextwrap.com/example_for_demo.php
>> - indenting
>> - padding around text.
>> - text color
>> - text render method.
>>
>>
>>
>> Anything else?
>>
>>
>>
>>
>> On Fri, Sep 19, 2008 at 6:16 PM, Charlie Nolan <[EMAIL PROTECTED]>
>> wrote:
>> > I'll happily chip in my word-wrap code, if you want it as a starting
>> > point for pygame.  It's not beautiful, but it does have a very nice
>> > property:
>> >
>> > orig_string[x] -> "".join(wrapped_string)[x]
>> >
>> > They're not always equal, because it converts some spaces to a
>> > zero-width character for alignment purposes.  (The char was originally
>> > \x00, hence strip_to_null, but that caused issues elsewhere,
>> > presumably with C strings.)
>> >
>> >
>> > http://code.google.com/p/endgame-singularity/source/browse/trunk/code/graphics/text.py?r=892
>> >
>> > -FM
>> >
>> > On 9/17/08, pymike <[EMAIL PROTECTED]> wrote:
>> >> Yeah pygame.font needs support for \n. :P
>> >>
>> >> On Wed, Sep 17, 2008 at 2:31 PM, Charlie Nolan
>> >> <[EMAIL PROTECTED]>wrote:
>> >>
>> >>> Hmm, I've written this too.  Given that it seems pretty common,
>> >>> wouldn't this be a good candidate for adding to pygame.font.Font?
>> >>>
>> >>> -FM
>> >>>
>> >>> On 9/16/08, Marius Gedminas <[EMAIL PROTECTED]> wrote:
>> >>> > On Tue, Sep 16, 2008 at 12:11:45PM +1000, René Dudfield wrote:
>> >>> >> The cookbook has this entry, but it doesn't work with new lines.
>> >>> >> http://www.pygame.org/wiki/TextWrapping
>> >>> >>
>> >>> >> Anyone have any code like this that supports new lines?
>> >>> >
>> >>> >
>> >>> > http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466
>> >>> >
>> >>> > Output example:
>> >>> > http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png
>> >>> >
>> >>> > It's GPL-ed, feel free to use or ask me for a licence change if
>> >>> > that's
>> >>> > not suitable.
>> >>> >
>> >>> > Marius Gedminas
>> >>> > --
>> >>> > If you are smart enough to know that you're not smart enough to be
>> >>> > an
>> >>> > Engineer, then you're in Business.
>> >>> >
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> - pymike (http://pymike.4rensics.org/)
>> >>
>> >
>
>


Re: [pygame] Good code for text wrapping?

2008-09-21 Thread Hugo Arts
LaTeX support ;-)

On Sun, Sep 21, 2008 at 9:18 PM, René Dudfield <[EMAIL PROTECTED]> wrote:

> awesome :)
>
>
> yeah, maybe some text layout code would be a useful addition to
> pygame.font ?  Or even as a separate download.
>
>
>
> Shall we start by making an ultimate list of features, or use cases...
>
> - aligning text, left, right, center etc.
> - vertical alignment... top, bottom, center.
> - justify text.
> - breaking words (word-break), so it can add a long word like
> "complexifcation" as "complexif-\ncation"
> - splitting text up into 'pages',
>- different sized pages or Rects could be useful too.
> - scrolling text.
> - selecting text.  Based on mouse click, which letter and word does it
> collide with?
> - each part of text having a separate font/attributes.  So you can
> then do words with bold, italics etc.
> - letter spacing
> - line spacing
> - word spacing
> - flowing around areas...
>- eg( place an image, and the text flows around it)
>- example here:  http://www.csstextwrap.com/example_for_demo.php
> - indenting
> - padding around text.
> - text color
> - text render method.
>
>
>
> Anything else?
>
>
>
>
> On Fri, Sep 19, 2008 at 6:16 PM, Charlie Nolan <[EMAIL PROTECTED]>
> wrote:
> > I'll happily chip in my word-wrap code, if you want it as a starting
> > point for pygame.  It's not beautiful, but it does have a very nice
> > property:
> >
> > orig_string[x] -> "".join(wrapped_string)[x]
> >
> > They're not always equal, because it converts some spaces to a
> > zero-width character for alignment purposes.  (The char was originally
> > \x00, hence strip_to_null, but that caused issues elsewhere,
> > presumably with C strings.)
> >
> >
> http://code.google.com/p/endgame-singularity/source/browse/trunk/code/graphics/text.py?r=892
> >
> > -FM
> >
> > On 9/17/08, pymike <[EMAIL PROTECTED]> wrote:
> >> Yeah pygame.font needs support for \n. :P
> >>
> >> On Wed, Sep 17, 2008 at 2:31 PM, Charlie Nolan
> >> <[EMAIL PROTECTED]>wrote:
> >>
> >>> Hmm, I've written this too.  Given that it seems pretty common,
> >>> wouldn't this be a good candidate for adding to pygame.font.Font?
> >>>
> >>> -FM
> >>>
> >>> On 9/16/08, Marius Gedminas <[EMAIL PROTECTED]> wrote:
> >>> > On Tue, Sep 16, 2008 at 12:11:45PM +1000, René Dudfield wrote:
> >>> >> The cookbook has this entry, but it doesn't work with new lines.
> >>> >> http://www.pygame.org/wiki/TextWrapping
> >>> >>
> >>> >> Anyone have any code like this that supports new lines?
> >>> >
> >>> >
> http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466
> >>> >
> >>> > Output example:
> http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png
> >>> >
> >>> > It's GPL-ed, feel free to use or ask me for a licence change if
> that's
> >>> > not suitable.
> >>> >
> >>> > Marius Gedminas
> >>> > --
> >>> > If you are smart enough to know that you're not smart enough to be an
> >>> > Engineer, then you're in Business.
> >>> >
> >>>
> >>
> >>
> >>
> >> --
> >> - pymike (http://pymike.4rensics.org/)
> >>
> >
>


Re: [pygame] Good code for text wrapping?

2008-09-21 Thread René Dudfield
awesome :)


yeah, maybe some text layout code would be a useful addition to
pygame.font ?  Or even as a separate download.



Shall we start by making an ultimate list of features, or use cases...

- aligning text, left, right, center etc.
- vertical alignment... top, bottom, center.
- justify text.
- breaking words (word-break), so it can add a long word like
"complexifcation" as "complexif-\ncation"
- splitting text up into 'pages',
- different sized pages or Rects could be useful too.
- scrolling text.
- selecting text.  Based on mouse click, which letter and word does it
collide with?
- each part of text having a separate font/attributes.  So you can
then do words with bold, italics etc.
- letter spacing
- line spacing
- word spacing
- flowing around areas...
- eg( place an image, and the text flows around it)
- example here:  http://www.csstextwrap.com/example_for_demo.php
- indenting
- padding around text.
- text color
- text render method.



Anything else?




On Fri, Sep 19, 2008 at 6:16 PM, Charlie Nolan <[EMAIL PROTECTED]> wrote:
> I'll happily chip in my word-wrap code, if you want it as a starting
> point for pygame.  It's not beautiful, but it does have a very nice
> property:
>
> orig_string[x] -> "".join(wrapped_string)[x]
>
> They're not always equal, because it converts some spaces to a
> zero-width character for alignment purposes.  (The char was originally
> \x00, hence strip_to_null, but that caused issues elsewhere,
> presumably with C strings.)
>
> http://code.google.com/p/endgame-singularity/source/browse/trunk/code/graphics/text.py?r=892
>
> -FM
>
> On 9/17/08, pymike <[EMAIL PROTECTED]> wrote:
>> Yeah pygame.font needs support for \n. :P
>>
>> On Wed, Sep 17, 2008 at 2:31 PM, Charlie Nolan
>> <[EMAIL PROTECTED]>wrote:
>>
>>> Hmm, I've written this too.  Given that it seems pretty common,
>>> wouldn't this be a good candidate for adding to pygame.font.Font?
>>>
>>> -FM
>>>
>>> On 9/16/08, Marius Gedminas <[EMAIL PROTECTED]> wrote:
>>> > On Tue, Sep 16, 2008 at 12:11:45PM +1000, René Dudfield wrote:
>>> >> The cookbook has this entry, but it doesn't work with new lines.
>>> >> http://www.pygame.org/wiki/TextWrapping
>>> >>
>>> >> Anyone have any code like this that supports new lines?
>>> >
>>> > http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466
>>> >
>>> > Output example: http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png
>>> >
>>> > It's GPL-ed, feel free to use or ask me for a licence change if that's
>>> > not suitable.
>>> >
>>> > Marius Gedminas
>>> > --
>>> > If you are smart enough to know that you're not smart enough to be an
>>> > Engineer, then you're in Business.
>>> >
>>>
>>
>>
>>
>> --
>> - pymike (http://pymike.4rensics.org/)
>>
>


Re: [pygame] Good code for text wrapping?

2008-09-19 Thread Charlie Nolan
I'll happily chip in my word-wrap code, if you want it as a starting
point for pygame.  It's not beautiful, but it does have a very nice
property:

orig_string[x] -> "".join(wrapped_string)[x]

They're not always equal, because it converts some spaces to a
zero-width character for alignment purposes.  (The char was originally
\x00, hence strip_to_null, but that caused issues elsewhere,
presumably with C strings.)

http://code.google.com/p/endgame-singularity/source/browse/trunk/code/graphics/text.py?r=892

-FM

On 9/17/08, pymike <[EMAIL PROTECTED]> wrote:
> Yeah pygame.font needs support for \n. :P
>
> On Wed, Sep 17, 2008 at 2:31 PM, Charlie Nolan
> <[EMAIL PROTECTED]>wrote:
>
>> Hmm, I've written this too.  Given that it seems pretty common,
>> wouldn't this be a good candidate for adding to pygame.font.Font?
>>
>> -FM
>>
>> On 9/16/08, Marius Gedminas <[EMAIL PROTECTED]> wrote:
>> > On Tue, Sep 16, 2008 at 12:11:45PM +1000, René Dudfield wrote:
>> >> The cookbook has this entry, but it doesn't work with new lines.
>> >> http://www.pygame.org/wiki/TextWrapping
>> >>
>> >> Anyone have any code like this that supports new lines?
>> >
>> > http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466
>> >
>> > Output example: http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png
>> >
>> > It's GPL-ed, feel free to use or ask me for a licence change if that's
>> > not suitable.
>> >
>> > Marius Gedminas
>> > --
>> > If you are smart enough to know that you're not smart enough to be an
>> > Engineer, then you're in Business.
>> >
>>
>
>
>
> --
> - pymike (http://pymike.4rensics.org/)
>


Re: [pygame] Good code for text wrapping?

2008-09-17 Thread pymike
Yeah pygame.font needs support for \n. :P

On Wed, Sep 17, 2008 at 2:31 PM, Charlie Nolan <[EMAIL PROTECTED]>wrote:

> Hmm, I've written this too.  Given that it seems pretty common,
> wouldn't this be a good candidate for adding to pygame.font.Font?
>
> -FM
>
> On 9/16/08, Marius Gedminas <[EMAIL PROTECTED]> wrote:
> > On Tue, Sep 16, 2008 at 12:11:45PM +1000, René Dudfield wrote:
> >> The cookbook has this entry, but it doesn't work with new lines.
> >> http://www.pygame.org/wiki/TextWrapping
> >>
> >> Anyone have any code like this that supports new lines?
> >
> > http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466
> >
> > Output example: http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png
> >
> > It's GPL-ed, feel free to use or ask me for a licence change if that's
> > not suitable.
> >
> > Marius Gedminas
> > --
> > If you are smart enough to know that you're not smart enough to be an
> > Engineer, then you're in Business.
> >
>



-- 
- pymike (http://pymike.4rensics.org/)


Re: [pygame] Good code for text wrapping?

2008-09-17 Thread Ian Mallett
I'd appreciate it.


Re: [pygame] Good code for text wrapping?

2008-09-17 Thread Charlie Nolan
Hmm, I've written this too.  Given that it seems pretty common,
wouldn't this be a good candidate for adding to pygame.font.Font?

-FM

On 9/16/08, Marius Gedminas <[EMAIL PROTECTED]> wrote:
> On Tue, Sep 16, 2008 at 12:11:45PM +1000, René Dudfield wrote:
>> The cookbook has this entry, but it doesn't work with new lines.
>> http://www.pygame.org/wiki/TextWrapping
>>
>> Anyone have any code like this that supports new lines?
>
> http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466
>
> Output example: http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png
>
> It's GPL-ed, feel free to use or ask me for a licence change if that's
> not suitable.
>
> Marius Gedminas
> --
> If you are smart enough to know that you're not smart enough to be an
> Engineer, then you're in Business.
>


Re: [pygame] Good code for text wrapping?

2008-09-16 Thread Marius Gedminas
On Tue, Sep 16, 2008 at 12:11:45PM +1000, René Dudfield wrote:
> The cookbook has this entry, but it doesn't work with new lines.
> http://www.pygame.org/wiki/TextWrapping
> 
> Anyone have any code like this that supports new lines?

http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/ui.py#L466

Output example: http://mg.pov.lt/pyspacewar/pyspacewar-help-screen.png

It's GPL-ed, feel free to use or ask me for a licence change if that's
not suitable.

Marius Gedminas
-- 
If you are smart enough to know that you're not smart enough to be an
Engineer, then you're in Business.


signature.asc
Description: Digital signature


Re: [pygame] Good code for text wrapping?

2008-09-16 Thread René Dudfield
hi,

The cookbook entry has been updated with a multiline function, that
seems to work ok.
http://www.pygame.org/wiki/TextWrapping

I guess for right justify, the lines could be blit from the right of
the screen minus text width.  To center it, you would blit at the
(screen_width - text_width) / 2.

cheers,



On Tue, Sep 16, 2008 at 10:09 PM, Michael <[EMAIL PROTECTED]> wrote:
> On Tuesday 16 September 2008 03:11:45 René Dudfield wrote:
>> The cookbook has this entry, but it doesn't work with new lines.
>> http://www.pygame.org/wiki/TextWrapping
>>
>> Anyone have any code like this that supports new lines?
>
> Is this any use to you?
> https://kamaelia.svn.sourceforge.net/svnroot/kamaelia/trunk/Code/Python/Kamaelia/Kamaelia/UI/Pygame/Text.py
>
> The code can be used by itself but will look a little odd - it's got a
> slightly wierd way of getting a surface to display on inside "initPygame"
> and the equivalent of pygame.flip() is in the end of "updateLine" (the redraw
> request), but other than than it's pretty normal normal code.
>
> (The reason for the oddity is because it allows pygame based components to be
> written as if they own the whole display, and then to be changed slightly in
> small steps to share the display)
>
> To see what it looks like quickly, it'd probably be easiest to grab the latest
> kamaelia release:
>http://edit.kamaelia.org/release/Kamaelia-0.6.0-rc7.tar.gz
>
> Do the usual setup.py dance, and then:
> ~/Kamaelia-0.6.0-rc7> cd Examples/SimpleGraphicalApps/TextBox/
> ~/Kamaelia-0.6.0-rc7/Examples/SimpleGraphicalApps/TextBox> 
> ./Textbox_TextDisplayer_Demo.py
>
> Handles different font sizes etc happily. Only supports left justified text at
> the moment.
>
>
> Michael.
>


Re: [pygame] Good code for text wrapping?

2008-09-16 Thread René Dudfield
ah, yes.  That's almost exactly what I want :)

If the width per character was fixed that could be used I think.


On Tue, Sep 16, 2008 at 12:23 PM, Douglas Bagnall
<[EMAIL PROTECTED]> wrote:
> Ah no, sorry. I didn't see the font/width part.
>
> d
>
> 2008/9/16 Douglas Bagnall <[EMAIL PROTECTED]>:
>>> The cookbook has this entry, but it doesn't work with new lines.
>>> http://www.pygame.org/wiki/TextWrapping
>>>
>>> Anyone have any code like this that supports new lines?
>>
>> Batteries are included:
>>
>> http://docs.python.org/lib/module-textwrap.html
>>
>> does that help?
>>
>> Douglas
>>
>


Re: [pygame] Good code for text wrapping?

2008-09-16 Thread Michael
On Tuesday 16 September 2008 03:11:45 René Dudfield wrote:
> The cookbook has this entry, but it doesn't work with new lines.
> http://www.pygame.org/wiki/TextWrapping
>
> Anyone have any code like this that supports new lines?

Is this any use to you?
https://kamaelia.svn.sourceforge.net/svnroot/kamaelia/trunk/Code/Python/Kamaelia/Kamaelia/UI/Pygame/Text.py

The code can be used by itself but will look a little odd - it's got a
slightly wierd way of getting a surface to display on inside "initPygame"
and the equivalent of pygame.flip() is in the end of "updateLine" (the redraw
request), but other than than it's pretty normal normal code. 

(The reason for the oddity is because it allows pygame based components to be
written as if they own the whole display, and then to be changed slightly in
small steps to share the display)

To see what it looks like quickly, it'd probably be easiest to grab the latest 
kamaelia release:
http://edit.kamaelia.org/release/Kamaelia-0.6.0-rc7.tar.gz

Do the usual setup.py dance, and then:
~/Kamaelia-0.6.0-rc7> cd Examples/SimpleGraphicalApps/TextBox/
~/Kamaelia-0.6.0-rc7/Examples/SimpleGraphicalApps/TextBox> 
./Textbox_TextDisplayer_Demo.py

Handles different font sizes etc happily. Only supports left justified text at 
the moment.


Michael.


Re: [pygame] Good code for text wrapping?

2008-09-15 Thread Douglas Bagnall
Ah no, sorry. I didn't see the font/width part.

d

2008/9/16 Douglas Bagnall <[EMAIL PROTECTED]>:
>> The cookbook has this entry, but it doesn't work with new lines.
>> http://www.pygame.org/wiki/TextWrapping
>>
>> Anyone have any code like this that supports new lines?
>
> Batteries are included:
>
> http://docs.python.org/lib/module-textwrap.html
>
> does that help?
>
> Douglas
>


Re: [pygame] Good code for text wrapping?

2008-09-15 Thread Douglas Bagnall
> The cookbook has this entry, but it doesn't work with new lines.
> http://www.pygame.org/wiki/TextWrapping
>
> Anyone have any code like this that supports new lines?

Batteries are included:

http://docs.python.org/lib/module-textwrap.html

does that help?

Douglas


[pygame] Good code for text wrapping?

2008-09-15 Thread René Dudfield
hello,


The cookbook has this entry, but it doesn't work with new lines.
http://www.pygame.org/wiki/TextWrapping

Anyone have any code like this that supports new lines?


cheers,


Re: [pygame] Good code

2007-12-10 Thread Mundial 82

Hi all,

Thanks a bunch for the advice! I will try to follow it (even though I  
can already tell I am terrible at using functions :)


mundial


On Dec 9, 2007, at 10:33 AM, David Gowers wrote:


Hi Laura

On Dec 9, 2007 6:04 PM, Laura Creighton <[EMAIL PROTECTED]> wrote:


I think one of the most useful places to write comments -- and one
which I think is rarely done -- is

# hack hack hack ! this function should really do XXX instead of YYY
# that it does now


This is a great use of comments.
In open source software, there is a casual convention like:

# XXX simplify the logic of this function

. In some games, notably *angband, this evolves into

# XXX hack: force a 'good' depth.
(in distinction from XXX - 'XXX' just meaning code that does not give
you a good feeling about how it does things, whereas 'XXX hack' is
meaning something that you know is inappropriate to do but currently
works.)



That way, when you come across it later, you can be sure that
this is code you meant to clean up and never got around to, rather
than code that was done in this strange way on purpose.

Laura






Re: [pygame] Good code

2007-12-09 Thread David Gowers
Hi Laura

On Dec 9, 2007 6:04 PM, Laura Creighton <[EMAIL PROTECTED]> wrote:
>
> I think one of the most useful places to write comments -- and one
> which I think is rarely done -- is
>
> # hack hack hack ! this function should really do XXX instead of YYY
> # that it does now

This is a great use of comments.
In open source software, there is a casual convention like:

# XXX simplify the logic of this function

. In some games, notably *angband, this evolves into

# XXX hack: force a 'good' depth.
(in distinction from XXX - 'XXX' just meaning code that does not give
you a good feeling about how it does things, whereas 'XXX hack' is
meaning something that you know is inappropriate to do but currently
works.)

>
> That way, when you come across it later, you can be sure that
> this is code you meant to clean up and never got around to, rather
> than code that was done in this strange way on purpose.
>
> Laura
>
>


Re: [pygame] Good code

2007-12-08 Thread Laura Creighton

I think one of the most useful places to write comments -- and one
which I think is rarely done -- is

# hack hack hack ! this function should really do XXX instead of YYY 
# that it does now

That way, when you come across it later, you can be sure that
this is code you meant to clean up and never got around to, rather
than code that was done in this strange way on purpose.

Laura



Re: [pygame] Good code

2007-12-08 Thread Casey Duncan

On Dec 8, 2007, at 6:06 AM, Chris Smith wrote:

I usually write out my comments first because it lets me define  
what I'm trying to do. The code should be a reflection of the  
comments.


On 08/12/2007, Greg Ewing <[EMAIL PROTECTED]> wrote: Ian  
Mallett wrote:
> When writing code, it is good to have comments, but it is not  
usually

> wise to put them in until you've tested the relevant code.

Although sometimes it can be helpful to write a comment
beforehand as a sort of mini design document, to help
clarify your thoughts about what the code needs to
accomplish and how you intend to go about it.

If you later change the code in a way that invalidates
the comment, you should of course update the comment
to match.

--
Greg


Comments do not good code make.

-Yoda

Try to write code that makes it easy to see what and how things are  
being done. Use meaningful, descriptive variable, method and class  
names. Write the code as though someone else will need to read it and  
understand it -- 6 months from now that someone may be you. Be  
explicit, try not to rely-on magical side-effects. Don't optimize  
code for speed unless it needs it (proven via profiling) since  
optimization almost always makes code less readable/maintainable.


In general, do not write comments that describe *what* the code is  
doing, let the code be self explanatory. Write comments that describe  
*why* the code is there doing what it does. Document the intended  
usage of methods and classes in docstrings. In all, keep comments to  
a minimum and worry more about writing clear readable code.


-Casey


Re: [pygame] Good code

2007-12-08 Thread Chris Smith
I usually write out my comments first because it lets me define what I'm
trying to do. The code should be a reflection of the comments.

On 08/12/2007, Greg Ewing <[EMAIL PROTECTED]> wrote:
>
> Ian Mallett wrote:
> > When writing code, it is good to have comments, but it is not usually
> > wise to put them in until you've tested the relevant code.
>
> Although sometimes it can be helpful to write a comment
> beforehand as a sort of mini design document, to help
> clarify your thoughts about what the code needs to
> accomplish and how you intend to go about it.
>
> If you later change the code in a way that invalidates
> the comment, you should of course update the comment
> to match.
>
> --
> Greg
>



-- 
Science is open source religion


Re: [pygame] Good code

2007-12-07 Thread Greg Ewing

Ian Mallett wrote:

When writing code, it is good to have comments, but it is not usually
wise to put them in until you've tested the relevant code.


Although sometimes it can be helpful to write a comment
beforehand as a sort of mini design document, to help
clarify your thoughts about what the code needs to
accomplish and how you intend to go about it.

If you later change the code in a way that invalidates
the comment, you should of course update the comment
to match.

--
Greg


Re: [pygame] Good code

2007-12-07 Thread Ian Mallett
When writing code, it is good to have comments, but it is not usually
wise to put them in until you've tested the relevant code.  E.g., you
wouldn't want to write some code, then a bunch of comments about it,
then find that your method is useless, so the comments are useless
too.  Also, try to keep comments short and to the point.
Ian


Re: [pygame] Good code

2007-12-07 Thread Marius Gedminas
On Thu, Dec 06, 2007 at 05:52:59PM +0100, Mundial 82 wrote:
> Thanks to all your help, my little newbie project is shaping up. So now I 
> have a different question: being a non-programmer, I like to learn by 
> reading other people's code when it is available. I find it difficult, 
> though, to understand what are the good practices and structures that are 
> present in good coding.

Hint: it's whatever makes reading and understanding the code easier.
Usually the best way to do that is to split the code into separate
chunks (such as modules, classes and functions) that can be reasoned
about and used without having to remember what's inside them.

> So, for the code reading newbies: what are your examples of nice, clean, 
> elegant code for games that I could take a look at (beyond the pygame.org 
> tutorials, that is)?

I've tried to make pyspacewar code nice and clean:
http://mg.pov.lt/pyspacewar/trac/browser/trunk/src/pyspacewar/

Regards,
Marius Gedminas
-- 
lg_PC.gigacharset (lg = little green men language, PC = proxima centauri)
-- Markus Kuhn provides an example of a locale


signature.asc
Description: Digital signature


Re: [pygame] Good code

2007-12-06 Thread Ian Mallett
Organisation is good, so try to organise things into functions, and
name them something.  For example, my basecode for most of my programs
looks like:
#imports
#variables
#functions
def get_input():
#get input
def update_game_stuff():
#Move objects, update fps, etc.
def draw():
draw()
def main():
while True:
get_input()
update_game_stuff()
draw()

Next, name your variables coherently.  Work up a system.  Will you use
capital letters like 'FrameRateCounter' or with underscores:
'frame_rate_counter', or both?  Will you put suffixes on your
variables?  Like what I do for Surface pointers?:
SpaceShip_Surface
Planet_Surface
Bullet_Surface

Whatever you do, make sure it's consistent.  If your program gets big,
especially, similar sounding variables start getting used
interchangeably.  That's bad.  Make sure that each is different, and
that you know the difference.

Will you use classes for individual items?  Will you use lists?  I
like classes because they are organised, but lists because they are
fast.  If you have something simple, like a tennis ball you could make
a list like:
tennisballs = 
[[xpos,ypos,speedx,speedy],[xpos,ypos,speedx,speedy],[xpos,ypos,speedx,speedy],[xpos,ypos,speedx,speedy]]
OR, you could do:
class tennisball:
def __init__(self):
self.x = xpos
self.y = ypos
self.speedx = speedx
self.speedy = speedy
tennisballs = []
tennisballs.append(tennisball())
tennisballs.append(tennisball())
tennisballs.append(tennisball())
tennisballs.append(tennisball())

Will you specify positions like: 'pos = [3,4]' or like 'posx = 3; posy
= 4'?  Separate variables or not?

There's a lot of stuff to think about, and it might seem obvious, but
until I thought about stuff like this, I had problems.

Ian


[pygame] Good code

2007-12-06 Thread Mundial 82

Hi all,

Thanks to all your help, my little newbie project is shaping up. So  
now I have a different question: being a non-programmer, I like to  
learn by reading other people's code when it is available. I find it  
difficult, though, to understand what are the good practices and  
structures that are present in good coding.
So, for the code reading newbies: what are your examples of nice,  
clean, elegant code for games that I could take a look at (beyond the  
pygame.org tutorials, that is)?
(I am more thinking in newbie-friendly code rather than great  
solutions for problems, but both would help).


thanks in advance!

Naranjito