String text fields loosing values

Hi,
I’m quite new to Blender and Python.
At the moment I’m trying to create a simple xml exporter. Everything worked fine until I began to add some GUI elements for setting parameters. One huge problem I have is that when I type something into a textfield (String), focus some other element and then move the mouse cursor out of the python window the textfield becomes blank again.
Same with sliders. Those reset to their initial position.

Maybe you could point me to some commom error that could cause this. The GUI code is very close to the one in the Blender Python tutorial.

BTW: I’m using blender 2.34 on Linux if that is of any relevance.

Are you sure you create() the button only once? One thing I can think of that would cause this is creating the button inside the draw function, or simply by the code altering the text (the val button parameter).

Yes, I’m sure.
this is a stripped down example from the code:


B_Filename = Create('')

def DrawNormal():
	global B_Filename

	glClear(GL_COLOR_BUFFER_BIT)
	glRasterPos2d(60,170)
	Text('XML Exporter','normal')
	
	glRasterPos2d(8,145)
	Text('Filename:')
	B_Filename = String('',EVENT_NOEVENT,90,140,165,18,'',100,'the filename you want to export to')


It seems like the script is always reinitialized when the cursor leaves the script window.

Ok, in that case the code for the string button is not correct. It should be:


B_Filename = String('',EVENT_NOEVENT,90,140,165,18, B_Filename.val,100,'the filename you want to export to')

Blender must know the parameter to return the text you type in. The Blender python documentation is misleading, it is not just the initial value of the string.

Great tip, thanks!

Everything is working fine now.

Also you can replace

glRasterPos2d(8,145)
   Text('Filename:')
   B_Filename = String('',EVENT_NOEVENT,90,140,165,18,'',100,'the filename you want to export

With


   B_Filename = String('Filename: ',EVENT_NOEVENT,90,140,165,18,'',100,'the filename you want to export

Putting the label inside the textbox is more standard for the Blender interface, but you may like your original method better.

Good suggestion. I’ll think about it. Problem is that the alignment of all the text fields doesn’t look that good when using this method. I’ll probably stick to my custom layout.
But as my exporter is now feature complete (for now) I won’t change a thing until something else needs fixing.