OCX and PythonWin....

andy.smith at iname.com andy.smith at iname.com
Tue Aug 10 16:31:58 EDT 1999


Hi All,

I'm trying to use Pythonwin to host an OCX which provides realtime stock
quotes.

The code I've been using to access the OCX is based on
the 'webbrowser.py'
file in the pythonwin ocx demos directory. The OCX returns quotes to the
application by calling an 'OnDynamicQuoteResponse' method, in response
to a
call to ''SubmitDynamicQuote'. I thought I could catch the event by
mimmicking the way the webbrowser demo catches an 'OnBeforeNavigate2'
event.
Unfortunately though, my 'OnDynamicQuoteResponse' method is not getting
called.

When the OCX is initialised, it requires that the application 'register'
with it. An initial call to the IsRegistered() method returns 0. After
this,
my script calls the Register("MYAPP") method. After this, a further
call to
IsRegistered() returns a one, which signifies that the application has
successfully registered for service. I guess this means that the OCX is
correctly functioning, as I can successfully call its methods, it looks
like
it's just return events that aren't being caught.

Can anyone help?!

Cheers,

Andy.



CODE ##########################################

import win32ui, win32con, win32api, regutil
from pywin.mfc import window, activex
from win32com.client import gencache
import sys

ReutersModule =
gencache.EnsureModule('{B4B75CF0-E748-11D0-9A4F-00A024D831CB}', 0, 1, 0)

if ReutersModule is None:
	raise ImportError, "IE4 does not appear to be installed."

class MyControl(activex.Control, ReutersModule.QOleSvr):
	def OnDynamicQuoteResponse(self, symbol, code, price):
		print "Quote response has been called!!!!"

class ControlFrame(window.MDIChildWnd):
	def Create(self, title, rect = None, parent = None):
		style = win32con.WS_CHILD | win32con.WS_VISIBLE |
win32con.WS_OVERLAPPEDWINDOW
		self._obj_ = win32ui.CreateMDIChild()
		self._obj_.AttachObject(self)
		self._obj_.CreateWindow(None, title, style, rect,
parent)
		rect = self.GetClientRect()
		rect = (0,0,rect[2]-rect[0], rect[3]-rect[1])
		self.ocx = MyControl()
		print "Self.ocx is %s" % self.ocx
		self.ocx.CreateControl("Reuters OCX",
win32con.WS_VISIBLE |
win32con.WS_CHILD, rect, self, 1000)

		print "IsRegistered returns %s" % self.ocx.IsRegistered
()

		self.ocx.Register("MYAPP")
		print "IsRegistered returns %s" % self.ocx.IsRegistered
()

		print "Submitting quote request"
		self.ocx.SubmitDynamicQuote("IBM", "P")
		print "Quote submitted"

if __name__=='__main__':
	f = ControlFrame()
	f.Create("Reuters OCX")


OUTPUT  #################################

PythonWin 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on
win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
Portions Copyright 1994-1999 Mark Hammond (MHammond at skippinet.com.au)
>>> Self.ocx is <win32com.gen_py.QOleSvr OLE Control module.MyControl>
IsRegistered returns 0
IsRegistered returns 1
Submitting quote request
Quote submitted

#################################


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list