codekingpro/portable-devtools
114k
1# By Bradley Schatz2# simple flash/python application demonstrating bidirectional3# communicaion between flash and python. Click the sphere to see4# behavior. Uses Bounce.swf from FlashBounce.zip, available from5# http://pages.cpsc.ucalgary.ca/~saul/vb_examples/tutorial12/6 7# Update to the path of the .swf file (note it could be a true URL)8flash_url = "c:\\bounce.swf"9 10import sys11 12import regutil13import win32api14import win32con15import win32ui16from pywin.mfc import activex, window17from win32com.client import gencache18 19FlashModule = gencache.EnsureModule("{D27CDB6B-AE6D-11CF-96B8-444553540000}", 0, 1, 0)20 21if FlashModule is None:22 raise ImportError("Flash does not appear to be installed.")23 24 25class MyFlashComponent(activex.Control, FlashModule.ShockwaveFlash):26 def __init__(self):27 activex.Control.__init__(self)28 FlashModule.ShockwaveFlash.__init__(self)29 self.x = 5030 self.y = 5031 self.angle = 3032 self.started = 033 34 def OnFSCommand(self, command, args):35 print("FSCommend", command, args)36 self.x = self.x + 2037 self.y = self.y + 2038 self.angle = self.angle + 2039 if self.x > 200 or self.y > 200:40 self.x = 041 self.y = 042 if self.angle > 360:43 self.angle = 044 self.SetVariable("xVal", self.x)45 self.SetVariable("yVal", self.y)46 self.SetVariable("angle", self.angle)47 self.TPlay("_root.mikeBall")48 49 def OnProgress(self, percentDone):50 print("PercentDone", percentDone)51 52 def OnReadyStateChange(self, newState):53 # 0=Loading, 1=Uninitialized, 2=Loaded, 3=Interactive, 4=Complete54 print("State", newState)55 56 57class BrowserFrame(window.MDIChildWnd):58 def __init__(self, url=None):59 if url is None:60 self.url = regutil.GetRegisteredHelpFile("Main Python Documentation")61 else:62 self.url = url63 pass # Dont call base class doc/view version...64 65 def Create(self, title, rect=None, parent=None):66 style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_OVERLAPPEDWINDOW67 self._obj_ = win32ui.CreateMDIChild()68 self._obj_.AttachObject(self)69 self._obj_.CreateWindow(None, title, style, rect, parent)70 rect = self.GetClientRect()71 rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])72 self.ocx = MyFlashComponent()73 self.ocx.CreateControl(74 "Flash Player", win32con.WS_VISIBLE | win32con.WS_CHILD, rect, self, 100075 )76 self.ocx.LoadMovie(0, flash_url)77 self.ocx.Play()78 self.HookMessage(self.OnSize, win32con.WM_SIZE)79 80 def OnSize(self, params):81 rect = self.GetClientRect()82 rect = (0, 0, rect[2] - rect[0], rect[3] - rect[1])83 self.ocx.SetWindowPos(0, rect, 0)84 85 86def Demo():87 url = None88 if len(sys.argv) > 1:89 url = win32api.GetFullPathName(sys.argv[1])90 f = BrowserFrame(url)91 f.Create("Flash Player")92 93 94if __name__ == "__main__":95 Demo()96 