944,196 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 7740
  • Python RSS
Dec 15th, 2006
0

write a flash player by python

Expand Post »
I want to write a flash player by using python,can someone help me .

Thanks a lot.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seasou is offline Offline
4 posts
since Dec 2006
Dec 15th, 2006
0

Re: write a flash player by python

I am not sure if there is a Python module out there that includes the .swf file format. However you can press your webbrowser into service ...
python Syntax (Toggle Plain Text)
  1. import webbrowser
  2.  
  3. # html code to embed a .swf flash file player
  4. str1 = """
  5. <html>
  6. <head>
  7. <title>Embedded SWF Player</title>
  8. </head>
  9. <body onLoad="resizeTo(560, 500);">
  10. <!-- you can put your own .swf movie file here -->
  11. <embed src = "Chickens.swf" width="500" height="350"
  12. hidden=false autostart=true loop=1>
  13. </body>
  14. </html>
  15. """
  16.  
  17. # write the html file to the working folder
  18. fout = open("EmbeddedFlash.htm", "w")
  19. fout.write(str1)
  20. fout.close()
  21.  
  22. # now open your web browser to run the file
  23. webbrowser.open("EmbeddedFlash.htm")
The sample Chicken.swf file is in the attached zip.
Attached Files
File Type: zip EmbeddedFlash.zip (9.6 KB, 168 views)
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Dec 16th, 2006
0

Re: write a flash player by python

hi vegaseat ,

thanks,it works,but I want that in my UI,
Do you know how to use the webbrowser module into a canvas.
any way thank you so much!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seasou is offline Offline
4 posts
since Dec 2006
Dec 17th, 2006
0

Re: write a flash player by python

Actually the Python25 version of wxPython has a flash player component. Here is the demo they give:
Python Syntax (Toggle Plain Text)
  1. import os
  2. import wx
  3.  
  4. if wx.Platform == '__WXMSW__':
  5. from wx.lib.flashwin import FlashWindow
  6.  
  7. from Main import opj
  8.  
  9. #----------------------------------------------------------------------
  10.  
  11. class TestPanel(wx.Panel):
  12. def __init__(self, parent, log):
  13. wx.Panel.__init__(self, parent, -1)
  14. self.pdf = None
  15.  
  16. sizer = wx.BoxSizer(wx.VERTICAL)
  17. btnSizer = wx.BoxSizer(wx.HORIZONTAL)
  18.  
  19. self.flash = FlashWindow(self, style=wx.SUNKEN_BORDER)
  20. self.flash.LoadMovie(0, 'file://' + os.path.abspath('data/Asteroid_blaster.swf'))
  21.  
  22. sizer.Add(self.flash, proportion=1, flag=wx.EXPAND)
  23.  
  24. btn = wx.Button(self, wx.NewId(), "Open Flash File")
  25. self.Bind(wx.EVT_BUTTON, self.OnOpenFileButton, btn)
  26. btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
  27.  
  28. btn = wx.Button(self, wx.NewId(), "Open Flash URL")
  29. self.Bind(wx.EVT_BUTTON, self.OnOpenURLButton, btn)
  30. btnSizer.Add(btn, proportion=1, flag=wx.EXPAND|wx.ALL, border=5)
  31.  
  32. btnSizer.Add((50,-1), proportion=2, flag=wx.EXPAND)
  33. sizer.Add(btnSizer, proportion=0, flag=wx.EXPAND)
  34.  
  35. self.SetSizer(sizer)
  36. self.SetAutoLayout(True)
  37.  
  38.  
  39.  
  40. def OnOpenFileButton(self, event):
  41. dlg = wx.FileDialog(self, wildcard="*.swf")
  42.  
  43. if dlg.ShowModal() == wx.ID_OK:
  44. wx.BeginBusyCursor()
  45. self.flash.LoadMovie(0, 'file://' + dlg.GetPath())
  46. wx.EndBusyCursor()
  47.  
  48. dlg.Destroy()
  49.  
  50.  
  51. def OnOpenURLButton(self, event):
  52. dlg = wx.TextEntryDialog(self, "Enter a URL of a .swf file", "Enter URL")
  53.  
  54. if dlg.ShowModal() == wx.ID_OK:
  55. wx.BeginBusyCursor()
  56. # setting the movie property works too
  57. self.flash.movie = dlg.GetValue()
  58. wx.EndBusyCursor()
  59.  
  60. dlg.Destroy()
  61.  
  62.  
  63.  
  64. #----------------------------------------------------------------------
  65.  
  66. def runTest(frame, nb, log):
  67. if wx.Platform == '__WXMSW__':
  68. win = TestPanel(nb, log)
  69. return win
  70. else:
  71. from Main import MessagePanel
  72. win = MessagePanel(nb, 'This demo only works on Microsoft Windows.',
  73. 'Sorry', wx.ICON_WARNING)
  74. return win
  75.  
  76.  
  77. overview = """\
  78. <html><body>
  79. <h2>wx.lib.flashwin.FlashWindow</h2>
  80.  
  81. The wx.lib.pdfwin.FlashWindow class is yet another example of using
  82. ActiveX controls from wxPython using the new wx.activex module. This
  83. allows you to use an ActiveX control as if it is a wx.Window, you can
  84. call its methods, set/get properties, and receive events from the
  85. ActiveX control in a very intuitive way.
  86.  
  87. <p> Using this class is simpler than ActiveXWrapper, doesn't rely on
  88. the win32all extensions, and is more "wx\'ish", meaning that it uses
  89. events and etc. as would be expected from any other wx window.
  90.  
  91. <p> This demo embeds the Shockwave Flash control, and lets you play a game.
  92.  
  93. </body></html>
  94. """
  95.  
  96. #----------------------------------------------------------------------
  97.  
  98.  
  99.  
  100. if __name__ == '__main__':
  101. import sys,os
  102. import run
  103. run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
  104.  
Reputation Points: 625
Solved Threads: 211
Posting Virtuoso
Ene Uran is offline Offline
1,704 posts
since Aug 2005
Dec 18th, 2006
0

Re: write a flash player by python

Hi,It can't work,the error info is below
Traceback (most recent call last):
File "F:\flashRobots\flashPlayer.py", line 7, in ?
from Main import opj
ImportError: No module named Main

thanks
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seasou is offline Offline
4 posts
since Dec 2006
Dec 18th, 2006
0

Re: write a flash player by python

I think wxPython demos were written by my C++ professor or his father. He always uses the C++ trick of putting in obscure header files, to make student's life harder!

I have simplified some code that works without those extra imports at:
http://www.daniweb.com/code/snippet615.html
Reputation Points: 404
Solved Threads: 180
Nearly a Posting Virtuoso
bumsfeld is offline Offline
1,422 posts
since Jul 2005
Dec 20th, 2006
0

Re: write a flash player by python

Thanks,it's working.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
seasou is offline Offline
4 posts
since Dec 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Extending A Class
Next Thread in Python Forum Timeline: unicode and pythonw.exe





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC