[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] File Loader Window
On Mon, 21 Jan 2008 09:36:39 -0500, "Bernard Quinn" <bjquinniii@xxxxxxxxx>
wrote:
> I need to load data files, from local and networked drives. Files will
> be xml, graphml or csv, all of which I can parse, but I need to get away
> from having the location/filename hard-coded in.
OK. Pygame doesn't offer any easy way to get an all-purpose widget that
does that, so as others said, if you want one you should look at the
existing UI toolkits out there for Pygame.
For a different way, look at the "os" module, eg:
here = os.getcwd()
GRAPHICS_SUBDIRECTORY = "graphics"
some_picture =
pygame.image.load(os.path.join(GRAPHICS_SUBDIRECTORY,"my_picture.jpg"))
## Print all PNG or GIF filenames in the graphics dir -- not sure this is
quite right
VALID_FILE_TYPES = (".png",".gif")
print [ filename for filename in
os.path.listdir(os.path.join(here,GRAPHICS_SUBDIRECTORY)) if
filename.lower()[:-4] in VALID_FILE_TYPES ]
This sort of function might be helpful. If I were coding such a
full-featured widget I'd probably use my existing button widget code, and
make a widget that has a bunch of lined-up buttons displaying the names of
files and subdirs in the current directory, with other buttons for "go up a
directory," "OK" and "Cancel." Basically this task is a matter of having
enough of a UI to display stuff and pass along information to the program
about what was clicked, plus enough mastery of the "os" module to feed the
right information to it. The last line above is close to part of what you'd
need.
I'm hoping to post a junky-but-functional game demo soon with an updated
version of my simple UI code, and you can use that for buttons if you want.
Kris