I have a wx.notebook used as a library database. The user can search for and display the details of a publication, and if necessary amend an entry.
Is there a quick way to know if the user has changed anything? I would like to catch any attempt to close the app if there is un-saved data.
Thanks.
Just set a flag on any change and clear it on a save.
···
On 22/11/2017 05:58, floatingshed@gmail.com wrote:
I have a wx.notebook used as a library database. The user can search for
and display the details of a publication, and if necessary amend an entry.
Is there a quick way to know if the user has changed anything? I would
like to catch any attempt to close the app if there is un-saved data.
Thanks.
--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
---
This email has been checked for viruses by AVG.
I don’t know how to do that, can you give me a bit more please?
···
On Wednesday, November 22, 2017 at 6:00:11 AM UTC, Gadget Steve wrote:
On 22/11/2017 05:58, floati...@gmail.com wrote:
I have a wx.notebook used as a library database. The user can search for
and display the details of a publication, and if necessary amend an entry.Is there a quick way to know if the user has changed anything? I would
like to catch any attempt to close the app if there is un-saved data.Thanks.
Just set a flag on any change and clear it on a save.
–
Steve (Gadget) BarnesAny opinions in this message are my personal opinions and do not reflect
those of my employer.
This email has been checked for viruses by AVG.
floatingshed@gmail.com wrote:
I don't know how to do that, can you give me a bit more please?
The main idea here is that you have a set of widgets; each one of those widgets fires an event when its content, position, value etc. changes. But the event type differs by widget. For instance you would bind a handler to wx.EVT_TEXT to catch changes to a wx.TextCtrl, wx.EVT_SLIDER to catch changes to the value of a wx.Slider, and the list goes on.
So, the basic idea is to find the events which correspond to the types of widgets you're using, and bind handlers to them which set a flag inside your application saying "hey, the user made a change". Call it unsavedChanges or something along those lines and make it a boolean. When they edit a value, set it to True. Catch the wx.EVT_CLOSE event so that when the user tries to exit, you can check the flag and alert them appropriately. Once they actually save the data, e.g. by pressing Ctrl+S or whatever mechanism you give them, set the flag back to False.
Regards,
James Scholes
https://twitter.com/JamesScholes
Thanks Steve, I have everything set up and working, handlers etc. I just wondered if there was a: “somebody clicked somewhere” catch-all rather than having to modify the code for every widget. Sometimes python and wxpython have nifty shortcuts that you don’t know about until you ask. Looks like this isn’t one of those occasions.
Thanks.
···
On Wednesday, November 22, 2017 at 5:58:40 AM UTC, floati...@gmail.com wrote:
I have a wx.notebook used as a library database. The user can search for and display the details of a publication, and if necessary amend an entry.
Is there a quick way to know if the user has changed anything? I would like to catch any attempt to close the app if there is un-saved data.
Thanks.
floatingshed@gmail.com wrote:
Thanks Steve, I have everything set up and working, handlers etc. I
just wondered if there was a: "somebody clicked somewhere" catch-all
rather than having to modify the code for every widget. Sometimes
python and wxpython have nifty shortcuts that you don't know about
until you ask. Looks like this isn't one of those occasions.
No, because really, you're the only person that knows which parts of
your state are important. There's no "general rule" that a dialog could
follow.
The process James described is extremely common. In many property
pages, for example, there will be a "Close" button that changes to
"Apply" if you touch any of the settings, to tell you that something
changed. It's done by handling events from each of the data-containing
controls individually.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
You must have some function that populates the data entry screen from your database data.
And a function that creates a new database record from the data on the screen.
Just save a copy of the database record that you populated the screen from.
When the user exits, create what would be the new database record, and compare it
to the old database record, to see if anything changed.
If your record is just a list, you can compare the lists directly, I believe.
If your record is a dict, you probably have to do field-by-field compares. Still not too tough.
The flag method Steve mentions is easy too:
Just set a flag on your data (sometimes known as the “dirty” flag).
When you load the data to the screen, have a line:
self.dirty = False
In every event that could modify, have a simple line like:
self.dirty = True
When you are ready to exit use:
if (self.dirty):
# update the data
Rufus
···
On Nov 22, 2017, at 7:20 AM, floatingshed@gmail.com wrote:
Thanks Steve, I have everything set up and working, handlers etc. I just wondered if there was a: “somebody clicked somewhere” catch-all rather than having to modify the code for every widget. Sometimes python and wxpython have nifty shortcuts that you don’t know about until you ask. Looks like this isn’t one of those occasions.
Thanks.On Wednesday, November 22, 2017 at 5:58:40 AM UTC, floati…@gmail.com wrote:
I have a wx.notebook used as a library database. The user can search for and display the details of a publication, and if necessary amend an entry.
Is there a quick way to know if the user has changed anything? I would like to catch any attempt to close the app if there is un-saved data.
Thanks.
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Got it, thanks guys. I was just being lazy!
···
On Wednesday, November 22, 2017 at 5:58:40 AM UTC, floati...@gmail.com wrote:
I have a wx.notebook used as a library database. The user can search for and display the details of a publication, and if necessary amend an entry.
Is there a quick way to know if the user has changed anything? I would like to catch any attempt to close the app if there is un-saved data.
Thanks.