Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Linux App Tutorial

  1. #1
    Raw Wave hijinks21's Avatar
    Join Date
    May 2002
    Location
    Albany, NY
    Posts
    1,803

    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 Attached Files
    '98 Explorer Sport
    http://mp3car.zcentric.com (down atm)
    AMD 800mhz 192megs RAM 60gig hard drive 9 inch widescreen VGA
    80% done

  2. #2
    Hosting Guru
    Join Date
    Oct 2001
    Location
    Atlanta, GA
    Posts
    558
    I'm just not a huge fan of python
    -- WireSix, Inc. --
    MP3Car Lives Here!

  3. #3
    Raw Wave hijinks21's Avatar
    Join Date
    May 2002
    Location
    Albany, NY
    Posts
    1,803
    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

  4. #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.

  5. #5
    Raw Wave hijinks21's Avatar
    Join Date
    May 2002
    Location
    Albany, NY
    Posts
    1,803
    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

  6. #6
    Hosting Guru
    Join Date
    Oct 2001
    Location
    Atlanta, GA
    Posts
    558
    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!

  7. #7
    Raw Wave hijinks21's Avatar
    Join Date
    May 2002
    Location
    Albany, NY
    Posts
    1,803
    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

  8. #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.

  9. #9
    Raw Wave hijinks21's Avatar
    Join Date
    May 2002
    Location
    Albany, NY
    Posts
    1,803
    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

  10. #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.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •