/Mac/Demo/quicktime/VerySimplePlayer.py

http://unladen-swallow.googlecode.com/ · Python · 92 lines · 57 code · 16 blank · 19 comment · 10 complexity · e4daf3591ae6ab34842d30af4f556b62 MD5 · raw file

  1. """VerySimplePlayer converted to python
  2. Jack Jansen, CWI, December 1995
  3. """
  4. from Carbon import Qt
  5. from Carbon import QuickTime
  6. from Carbon import Qd
  7. from Carbon import QuickDraw
  8. from Carbon import Evt
  9. from Carbon import Events
  10. from Carbon import Win
  11. from Carbon import Windows
  12. from Carbon import File
  13. import EasyDialogs
  14. import sys
  15. # XXXX maxbounds = (40, 40, 1000, 1000)
  16. def main():
  17. print 'hello world' # XXXX
  18. # skip the toolbox initializations, already done
  19. # XXXX Should use gestalt here to check for quicktime version
  20. Qt.EnterMovies()
  21. # Get the movie file
  22. fss = EasyDialogs.AskFileForOpen(wanted=File.FSSpec) # Was: QuickTime.MovieFileType
  23. if not fss:
  24. sys.exit(0)
  25. # Open the window
  26. bounds = (175, 75, 175+160, 75+120)
  27. theWindow = Win.NewCWindow(bounds, fss.as_tuple()[2], 0, 0, -1, 1, 0)
  28. # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil)
  29. Qd.SetPort(theWindow)
  30. # Get the movie
  31. theMovie = loadMovie(fss)
  32. # Relocate to (0, 0)
  33. bounds = theMovie.GetMovieBox()
  34. bounds = 0, 0, bounds[2]-bounds[0], bounds[3]-bounds[1]
  35. theMovie.SetMovieBox(bounds)
  36. # Create a controller
  37. theController = theMovie.NewMovieController(bounds, QuickTime.mcTopLeftMovie)
  38. # Get movie size and update window parameters
  39. rv, bounds = theController.MCGetControllerBoundsRect()
  40. theWindow.SizeWindow(bounds[2], bounds[3], 0) # XXXX or [3] [2]?
  41. Qt.AlignWindow(theWindow, 0)
  42. theWindow.ShowWindow()
  43. # XXXX MCDoAction(theController, mcActionSetGrowBoxBounds, &maxBounds)
  44. theController.MCDoAction(QuickTime.mcActionSetKeysEnabled, '1')
  45. # XXXX MCSetActionFilterWithRefCon(theController, movieControllerEventFilter, (long)theWindow)
  46. done = 0
  47. while not done:
  48. gotone, evt = Evt.WaitNextEvent(0xffff, 0)
  49. (what, message, when, where, modifiers) = evt
  50. ## print what, message, when, where, modifiers # XXXX
  51. if theController.MCIsPlayerEvent(evt):
  52. continue
  53. if what == Events.mouseDown:
  54. part, whichWindow = Win.FindWindow(where)
  55. if part == Windows.inGoAway:
  56. done = whichWindow.TrackGoAway(where)
  57. elif part == Windows.inDrag:
  58. Qt.DragAlignedWindow(whichWindow, where, (0, 0, 4000, 4000))
  59. elif what == Events.updateEvt:
  60. whichWindow = Win.WhichWindow(message)
  61. if not whichWindow:
  62. # Probably the console window. Print something, hope it helps.
  63. print 'update'
  64. else:
  65. Qd.SetPort(whichWindow)
  66. whichWindow.BeginUpdate()
  67. Qd.EraseRect(whichWindow.GetWindowPort().GetPortBounds())
  68. whichWindow.EndUpdate()
  69. def loadMovie(theFile):
  70. """Load a movie given an fsspec. Return the movie object"""
  71. movieResRef = Qt.OpenMovieFile(theFile, 1)
  72. movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
  73. return movie
  74. if __name__ == '__main__':
  75. main()