Re: [pygame] File Copying
Ian Mallett wrote: New issue: If I do something like: font = pygame.font.SysFont(Times New Roman, 12) FontObject = font.render(this is line 1 this is line 2 this is line 3, 1, (255,255,255), (3,3,3)) surface.blit(FontObject, (0,0)) instead of putting a newline thing it puts a rectangle and a space. I remember the docs saying to do it that way though... The font object's render method doesn't do newlines. It says that in the docs. You have to render each line of text seperately. -Luke
Re: [pygame] File Copying
Yes, I know, it just seems a little weird- text with no return function? I'm probably just used to notepad and similar programs. On 7/8/07, Luke Paireepinart [EMAIL PROTECTED] wrote: Ian Mallett wrote: OK, that too bad. I don't suppose pygame has a suggestion box. (Other than that in the docs). You could easily write a class that did multi-line text. That's probably why it's not included in Pygame. All the text processing you need to do - centering text, word-wrap, etc. - are all things you do yourself in python, and you pass the text for each line after it's been processed to the font rendering. Part of the reason for this is probably because that's how SDL does it. HTH, -Luke On 7/8/07, *Luke Paireepinart* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: Ian Mallett wrote: New issue: If I do something like: font = pygame.font.SysFont(Times New Roman, 12) FontObject = font.render(this is line 1 this is line 2 this is line 3, 1, (255,255,255), (3,3,3)) surface.blit(FontObject, (0,0)) instead of putting a newline thing it puts a rectangle and a space. I remember the docs saying to do it that way though... The font object's render method doesn't do newlines. It says that in the docs. You have to render each line of text seperately. -Luke
Re: [pygame] File Copying
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dave LeCompte (really) wrote: It's pretty simple to split your string on carriage returns (and/or line feeds), create surfaces for each line of text, and blit those surfaces to the destination surface. But this would be a nice addition to pygame, as I'm sure a lot of games do it. Maybe combine with http://www.pygame.org/wiki/TextWrapping?parent=CookBook ? Ethan -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGkaZShRlgoLPrRPwRAlVaAJ99H+vWEXq0rmua/nWIeJCqx5uOaACgk+F/ yB/hnzqo17jR5jKPhUfX4vs= =24kD -END PGP SIGNATURE-
Re: [pygame] File Copying
On 7/8/07, Ethan Glasser-Camp [EMAIL PROTECTED] wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Dave LeCompte (really) wrote: It's pretty simple to split your string on carriage returns (and/or line feeds), create surfaces for each line of text, and blit those surfaces to the destination surface. But this would be a nice addition to pygame, as I'm sure a lot of games do it. Maybe combine with http://www.pygame.org/wiki/TextWrapping?parent=CookBook ? I second that. Ethan -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGkaZShRlgoLPrRPwRAlVaAJ99H+vWEXq0rmua/nWIeJCqx5uOaACgk+F/ yB/hnzqo17jR5jKPhUfX4vs= =24kD -END PGP SIGNATURE-
[pygame] File Copying
Hi, Suppose you have an image file. Call it blah.png. If I want to copy it to another directory and rename it Ogg.png, how would I do that with python code?
Re: [pygame] File Copying
OK, that worked the first time I tried it, but the file was not valid, i.e. corrupted. On 7/7/07, Rolando Pereira [EMAIL PROTECTED] wrote: Ian Mallett escreveu: Hi, Suppose you have an image file. Call it blah.png. If I want to copy it to another directory and rename it Ogg.png, how would I do that with python code? Well, this is more of a [Tutor]'s question than a Pygame's question, but at least this one I can anwser. (This was done in 5 minutes or so, so it might have a but or something :D ) f = file(full_path_to_blah.png) n = file(full_path_to_Ogg.png, w) # We add w, so that if the fileso that if the file doesn't exist, it will be created n.write(f.read()) n.close() Presto, there should be now two similar images :D -- _ ASCII ribbon campaign ( ) - against HTML email X vCards / \
Re: [pygame] File Copying
On Sun, 8 Jul 2007, Ian Mallett wrote: Suppose you have an image file. Call it blah.png. If I want to copy it to another directory and rename it Ogg.png, how would I do that with python code? pydoc shutil.copyfile Richard
Re: [pygame] File Copying
On Sat, Jul 07, 2007 at 10:45:30PM +0100, Rolando Pereira wrote: Ian Mallett escreveu: Hi, Suppose you have an image file. Call it blah.png. If I want to copy it to another directory and rename it Ogg.png, how would I do that with python code? Well, this is more of a [Tutor]'s question than a Pygame's question, but at least this one I can anwser. (This was done in 5 minutes or so, so it might have a but or something :D ) f = file(full_path_to_blah.png) n = file(full_path_to_Ogg.png, w) # We add w, so that if the file so that if the file doesn't exist, it will be created n.write(f.read()) n.close() Presto, there should be now two similar images :D Hi, I tend to use the shutil module for this kind of work. See shutil.copy() and shutil.copy2(). To manipulate file path/names I tend to use the os.path functions. See os.path.join(), os.path.split(), os.path.splitext(). cheers, John.
Re: [pygame] File Copying
On Sun, 8 Jul 2007, Rolando Pereira wrote: f = file(full_path_to_blah.png) n = file(full_path_to_Ogg.png, w) # We add w, so that if the file so that if the file doesn't exist, it will be created n.write(f.read()) n.close() Presto, there should be now two similar images :D If you're going to do it manually like this then you must open the files in binary mode, or the images will be somewhat similar, but not the same. Richard
Re: [pygame] File Copying
Rolando, it works with .txt files. Richard, John, I will look into that. On 7/7/07, John Popplewell [EMAIL PROTECTED] wrote: On Sat, Jul 07, 2007 at 10:45:30PM +0100, Rolando Pereira wrote: Ian Mallett escreveu: Hi, Suppose you have an image file. Call it blah.png. If I want to copy it to another directory and rename it Ogg.png, how would I do that with python code? Well, this is more of a [Tutor]'s question than a Pygame's question, but at least this one I can anwser. (This was done in 5 minutes or so, so it might have a but or something :D ) f = file(full_path_to_blah.png) n = file(full_path_to_Ogg.png, w) # We add w, so that if the file so that if the file doesn't exist, it will be created n.write(f.read()) n.close() Presto, there should be now two similar images :D Hi, I tend to use the shutil module for this kind of work. See shutil.copy() and shutil.copy2(). To manipulate file path/names I tend to use the os.path functions. See os.path.join(), os.path.split(), os.path.splitext(). cheers, John.
Re: [pygame] File Copying
Like how? file([Filepath], b) is invalid. On 7/7/07, Richard Jones [EMAIL PROTECTED] wrote: On Sun, 8 Jul 2007, Rolando Pereira wrote: f = file(full_path_to_blah.png) n = file(full_path_to_Ogg.png, w) # We add w, so that if the file so that if the file doesn't exist, it will be created n.write(f.read()) n.close() Presto, there should be now two similar images :D If you're going to do it manually like this then you must open the files in binary mode, or the images will be somewhat similar, but not the same. Richard
Re: [pygame] File Copying
This works: import pygame import sys, os from pygame.locals import * import shutil def main(): shutil.copyfile([SourceDir], [TargetDir]) main() On 7/7/07, Ian Mallett [EMAIL PROTECTED] wrote: Like how? file([Filepath], b) is invalid. On 7/7/07, Richard Jones [EMAIL PROTECTED] wrote: On Sun, 8 Jul 2007, Rolando Pereira wrote: f = file(full_path_to_blah.png) n = file(full_path_to_Ogg.png, w) # We add w, so that if the file so that if the file doesn't exist, it will be created n.write(f.read()) n.close() Presto, there should be now two similar images :D If you're going to do it manually like this then you must open the files in binary mode, or the images will be somewhat similar, but not the same. Richard
Re: [pygame] File Copying
Thanks everybody! On 7/7/07, Ian Mallett [EMAIL PROTECTED] wrote: This works: import pygame import sys, os from pygame.locals import * import shutil def main(): shutil.copyfile([SourceDir], [TargetDir]) main() On 7/7/07, Ian Mallett [EMAIL PROTECTED] wrote: Like how? file([Filepath], b) is invalid. On 7/7/07, Richard Jones [EMAIL PROTECTED] wrote: On Sun, 8 Jul 2007, Rolando Pereira wrote: f = file(full_path_to_blah.png) n = file(full_path_to_Ogg.png, w) # We add w, so that if the file so that if the file doesn't exist, it will be created n.write(f.read()) n.close() Presto, there should be now two similar images :D If you're going to do it manually like this then you must open the files in binary mode, or the images will be somewhat similar, but not the same. Richard
Re: [pygame] File Copying
On Sun, 8 Jul 2007, Ian Mallett wrote: Like how? file([Filepath], b) is invalid. % pydoc file Help on class file in module __builtin__: class file(object) | file(name[, mode[, buffering]]) - file object | | Open a file. The mode can be 'r', 'w' or 'a' for reading (default), | writing or appending. The file will be created if it doesn't exist | when opened for writing or appending; it will be truncated when | opened for writing. Add a 'b' to the mode for binary files.
Re: [pygame] File Copying
So like rb, wb, andab? On 7/7/07, Richard Jones [EMAIL PROTECTED] wrote: On Sun, 8 Jul 2007, Ian Mallett wrote: Like how? file([Filepath], b) is invalid. % pydoc file Help on class file in module __builtin__: class file(object) | file(name[, mode[, buffering]]) - file object | | Open a file. The mode can be 'r', 'w' or 'a' for reading (default), | writing or appending. The file will be created if it doesn't exist | when opened for writing or appending; it will be truncated when | opened for writing. Add a 'b' to the mode for binary files.
Re: [pygame] File Copying
Ian Mallett [EMAIL PROTECTED] asked: So that would explain why .png didn't work, but then why did it work with .txt? Win32's file handling handles certain characters specially: 0xff is interpreted as an end-of-file marker, even if it occurs in the middle of the file, also carriage return/line feeds are parsed in a 'best guess' of what you might mean, as opposed to what's literally in the file. With text files, this tends to work out fine, though. You're not going to have weird non-printable characters interspersed in your file. With binary files (like graphics images, where all byte values need to be able to be represented), opening them in ASCII mode on Win32 will cause corruption if your file contains any of these special characters. However, this isn't really a pygame issue. -Dave LeCompte
Re: [pygame] File Copying
So that would explain why .png didn't work, but then why did it work with .txt? On 7/7/07, Richard Goedeken [EMAIL PROTECTED] wrote: That is correct; The 'b' is only necessary for Windows/DOS systems; under Unix all files are opened in Binary mode and the extra letter isn't required. Richard Ian Mallett wrote: So like rb, wb, andab? On 7/7/07, *Richard Jones* [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] wrote: On Sun, 8 Jul 2007, Ian Mallett wrote: Like how? file([Filepath], b) is invalid. % pydoc file Help on class file in module __builtin__: class file(object) | file(name[, mode[, buffering]]) - file object | | Open a file. The mode can be 'r', 'w' or 'a' for reading (default), | writing or appending. The file will be created if it doesn't exist | when opened for writing or appending; it will be truncated when | opened for writing. Add a 'b' to the mode for binary files.
Re: [pygame] File Copying
New issue: If I do something like: font = pygame.font.SysFont(Times New Roman, 12) FontObject = font.render(this is line 1 this is line 2 this is line 3, 1, (255,255,255), (3,3,3)) surface.blit(FontObject, (0,0)) instead of putting a newline thing it puts a rectangle and a space. I remember the docs saying to do it that way though... On 7/7/07, Dave LeCompte (really) [EMAIL PROTECTED] wrote: I just said: Win32's file handling handles certain characters specially: 0xff is interpreted as an end-of-file marker Oops, forgive me on this. EOF is actually 0x1a, not 0xff. See also: http://mail.python.org/pipermail/python-list/2004-September/284028.html -Dave LeCompte