[Tutor] Command not issued until after escape from loop

David Hutto dwightdhutto at yahoo.com
Mon Mar 15 07:15:51 CET 2010


In the following code, the portion I'm having a problem with is outlined in stars, but since the overall code was short, I included it, just in case something else might be hindering the process.

When I execute the script, it shows my main window, then if I press the CKEY it's *supposed* to call the cleanSlate() function, which grabs and deletes objects in the contents of another window.

My problem is, it doesn't execute cleanSlate() until I hit the ESCKEY, or the QKEY. In the original example code I'm using as a template(I put in the ev() portion of the main template below my current code, so maybe someone could see where I deviated from the original, and why the differences in implementing redraw) , it's setup in the same manner. 

Why would it not execute immediately(during the main loop) in mine, but in the original it does?

import Blender
from Blender.BGL import *
from Blender import Draw, Scene, Object, Mesh
R = G = 0
B = A = 1
title = "Basic Object Manipulation"
instructions = "Select an object to manipulate"
len1 = Draw.GetStringWidth(title)
len2 = Draw.GetStringWidth(instructions)

# Removes default objects in scene

def cleanSlate(scn):
		for ob in scn.objects:
				if ob.getType == 'Mesh' or 'Camera':
						scn.objects.unlink(ob)

#defining the window
def show_win():
		glClearColor(R,G,B,A)                # define color used to clear buffers 
		glClear(GL_COLOR_BUFFER_BIT)         # use it to clear the color buffer
		glColor3f(0.35,0.18,0.92)            # define default color
		glColor3f(.0,0.0,0.0)                # change default color for next item
		glRecti(10, 450, 20+len2, 113)       # sets a box border
		glColor3f(0.2,0.2,0.2)               # change default color for next item
		glRasterPos2i(14,435)                # move cursor
		Draw.Text(title)                     # draw this text there
		glRasterPos2i(14,410)                # move cursor again
		Draw.Text(instructions)   # draw another msg
******************************************************************		
# defining the event handling list
def ev(evt, val):
		scn = Scene.getCurrent()
		if evt == Draw.ESCKEY or evt == Draw.QKEY:
				Draw.Exit()
		elif not val:
				return
		elif evt == Draw.CKEY: 
				cleanSlate(scn) 
		else:
				return
		Draw.Redraw(1)
******************************************************************

# build the window
Draw.Register(show_win, ev, None)      # start the main loop


#End code


This is the original ev()
**********************************************************

def ev(evt, val):                      # event callback for Draw.Register()
   global R,G,B,A                       # ... it handles input events
   if evt == Draw.ESCKEY or evt == Draw.QKEY:
     Draw.Exit()                        # this quits the script
   elif not val: return
   elif evt == Draw.LEFTMOUSE: R = 1 - R
   elif evt == Draw.MIDDLEMOUSE: G = 1 - G
   elif evt == Draw.RIGHTMOUSE: B = 1 - B
   elif evt == Draw.WHEELUPMOUSE:
     R += 0.1
     if R > 1: R = 1
   elif evt == Draw.WHEELDOWNMOUSE:
     R -= 0.1
     if R < 0: R = 0
   else:
     return                             # don't redraw if nothing changed
   Draw.Redraw(1)


TIA,
David


      


More information about the Tutor mailing list