A simple text editor with wx.Frame, StyledTextCtrl, and some basic menue items : As File menue; Open, Save, Save As, Close : as Edit menue; Copy, Cut, Paste, Undo, Redo.
Operations are just open file, do something, and close. Quite simple.
If the data in the StyledTextCtrl is changed, I want to open a dialog box (ShowModal()) to confirm save or not by both the Xbox of the wx.Frame and the Close(Cmd-W) menu.
To get whether the data is changed or not, when the stc.EVT_STC_CHANGE is sent to the application, the variable I set as ‘flagDirty’=True.(This editor doesn’t need to save the Style change, so stc.EVT_STC_CHANGE, not stc.EVT_STC_MODIFIED.)
I bind in the wx.Frame’s init(self, title) function, I bound the Close event to handler.
self.Bind(wx.EVT_CLOSE, self.OnClose)
And the Close menuitem
menu_File_Close = menu_File.Append(wx.ID_CLOSE, “&Close”+"\t"+“Ctrl+W”, “Close”)
Xbox seems work all right.
The menuitem Close is the problem. The dialog displayed OK. But when No(= wx.ID_NO );
THE PROBLEMS ARE::
1 At the first time pushed, the dialog doesn’t work. Second time, dialog closes, but the wx.Frame doesn’t close.
Why dialog works funny like this?
2 Isn’t there BETTER WAY for the case like this?
For example, I’m not sure about setting variable like ‘flagDirty’ is good for getting whether the data is changed.
3 When just open the window and close without editing, the dialog box opens for the variable is True. What’s wrong with the setting of the StyledTextCtrl?
smallEdit.py (5.34 KB)
sample.txt (175 Bytes)