Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pythonCOM with Flash

5 views
Skip to first unread message

Bradley Schatz

unread,
Jun 11, 2003, 8:08:17 PM6/11/03
to
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?

Many thanks,

Bradley

# Flashevents - test flash/python interop
from win32com.client import DispatchWithEvents, Dispatch
import msvcrt, pythoncom
import time, sys
import types

import threading
stopEvent = threading.Event()

def TestFlash():
class FlashEvents:
def OnFSCommand(self, command, args):
print "FSCommend" , command
def OnProgress(self, percentDone):
print "PercentDone", percentDone
def OnReadyStateChange(self, newState):
print "State", newState

e = DispatchWithEvents("ShockwaveFlash.ShockwaveFlash", FlashEvents)
e.seen_events = {}
e.LoadMovie(0,
"http://atomfilms.shockwave.com/afassets/flash/hump_starwars.swf")
e.Play()
if not _WaitForFinish(e, 10000):
e.Quit()

def _WaitForFinish(ob, timeout):
end = time.time() + timeout
while 1:
if msvcrt.kbhit():
msvcrt.getch()
break
pythoncom.PumpWaitingMessages()
stopEvent.wait(.2)
if stopEvent.isSet():
stopEvent.clear()
break

return 1


def test():
import sys
TestFlash()

if __name__=='__main__':
test()

Guyon Morée

unread,
Jun 12, 2003, 8:49:26 AM6/12/03
to
I am afraid that I can not answer this question for you, but I am very
interested in the Flash/Python combination though. I allways like to try out
new gui/code combinations.

Please let me know if you have any url's or something like that


"Bradley Schatz" <bra...@greystate.com> wrote in message
news:RvPFa.37$zx6....@news.optus.net.au...

Mark Hammond

unread,
Jun 12, 2003, 10:15:02 AM6/12/03
to
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.

Doug

unread,
Jun 12, 2003, 11:15:21 AM6/12/03
to
I'm also very interested in flash/python. in paticular porting amfphp to
python. i'm pretty busy recently with work but would like to get in touch
with others who feel they might be interested in porting amfphp to python.
if you reply to this i'll email you privately if you want, my email in this
post is no-valid.

Cheers,
Doug

"Guyon Morée" <gu...@looze.net> wrote in message
news:3ee87647$0$13808$4d4e...@news.nl.uu.net...

Bradley Schatz

unread,
Jun 13, 2003, 4:01:39 AM6/13/03
to
Hi Mark,

I found this post (below) by you. Is it still the case that you can only get
OCX events from within pythonwin? Can this not be done from a console app?
If not, how come?

Thanks,

Bradley


You can only get events from an OCX by using code from within Pythonwin.

You can subclass from the generated code.

You should check out the Pythonwin demos. Depending on the version you
have, these will be either in "pywin\Demos" or "pywin\Demos\ocx". You
should look for "ocxserialtest.py", "ocxtest.py", "webbrowser.py" and a
later one "msoffice.py"

Mark.

"Mark Hammond" <mham...@skippinet.com.au> wrote in message
news:GV%Fa.2949$GU5....@news-server.bigpond.net.au...

Bradley Schatz

unread,
Jun 13, 2003, 4:27:31 AM6/13/03
to
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" <mham...@skippinet.com.au> wrote in message
news:GV%Fa.2949$GU5....@news-server.bigpond.net.au...

Guyon Morée

unread,
Jun 13, 2003, 4:22:46 AM6/13/03
to
hmmm, this is the first time I see this amfphp, but this is somewhat what I
was thinking of when I heard about the the python/flash combination.

So, I am very interested in this, but I need to dig a little bit deeper into
this stuff.
keep me updated

"Doug" <do...@notAvalidEmail.com> wrote in message
news:dO0Ga.57821$4_1.15...@twister.nyc.rr.com...

Mark Hammond

unread,
Jun 13, 2003, 6:25:33 AM6/13/03
to
Bradley Schatz wrote:

> 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'm not familiar with .oca files.

I'm uninterested in flash :) I use Mozilla as my day-to-day browser for
a number of reasons, and am happy that I actually need to go out of my
way to enable flash support there.

