How do I get type methods?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • yavannadil@yahoo.com

    How do I get type methods?

    Hello!

    If I do

    import uno
    localContext=un o.getComponentC ontext()

    then localContext is of type <type 'pyuno'>
    I guess it's a new type provided by PyUNO extension.
    localContext.__ class__ is None
    Is there any way to list all methods of that new type, via Python C
    API or through interpreter (other then dir(localContex t) )?
    What I want is to call localContext's methods like in the tutorial
    example:

    x=MyClass()
    MyClass.f(x)

    Thank you,
    Dmitri

  • Stargaming

    #2
    Re: How do I get type methods?

    yavannadil@yaho o.com schrieb:
    Hello!
    >
    If I do
    >
    import uno
    localContext=un o.getComponentC ontext()
    >
    then localContext is of type <type 'pyuno'>
    I guess it's a new type provided by PyUNO extension.
    localContext.__ class__ is None
    Is there any way to list all methods of that new type, via Python C
    API or through interpreter (other then dir(localContex t) )?
    What's wrong about `dir()`?
    What I want is to call localContext's methods like in the tutorial
    example:
    >
    x=MyClass()
    MyClass.f(x)
    I'd prefer::

    x = MyClass()
    x.f()
    >
    Thank you,
    Dmitri
    >

    Comment

    • yavannadil@yahoo.com

      #3
      Re: How do I get type methods?

      On May 4, 3:21 am, Stargaming <stargam...@gma il.comwrote:
      What's wrong about `dir()`?
      x = MyClass()
      x.f()
      I want to cashe pointers to Python functions in a non-Python app.
      'dir()' requires an argument, and I want to get function pointers
      before I have any variable of given type or class.
      That's why 'MyClass.f(x)'
      I'm not against 'dir(MyClass)'; the question is, what should I 'dir()'
      to get methods of 'pyuno' type instance?

      Sincerely yours,
      Dmitri

      Comment

      • Gabriel Genellina

        #4
        Re: How do I get type methods?

        En Fri, 04 May 2007 01:34:20 -0300, <yavannadil@yah oo.comescribió:
        I'm not against 'dir(MyClass)'; the question is, what should I 'dir()'
        to get methods of 'pyuno' type instance?
        Usually instances don't have its own methods, they get them from the
        class. So you actually need dir(MyClass).
        Note that dir() might not show all available methods.

        --
        Gabriel Genellina

        Comment

        • yavannadil@yahoo.com

          #5
          Re: How do I get type methods?

          On 4 ÍÁÊ, 09:08, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
          En Fri, 04 May 2007 01:34:20 -0300, <yavanna...@yah oo.comescribio:
          I'm not against 'dir(MyClass)'; the question is, what should I 'dir()'
          to get methods of 'pyuno' type instance?
          Usually instances don't have its own methods, they get them from the
          class. So you actually need dir(MyClass).
          Note that dir() might not show all available methods.
          Let me retype my question: what I 'dir()' in case of 'pyuno' type
          instance?
          Or in case of 'dict' type instance? Or in case of any other new python
          type?

          Comment

          • Thomas Nelson

            #6
            Re: How do I get type methods?

            On May 4, 7:59 am, yavanna...@yaho o.com wrote:
            On 4 ÍÁÊ, 09:08, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
            >
            En Fri, 04 May 2007 01:34:20 -0300, <yavanna...@yah oo.comescribio:
            I'm not against 'dir(MyClass)'; the question is, what should I 'dir()'
            to get methods of 'pyuno' type instance?
            Usually instances don't have its own methods, they get them from the
            class. So you actually need dir(MyClass).
            Note that dir() might not show all available methods.
            >
            Let me retype my question: what I 'dir()' in case of 'pyuno' type
            instance?
            Or in case of 'dict' type instance? Or in case of any other new python
            type?
            >>class Foo:
            .... def f(self,x):
            .... print x+1
            .... def g(self,x):
            .... print x-1
            ....
            >>dir(Foo)
            ['__doc__', '__module__', 'f', 'g']

            Is this not what you want? These are the only methods in the Foo
            class.

            Tom

            Comment

            • Marc 'BlackJack' Rintsch

              #7
              Re: How do I get type methods?

              In <1178289484.265 718.198060@c35g 2000hsg.googleg roups.com>, Thomas Nelson
              wrote:
              On May 4, 7:59 am, yavanna...@yaho o.com wrote:
              >Let me retype my question: what I 'dir()' in case of 'pyuno' type
              >instance?
              >Or in case of 'dict' type instance? Or in case of any other new python
              >type?
              >
              >>>class Foo:
              ... def f(self,x):
              ... print x+1
              ... def g(self,x):
              ... print x-1
              ...
              >>>dir(Foo)
              ['__doc__', '__module__', 'f', 'g']
              >
              Is this not what you want? These are the only methods in the Foo
              class.
              The OPs problem is, there is no access to the class or type because
              there is no name. You can get just instances from a factory function.

              Ciao,
              Marc 'BlackJack' Rintsch

              Comment

              • Fuzzyman

                #8
                Re: How do I get type methods?

                On May 3, 8:33 pm, yavanna...@yaho o.com wrote:
                Hello!
                >
                If I do
                >
                import uno
                localContext=un o.getComponentC ontext()
                >
                dir(type(localC ontext))

                Perhaps ?

                Fuzzyman


                then localContext is of type <type 'pyuno'>
                I guess it's a new type provided by PyUNO extension.
                localContext.__ class__ is None
                Is there any way to list all methods of that new type, via Python C
                API or through interpreter (other then dir(localContex t) )?
                What I want is to call localContext's methods like in the tutorial
                example:
                >
                x=MyClass()
                MyClass.f(x)
                >
                Thank you,
                Dmitri

                Comment

                • yavannadil@yahoo.com

                  #9
                  Re: How do I get type methods?

                  On May 5, 1:17 am, Fuzzyman <fuzzy...@gmail .comwrote:
                  dir(type(localC ontext))
                  Perhaps ?
                  It gives
                  ['__class__', '__cmp__', '__delattr__', '__doc__', '__getattribute __',
                  '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__' ,
                  '__repr__', '__setattr__', '__str__']

                  while

                  import sys
                  dir(type(sys.mo dules))

                  gives
                  ['__class__', '__cmp__', '__contains__', '__delattr__', '__delitem__',
                  '__doc__', '__eq__', '__ge__', '__getattribute __', '__getitem__',
                  '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__',
                  '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__' ,
                  '__repr__', '__setattr__', '__setitem__', '__str__', 'clear', 'copy',
                  'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys',
                  'itervalues', 'keys', 'pop', 'popitem', 'setdefault', 'update',
                  'values']

                  so I guess PyUNO extension doesn't provide proper introspection :-(

                  Comment

                  • yavannadil@yahoo.com

                    #10
                    Re: How do I get type methods?

                    On May 4, 7:13 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
                    The OPs problem is, there is no access to the class or type because
                    there is no name.
                    Exactly :-(
                    You can get just instances from a factory function.
                    Worse, if I call

                    localContext.Se rviceManage

                    I'll get something with different set of methods, but of the same type
                    - 'pyuno' :-(

                    Comment

                    • Carsten Haese

                      #11
                      Re: How do I get type methods?

                      On Sat, 2007-05-05 at 01:19 -0700, yavannadil@yaho o.com wrote:
                      On May 4, 7:13 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
                      The OPs problem is, there is no access to the class or type because
                      there is no name.
                      >
                      Exactly :-(
                      >
                      You can get just instances from a factory function.
                      >
                      Worse, if I call
                      >
                      localContext.Se rviceManage
                      >
                      I'll get something with different set of methods, but of the same type
                      - 'pyuno' :-(
                      'pyuno' objects are proxy objects that represent UNO objects, services,
                      and interfaces. Since all attribute lookups are handled by the UNO
                      bridge, the proxy object doesn't actually know what attributes it has,
                      which is why it won't respond anything useful to the usual dir()
                      inspection.

                      To list the methods and properties that the UNO object behind a pyuno
                      proxy object has, you need to use UNO inspection capabilities. Something
                      like the following seems to work:

                      # unodir.py
                      def unodir(unoobj):
                      import uno
                      from com.sun.star.be ans.MethodConce pt import ALL as ALLMETHS
                      from com.sun.star.be ans.PropertyCon cept import ALL as ALLPROPS
                      ctx = uno.getComponen tContext()
                      introspection = ctx.ServiceMana ger.createInsta nceWithContext(
                      "com.sun.star.b eans.Introspect ion", ctx)
                      access = introspection.i nspect(unoobj)
                      meths = access.getMetho ds(ALLMETHS)
                      props = access.getPrope rties(ALLPROPS)
                      return [ x.getName() for x in meths ] + [ x.Name for x in props ]
                      >>import uno
                      >>from unodir import unodir
                      >>localContex t = uno.getComponen tContext()
                      >>unodir(localC ontext)
                      [u'queryInterfac e', u'acquire', u'release', u'getValueByNam e',
                      u'getServiceMan ager', u'getElementTyp e', u'hasElements', u'getByName',
                      u'getElementNam es', u'hasByName', u'replaceByName ', u'insertByName' ,
                      u'removeByName' , u'getTypes', u'getImplementa tionId', u'queryAdapter' ,
                      u'dispose', u'addEventListe ner', u'removeEventLi stener',
                      u'ServiceManage r', u'ElementType', u'ElementNames' , u'Types',
                      u'Implementatio nId']

                      Hope this helps,

                      Carsten


                      Comment

                      • yavannadil@yahoo.com

                        #12
                        Re: How do I get type methods?

                        On May 5, 5:21 pm, Carsten Haese <cars...@uniqsy s.comwrote:
                        'pyuno' objects are proxy objects that represent UNO objects, services,
                        and interfaces. Since all attribute lookups are handled by the UNO
                        bridge, the proxy object doesn't actually know what attributes it has,
                        which is why it won't respond anything useful to the usual dir()
                        inspection.
                        I suspected something like that, but couldn't quite believe as CORBA
                        proxies generated by C++/C/Java/Lisp/Python IDL compiler are normal
                        classes which know what methods they have...
                        To list the methods and properties that the UNO object behind a pyuno
                        proxy object has, you need to use UNO inspection capabilities. Something
                        like the following seems to work:
                        Thanks a lot! After reading your example I googled and found
                        unohelper.inspe ct, which provides all information. But I still need
                        instances, as 'dir(XSingleCom ponentFactory)' gives just ['__doc__',
                        '__module__', '__pyunointerfa ce__'], and
                        'unohelper.insp ect(XSingleComp onentFactory, sys.stdout)' gives
                        segmentation fault.

                        Sincerely yours,
                        Dmitri

                        Comment

                        Working...