Back to index

salome-paravis  6.5.0
Public Member Functions | Public Attributes | Private Member Functions
paravisSM.Proxy Class Reference
Inheritance diagram for paravisSM.Proxy:
Inheritance graph
[legend]

List of all members.

Public Member Functions

def __init__
def __setattr__
def add_attribute
def __del__
def InitializeFromProxy
def Initialize
def __eq__
def __ne__
def __iter__
def SetPropertyWithName
def GetPropertyValue
def GetProperty
def ListProperties

Public Attributes

 Port
 Observed
 ObserverTag
 SMProxy

Private Member Functions

def __ConvertArgumentsAndCall
def __GetActiveCamera

Detailed Description

Proxy for a server side object. A proxy manages the lifetime of
one or more server manager objects. It also provides an interface
to set and get the properties of the server side objects. These
properties are presented as Python properties. For example,
you can set a property Foo using the following:
 proxy.Foo = (1,2)
or
 proxy.Foo.SetData((1,2))
or
 proxy.Foo[0:2] = (1,2)
For more information, see the documentation of the property which
you can obtain with
help(proxy.Foo).

This class also provides an iterator which can be used to iterate
over all properties.
eg:
  proxy = Proxy(proxy=smproxy)
  for property in proxy:
      print property

For advanced users:
This is a python class that wraps a vtkSMProxy.. Makes it easier to
set/get properties.
Instead of:
 proxy.GetProperty("Foo").SetElement(0, 1)
 proxy.GetProperty("Foo").SetElement(0, 2)
you can do:
 proxy.Foo = (1,2)
or
 proxy.Foo.SetData((1,2))
or
 proxy.Foo[0:2] = (1,2)
Instead of:
  proxy.GetProperty("Foo").GetElement(0)
you can do:
  proxy.Foo.GetData()[0]
or
  proxy.Foo[0]
For proxy properties, you can use append:
 proxy.GetProperty("Bar").AddProxy(foo)
you can do:
 proxy.Bar.append(foo)
Properties support most of the list API. See VectorProperty and
ProxyProperty documentation for details.

Please note that some of the methods accessible through the Proxy
class are not listed by help() because the Proxy objects forward
unresolved attributes to the underlying object. To get the full list,
see also dir(proxy.SMProxy). See also the doxygen based documentation
of the vtkSMProxy C++ class.

Definition at line 101 of file paravisSM.py.


Constructor & Destructor Documentation

def paravisSM.Proxy.__init__ (   self,
  args 
)
Default constructor. It can be used to initialize properties
by passing keyword arguments where the key is the name of the
property. In addition registrationGroup and registrationName (optional)
can be specified (as keyword arguments) to automatically register
the proxy with the proxy manager. 

Definition at line 155 of file paravisSM.py.

00155 
00156     def __init__(self, **args):
00157         """ Default constructor. It can be used to initialize properties
00158         by passing keyword arguments where the key is the name of the
00159         property. In addition registrationGroup and registrationName (optional)
00160         can be specified (as keyword arguments) to automatically register
00161         the proxy with the proxy manager. """
00162         self.add_attribute('Observed', None)
00163         self.add_attribute('ObserverTag', -1)
00164         self.add_attribute('_Proxy__Properties', {})
00165         self.add_attribute('_Proxy__LastAttrName', None)
00166         self.add_attribute('SMProxy', None)
00167         self.add_attribute('Port', 0)
00168 
00169         if 'port' in args:
00170             self.Port = args['port']
00171             del args['port']
00172 
00173         update = True
00174         if 'no_update' in args:
00175             if args['no_update']:
00176                 update = False
00177             del args['no_update']
00178 
00179         if 'proxy' in args:
00180             self.InitializeFromProxy(args['proxy'])
00181             del args['proxy']
00182         else:
00183             self.Initialize(None, update)
00184         if 'registrationGroup' in args:
00185             registrationGroup = args['registrationGroup']
00186             del args['registrationGroup']
00187             registrationName = self.SMProxy.GetGlobalIDAsString()
00188             if 'registrationName' in args:
00189                 registrationName = args['registrationName']
00190                 del args['registrationName']
00191             pxm = ProxyManager()
00192             pxm.RegisterProxy(registrationGroup, registrationName, self.SMProxy)
00193         if update:
00194             self.UpdateVTKObjects()
00195         for key in args.keys():
00196             setattr(self, key, args[key])
00197         # Visit all properties so that they are created
00198         for prop in self:
00199             pass

