I’ve created an app that has a textctrl that is spell checked by an instance of , class SpellCheckerDialog(wx.Dialog). When the instance is created the text that needs to be checked is passed to the class and the spell checking dialog is opened and you complete the spell checking.
In the main app, class Myframe(wx.Frame), I’ve got a wx.Timer running when the instance is created that runs the event OnTickTwo below. It checks for any corrected text and changes it in the textctrl. Which works splendid.
The problem I’ve come across that I can’t seem to google efficiently is that I need to check to see if the instance/dialog is running/open but I not sure how to do this.
def OnTickTwo(self, event):
'''When wx.Timer hits, checks for return text from spellchecker'''
if self.spellDlg: # This is where the check to see is the instance is running/open or not should be
try:
newText = self.spellDlg.returnText()
print 'returned value,', newText
self.t1.Clear()
self.t1.AppendText(newText)
except AttributeError:
pass
else:
self.timer1.Stop() # if not open timer stops
event.Skip()
Hope this makes sense as I’m just starting to grasp simple python oop concepts so the terminology could be all over the place =]
I've created an app that has a textctrl that is spell checked by an instance of , class SpellCheckerDialog(wx.Dialog). When the instance is created the text that needs to be checked is passed to the class and the spell checking dialog is opened and you complete the spell checking.
In the main app, class Myframe(wx.Frame), I've got a wx.Timer running when the instance is created that runs the event OnTickTwo below. It checks for any corrected text and changes it in the textctrl. Which works splendid.
The problem I've come across that I can't seem to google efficiently is that I need to check to see if the instance/dialog is running/open but I not sure how to do this.
def OnTickTwo(self, event):
'''When wx.Timer hits, checks for return text from spellchecker'''
if self.spellDlg: # This is where the check to see is the instance is running/open or not should be
try:
newText = self.spellDlg.returnText()
print 'returned value,', newText
self.t1.Clear()
self.t1.AppendText(newText)
except AttributeError:
pass
else:
self.timer1.Stop() # if not open timer stops
event.Skip()
Hope this makes sense as I'm just starting to grasp simple python oop concepts so the terminology could be all over the place =]
I am not an expert but I do wonder why you are using a timer for this.
Wouldn't something like this do when you want to call the spell check dialog:
try:
dlg = spell.DialogSpell(parent=self)
dlg.CenterOnScreen()
val = dlg.ShowModal()
newText = dlg.returnText()
... etc
finally:
dlg.Destroy()
Or if you do not want to create the dialog each time:
if not hasattr(self, 'spellDlg'):
self.spellDlg = spell.DialogSpell(parent=self)
self.spellDlg.CenterOnScreen()
val = self.spellDlg.ShowModal()
newText = self.spellDlg.returnText()
... etc
In app close or somewhere else:
if hasattr(self, 'spellDlg'):
self.spellDlg.Destroy()