I have a gui interface in blender and the following should be the scenario for the user :
after pressing the button "Run" then the user could enter sentences in the input text box such that each sentence should be ended with a dot point '.' then if the user enter a sentence then the input box should be cleared and the entered sentence should be displayed in the output text box.
The problem is in the following part of code :
while 1:
input = Textbox1.val
if input.__contains__('.'):
Textbox1.val = ''
Textbox2.val = input
And here is all of my code:
import Blender
from Blender.BGL import *
from Blender.Draw import *
def draw_gui():
global Textbox1, Textbox2
Textbox1 = Create('input')
Textbox2 = Create('output')
glClearColor(0.753, 0.753, 0.753, 0.0)
glClear(GL_COLOR_BUFFER_BIT)
glColor3f(0.000, 0.000, 0.627)
glRecti(20, 150, 730,500)
Button('Exit', 1, 450, 220, 87, 31)
Button('Quit', 2, 350, 220, 87, 31)
Button('Run', 3, 250, 220, 87, 31)
Textbox1 = String('', 4, 50, 400, 650, 50, Textbox1.val, 399, '')
Textbox2 = String('', 4, 50, 300, 650, 50, Textbox2.val, 399, '')
def event(evt, val):
if (evt==QKEY and not val): Exit()
def bevent(evt):
if evt == 1: #cmdExit
Exit()
elif evt == 2 : #cmdQuit
Blender.Quit()
elif evt == 3 : #cmdRun
########################### from here the problem starts
while 1:
input =Textbox1.val
if input.__contains__('.'):
开发者_StackOverflow中文版 Textbox1.val=''
Textbox2.val=input
#################### and here is the end of it
Blender.Redraw()
Register(draw_gui, event, bevent)
This is very old Blender (pre Blender 2.5), and back then it was practically impossible to do that. With current Blender (since 2.5 series, currently in 2.67 as of this writing) you could solve this with a model operator that triggers also on Python time events. Not so long ago I answered to another SO question here: https://stackoverflow.com/a/16744008/2419030 . It gives a simple structure for such a modal operator in current Blender that also listens on time events. It also has a link to a simple Conways Game of Life implementation running as modal operator.
In your case you'd be checking the value of an input box (you can create your own panels that seamlessly integrate in the rest of blender) and updating the other parts you want to react on it. In the example file the modal handler does one step of the simulation. You'll notice that the entire interface stays responsive.
Specifically you'd be doing the checks in the model() handler under the 'TIMER' if-block.
To create panels (and other forms of scripts) open up the Blender text editor and check the Templates menu entry. You'll find a huge amount of good stuff.
精彩评论