[POS-commit] Kiwi/Kiwi Proxies.py,1.66,1.67
kiko at async.com.br
kiko at async.com.br
Thu May 22 19:13:05 BRST 2003
Update of /cvs/Kiwi/Kiwi
In directory anthem:/tmp/cvs-serv14248/Kiwi
Modified Files:
Proxies.py
Log Message:
Implement a change requested by Bruno Trevisan in bug 656: allow a null
model to be passed into Proxy. We just postpone attaching signals to
widgets and do it when new_model() is called. This is specially useful
for forms which need to use a selector to identify which object should
be displayed.
Added a test for the new functionality and updated docs on an old test
that has a bad name.
Index: Proxies.py
===================================================================
RCS file: /cvs/Kiwi/Kiwi/Proxies.py,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- Proxies.py 21 May 2003 05:53:45 -0000 1.66
+++ Proxies.py 22 May 2003 22:13:03 -0000 1.67
@@ -94,11 +94,16 @@
defined in your View or glade file.
"""
- def __init__(self, model):
+ def __init__(self, model=None):
"""The VirtualProxy constructor should be called *before*
FrameWork.BaseController.__init__ or bad things happen. Keep this in
mind.
- - model: the model instance to be attached to the proxy.
+ - model: the model instance to be attached to the proxy.
+
+ If None, the interface will be displayed as-is and no changes to
+ it will be caught. *Danger*: any data entered in the widgets
+ will be used as a *default* for the next model, so be sure to make
+ the parts that contain the widgets read-only and/or insensitive.
"""
# Maps attribute name to widgetproxy
self._attr_map = {}
@@ -112,8 +117,12 @@
if sep:
self.set_decimal_separator(sep)
- self._setup_state(model)
- self._setup_widgets()
+ self._setup_state()
+ # If not None, setup signals
+ if model is not None:
+ self._setup_widgets()
+
+ self.model = model
def notify(self, name, value=ValueUnset):
"""
@@ -187,17 +196,27 @@
interface to change model without the need to destroy and recreate the
UI (which would cause flashing, at least)"""
if model is None:
- raise TypeError, "model must not an instance"
+ raise TypeError, "model passed to new_model must not be None"
+
# unregister previous proxy
- if hasattr(self.model, "unregister_proxy"):
+ if self.model and hasattr(self.model, "unregister_proxy"):
self.model.unregister_proxy(self)
+
# the following clear isn't strictly necessary, but it currently
# works around a bug with reused ids in the attribute cache and
# also makes a lot of sense for most applications (you don't
# want a huge eternal cache)
clear_attr_cache()
- self._setup_state(model)
+ # If we were initialized with a None model, we need to setup the
+ # widgets.
+ if not self.model:
+ self._setup_state()
+ self._setup_widgets()
+ else:
+ self._setup_state()
+
+ self.model = model
# During the initialization, the OptionMenu needs to preserve
# the original model value, which is why we use this ha^Wlock.
self._avoid_clobber = TRUE
@@ -373,9 +392,7 @@
self._attrs = attrs
return widgets
- def _setup_state(self, model):
- self.model = model
-
+ def _setup_state(self):
# see _parse_widgets
self._attrs = getattr(self, "_attrs", [])
@@ -518,7 +535,7 @@
View or Delegate by using attach_slave. See documentation for
VirtualProxy for Proxy-related issues.
"""
- def __init__(self, model, toplevel=None, widgets=[]):
+ def __init__(self, model=None, toplevel=None, widgets=[]):
"""
Creates a new SlaveProxy. Parameters:
- model: the model instance to be attached to the proxy.
@@ -537,7 +554,8 @@
toplevel widgets, and it is to be embedded in a View or Delegate by
using attach_slave. See documentation for VirtualProxy for Proxy-related
issues."""
- def __init__(self, model, gladefile=None, container_name=None, widgets=[]):
+ def __init__(self, model=None, gladefile=None, container_name=None,
+ widgets=[]):
"""
Creates new GladeSlaveProxy:
- model: the model instance to be attached to the proxy.
@@ -556,7 +574,8 @@
"""The Proxy class defines a proxy that has its interface built
programatically, using PyGTK calls. See documentation for VirtualProxy.
"""
- def __init__(self, model, toplevel=None, delete_handler=None, widgets=[]):
+ def __init__(self, model=None, toplevel=None, delete_handler=None,
+ widgets=[]):
"""
Creates a new Proxy. Parameters:
@@ -573,7 +592,7 @@
"""GladeProxy is a proxy that uses a glade file as its interface
definition. See documentation for VirtualProxy.
"""
- def __init__(self, model, gladefile=None, toplevel_name=None,
+ def __init__(self, model=None, gladefile=None, toplevel_name=None,
delete_handler=None, widgets=[]):
"""
Creates a new GladeProxy. Parameters:
More information about the POS-commit
mailing list