how can i update the value of a textbox in a live manner in blender ?

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__('.'):

                   Textbox1.val=''

                   Textbox2.val=input
      ############# and here is the end of it ############
      Blender.Redraw()
      Register(draw_gui, event, bevent)
 

please ,i need a help very quickly .

Sorry, I don’t know exactly how to do it in Blender, but I think you would need to read and check each character one at a time.

This is a simple Python illustration that works in Windows only. The question is whether or not you can get this to work in a Blender Textbox input window. You will have to search for solutions for that. Or search for other solutions of reading each character or keypress in Blender.

Windows only Python code (not Blender script):

# windows
import msvcrt

def readChar(echo=True):
    "Get a single character on Windows."
    while msvcrt.kbhit():
        msvcrt.getch()
    ch = msvcrt.getch()
    while ch in b'\x00\xe0':
        msvcrt.getch()
        ch = msvcrt.getch()
    if echo:
        msvcrt.putch(ch)
    return ch.decode()

output = ""
input = ""

# ENTER key is \r

while input != '\r':
    input = readChar()
    if input != ".":
        output += input
    if input == ".":
        print "

output:", output, "
"
        output = ""

print "

output:", output

Example output:

This is a test of the Windows readChar().

output: This is a test of the Windows readChar()

It works.

output: It works

Now press ENTER to exit

output: Now press ENTER to exit

readChar() code from here:

getch()-like unbuffered character reading from stdin on both Windows and Unix (Python)

Here’s is an event driven way to do it on both platforms:

getch() Key Event Loop
Linux curses module, Windows msvcrt module.

Thank you so much for your reply .

I will try to use it now .

Any more suggestions from the others ?

please i need the solution very quickly.
I did many trials and i still trying but my results are not good cause i’m a beginner.

As I said, I don’t think this will work directly in Blender in a text input field. This is a Python example to give you an idea of what to search for.

As harveen stated, the problem is in getting each character as soon as it’s typed. The Draw.String() element in Blender simply doesn’t allow this. It only returns its value after you stop typing in it.
In the code of knowledge, the problem is in the first line of the problem area. “while 1:” always returns True, meaning that the code will always run. In Blender 2.4 we unfortunately have the problem that python scripts block all other functionality while they’re running, so you won’t be able to change the text in the input.
Harveen’s solution is a good one and also works inside Blender, but only in the console. If you want to have a working solution inside Blender’s gui you might want to investigate spacehandler scripts (you have to scroll down a bit). They can catch events in the 3d-view without blocking functionality. Unfortunately drawing buttons (like Draw.String() or Draw.Button) is impossible in the 3d-view. You’ll have to fake it using opengl calls which is a lot of work.

If you insist on having this in Blender I think you’ll have to let go of the idea of having it push the input to output as soon as the dot-key is pressed. Evaluation after the entire text has been typed (so once the user presses Enter, or clicks outside of the textbox) is your best bet.

Thanks so much for all ,i’m trying now in all paths .

I have a question about blender console window as a part of blender 2.49 application ?

I tried to run it in the NetBeans IDE 6.8 and in the blender to use the blender console window but in both cases the program is not responding .

what the mistake i made ?

or where did you run that code and is there is a previous step before running that code ?

please i need the answer this day .what the mistake i made ?
I tried to run it in the NetBeans IDE 6.8 and in the blender to use the blender console window but in both cases the program is not responding .

Is no one here can provide a help please ?

about harveen’s code :

I tried to run it in the NetBeans IDE 6.8 and in the blender to use the blender console window but in both cases the program is not responding .

also i asked my friend to run it and this is the error we get :

readChar
return ch.decode()
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xff in position 0: ordinal not in range(128)