Detecting changes

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Detecting changes

floatingshed
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Detecting changes

GadgetSteve


On 22/11/2017 05:58, [hidden email] 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) 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.
http://www.avg.com

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Detecting changes

floatingshed
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, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="or1c_LgEBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">floati...@... 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) 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.
<a href="http://www.avg.com" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.avg.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPVsPPPUdri1u74y4soGOX1W5g_g&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.avg.com\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHPVsPPPUdri1u74y4soGOX1W5g_g&#39;;return true;">http://www.avg.com

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Detecting changes

James Scholes
[hidden email] 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

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Detecting changes

floatingshed
In reply to this post by floatingshed
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, [hidden email] 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Detecting changes

Tim Roberts
[hidden email] 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, [hidden email]
Providenza & Boekelheide, Inc.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Detecting changes

Rufus V. Smith
In reply to this post by floatingshed
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, [hidden email] 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Detecting changes

floatingshed
In reply to this post by floatingshed
Got it, thanks guys. I was just being lazy!


On Wednesday, November 22, 2017 at 5:58:40 AM UTC, [hidden email] 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.