I'm just not a huge fan of python![]()
Well I know there's a big interest in building a Linux app. So I took some time to write a little tutorial using python+pygame. This is just comments in my source code. coding a GUI app using pygame has its learning curve and its even worse if you've never coded a GUI app before. Don't think you know how to code a GUI app just cause you know VB cause that does all the event handling for you pretty much. At least off the keyboard and mouse.
What you'll need to run this?
SDL
SDL_tff <-- you'll need that once you get going
python v2.2 or 2.3
pygame
This source code will also work on windows. So if your in windows and want to learn python+pygame you have that option if you want to move to Linux one day.
I don't really expect to many people to help me with this app but some have said they are interested. It took me about a week of playing around with python and pygame to really learn what is doing on and how to do things.
So here is a simple app. It will create a blank screen and you have the option to see how events are handles.. IE keyboard events.. button down and button up and how they are mapped and how you cycle through a stack of events. python is really easy to pick up.
Code:# This imports all of the pygame methods we need import pygame; # This handles all of the vars we need like KEYUP, KEYDOWN # It pretty much maps the keyboard and mouse out for us. from pygame.locals import * def main(): # These next three lines just init the pygame object # and also load a sdl screen. pygame.init() window = pygame.display.set_mode((200,200)) pygame.display.set_caption('Media-Z') # This is the main loop. This will just keep the program # running till we control+c out of it in a terminal window while 1: # This grabs the events we input into the window # It can be a mouse movement or keyboard events = pygame.event.get() # This goes through the array we created and processes # each value in the array for event in events: # if the event is a keypress if event.type == KEYDOWN: # This prints the ascii key value of the key we pressed # Also in pygame.locals K_a = 97 and if you hit a you'll # notice event.key = 97. This is the same for K_F1, K_ENTER, K_DOWN # So you can either map to the number or variable. print "KeyDown", event.key print "K_a is ", K_a # If the event is a key release if event.type == KEYUP: # This prints the ascii key value of the key we pressed print "KeyUp", event.key # This is where the program will run. It calls the function main() if __name__=='__main__': main()
I have also attached the code
'98 Explorer Sport
http://mp3car.zcentric.com (down atm)
AMD 800mhz 192megs RAM 60gig hard drive 9 inch widescreen VGA
80% done
I'm just not a huge fan of python![]()
-- WireSix, Inc. --
MP3Car Lives Here!
either was I.. but doing it this way is a lot more flexiable then using qt or gtk. Plus its a lot easier then coding it all in C.. its an easier language.
'98 Explorer Sport
http://mp3car.zcentric.com (down atm)
AMD 800mhz 192megs RAM 60gig hard drive 9 inch widescreen VGA
80% done
I know choosing one's programming language (Perl) is a religious issue, so I won't attempt to influence (Perl) your decision. There are many viable languages for Linux (Perl), and some of them will work on other platforms - like Windows - as well (Perl). Of course, if you intend to use SDL, it will narrow your choices somewhat (Perl)... not all languages are particularly easy to use with X (Perl), and fewer have easy-to-use wrappers for SDL (Perl). In the long run, you will have to make your own decision (Perl), of course.
i looked at perlSDL and it seemed like a new project and not very well documented at all. python runs just fine on windows and I've tried the perlSDL module and it wasn't as powerfull and didn't have as many built in features as pygame. Honestly if you know perl, python isn't that hard to pick right up.
'98 Explorer Sport
http://mp3car.zcentric.com (down atm)
AMD 800mhz 192megs RAM 60gig hard drive 9 inch widescreen VGA
80% done
why can't someone extened php into a language usefull outside of the web worldgod I love its simplicity
![]()
-- WireSix, Inc. --
MP3Car Lives Here!
you can
#!/usr/local/bin/php
echo "bla";
i forget if you need the <? ?> if your using it as a scripting language. there's gtk module for php also
'98 Explorer Sport
http://mp3car.zcentric.com (down atm)
AMD 800mhz 192megs RAM 60gig hard drive 9 inch widescreen VGA
80% done
Ah well... I was mostly just hoping we would be in a position to share code. My codebase is around 1300 lines and counting, so sadly I don't anticipate switching over to Python at this point.
if you wanna let me see it i'll take a look at it. I've worked with a lot of perl .. just thought pygame was more powerful for this app
'98 Explorer Sport
http://mp3car.zcentric.com (down atm)
AMD 800mhz 192megs RAM 60gig hard drive 9 inch widescreen VGA
80% done
Sure; if you want to PM me with an e-mail address I can send attachments to, I'll get you a tarball of my script, config file, and image resources.
Bookmarks