1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="howto.css" type='text/css' />
<link rel="first" href="howto.html" title='Developing applications with Kiwi' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="undo.html" />
<link rel="prev" href="node23.html" />
<link rel="parent" href="node16.html" />
<link rel="next" href="undo.html" />
<meta name='aesop' content='information' />
<title>2.9.8 Multiple Proxies</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="2.9.7 Models"
href="node23.html"><img src='previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="2.9 Proxies and Models"
href="node16.html"><img src='up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="2.9.9 Other Proxy features"
href="undo.html"><img src='next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Developing applications with Kiwi</td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node23.html">2.9.7 Models</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="node16.html">2.9 Proxies and Models</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="undo.html">2.9.9 Other Proxy features</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H3><A NAME="SECTION000298000000000000000"></A>
<A NAME="multipleproxies"></A>
<BR>
2.9.8 Multiple Proxies
</H3>
<P>
One feature of the <tt class="class">Model</tt> class is that it allows multiple
proxies to be attached to the same model, performing automatic
notification to all of them. Internally, when a proxy attaches itself to
a model, it lets the model know what attributes it is interested in;
later, when that attribute changes, the model lets the proxy know. The
syntax for using multiple proxies is straightforward; simply create the
proxies and attach the same model to them. A small example
(<span class="file">NewsForm/newsform4.py</span>) follows:
<P>
This example shows some of the power of multiple proxies; as you edit
the title you can see the label update immediately. If you look at the
lines at the bottom, two proxies are attached to <code>item</code> - a
<tt class="class">NewsProxy</tt> instance, and a <tt class="class">NewsLabels</tt> instance, which has
labels that display the current contents of the model.
<P>
This feature can be used in many different ways, and if you create small
proxies (that represent a part of the model, instead of the whole model)
and embed them in other interfaces you can end up with very dynamic
representations of your data. However, it should be noted that there are
a few gotchas that you can run into when using multiple Proxies:
<P>
<UL>
<LI>Trying to edit the same value in two proxies. This is actually
possible, but it is a bad idea, both UI-wise and implementation-wise. If
you are using multiple proxies for a single model, have only one be
editable and the others read-only (displaying information using labels,
for instance). See in our example how the use of labels only in
<tt class="class">NewsLabels</tt> fits nicely into this rule.
<P>
</LI>
<LI>Attaching two proxies to the same model and forgetting about it.
This can be quite misleading and hard to debug if you have a large
application. If you have many proxies for the same class, and they are
instantiated and run simultaneously, it may be tricky to notice that the
model sends messages to update both when it changes. Thankfully, it is
not common to have two windows with the same data loaded in the
application. This is related to the "Undo" problem discussed further in
section <A href="undo.html#undo">2.9</A>.
</LI>
</UL>
<P>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="2.9.7 Models"
href="node23.html"><img src='previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="2.9 Proxies and Models"
href="node16.html"><img src='up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="2.9.9 Other Proxy features"
href="undo.html"><img src='next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Developing applications with Kiwi</td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
<td class='online-navigation'><img src='blank.png'
border='0' height='32' alt='' width='32' /></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node23.html">2.9.7 Models</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="node16.html">2.9 Proxies and Models</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="undo.html">2.9.9 Other Proxy features</A>
</div>
</div>
<hr />
<span class="release-info">Release 1.9.22, documentation updated on August, 2006.</span>
</DIV>
<!--End of Navigation Panel-->
</BODY>
</HTML>
|