python and COM

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian Blais

    #1

    python and COM

    Hello,

    I am trying to communicate to a Reuters feed using Python, using a particular set of
    libraries called the Adfin Real Time library. I have VB code, and am trying to port
    it to python, and admit I really do not understand COM objects and being a Linux guy
    mainly, I don't use VB at all. I've had some marginal success, but am coming up
    empty when it comes to setting up callbacks.

    For example, this works:

    import win32com.client
    import time

    symb='GOOG.O'

    mylist=win32com .client.Dispatc h('AdfinXRTLib. AdxRtList')

    mylist.Source=" IDN_RDF"
    mylist.Register Items(symb,"ASK ")
    mylist.StartUpd ates(4) # Mode Image

    while mylist.ItemStat us(symb):
    pass

    for i in range(100):
    m=mylist.Value( symb,"ASK")
    print m
    time.sleep(2)


    but to get it to automatically updated quotes, in VB they do something like

    #============== ==
    Public Class Form1
    # Dimension a Public Real Time list object that is capable of handling events
    # note from me: not sure what this line does really
    Dim WithEvents AdxList As New AdfinXRTLib.Adx RTList

    Public Sub AdxList_OnUpdat e( <some args deleted>) Handles AdxList.OnUpdat e

    do stuff with the updated data

    End Sub

    Private Sub Button1_Click(< some args deleted>)

    do stuff with button click
    End Sub
    End Class
    #============== ==

    It seems as if the important part is the "Handles AdxList.OnUpdat e", which I assume
    is basically saying "call me when AdxList.OnUpdat e is called". I have no idea how to
    get this to point to a python function, so I can make the AdxList.OnUpdat e call
    python code.

    Is there a tutorial somewhere about this stuff, or is there a proper place to ask
    such questions?


    thanks,


    Brian Blais

    --
    -----------------

    bblais@bryant.e du

  • kyosohma@gmail.com

    #2
    Re: python and COM

    On Apr 27, 2:50 pm, Brian Blais <bbl...@bryant. eduwrote:
    Hello,
    >
    I am trying to communicate to a Reuters feed using Python, using a particular set of
    libraries called the Adfin Real Time library. I have VB code, and am trying to port
    it to python, and admit I really do not understand COM objects and being a Linux guy
    mainly, I don't use VB at all. I've had some marginal success, but am coming up
    empty when it comes to setting up callbacks.
    >
    For example, this works:
    >
    import win32com.client
    import time
    >
    symb='GOOG.O'
    >
    mylist=win32com .client.Dispatc h('AdfinXRTLib. AdxRtList')
    >
    mylist.Source=" IDN_RDF"
    mylist.Register Items(symb,"ASK ")
    mylist.StartUpd ates(4) # Mode Image
    >
    while mylist.ItemStat us(symb):
    pass
    >
    for i in range(100):
    m=mylist.Value( symb,"ASK")
    print m
    time.sleep(2)
    >
    but to get it to automatically updated quotes, in VB they do something like
    >
    #============== ==
    Public Class Form1
    # Dimension a Public Real Time list object that is capable of handling events
    # note from me: not sure what this line does really
    Dim WithEvents AdxList As New AdfinXRTLib.Adx RTList
    >
    Public Sub AdxList_OnUpdat e( <some args deleted>) Handles AdxList.OnUpdat e
    >
    do stuff with the updated data
    >
    End Sub
    >
    Private Sub Button1_Click(< some args deleted>)
    >
    do stuff with button click
    End Sub
    End Class
    #============== ==
    >
    It seems as if the important part is the "Handles AdxList.OnUpdat e", which I assume
    is basically saying "call me when AdxList.OnUpdat e is called". I have no idea how to
    get this to point to a python function, so I can make the AdxList.OnUpdat e call
    python code.
    >
    Is there a tutorial somewhere about this stuff, or is there a proper place to ask
    such questions?
    >
    thanks,
    >
    Brian Blais
    >
    --
    -----------------
    >
    bbl...@bryant.e du
    http://web.bryant.edu/~bblais
    I found some info on Python, VB, and COM. Check out the links below:



    http://www.oreilly.com/catalog/pytho...pter/ch12.html


    Not sure if those will help, but they might give you some food for
    thought.

    Mike

    Comment

    • Larry Bates

      #3
      Re: python and COM

      Brian Blais wrote:
      Hello,
      >
      I am trying to communicate to a Reuters feed using Python, using a
      particular set of libraries called the Adfin Real Time library. I have
      VB code, and am trying to port it to python, and admit I really do not
      understand COM objects and being a Linux guy mainly, I don't use VB at
      all. I've had some marginal success, but am coming up empty when it
      comes to setting up callbacks.
      >
      For example, this works:
      >
      import win32com.client
      import time
      >
      symb='GOOG.O'
      >
      mylist=win32com .client.Dispatc h('AdfinXRTLib. AdxRtList')
      >
      mylist.Source=" IDN_RDF"
      mylist.Register Items(symb,"ASK ")
      mylist.StartUpd ates(4) # Mode Image
      >
      while mylist.ItemStat us(symb):
      pass
      >
      for i in range(100):
      m=mylist.Value( symb,"ASK")
      print m
      time.sleep(2)
      >
      >
      but to get it to automatically updated quotes, in VB they do something like
      >
      #============== ==
      Public Class Form1
      # Dimension a Public Real Time list object that is capable of handling
      events
      # note from me: not sure what this line does really
      Dim WithEvents AdxList As New AdfinXRTLib.Adx RTList
      >
      Public Sub AdxList_OnUpdat e( <some args deleted>) Handles
      AdxList.OnUpdat e
      >
      do stuff with the updated data
      >
      End Sub
      >
      Private Sub Button1_Click(< some args deleted>)
      >
      do stuff with button click
      End Sub
      End Class
      #============== ==
      >
      It seems as if the important part is the "Handles AdxList.OnUpdat e",
      which I assume is basically saying "call me when AdxList.OnUpdat e is
      called". I have no idea how to get this to point to a python function,
      so I can make the AdxList.OnUpdat e call python code.
      >
      Is there a tutorial somewhere about this stuff, or is there a proper
      place to ask such questions?
      >
      >
      thanks,
      >
      >
      Brian Blais
      >
      It looks like you are correct. This is a callback function that gets
      called when the update occurs. The only coverage of this I've found is
      in "Python Programming on Win32" but it is rather brief even there. I
      have not any event driven callbacks, so I can't help all that much.
      Normally you define a Python class that has methods that ADxList.OnUpdat e
      is expecting to be able to call. Then depending on implementation you
      either call it with an instance of that class or you may have to wrap
      the instance in a COM IDispatch object by calling win32com.server .util.wrap()
      around an instance of the function. Sorry I can't be more helpful.

      -Larry

      Comment

      Working...