Here's how I did it:
In the __init__(self) section of the class, define your edit control, add the control, set focus, initialize a string variable to hold the final text of the edit control, and call self.doModal(). (I found it easier to define the edit control itself in the WindowDialog python class rather than use a WindowXMLDialog. I think this method works for WindowXMLDialog, too.)
Then override the window's class 'OnControl' to trap the window close event. When the dialog closes, it spits out the string that is in the edit control. I used a button in the dialog, but you could also trap the esc or del keys depending on how you want the UI flow to go with your dialog. In the codeblock for the onControl event, you'll close the window, and assign the text to the class string variable you made earlier.
Since you called self.close, the window closes, but the window instance is not actually deleted as it would be with 'del <dialogwindow>. Thus the function/class that first opened the dialog instance still has access to the string variable contained in that instance.
Here's my awful, messy, beginner-ish code that accomplishes all this (I'm capturing a username and password with my dialog). (There's some other stuff going on with the LoginWin class, where I'm extending the regular WindowXML class so I can also pass my Member() class in to hold the userdata):
Code:
class LoginWin(LoginBase):
def __init__(self,*args,**kwargs):
LoginBase.__init__(self, *args)
self.mem = kwargs.get('member')
def onInit(self):
print "Starting onInit Loop"
while not self.mem.logged_in:
if self.mem.bad_creds == True:
self.getControl(10).setLabel('Login failed! Try again...')
print "Set fail label message"
self.inputwin = InputDialog()
self.inputwin.showInputDialog()
self.mem.login_member(self.inputwin.name_txt, self.inputwin.pswd_txt)
print "Logged_in value: "+str(self.mem.logged_in)
print "Bad Creds value: "+str(self.mem.bad_creds)
print "Exited the while loop! Calling the close function"
self.close()
class InputDialog(xbmcgui.WindowDialog):
def __init__(self):
self.name = xbmcgui.ControlEdit(530, 320, 400, 120, '', 'font16', '0xDD171717')
self.addControl(self.name)
#self.inputbox_username.setText("Here's some sample text")
self.pswd = xbmcgui.ControlEdit(530, 320, 400, 120, '', font='font16', textColor='0xDD171717', isPassword=1)
self.addControl(self.pswd)
#self.inputbox_password.setText("Here's the password field")
self.butn = xbmcgui.ControlButton(900, 480, 130, 50, 'Sign In', font='font24_title', textColor='0xDD171717', focusedColor='0xDD171717')
self.addControl(self.butn)
self.setFocus(self.name)
self.name_txt = ""
self.pswd_txt = ""
def onControl(self, control):
if control == self.butn:
#print "if condition met: control == self.butn"
#print "closing dialog window"
self.close()
self.name_txt = self.name.getText()
self.pswd_txt = self.pswd.getText()
#print self.name_txt
#print self.pswd_txt
def showInputDialog(self):
self.name.setPosition(600, 320)
self.name.setWidth(400)
self.name.controlDown(self.pswd)
self.pswd.setPosition(600, 410)
self.pswd.setWidth(400)
self.pswd.controlUp(self.name)
self.pswd.controlDown(self.butn)
self.butn.controlUp(self.pswd)
self.doModal()