But I did have a fiddle, and it all seems to work OK

> 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:

...

> com_error: (-2147319779, 'Library not registered.', None, None)

I just removed that line :)

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

Deleting that second line, and uncommenting that assignment works for
me. I get an AtributeError for Navigate, but examinining the generated
.py file shows no such method. I see state event change calls. You are
going to need to be willing to experiment :)

Mark.

Guyon Morée

unread,
Jun 13, 2003, 8:16:17 AM6/13/03
to
So, if I understand correctly I cannot use Flash as a GUI without another
GUI to contain the flash object.

am I right?

"Mark Hammond" <mham...@skippinet.com.au> wrote in message

news:xEhGa.3736$GU5....@news-server.bigpond.net.au...

Dave Brueck

unread,
Jun 13, 2003, 12:22:52 PM6/13/03
to
On Fri, 13 Jun 2003, wrote:

> So, if I understand correctly I cannot use Flash as a GUI without another
> GUI to contain the flash object.
>
> am I right?

That is probably the case, but that doesn't mean that the other GUI needs
to be a full GUI framework (like wxPython, Tkinter, Qt) - you could use
native Win32 calls to create the toplevel window that contains the Flash
object and that's most of what you need.

If you go this route, first figure out how you would do it in plain old C
(by referencing MSDN, for example) and then the Win32 calls will translate
almost directly into Python calls via Mark's win32 extensions or Thomas
Heller's ctypes package.

-Dave

Bradley Schatz

unread,
Jun 14, 2003, 5:41:25 AM6/14/03
to
Thanks Mark - Distributed testing pays off again.:) What didnt work on my
work pc worked on yours and also my home pc. I am pleased to report that
events work as expected too.

> I'm uninterested in flash :) I use Mozilla as my day-to-day browser for
> a number of reasons, and am happy that I actually need to go out of my
> way to enable flash support there.

I cant say that I have bothered to get flash working under my linux mozilla.
My primary interest is using flash as the UI for python apps (on win32 of
course). Not because I want to learn yet another gui toolkit, but because
creative types seem pretty comfortable designing really good looking UI
prototypes in flash.

A couple of sites have covered this from a VB perspective - this article
covers it in depth
http://www.macromedia.com/devnet/mx/flash/articles/flash_vb.pdf

Find a working demo attached below - click on the sphere in the flash
window, and python will respond and change the gui based on the event.

My next goal is to get this working outside of pythonwin, as a standard app.
Any further suggestions on how how to throw together a simple activex gui
container?

-Bradley


# simple flash/python application demonstrating bidirectional communicaion
between
# flash and python. Click the sphere to see behavior.
# Uses Bounce.swf from FlashBounce.zip, available from
# http://pages.cpsc.ucalgary.ca/~saul/vb_examples/tutorial12/
# make sure this .py has the right filesystem path to the swf


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)

if FlashModule is None:


raise ImportError, "Flash does not appear to be installed."

class MyFlashComponent(activex.Control, FlashModule.ShockwaveFlash):
def __init__(self):
activex.Control.__init__(self)
FlashModule.ShockwaveFlash.__init__(self)
self.x = 50
self.y = 50
self.angle = 30
self.started = 0

def OnFSCommand(self, command, args):
print "FSCommend" , command, args
self.x = self.x + 20
self.y = self.y + 20
self.angle = self.angle + 20
if self.x > 200 or self.y > 200:
self.x = 0
self.y = 0
if self.angle > 360:
self.angle = 0
self.SetVariable("xVal", self.x)
self.SetVariable("yVal", self.y)
self.SetVariable("angle", self.angle)
self.TPlay("_root.mikeBall")

def OnProgress(self, percentDone):
print "PercentDone", percentDone
def OnReadyStateChange(self, newState):

# 0=Loading, 1=Uninitialized, 2=Loaded, 3=Interactive, 4=Complete
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,"C:\\Projects\\flash\\Bounce.swf")
self.ocx.Play()

Zac Jensen

