The MP3car.com Store The MP3car.com Store    

Sponsored links

Go Back   MP3Car.com > Mp3Car Technical > Software & Software Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-27-2003, 09:36 AM   #1
Super Moderator
 
hijinks21's Avatar
 
Join Date: May 2002
Location: Albany, NY
Posts: 1,802
Linux App Tutorial

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
Attached Files
File Type: txt tut-1.txt (1.4 KB, 141 views)
__________________
'98 Explorer Sport
http://mp3car.zcentric.com (down atm)
AMD 800mhz 192megs RAM 60gig hard drive 9 inch widescreen VGA
80% done
hijinks21 is offline   Reply With Quote
Advertisement
 
Advertisement
Sponsored links

Old 08-27-2003, 09:48 AM   #2
Hosting Guru
 
Join Date: Oct 2001
Location: Atlanta, GA
Posts: 560
I'm just not a huge fan of python
__________________
-- WireSix, Inc. --
MP3Car Lives Here!
W6-Ryan is offline   Reply With Quote
Old 08-27-2003, 09:55 AM   #3
Super Moderator
 
hijinks21's Avatar
 
Join Date: May 2002
Location: Albany, NY
Posts: 1,802
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
hijinks21 is offline   Reply With Quote
Old 08-28-2003, 08:13 AM   #4
Low Bitrate
 
Join Date: Jul 2002
Posts: 89
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.
Mxyzpltk is offline   Reply With Quote
Old 08-28-2003, 08:25 AM   #5
Super Moderator
 
hijinks21's Avatar
 
Join Date: May 2002
Location: Albany, NY
Posts: 1,802
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
hijinks21 is offline   Reply With Quote
Old 08-28-2003, 08:36 AM   #6
Hosting Guru
 
Join Date: Oct 2001
Location: Atlanta, GA
Posts: 560
why can't someone extened php into a language usefull outside of the web world god I love its simplicity
__________________
-- WireSix, Inc. --
MP3Car Lives Here!
W6-Ryan is offline   Reply With Quote
Old 08-28-2003, 08:41 AM   #7
Super Moderator
 
hijinks21's Avatar
 
Join Date: May 2002
Location: Albany, NY
Posts: 1,802
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
hijinks21 is offline   Reply With Quote
Old 08-28-2003, 09:49 AM   #8
Low Bitrate
 
Join Date: Jul 2002
Posts: 89
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.
Mxyzpltk is offline   Reply With Quote
Old 08-28-2003, 09:52 AM   #9
Super Moderator
 
hijinks21's Avatar
 
Join Date: May 2002
Location: Albany, NY
Posts: 1,802
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
hijinks21 is offline   Reply With Quote
Old 08-28-2003, 10:28 AM   #10
Low Bitrate
 
Join Date: Jul 2002
Posts: 89
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.
Mxyzpltk is offline   Reply With Quote
Old 08-28-2003, 12:49 PM   #11
Variable Bitrate
 
Join Date: Sep 1999
Location: Yarmouth NS, Canada
Posts: 336
Quote: Originally Posted by techm3
why can't someone extened php into a language usefull outside of the web world god I love its simplicity

http://gtk.php.net

That what you are looking for?
__________________
MP3 Cavalier - http://www.mp3cavalier.com
MP3 Grand Prix - http://www.mp3gp.com
Callahan is offline   Reply With Quote
Old 09-05-2003, 07:47 PM   #12
Low Bitrate
 
Join Date: Jul 2002
Posts: 89
hijinks - just wanted to say that I've not forgotten my promise to send you my code. It's in a bit of a mess right now, but I'm cleaning it up and incorporating some new stuff in the process. I'll send it to you as soon as I can do so without blushing overmuch... really!
Mxyzpltk is offline   Reply With Quote
Sponsored links
Advertisement
 
Advertisement
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off


All times are GMT -5. The time now is 02:29 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Copyright © 1999 - 2008 Mp3Car.com Inc.Ad Management by RedTyger
Message Board Statistics