Re: abstract layer question

"Joseph A. Knapka" <[email protected]>
Newsgroups gmane.comp.python.anygui.devel
Message-ID <[email protected]>
Robin Becker wrote:
> 
> In article <[email protected]>, Magnus Lie Hetland
> <[email protected]> writes
> .......
> >> How should I achieve the same kind of thing in 0.2.
> >
> >This sort of thing is still handled by the Attrib class (which has
> >been rewritten quite a bit). If there is a setter method available (as
> >defined by anygui.Utils.getSetter) then that will be called instead of
> >the generic set(). set() is basically a rawSet() (which updates
> >self.state) followed by a push() (which pushes thing through to the
> >wrapper).
> >
> >So... To make a long story short, what you have to do is simply:
> >
> >  def setRange(self, range):
> >      assert range[0]<range[1], "reversed or zero range"
> >      self.set(range=range)
> >
> .....
> thanks, I assumed we needed a setRange, but was a bit confused as to
> where it went. Presumably in this scheme I need a setRange on the
> wrapper class as well to allow it to know that range has changed.

Exactly. And you may or may not want to implement
getRange() on the wrapper, depending on whether the
range can be modified by the user via the native
widget without the proxy's knowledge - if so, you
need wrapper.getRange().

The Attrib class normally just maps proxy.attr access
to proxy.state['attr'] access. However, iff a
wrapper.set<Name>() is defined, it will be called
with the value in the proxy's state dictionary
whenever the attrib "name" is set; and iff there is a
wrapper.get<Name>(), it will be called and its
return value used to update the proxy.state dict
whenever the attrib "name" is read. Note that
if you define setName(name) on a wrapper, the
method name and the argname *must match* -
setName(some_other_argname) will not work
(you'll get "unexpected keyword argument"
errors).

(There's magic in Attrib for defining get<Name>()
and set<Name>() on *proxies* as well; if you do
that those methods will be used exclusively - the
whole normal proxy.state/push/pull machinery will
*not* be invoked. The only place this is being
used at the moment is Frame.setLayout(); maybe
it's otherwise useless, in which case it probably
ought to be removed.)

Cheers,

-- Joe
  "I'd rather chew my leg off than maintain Java code, which
   sucks, 'cause I have a lot of Java code to maintain and
   the leg surgery is starting to get expensive." - Me


-------------------------------------------------------
This sf.net email is sponsored by: OSDN - Tired of that same old
cell phone?  Get a new here for FREE!
https://www.inphonic.com/r.asp?r=sourceforge1&refcode1=vs3390
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.