Re: [Tutor] loops to assign variables
I've been on vacation so missed the start of this, apologies if i'm missing a point somewhere but... > Ah. I see. A copy, eh? Or, at least a new dictionary separate > from the "real" namespace. OK. I don't know why locals() returns > a copy as opposed to the original, What else can it do? When you enter a function you enter a new namespace. It starts out containing the global names and any parameters to the function then adds new names as they are created plus overrides any global names that get replaced with local versions. It can only do that if it is working on a copy of the global namespace to start with otherwise it would be polluting the global namespace with local functon versions and in a multithreaded environment creating havoc across threads!... I hope I haven't missed the point and have added some clarification, if not forgive me for butting in late! :-) Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] images in pygame
Hello, I have a code here. and I want to make the "rockwholescreen.gif" blocked, but still displayed. I want it so "001.png" can't walk through that gif. any ideas?import pygame, os, sysfrom pygame.locals import * pygame.init( ) def _loadImages_ ( path, name ): image_obj = os.path.join( path, name ) image_load = pygame.image.load( image_obj ) return image_load images_path = './img/'images_dict = {}image_names = { 1:"001.png", 2:"rockwholescreen.gif" } for dir, name in image_names.items( ): images_dict[dir] = _loadImages_( images_path, name ) setwinsize = ( 640, 480 )windows = pygame.display.set_mode( setwinsize ) #load First Imageimageload = images_dict[1]imagerect = imageload.get_rect( 0, 0, * windows.get_size( )) #load Second Imageimageloads = images_dict[2]imagerects = pygame.Rect( 0, 448, * windows.get_size( )) while True: events = pygame.event.wait( ) if events.type == pygame.QUIT: break if events.type == pygame.KEYDOWN: if events.key == K_DOWN: imagerect.move_ip( 0, 10 ); imageload = images_dict[1] if events.key == K_UP: imagerect.move_ip( 0, -10 ); imageload = images_dict[1] if events.key == K_RIGHT: imagerect.move_ip( 10, 0 ); imageload = images_dict[1] if events.key == K_LEFT: imagerect.move_ip( -10, 0 ); imageload = images_dict[1] windows.fill(( 25, 110, 189 )) windows.blit( imageload, imagerect ) windows.blit( imageloads, imagerects ) pygame.display.flip( ) print "Image One Rect: %s \n" % imagerect print "Image Two Rect: %s \n" % imagerectsfonts = pygame.font.Font(None, 26)_colors_ = { "black" : (0, 0, 0), "red" : (255, 0, 0) }_text_ = fonts.render('Testing', 0, _colors_['red'] )_rtext_ = screensize[0] - _text_.get_width( ), 0while True: events = pygame.event.wait( ) if events.type == pygame.QUIT: break windows.blit( _text_, _rtext_ ) pygame.display.flip( )pygame.quit( )thanks.. __Do You Yahoo!?Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] starting a program from python
johnsonv3 wrote: > Hi, > Using Windows XP Home & python 234 > I am trying to start python programs that run Panda 3D without having > to open command prompt and type a path every time I run a program. > > This pandastart.bat file works... > > cd C:\Panda3D-1.2.3\mystuff > ppython bvd.py > > and from python shell this works > > >>> subprocess.Popen("pandastart.bat") > > > But it is not flexible to start other file names.. > > So I would like to write a python script similar to this > > import subprocess > panda = raw_input("Enter name of Panda python program to start > (fileName.py)") > subprocess.Popen("C:\panda3D-1.2.3\mystuff\panda") Here panda is the name of a variable whose value is the name of the file you want to run. Python won't automatically insert the value of a variable into a string, it thinks you want to Popen a file called "C:\panda3D-1.2.3\mystuff\panda". Since there is no file with that name, you get an error. You can use string formatting to get the name of the file into the string for Popen(). Try this: subprocess.Popen("C:\panda3D-1.2.3\mystuff\%s" % panda) For more info on string formatting: http://docs.python.org/lib/typesseq-strings.html Kent > > But this is the result... > > >>> subprocess.Popen("C:\panda3D-1.2.3\mystuff\bvd.py") > Traceback (most recent call last): > File "", line 1, in ? > subprocess.Popen("C:\panda3D-1.2.3\mystuff\bvd.py") > File "C:\Python24\lib\subprocess.py", line 542, in __init__ > errread, errwrite) > File "C:\Python24\lib\subprocess.py", line 706, in _execute_child > startupinfo) > WindowsError: [Errno 123] The filename, directory name, or volume > label syntax is incorrect > > Also tried the below (change to the path) with result as indicate > below > > >>> subprocess.Popen("C:\panda3D-1.2.3\mystuff bvd.py") > Traceback (most recent call last): > File "", line 1, in ? > subprocess.Popen("C:\panda3D-1.2.3\mystuff bvd.py") > File "C:\Python24\lib\subprocess.py", line 542, in __init__ > errread, errwrite) > File "C:\Python24\lib\subprocess.py", line 706, in _execute_child > startupinfo) > WindowsError: [Errno 5] Access is denied > > Have tried using os.system and os.startfile with similar results > > Suggested solution? > Thanks. > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Writing python scripts to control GIMP
Richard Querin wrote: > Hi, > > I'm interested in learning about how to write python scripts that can > control the GIMP. I've read about several scripts but I'd like to know > where to start learning about how it's done. Anybody got any good > places to look for tutorials, references etc? Have you looked at the Gimp-Python docs? http://www.jamesh.id.au/software/pygimp/ Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] images in pygame
Dunno if this is the best way, but it works... Replace this: > if events.key == K_DOWN: with this: > if events.key == K_DOWN and not imagerect.colliderect(imagerects): Alan ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] images in pygame
the tutor mailing list didn't like the zip I attached, so here's the text of the e-mail I wrote to Joe without the zip included. start- Pygame-specific questions should be posted to the pygame mailing list, not tutor, probably. Joe F wrote: > Hello, I have a code here. and I want to make the > "rockwholescreen.gif" blocked, but still displayed. I want it so > "001.png" can't walk through that gif. any ideas? > > import pygame, os, sys > from pygame.locals import * > > > pygame.init( ) > > def _loadImages_ ( path, name ): > image_obj = os.path.join( path, name ) > image_load = pygame.image.load( image_obj ) > > return image_load why do you have underscores in the name of this function? Usually underscores denote functions that are supposed to be private to a class, I believe, and this function's not in a class at all! also,there's no reason to create an 'image_load' variable. return pygame.image.load( image_obj ) would do just as well. > > images_path = './img/' > images_dict= {} > image_names = { 1:"001.png", 2:"rockwholescreen.gif" } > > for dir, name in image_names.items( ): > images_dict[dir] = _loadImages_( images_path, name ) this strikes me as a very odd way to handle image-loading. if you're using integers as a reference for a dict why not just use list indices? #--- images_path = './img/' image_names = ['001.png','rockwholescreen.gif'] images = [_loadImages_(images_path,name) for name in image_names] #--- It took me a minute to figure out what you were doing, and this way I think your intent is more clear. > > setwinsize = ( 640, 480 ) > windows= pygame.display.set_mode( setwinsize ) I'm guessing you're using a global 'setwinsize' so you don't hard-code in your resolution. If you're going to do this, why not just put your globals at the top, so they're easier to change? If you have to go hunting through your code for a global you want, it's just barely better than hunting through your code to find the place where you need to change the hardcoded value. > > #load First Image > imageload = images_dict[1] > imagerect = imageload.get_rect( 0, 0, * windows.get_size( )) why not just use setwinsize here also instead of getting the size of the display surface? it'll probably be faster. also, I don't understand why you're doing get_rect on (0,0,640,480) does get_rect select a subsurface of the image? > > #load Second Image > imageloads = images_dict[2] > imagerects = pygame.Rect( 0, 448, * windows.get_size( )) if you find yourself appending letters to variable names to distinguish them you're probably at the point where you should be using lists. If someone weren't reading your code very carefully they may get confused here and think these variables are the same as the ones above. Also, later in your code, you might get confused and use the wrong one of these variables without even realizing and give yourself debugging headaches. I don't understand what the * here is doing. it doesn't seem to work for me. > > > > while True: > events = pygame.event.wait( ) I'm pretty sure pygame.event.wait() blocks until if gets an event. Think about this, is this really what you want? If the user sits there not sending any events, the screen won't update, but if they move their mouse, you'll get a lot of mousemovement events and such, and then your program will be rapidly filling the whole screen with the color (25,110,189) and re-blitting everything even though nothing moved. > > if events.type == pygame.QUIT: > break > > if events.type == pygame.KEYDOWN: > if events.key == K_DOWN: > imagerect.move_ip( 0, 10 ); imageload = images_dict[1] > if events.key == K_UP: > imagerect.move_ip( 0, -10 ); imageload = images_dict[1] > if events.key == K_RIGHT: > imagerect.move_ip( 10, 0 ); imageload = images_dict[1] > if events.key == K_LEFT: > imagerect.move_ip( -10, 0 ); imageload = images_dict[1] I don't think the escape key raises a pygame.QUIT so if you want the user to be able to exit with the escape key, you should put also, since you imported everything from pygame.locals you don't need a 'pygame.' here #-- if events.key == K_ESCAPE: break #- to get this effect. > > > windows.fill(( 25, 110, 189 )) > windows.blit( imageload, imagerect ) > windows.blit( imageloads, imagerects ) > pygame.display.flip( ) here you're not doing dirty-rect animation. you're just updating the whole screen every time you get an event. This is okay for an example but for a real game you'll need to use some form of dirty-rect updating method if it needs good performance. > > print "Image One Rect: %s \n" % imagerect > print "Image Two Rect: %s \n" % imagerects > > fonts = pygame.font.Font(None, 26) > > _colors_ = { "black" : (0, 0, 0), > "red" : (255, 0, 0) > } again, why the underlines?
[Tutor] IDLE Caching
Hi,I have a problem with IDLE on Windows.While I'm executing a python script in IDLE subsequenceediting and executions on the file sometimes doesn't reflect the changes.For example, i changed the file then save it, execute it, although i changed the file, IDLE shows the previous version of the file. If I close and run the IDLEthen it correctly shows the execution of the current source file. What will bethe problem ? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] IDLE Caching
Bugra Cakir wrote: > Hi, > > I have a problem with IDLE on Windows. > While I'm executing a python script in IDLE subsequence you mean subsequent :) > editing and executions on the file sometimes doesn't reflect the changes. > For example, i changed the file then save it, execute it, although i > changed > the file, IDLE shows the previous version of the file. If I close and > run the IDLE > then it correctly shows the execution of the current source file. What > will be > the problem ? this is what (I believe) usually causes this for me: I make a file called 'temp.py' for example in the directory 'c:/python scripts/' I open it in IDLE to edit it. I say 'oops, I meant for the file to be in a different directory so I save the file as 'temp.py' in the directory 'c:/python scripts/7-24-2006/' now whenever I save changes it saves to the 'temp.py' that's in 'c:/python scripts/7-24-2006/' but whenever I execute the code it executes 'temp.py' that's in 'c:/python scripts/' Have you been moving your files or saving them in different directories? Otherwise, I don't know what your problem could be. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor