On 03/11/2015 03:32,
c.b...@posteo.jp wrote:
> I think about if there is a pattern or another intelligent solution for
> that problem.
>
> I load an existing and still persistent row/object from a database and
> display this data in a editable dialog-window to the user.
>
> When closing the window I want to know if the user modfied the data in
> that dialog. e.g. I should write that modifications back to the
> database instance and store it.
>
> I could simply check each attribut from the window with the database.
> Or I could add event-handlers to each component of the window that will
> set a isModified-flag or something like that. But this doesn't sounds
> intelligent to me.
>
> Maybe wxPhoenix offer a half-generalizing solution to implement
> something like that? Maybe register gui-components to a
> is-modified-messaging-system?
>
The obvious problem with an is modified flag set by an event handler is
when the operator changes a value and then, rather than pressing cancel
changes it back to the old value presses OK. Personally, I find that
having your dialogue take a record of the structure that you are
interested in as an initialiser to populate the fields and return the
field values in the same structure simplifies thins enormously.
You can then follow a pattern of:
(result, new_record) = prompt_user(old_record)
# Check if they pressed OK & made changes
if result == wx.OK and new_record != old_record:
If you would like to get really cleaver you create your dialogue with
field names, types & validators derived from your database field structures.
--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.