unread,
Jun 14, 2003, 6:00:43 AM6/14/03
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Saturday 14 June 2003 03:41 am, Bradley Schatz wrote:
> Thanks Mark - Distributed testing pays off again.:) What didnt work on my
> work pc worked on yours and also my home pc. I am pleased to report that
> events work as expected too.
>
> > I'm uninterested in flash :) I use Mozilla as my day-to-day browser for
> > a number of reasons, and am happy that I actually need to go out of my
> > way to enable flash support there.
>
> I cant say that I have bothered to get flash working under my linux
> mozilla. My primary interest is using flash as the UI for python apps (on
> win32 of course). Not because I want to learn yet another gui toolkit, but
> because creative types seem pretty comfortable designing really good
> looking UI prototypes in flash.

Why don't you just use Visual C++ if you're going to be proprietary and
limited to one OS?

- -Zac
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE+6vJNV3L7YsSif1URAugWAJ0Rou/elSOGmXSl+iLtDwFI1cUkxACfUau/
8vCFVXV5EBWC8K+k/estS5o=
=ge+f
-----END PGP SIGNATURE-----


John J. Lee

unread,
Jun 14, 2003, 11:39:43 AM6/14/03
to
Dave Brueck <da...@pythonapocrypha.com> writes:

> On Fri, 13 Jun 2003, wrote:
>
> > So, if I understand correctly I cannot use Flash as a GUI without another
> > GUI to contain the flash object.
> >
> > am I right?
>
> That is probably the case, but that doesn't mean that the other GUI needs
> to be a full GUI framework (like wxPython, Tkinter, Qt) - you could use

[...]

Would that even work? I know Qt has suport for ActiveX controls (or
whatever you want to call them), but do wx & Tk?


> native Win32 calls to create the toplevel window that contains the Flash
> object and that's most of what you need.

[...]

Or use IE as the control container. I think Alex Martelli has posted
here about this (probably at length ;-) in the past.


John

Dave Brueck

unread,
Jun 14, 2003, 4:58:36 PM6/14/03
to
On Sat, 14 Jun 2003, John J. Lee wrote:

> Dave Brueck <da...@pythonapocrypha.com> writes:
>
> > On Fri, 13 Jun 2003, wrote:
> >
> > > So, if I understand correctly I cannot use Flash as a GUI without another
> > > GUI to contain the flash object.
> > >
> > > am I right?
> >
> > That is probably the case, but that doesn't mean that the other GUI needs
> > to be a full GUI framework (like wxPython, Tkinter, Qt) - you could use
> [...]
>
> Would that even work? I know Qt has suport for ActiveX controls (or
> whatever you want to call them), but do wx & Tk?

Can't speak for Tk (althought I'd be willing to bet that it does have
support for ActiveX controls somehow - maybe Pmw?) but wx certainly does.
In fact, the wxPython demo includes two examples. But still, for this case
the most lightweight approach would be ctypes.

> > native Win32 calls to create the toplevel window that contains the Flash
> > object and that's most of what you need.
> [...]
>
> Or use IE as the control container. I think Alex Martelli has posted
> here about this (probably at length ;-) in the past.

I don't think this would do what the OP wants, though. The point (as I
understood it) was to be able to use Python for the underlying app logic
and Flash as the UI. If you put the Flash control inside IE you're really
not that much closer to the goal and you've created more work for yourself
since you have to fiddle with both Python <--> IE as well as IE <--> Flash
control.

-Dave

John J. Lee

unread,
Jun 14, 2003, 4:48:04 PM6/14/03
to
Dave Brueck <da...@pythonapocrypha.com> writes:
> On Sat, 14 Jun 2003, John J. Lee wrote:
[...]
> > Or use IE as the control container. I think Alex Martelli has posted
> > here about this (probably at length ;-) in the past.
>
> I don't think this would do what the OP wants, though. The point (as I
> understood it) was to be able to use Python for the underlying app logic
> and Flash as the UI.

Yep, I understood that.

> If you put the Flash control inside IE you're really
> not that much closer to the goal and you've created more work for yourself
> since you have to fiddle with both Python <--> IE as well as IE <--> Flash
> control.

