sccs cscs wrote:
> Hello, Our team uses Visual Basic for Rhapsody Automation,
> but we now would like to use Python. But it seems to be IMPOSSIBLE.
> Indeed, it seems that there is no Polymorphism in Python so that when i get 
> back 
> a daughter instance Class, it does not not work, i continue to have the 
> corresponding Mother Class.
> Exemple:

Python does have polymorphism, but it's very different from how VB or
C++ thinks of polymorphism.  It's a purer form of polymorphism, in my
opinion.  More smalltalk-like.

Python instances are all first-class objects.  So Python implements a
protocol-based polymorphism.  In other words, rather than say I want an
object of type foo or a descendant class, we just say, we want an object
foo that implements a method bar.  It doesn't matter what class that
object  is, so long as it implements something we want.  In the long
run, this gives consistent behavior that's very flexible and extensible.

None of that solves your problem though.

For those of us not familiar with driving an application through COM,
can you explain how how the polymorphism worked in your VB code?
Perhaps there's a pythonic way of doing this.

>     
> Here is my code:
>     
>     The Application used is "Rhapsody"
>     
> import pythoncom       # Window word wrapper for Rhapsody
> import win32com.client # Window word wrapper for Rhapsody
> import sys
>    
>   class TestRhapsody(object):
>       def connectRhapsody(self):
>         print "connecting to Rhapsody.."
>         self.rhapsody = 
> win32com.client.gencache.EnsureDispatch("Rhapsody.Application")
>         self.project = self.rhapsody.activeProject()
>         if self.project == None :
>             raise Exception("Load a Rhapsody project!")
>         print "OK"
>       def listAllLanguageTypes(self):
>         theIRPModelElement = 
> self.project.findNestedElementRecursive("T_Boolean", "Type")
>           print theIRPModelElement.getFullPathName()
>         print theIRPModelElement.name
>           # HERE IS THE ERROR: The theIRPModelElement is a "IRPType" which is 
>         # a specialization of a IRPModelElement, but Python continue to see 
> it like an IRPModelElement
>         
>         print "Declaration : %s\n" % (theIRPModelElement.declaration) 
>   
> def test():
>     try:
>         thePatch = TestRhapsody()
>         thePatch.connectRhapsody()
>         thePatch.listAllLanguageTypes()
>       except Exception ,err:
>         print "ERROR ! \n %s"%( str (err))
>   if __name__ == '__main__':
>     test()
>    
>   I got the following  message:
>  '<win32com.gen_py.47DBF9D5-F318-11D2-B825-00104B3E6572x0x1x0.IRPModelElement 
> instance at 0x59532032>'
>  object has no attribute 'declaration'
>  
> Here is the Py32Com Wrapper extract:
>   class IRPModelElement(DispatchBaseClass):
>  """IRPModelElement Interface"""
>  CLSID = IID('{57DBF9EF-F318-11D2-B825-00104B3E6572}')
>  coclass_clsid = IID('{57DBF9F0-F318-11D2-B825-00104B3E6572}')
>   
> class IRPType(DispatchBaseClass):
>  """IRPType Interface"""
>  CLSID = IID('{EB754AE3-0D76-11D3-8E4D-0060080B70BC}')
>  coclass_clsid = IID('{EB754AE4-0D76-11D3-8E4D-0060080B70BC}')
>    # Result is of type IRPFlowchart
>  def addActivityDiagram(self):
>   """method addActivi
>                 
>                 
>     _prop_map_get_ = {
>            ...
>             "currentDirectory": (110, 2, (8, 0), (), "currentDirectory", 
> None),
>             "declaration": (803, 2, (8, 0), (), "declaration", None),
>         ...
>         
>         
> 
>        
> ---------------------------------
>  Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Python-win32 mailing list
> Python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32

_______________________________________________
Python-win32 mailing list
Python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to