[pygobject] Gtk: add an override for Gtk.main_quit
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Gtk: add an override for Gtk.main_quit
- Date: Sat, 4 Dec 2010 00:55:51 +0000 (UTC)
commit cda317195566711d66190145b545e26ed7226172
Author: Johan Dahlin <johan gnome org>
Date: Thu Dec 2 23:47:40 2010 -0200
Gtk: add an override for Gtk.main_quit
Override gtk.main_quit so that it can be used as a callback
to signals, most importantly to the destroy signal of a widget:
widget.connect('destroy', gtk.main_quit)
This is compatible with what PyGTK does.
https://bugzilla.gnome.org/show_bug.cgi?id=636336
gi/overrides/Gtk.py | 5 ++++-
gi/overrides/__init__.py | 27 +++++++++++++++++++++++++--
2 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/gi/overrides/Gtk.py b/gi/overrides/Gtk.py
index ca39682..6e8e566 100644
--- a/gi/overrides/Gtk.py
+++ b/gi/overrides/Gtk.py
@@ -1044,7 +1044,10 @@ class Button(Gtk.Button, Container):
Button = override(Button)
__all__.append('Button')
-import sys
+_Gtk_main_quit = Gtk.main_quit
+ override(Gtk.main_quit)
+def main_quit(*args):
+ _Gtk_main_quit()
initialized, argv = Gtk.init_check(sys.argv)
sys.argv = list(argv)
diff --git a/gi/overrides/__init__.py b/gi/overrides/__init__.py
index d4cd80b..c634a2f 100644
--- a/gi/overrides/__init__.py
+++ b/gi/overrides/__init__.py
@@ -1,3 +1,6 @@
+import sys
+import types
+
import gobject
registry = None
@@ -34,10 +37,30 @@ class _Registry(dict):
def register(self, override_class):
self[override_class] = override_class
+
+class overridefunc(object):
+ '''decorator for overriding a function'''
+ def __init__(self, func):
+ if not hasattr(func, '__info__'):
+ raise TypeError("func must be an gi function")
+ from ..importer import modules
+ self.module = modules[func.__module__].introspection_module
+
+ def __call__(self, func):
+ def wrapper(*args, **kwargs):
+ return func(*args, **kwargs)
+ wrapper.__name__ = func.__name__
+ setattr(self.module, func.__name__, wrapper)
+ return wrapper
+
registry = _Registry()
def override(type_):
'''Decorator for registering an override'''
- registry.register(type_)
- return type_
+ if type(type_) == types.FunctionType:
+ return overridefunc(type_)
+ else:
+ registry.register(type_)
+ return type_
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]