473,385 Members | 1,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

IronPython and COM Interface

Hello,

I'm new to IronPython and COM so please bear with me.

I have a COM interface provided to me. I need to implement this
interface and pass it to a method as a way of implementing
'callbacks'.

However it appears that the methods of my interface object are never
called.

As a alternative, I implemented the interface in C# and then extended
the C# class in IronPython. However, on running the code, methods of
my C# class rather than the IronPython class are being called.

Can anyone advise? Is this possible in IronPython?

The code is listed below.

Regards,
Divya

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

import time

import clr
clr.AddReference('Interop.MBTCOMLib.dll')
clr.AddReference('Interop.MBTORDERSLib.dll')
clr.AddReference('Interop.MBTQUOTELib.dll')

import MBTCOMLib
import MBTORDERSLib
import MBTQUOTELib

demo_user='user'
demo_pass='pass'
demo_host=9

class MBEvents(MBTQUOTELib.IMbtQuotesNotify):
def __init__(self):
MBTQUOTELib.IMbtQuotesNotify.__init__(self)

def OnLevel2Data(data):
print 'OnLevel2Data'

def OnOptionsData(self, data):
print 'OnOptionsData'

def OnQuoteData(self, data):
print 'OnQuoteData'

def OnTSData(self, data):
print 'OnTSData'

class MB:
def __init__(self):
self.conn = MBTCOMLib.MbtComMgrClass()
#self.conn.EnableSplash(False)
self.orders = self.conn.OrderClient
self.quotes = self.conn.Quotes
self.events = MBEvents()

def login(self, host=demo_host, user=demo_user, passwd=demo_pass):
self.conn.DoLogin(host, user, passwd, '')
print self.quotes.RemoteAddress, self.quotes.RemotePort
self.quotes.AdviseSymbol(self.events, 'EUR/USD', 1|2|3|4)

Mar 14 '07 #1
1 4863
Divya wrote:
Hello,

I'm new to IronPython and COM so please bear with me.

I have a COM interface provided to me. I need to implement this
interface and pass it to a method as a way of implementing
'callbacks'.

However it appears that the methods of my interface object are never
called.

As a alternative, I implemented the interface in C# and then extended
the C# class in IronPython. However, on running the code, methods of
my C# class rather than the IronPython class are being called.

Can anyone advise? Is this possible in IronPython?

The code is listed below.

Regards,
Divya

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

import time

import clr
clr.AddReference('Interop.MBTCOMLib.dll')
clr.AddReference('Interop.MBTORDERSLib.dll')
clr.AddReference('Interop.MBTQUOTELib.dll')

import MBTCOMLib
import MBTORDERSLib
import MBTQUOTELib

demo_user='user'
demo_pass='pass'
demo_host=9

class MBEvents(MBTQUOTELib.IMbtQuotesNotify):
def __init__(self):
MBTQUOTELib.IMbtQuotesNotify.__init__(self)

def OnLevel2Data(data):
print 'OnLevel2Data'

def OnOptionsData(self, data):
print 'OnOptionsData'

def OnQuoteData(self, data):
print 'OnQuoteData'

def OnTSData(self, data):
print 'OnTSData'

class MB:
def __init__(self):
self.conn = MBTCOMLib.MbtComMgrClass()
#self.conn.EnableSplash(False)
self.orders = self.conn.OrderClient
self.quotes = self.conn.Quotes
self.events = MBEvents()

def login(self, host=demo_host, user=demo_user, passwd=demo_pass):
self.conn.DoLogin(host, user, passwd, '')
print self.quotes.RemoteAddress, self.quotes.RemotePort
self.quotes.AdviseSymbol(self.events, 'EUR/USD', 1|2|3|4)
It may not help but I was struggling with the COM-callback issue
yesterday and found that this works in regular python:

import win32com.server.util

def callback:
_public_methods_=['progress']
def progress(self, total, number):
print "completed %i of %i" % (number, total)

#
# Get instance of callback class
#
cb=callback()
#
# Wrap the callback class to turn it into an IDispatch (COM) object
# so I can pass it to my COM object.
#
idCallback=win32com.server.util.wrap(cb)
#
# Call the COM interface and pass it the callback function
#
r=oC.WSset_callback(idCallback)

In my case the COM object was also written in Python so to get
to the python object I do following:

def WSset_callback(idCallback)
self.callback=win32com.client.Dispatch(idCallback)

Now I can call .progress method of callback class from the COM
object.

self.callback.progress(total, number)

Hope this helps in some way.

-Larry
Mar 14 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

82
by: Neuruss | last post by:
IronPython is currently at a pre-alpha stage suitable for experimentation but not for serious development work. http://www.ironpython.com
27
by: James | last post by:
http://www.gotdotnet.com/workspaces/workspace.aspx?id=ad7acff7-ab1e-4bcb-99c0-57ac5a3a9742
3
by: Carl Johan Rehn | last post by:
What is the difference between CPython, Python for .NET, and IronPython? For example, if I'm running IronPython, can I access modules such as Numeric and numarray? As I understand it,...
3
by: Sanghyeon Seo | last post by:
I took some time to write this HOWTO: http://sparcs.kaist.ac.kr/~tinuviel/fepy/howto/simplehttpserver-ironpython-mono-howto.html IronPython seems to get much less interest than it deserves. This...
0
by: Sanghyeon Seo | last post by:
ctypes is a popular CPython extension planned for inclusion in Python 2.5. It is a foreign function interface library. Homepage: http://starship.python.net/crew/theller/ctypes/ Documentation:...
7
by: sanxiyn | last post by:
Skip wrote: For those of us who have never used IronPython or Mono, is there a quick start document laying about somewhere? It wasn't clear to me where to even look. Okay, here we go: 1....
9
by: Claudio Grondi | last post by:
(just wanted to share my experience with IronPython 1.0) The context: C:\IronPythonipy.exe IronPython 1.0.60816 on .NET 2.0.50727.42 Copyright (c) Microsoft Corporation. All rights reserved....
2
by: edfialk | last post by:
Hi all, I'm pretty much totally new to IronPython and have come to the point that I need an interface to interact with a co-worker's code, but I can't seem to find any documents or discussion on...
2
by: Troels Thomsen | last post by:
Hello , When an exeption occurs in a IronPython executet script, and I print the sys.exc , i get something ugly like the example below. How can I get the fileName and line number? Thx in...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.