How to Redraw GUI at runtime. eg Add a new Textbox

Hello Everyone.

I am new to Blender GUI, & the older version is tough because there is no code_Completion on the Console which I used to learn libraries in the latest Blenders 2.5~. But my problem is that my Mentor has asked me to create a clean WIndow rather than the Panels that are under existing Windows in the so called Blender 2.5~

I need to create a row consisting of a series of Textboxes according to the Number of Selected Polygons(faces) on EditMode.

Eg If I select two Polygons then only two rows appear.
I have figured how to create the GUI Widgets in Blender 2.49. But Documentation or Tuturials are not there on the Net maybe because this version is old. So I have plans to post a PDF Beginners to Blender 2.49 python GUI scripting :eyebrowlift2:.

There is the Code

https://www.box.com/s/nfyi79n7xgjtlx6g8kur

#!BPY

import bpy
import Blender
import activeFace as faceOperations

strInput = “empty”

Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT)
def drawMe():
Blender.BGL.glClear(Blender.BGL.GL_COLOR_BUFFER_BIT)
# Create my Toggle buttons
Blender.Draw.Toggle(“ClearLocation”,1, 10,20, 100,20,0,“Tooltip”)
Blender.Draw.Toggle(“TransLate”,2,20,100, 100,20,0,“Tooltip2”)

#Create LabelBox
Blender.Draw.Label("myLabel",10,150,100,20)

#Create inputs, Globalized "strInput" to keep my values after the GUI refreshes
global textInput,strInput
textInput = Blender.Draw.Create(strInput)
intInput = Blender.Draw.Create(0)

#Create TextBox
textInput= Blender.Draw.String("Str: ",3,100,150,100,20,strInput,20,"its tooltip")
#Try to store Text from Textbox
strInput = textInput.val

def event(evt,val):
if evt == Blender.Draw.ESCKEY:

[INDENT=2]Blender.Draw.Exit()
[/INDENT]
[INDENT=3]return
[/INDENT]

#BlenderArtist friends Ignore this Function
def buttonMe(eventPassd):
global textInput,strInput

#***Just events for Buttons. Ignore this section***#
if eventPassd == 1:

[INDENT=2]Blender.Scene.GetCurrent().getActiveObject().loc = (0,0,0) #Move object to origin[/INDENT]
[INDENT=2]Blender.Window.Redraw() [/INDENT]
if eventPassd == 2:

[INDENT=2]Blender.Scene.GetCurrent().getActiveObject().loc = (0,0,4) #Move object up by z+=4
[/INDENT]

Blender.Draw.Register(drawMe,event,buttonMe)

Hi Dumisani,

you can use [noparse]


[/noparse] tags to present code snippets.

Thank you let me try it:


from Blender import Draw,Window
import Blender

#Trying to use this .py script to Re-Run this GUI script
import RefreshGui,MeshFunctions

obj = MeshFunctions.getActiveObject()
n = len(MeshFunctions.getSelectedFaces())
listWidgets = []


def myGui():
    global listWidgets,n
    
    #Initialize Global variables to store textbox values
    for i in range(n):
        listWidgets.append( Draw.Create("")  )
    
    #Create the Textboxes    
    y = 100
    for i in range(n):
        y = 20
        y *= i
        listWidgets[i] = Draw.String("Text"+str(i)+": ",2,50,y, 300,20,\
        listWidgets[i].val,20," tooltip for "+str(i) )

    #Place it at the center of the Window
    xbtn = Window.GetAreaSize()[0]/2
    ybtn = Window.GetAreaSize()[1]/2
    #Create the Buttons    
    Draw.PushButton("PrintIt",1,xbtn,ybtn, 100,20,"All Textboxes & values")
    Draw.PushButton("Refresh",3,xbtn,ybtn-20, 100,20,"All Textboxes & values")
    Draw.PushButton("Exit",10,xbtn*2-100,0, 100,20,"Exit the Program")



def keyboardEvents(event,val):
    global n,listWidgets
    if event == Draw.ESCKEY:
        Draw.Exit()
        return

def buttons(event):
    global n,listWidgets
    
    if event == 1:
        for i in range(n):
            print "Textbox[%d]: %s" % (i,str(listWidgets[i]))
            
    if event == 2:
        print "Event 2"

    #*Here I was trying to run another script them Rerun this Script but Blender does not Seem to close the last one *#    
    if event == 3:
        run = RefreshGui.parseStr("TableBoxes.py")
        #Blender.Run("RefreshGui.py")
        
        Draw.Redraw(1)
        Draw.Draw()
        

    
    if event == 10:
        Draw.Exit()



#Reserved Structure for Blender GUI. Functions for windowing
#Register the 3 required functions (draw, event, button)
Draw.Register(myGui, keyboardEvents, buttons)   



Sorry I have pasted this in a wrong Thread


from Blender import Draw,Window
import Blender

#Trying to use this .py script to Re-Run this GUI script
import RefreshGui,MeshFunctions

obj = MeshFunctions.getActiveObject()
n = len(MeshFunctions.getSelectedFaces())
listWidgets = []


def myGui():
    global listWidgets,n
    
    #Initialize Global variables to store textbox values
    for i in range(n):
        listWidgets.append( Draw.Create("")  )
    
    #Create the Textboxes    
    y = 100
    for i in range(n):
        y = 20
        y *= i
        listWidgets[i] = Draw.String("Text"+str(i)+": ",2,50,y, 300,20,\
        listWidgets[i].val,20," tooltip for "+str(i) )

    #Place it at the center of the Window
    xbtn = Window.GetAreaSize()[0]/2
    ybtn = Window.GetAreaSize()[1]/2
    #Create the Buttons    
    Draw.PushButton("PrintIt",1,xbtn,ybtn, 100,20,"All Textboxes & values")
    Draw.PushButton("Refresh",3,xbtn,ybtn-20, 100,20,"All Textboxes & values")
    Draw.PushButton("Exit",10,xbtn*2-100,0, 100,20,"Exit the Program")



def keyboardEvents(event,val):
    global n,listWidgets
    if event == Draw.ESCKEY:
        Draw.Exit()
        return

def buttons(event):
    global n,listWidgets
    
    if event == 1:
        for i in range(n):
            print "Textbox[%d]: %s" % (i,str(listWidgets[i]))
            
    if event == 2:
        print "Event 2"

    #*Here I was trying to run another script them Rerun this Script but
    #Blender does not Seem to close the last one  

    if event == 3:
        run = RefreshGui.parseStr("TableBoxes.py")
        #Blender.Run("RefreshGui.py")
        
        Draw.Redraw(1)
        Draw.Draw()
        

    
    if event == 10:
        Draw.Exit()



#Reserved Structure for Blender GUI. Functions for windowing
#Register the 3 required functions (draw, event, button)
Draw.Register(myGui, keyboardEvents, buttons)




For an expample. I would like to show the number of Textboxes on the GUI in respected to the number of Polygons(faces) selected.

Is there a way to close a specific script. Becasue Blender.Draw.Exit() just does not allow me to Re-Run the GUI. It just terminates everything.

Thanks to anyone that tried looking at this but once again I solved the Problem.

Just a Lousy stupid solution. Mainly due to the fact that I did not realize that Blender myGUI() function creates new variable everytime Blender.Draw.Registry() calls myGUI() function.

So I had to move my integer n = len(MeshFunctions.getSelectedFaces() inside myGui function for the Foorloop that creates the Textboxes. What really confused me was that I saw some functions called Draw() and Redraw I thought Blender relies on them to update the GUI.:spin: