pythonCOM with Flash

Bradley Schatz bradley at greystate.com
Fri Jun 13 04:27:31 EDT 2003


Hi Mark,

thanks for the pointers previously.

I have had a further play using the demos you mention, from within
pythonwin.

Here are some notes for things that I dont quite understand..

Makpy finds two typelibraries for Shockwave Flash 1.0 If I look at them
using the MS COM Object viewer, I see that one of them points to an .ocx and
the other points to a .oca

I have modified the webbrowser.py example to use flash - the source is
below.

When I use the IID that points to the ocx (begins with D27) I get the
following trace from within pythonwin:

  File
"C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\projects\flash\flash2.py", line 13, in ?
    FlashModule =
gencache.EnsureModule("{D27CDB6E-AE6D-11CF-96B8-444553540000}", 0, 1, 0)
  File "C:\Python23\lib\site-packages\win32com\client\gencache.py", line
347, in EnsureModule
    tlbAttr = pythoncom.LoadRegTypeLib(typelibCLSID, major, minor,
lcid).GetLibAttr()
com_error: (-2147319779, 'Library not registered.', None, None)

When I use the IID that points to the .oca I get the following.

  File
"C:\Python23\lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\projects\flash\flash2.py", line 60, in ?
    Demo()
  File "C:\projects\flash\flash2.py", line 57, in Demo
    f.Create("Flash Player")
  File "C:\projects\flash\flash2.py", line 42, in Create
    self.ocx.CreateControl("Flash Player", win32con.WS_VISIBLE |
win32con.WS_CHILD, rect, self, 1000)
  File "C:\Python23\lib\site-packages\Pythonwin\pywin\mfc\activex.py", line
23, in CreateControl
    self.__dict__["_obj_"] = win32ui.CreateControl(clsid, windowTitle,
style, rect, parent, id, lic_string)
win32ui: CreateControl failed

Any suggestions on what I may be misunderstanding here would be greatly
appreciated.

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

#FlashModule =
gencache.EnsureModule("{D27CDB6B-AE6D-11CF-96B8-444553540000}", 0, 1, 0)
FlashModule =
gencache.EnsureModule("{E69E19FB-B24A-4AA2-9E1A-3C6E59F587FC}", 0, 1, 0)

if FlashModule is None:
 raise ImportError, "Flash does not appear to be installed."

class MyFlashComponent(activex.Control, FlashModule.ShockwaveFlash):
 def OnFSCommand(self, command, args):
  print "FSCommend" , command
 def OnProgress(self, percentDone):
  print "PercentDone", percentDone
 def OnReadyStateChange(self, newState):
  print "State", newState

class BrowserFrame(window.MDIChildWnd):
 def __init__(self, url = None):
  if url is None:
   self.url = regutil.GetRegisteredHelpFile("Main Python Documentation")
  else:
   self.url = url
  pass # Dont call base class doc/view version...
 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 = MyFlashComponent()
  self.ocx.CreateControl("Flash Player", win32con.WS_VISIBLE |
win32con.WS_CHILD, rect, self, 1000)
  self.ocx.LoadMovie(0,
"http://atomfilms.shockwave.com/afassets/flash/hump_starwars.swf")
  self.ocx.Play()
  self.ocx.Navigate(self.url)
  self.HookMessage (self.OnSize, win32con.WM_SIZE)
 def OnSize (self, params):
  rect = self.GetClientRect()
  rect = (0,0,rect[2]-rect[0], rect[3]-rect[1])
  self.ocx.SetWindowPos(0, rect, 0)

def Demo():
 url = None
 if len(sys.argv)>1:
  url = win32api.GetFullPathName(sys.argv[1])
 f = BrowserFrame(url)
 f.Create("Flash Player")

if __name__=='__main__':
 Demo()


"Mark Hammond" <mhammond at skippinet.com.au> wrote in message
news:GV%Fa.2949$GU5.41737 at news-server.bigpond.net.au...
> Bradley Schatz wrote:
> > Hi,
> >
> > I am attempting to use Flash as a UI for a python program. I have
> > successfully prototyped this using VB/Flash, and am not trying to
convert it
> > over to work with python.
> >
> > My problem is this, when I run the following code (attached below)
nothing
> > happens.
> >
> > I assume that the Flash activex component needs to be placed in some
> > container to be seen, as I am not seeing any window come up when I run
this.
> >
> > Could anyone suggest how to embed this into a container?
>
> Look at the Pythonwin OCS demos, under the pywin\demos directory.
> wxPython also has some ActiveX container support, but I have never used
it.
>
> Mark.
>






More information about the Python-list mailing list