Not according to Alex. See the first message here:

http://www.google.com/groups?q=control+container+Martelli+IE+group:comp.lang.python


Admittedly, I haven't tried it myself.


John

Thomas Heller

unread,
Jun 14, 2003, 5:18:33 PM6/14/03
to
Dave Brueck <da...@pythonapocrypha.com> writes:

> On Sat, 14 Jun 2003, John J. Lee wrote:
>
>> Dave Brueck <da...@pythonapocrypha.com> writes:
>>
>> > On Fri, 13 Jun 2003, wrote:
>> >
>> > > So, if I understand correctly I cannot use Flash as a GUI without
>> > > another GUI to contain the flash object.
>> > >
>> > > am I right?
>> >
>> > That is probably the case, but that doesn't mean that the other GUI
>> > needs to be a full GUI framework (like wxPython, Tkinter, Qt) - you
>> > could use
>> [...]
>>
>> Would that even work? I know Qt has suport for ActiveX controls (or
>> whatever you want to call them), but do wx & Tk?
>
> Can't speak for Tk (althought I'd be willing to bet that it does have
> support for ActiveX controls somehow - maybe Pmw?) but wx certainly does.
> In fact, the wxPython demo includes two examples. But still, for this case
> the most lightweight approach would be ctypes.
>

Henk Punt's venster library, which is based on ctypes, has an example
which embeds the webbrowser ActiveX control.

Thomas

Mark Hammond

unread,
Jun 14, 2003, 9:23:59 PM6/14/03
to
Bradley Schatz wrote:

> Thanks Mark - Distributed testing pays off again.:) What didnt work on my
> work pc worked on yours and also my home pc. I am pleased to report that
> events work as expected too.

Excellent!

> Find a working demo attached below - click on the sphere in the flash
> window, and python will respond and change the gui based on the event.

Thanks! I have added that to the Demos directory. It is unfortunate
that the .swf it uses isn't able to be directly referenced on the web,
but cest-la-vie.

I guess if it was OK to redistribute, I could add it to starship.

> My next goal is to get this working outside of pythonwin, as a standard app.
> Any further suggestions on how how to throw together a simple activex gui
> container?

See the other posts in this thread, particularly references to Alex's
amazing posts some time ago.

Otherwise, a bare-boned, single Window Pythonwin based app shouldn't be
too hard.

Mark.

Henk Punt

unread,
Jun 15, 2003, 12:13:11 PM6/15/03
to
Hi,

I've created a sample flash player in Venster, embedding the Flash control.
it can be found in the source distribution of Venster @ venster.sourceforge.net
in the 'test' directory.

Grtz,

Henk.

Dave Brueck

unread,
Jun 15, 2003, 9:29:29 PM6/15/03
to
On Sat, 14 Jun 2003, John J. Lee wrote:

> > If you put the Flash control inside IE you're really
> > not that much closer to the goal and you've created more work for yourself
> > since you have to fiddle with both Python <--> IE as well as IE <--> Flash
> > control.
>
> Not according to Alex. See the first message here:
>
> http://www.google.com/groups?q=control+container+Martelli+IE+group:comp.lang.python

Well, he _did_ write that before the ctypes days. ;-) But either way there
do seem to be many alternatives.

> Admittedly, I haven't tried it myself.

I have, but I didn't get too far because that route depends (as far as I
understand it) on being able to install win32all (or something similar) so
that you can use Python as an Active Scripting language. That wasn't an
option for me, so I was still left with building the Python<->IE bridge as
well as the IE<->OCX bridge (although not Flash in this case). Having said
that, I'd be the first to admit that my struggles to get it working may
have been tied directly to a poor understanding of the various MS
technologies.

-Dave

Bradley Schatz

unread,
Jun 15, 2003, 8:13:38 PM6/15/03
to
Im checking if you can redistribute it. Let you know OOB when I know.

Thanks for all the help!

-bradley


"Mark Hammond" <mham...@skippinet.com.au> wrote in message

news:PUPGa.5478$GU5....@news-server.bigpond.net.au...

0 new messages