Here is the call graph for this function:

def paravisSM.Proxy.__del__ (   self)
Destructor. Cleans up all observers as well as remove
the proxy from the _pyproxies dictionary

Definition at line 217 of file paravisSM.py.

00217 
00218     def __del__(self):
00219         """Destructor. Cleans up all observers as well as remove
00220         the proxy from the _pyproxies dictionary"""
00221         # Make sure that we remove observers we added
00222         if self.Observed:
00223             observed = self.Observed
00224             tag = self.ObserverTag
00225             self.Observed = None
00226             self.ObserverTag = -1
00227             observed.RemoveObserver(tag)
00228         if self.SMProxy and (self.SMProxy, self.Port) in _pyproxies:
00229             del _pyproxies[(self.SMProxy, self.Port)]


Member Function Documentation

def paravisSM.Proxy.__ConvertArgumentsAndCall (   self,
  args 
) [private]
Internal function.
Used to call a function on SMProxy. Converts input and
output values as appropriate.

Definition at line 322 of file paravisSM.py.

00322 
00323     def __ConvertArgumentsAndCall(self, *args):
00324         """ Internal function.
00325         Used to call a function on SMProxy. Converts input and
00326         output values as appropriate.
00327         """
00328         newArgs = []
00329         for arg in args:
00330             if issubclass(type(arg), Proxy) or isinstance(arg, Proxy):
00331                 newArgs.append(arg.SMProxy)
00332             else:
00333                 newArgs.append(arg)
00334         func = getattr(self.SMProxy, self.__LastAttrName)
00335         retVal = func(*newArgs)
00336         if type(retVal) is type(self.SMProxy) and retVal.IsA("vtkSMProxy"):
00337             return _getPyProxy(retVal)
00338         elif type(retVal) is type(self.SMProxy) and retVal.IsA("vtkSMProperty"):
00339             return _wrap_property(self, retVal)
00340         else:
00341             return retVal

Here is the call graph for this function:

def paravisSM.Proxy.__eq__ (   self,
  other 
)

Definition at line 243 of file paravisSM.py.

00243 
00244     def __eq__(self, other):
00245         "Returns true if the underlying SMProxies are the same."
00246         if isinstance(other, Proxy):
00247             try:
00248                 if self.Port != other.Port:
00249                     return False
00250             except:
00251                 pass
00252             ## VSV using IsSame instead ==
00253             return self.SMProxy.IsSame(other.SMProxy)
00254         return self.SMProxy.IsSame(other)

Here is the caller graph for this function:

def paravisSM.Proxy.__GetActiveCamera (   self) [private]
This method handles GetActiveCamera specially. It adds
an observer to the camera such that everytime it is modified
the render view updated

Definition at line 342 of file paravisSM.py.

00342 
00343     def __GetActiveCamera(self):
00344         """ This method handles GetActiveCamera specially. It adds
00345         an observer to the camera such that everytime it is modified
00346         the render view updated"""
00347         import weakref
00348         c = self.SMProxy.GetActiveCamera()
        # VSV: Observers are not supported
def paravisSM.Proxy.__iter__ (   self)

Definition at line 259 of file paravisSM.py.

00259 
00260     def __iter__(self):
00261         "Creates an iterator for the properties."
00262         return PropertyIterator(self)

Here is the caller graph for this function:

def paravisSM.Proxy.__ne__ (   self,
  other 
)

Definition at line 255 of file paravisSM.py.

00255 
00256     def __ne__(self, other):
00257         "Returns false if the underlying SMProxies are the same."
00258         return not self.__eq__(other)

Here is the call graph for this function:

def paravisSM.Proxy.__setattr__ (   self,
  name,
  value 
)

Definition at line 200 of file paravisSM.py.

00200 
00201     def __setattr__(self, name, value):
00202         try:
00203             setter = getattr(self.__class__, name)
00204             setter = setter.__set__
00205         except AttributeError:
00206             if not hasattr(self, name):
00207                 raise AttributeError("Attribute %s does not exist. " % name +
00208                   " This class does not allow addition of new attributes to avoid " +
00209                   "mistakes due to typos. Use add_attribute() if you really want " +
00210                   "to add this attribute.")
00211             self.__dict__[name] = value
00212         else:
00213             setter(self, value)

