How to use stc SavePoint

Hi there,

Wx.stc.StyledTextCtrl has SaveFile and SetSavePoint methods but I don’t see how to use the saved point. Is it possible to get a flag like need-not-save after calling SetSavePoint? (of course without re-opening the saved file and comparing the contents :slight_smile:)

import wx
import wx.stc

class Frame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        
        ed = wx.stc.StyledTextCtrl(self)
        ed.write("Hello, wxPython!")
        
        print(ed.CanUndo()) # -> True (and need-save)
        
        ed.SaveFile('temp.txt') # save and set the point
        ed.SetSavePoint()       # What is going on here?
        
        print(ed.CanUndo()) # -> True (but need-not-save)

if __name__ == "__main__":
    app = wx.App()
    frm = Frame(None)
    frm.Show()
    app.MainLoop()

The docstring for SetSavePoint() says “Remember the current position in the undo history as the position at
which the document was saved.”

I notice there are events wxEVT_STC_SAVEPOINTLEFT and wxEVT_STC_SAVEPOINTREACHED.

Would they get triggered when you use undo/redo and leave or reach the position in the undo history where SetSavePoint() was called?

To determine if a save is needed I just call IsModified().

1 Like

Hi Richard,

Thank you very much for your reply. I really appreciate the help.

I tested both events, and yes, it exactly worked as you said!

I will use IsModified (why didn’t I notice this word… :sweat_smile:) which is obviously better than CanUndo, and event hooks are more helpful for my future purpose.
Many thanks!