After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 672324 - Support usage of freeze_notify in python "with" statement
Support usage of freeze_notify in python "with" statement
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-03-18 04:25 UTC by Simon Feltman
Modified: 2012-04-09 12:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Added context management to freeze_notify and handler_block (12.56 KB, patch)
2012-03-23 22:51 UTC, Simon Feltman
none Details | Review

Description Simon Feltman 2012-03-18 04:25:40 UTC
This will allow usage of the method along with the "with" statement. The returned context manager object would then call thaw_notify upon an exception or an exiting of the context. This technique keeps chunks of code that do heavy modification to objects in a frozen state clean and free of potential errors in regards to calling thaw.

with obj.freeze_notify():
    obj.props.width = 100
    obj.props.height = 100
    obj.props.opacity = 0.5

See: http://docs.python.org/reference/datamodel.html#context-managers
Comment 1 Simon Feltman 2012-03-23 22:51:47 UTC
Created attachment 210494 [details] [review]
Added context management to freeze_notify and handler_block

These methods now return a context manager object which implement
__enter__ and __exit__. Within the __exit__ method thaw_notify and
handler_unblock are called respectively. This allows statements like the
following:

with obj.freeze_notify():
    obj.props.width = 100
    obj.props.height = 100
    obj.props.opacity = 0.5

This does not affect standard usage of these methods. This could have been implemented in python in only a few lines of code, but cannot do to the lack of ability to override GObject methods in python, see:
https://bugzilla.gnome.org/show_bug.cgi?id=672727
Comment 2 Martin Pitt 2012-04-09 12:47:57 UTC
This looks like a fine, but nice detail indeed, and the patch looks good to me. Thank you!

Pushed with some whitespace/grammar fixes.