def paravisSM.Proxy.add_attribute (   self,
  name,
  value 
)

Definition at line 214 of file paravisSM.py.

00214 
00215     def add_attribute(self, name, value):
00216         self.__dict__[name] = value

Here is the caller graph for this function:

def paravisSM.Proxy.GetProperty (   self,
  name 
)
Given a property name, returns the property object.

Definition at line 292 of file paravisSM.py.

00292 
00293     def GetProperty(self, name):
00294         """Given a property name, returns the property object."""
00295         if name in self.__Properties and self.__Properties[name]():
00296             return self.__Properties[name]()
00297         smproperty = self.SMProxy.GetProperty(name)
00298         # Maybe they are looking by the label. Try to match that.
00299         if not smproperty:
00300             iter = PropertyIterator(self)
00301             for prop in iter:
00302                 if name == _make_name_valid(iter.PropertyLabel):
00303                     smproperty = prop.SMProperty
00304                     break
00305         if smproperty:
00306             property = _wrap_property(self, smproperty)
00307             if property is not None:
00308                 import weakref
00309                 self.__Properties[name] = weakref.ref(property)
00310             return property
00311         return None

Here is the call graph for this function:

Here is the caller graph for this function:

def paravisSM.Proxy.GetPropertyValue (   self,
  name 
)
Returns a scalar for properties with 1 elements, the property
itself for vectors.

Definition at line 270 of file paravisSM.py.

00270 
00271     def GetPropertyValue(self, name):
00272         """Returns a scalar for properties with 1 elements, the property
00273         itself for vectors."""
00274         p = self.GetProperty(name)
00275         if isinstance(p, VectorProperty):
00276             if p.GetNumberOfElements() == 1 and not p.GetRepeatable():
00277                 if p.SMProperty.IsA("vtkSMStringVectorProperty") or not p.GetArgumentIsArray():
00278                     return p[0]
00279         elif isinstance(p, InputProperty):
00280             if not p.GetMultipleInput():
00281                 if len(p) > 0:
00282                     return p[0]
00283                 else:
00284                     return None
00285         elif isinstance(p, ProxyProperty):
00286             if not p.GetRepeatable():
00287                 if len(p) > 0:
00288                     return p[0]
00289                 else:
00290                     return None
00291         return p

Here is the call graph for this function:

Definition at line 239 of file paravisSM.py.

00239 
00240     def Initialize(self):
00241         "Overridden by the subclass created automatically"
00242         pass

def paravisSM.Proxy.InitializeFromProxy (   self,
  aProxy,
  update = True 
)
Constructor. Assigns proxy to self.SMProxy, updates the server
object as well as register the proxy in _pyproxies dictionary.

Definition at line 230 of file paravisSM.py.

00230 
00231     def InitializeFromProxy(self, aProxy, update=True):
00232         """Constructor. Assigns proxy to self.SMProxy, updates the server
00233         object as well as register the proxy in _pyproxies dictionary."""
00234         import weakref
00235         self.SMProxy = aProxy
00236         if update:
00237             self.SMProxy.UpdateVTKObjects()
00238         _pyproxies[(self.SMProxy, self.Port)] = weakref.ref(self)

Returns a list of all property names on this proxy.

Definition at line 312 of file paravisSM.py.

00312 
00313     def ListProperties(self):
00314         """Returns a list of all property names on this proxy."""
00315         property_list = []
00316         iter = self.__iter__()
00317         for property in iter:
00318             name = _make_name_valid(iter.PropertyLabel)
00319             if name:
00320                 property_list.append(name)
00321         return property_list

Here is the call graph for this function:

def paravisSM.Proxy.SetPropertyWithName (   self,
  pname,
  arg 
)
Generic method for setting the value of a property.

Definition at line 263 of file paravisSM.py.

00263 
00264     def SetPropertyWithName(self, pname, arg):
00265         """Generic method for setting the value of a property."""
00266         prop = self.GetProperty(pname)
00267         if prop is None:
00268             raise RuntimeError, "Property %s does not exist. Please check the property name for typos." % pname
00269         prop.SetData(arg)

Here is the call graph for this function:


Member Data Documentation

Definition at line 224 of file paravisSM.py.

Definition at line 225 of file paravisSM.py.

Definition at line 169 of file paravisSM.py.

Definition at line 234 of file paravisSM.py.


The documentation for this class was generated from the following file: