From 256c055e88a61dac1cffadaeb7b302494e7bfc31 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 24 Nov 2004 19:21:30 +0000 Subject: [PATCH] Added wrappers for wx.MediaCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30761 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/demo/Main.py | 2 + wxPython/demo/MediaCtrl.py | 115 +++++++++++++++ wxPython/src/_media_rename.i | 13 ++ wxPython/src/media.i | 268 +++++++++++++++++++++++++++++++++++ wxPython/wxPython/media.py | 39 +++++ 5 files changed, 437 insertions(+) create mode 100644 wxPython/demo/MediaCtrl.py create mode 100644 wxPython/src/_media_rename.i create mode 100644 wxPython/src/media.i create mode 100644 wxPython/wxPython/media.py diff --git a/wxPython/demo/Main.py b/wxPython/demo/Main.py index 250ede5fc2..a31707912b 100644 --- a/wxPython/demo/Main.py +++ b/wxPython/demo/Main.py @@ -48,6 +48,7 @@ _treeList = [ # new stuff ('Recent Additions/Updates', [ 'StandardPaths', + 'MediaCtrl', ]), # managed windows == things with a (optional) caption you can close @@ -151,6 +152,7 @@ _treeList = [ 'FloatCanvas', 'HtmlWindow', 'IntCtrl', + 'MediaCtrl', 'MVCTree', 'MaskedEditControls', 'MaskedNumCtrl', diff --git a/wxPython/demo/MediaCtrl.py b/wxPython/demo/MediaCtrl.py new file mode 100644 index 0000000000..503648af9b --- /dev/null +++ b/wxPython/demo/MediaCtrl.py @@ -0,0 +1,115 @@ + +import wx +import wx.media +import os + +#---------------------------------------------------------------------- + +class TestPanel(wx.Panel): + def __init__(self, parent, log): + self.log = log + wx.Panel.__init__(self, parent, -1, + style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN) + + # Create some controls + self.mc = wx.media.MediaCtrl(self) + self.mc.SetMinSize((320,200)) + + btn1 = wx.Button(self, -1, "Load File") + self.Bind(wx.EVT_BUTTON, self.OnLoadFile, btn1) + + btn2 = wx.Button(self, -1, "Load URL") + self.Bind(wx.EVT_BUTTON, self.OnLoadURI, btn2) + + btn3 = wx.Button(self, -1, "Play") + self.Bind(wx.EVT_BUTTON, self.OnPlay, btn3) + + btn4 = wx.Button(self, -1, "Pause") + self.Bind(wx.EVT_BUTTON, self.OnPause, btn4) + + btn5 = wx.Button(self, -1, "Stop") + self.Bind(wx.EVT_BUTTON, self.OnStop, btn5) + + # setup the layout + sizer = wx.GridBagSizer(5,5) + sizer.Add(self.mc, (1,1), span=(5,1))#, flag=wx.EXPAND) + sizer.Add(btn1, (1,3)) + sizer.Add(btn2, (2,3)) + sizer.Add(btn3, (3,3)) + sizer.Add(btn4, (4,3)) + sizer.Add(btn5, (5,3)) + self.SetSizer(sizer) + + + def OnLoadFile(self, evt): + dlg = wx.FileDialog(self, message="Choose a media file", + defaultDir=os.getcwd(), defaultFile="", + style=wx.OPEN | wx.CHANGE_DIR ) + if dlg.ShowModal() == wx.ID_OK: + path = dlg.GetPath() + if not self.mc.Load(path): + wx.MessageBox("Unable to load %s." % path, + "ERROR: Unsupported format?", + wx.ICON_ERROR | wx.OK) + else: + self.mc.SetBestFittingSize() + self.GetSizer().Layout() + dlg.Destroy() + + + def OnLoadURI(self, evt): + dlg = wx.TextEntryDialog(self, "URL:", "Please enter the URL of a media file", + "http://www.mwscomp.com/movies/grail/tim-the-enchanter.avi") + if dlg.ShowModal() == wx.ID_OK: + url = dlg.GetValue() + if not self.mc.LoadFromURI(url): + wx.MessageBox("Unable to load %s." % url, + "ERROR", wx.ICON_ERROR | wx.OK) + else: + self.mc.SetBestFittingSize() + self.GetSizer().Layout() + dlg.Destroy() + + + def OnPlay(self, evt): + self.mc.Play() + + def OnPause(self, evt): + self.mc.Pause() + + def OnStop(self, evt): + self.mc.Stop() + + + + +#---------------------------------------------------------------------- + +def runTest(frame, nb, log): + try: + win = TestPanel(nb, log) + return win + except NotImplementedError: + from Main import MessagePanel + win = MessagePanel(nb, 'wx.MediaCtrl is not available on this platform.', + 'Sorry', wx.ICON_WARNING) + return win + + +#---------------------------------------------------------------------- + + + +overview = """ +

wx.MediaCtrl

+ + +""" + + + +if __name__ == '__main__': + import sys,os + import run + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:]) + diff --git a/wxPython/src/_media_rename.i b/wxPython/src/_media_rename.i new file mode 100644 index 0000000000..d18d38e5c6 --- /dev/null +++ b/wxPython/src/_media_rename.i @@ -0,0 +1,13 @@ +// A bunch of %rename directives generated by BuildRenamers in config.py +// in order to remove the wx prefix from all global scope names. + +#ifndef BUILDING_RENAMERS + +%rename(MEDIASTATE_STOPPED) wxMEDIASTATE_STOPPED; +%rename(MEDIASTATE_PAUSED) wxMEDIASTATE_PAUSED; +%rename(MEDIASTATE_PLAYING) wxMEDIASTATE_PLAYING; +%rename(MEDIATIMEFORMAT_TIME) wxMEDIATIMEFORMAT_TIME; +%rename(MediaEvent) wxMediaEvent; +%rename(MediaCtrl) wxMediaCtrl; + +#endif diff --git a/wxPython/src/media.i b/wxPython/src/media.i new file mode 100644 index 0000000000..bb5471677f --- /dev/null +++ b/wxPython/src/media.i @@ -0,0 +1,268 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: media.i +// Purpose: SWIG definitions for the wxMediaCtrl +// +// Author: Robin Dunn +// +// Created: 23-Nov-2004 +// RCS-ID: $Id$ +// Copyright: (c) 2004 by Total Control Software +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +%define DOCSTRING +"Classes for a medai player control" +%enddef + +%module(package="wx", docstring=DOCSTRING) media + + +%{ +#include "wx/wxPython/wxPython.h" +#include "wx/wxPython/pyclasses.h" + +#include +%} + +//---------------------------------------------------------------------- + +%import core.i +%pythoncode { wx = _core } +%pythoncode { __docfilter__ = wx.__DocFilter(globals()) } + +%include _media_rename.i + +//--------------------------------------------------------------------------- + +%typemap(in) wxLongLong { + $1 = PyLong_AsLongLong($input); +} + + +%typemap(out) wxLongLong { + $result = PyLong_FromLongLong($1.GetValue()); +} + +//--------------------------------------------------------------------------- +// Make a stubbed out class for platforms that don't have wxMediaCtrl +%{ +#if !wxUSE_MEDIACTRL +enum wxMediaState +{ + wxMEDIASTATE_STOPPED=0, + wxMEDIASTATE_PAUSED=0, + wxMEDIASTATE_PLAYING=0 +}; + +enum wxMediaTimeFormat +{ + wxMEDIATIMEFORMAT_TIME=0 +}; + +class WXDLLIMPEXP_MEDIA wxMediaEvent : public wxNotifyEvent +{ +public: + wxMediaEvent(wxEventTypL, int ) { wxPyRaiseNotImplemented(); } +}; + +class wxMediaCtrl : public wxControl +{ +public: + wxMediaCtrl() { wxPyRaiseNotImplemented(); } + + wxMediaCtrl(wxWindow* , wxWindowID , + const wxString& , + const wxPoint& , + const wxSize& , + long style , + const wxString& , + const wxValidator& , + const wxString& ) { wxPyRaiseNotImplemented(); } + + wxMediaCtrl(wxWindow* , + wxWindowID , + const wxURI& , + const wxPoint&, + const wxSize& . + long style, + const wxString& , + const wxValidator& , + const wxString& ) { wxPyRaiseNotImplemented(); } + + bool Create(wxWindow* , wxWindowID , + const wxString& , + const wxPoint& , + const wxSize& , + long style , + const wxString& , + const wxValidator& , + const wxString& ) { return false; } + + bool Create(wxWindow* , + wxWindowID , + const wxURI& , + const wxPoint&, + const wxSize& . + long style, + const wxString& , + const wxValidator& , + const wxString& ) { return false; } + + bool Play() { return false; } + bool Pause() { return false; } + bool Stop() { return false; } + + bool Load(const wxString& fileName) { return false; } + bool Load(const wxURI& location) { return false; } + + void Loop(bool bLoop = true) {} + bool IsLooped() { return false; } + + wxMediaState GetState() { return wxMEDIASTATE_STOPPED; } + + double GetPlaybackRate() { return 0.0; }; + bool SetPlaybackRate(double dRate) { return false; } + + bool SetPosition(wxLongLong where) { return false; } + wxLongLong GetPosition() { return 0; } + wxLongLong GetDuration() { return 0; } +}; +#endif +%} + + + +//--------------------------------------------------------------------------- + +enum wxMediaState +{ + wxMEDIASTATE_STOPPED, + wxMEDIASTATE_PAUSED, + wxMEDIASTATE_PLAYING +}; + +enum wxMediaTimeFormat +{ + wxMEDIATIMEFORMAT_TIME +}; + + +MAKE_CONST_WXSTRING(MEDIABACKEND_DIRECTSHOW); +MAKE_CONST_WXSTRING(MEDIABACKEND_MCI ); +MAKE_CONST_WXSTRING(MEDIABACKEND_QUICKTIME ); + +//--------------------------------------------------------------------------- + +class wxMediaEvent : public wxNotifyEvent +{ +public: + wxMediaEvent(wxEventType commandType = wxEVT_NULL, int id = 0); +}; + + +//--------------------------------------------------------------------------- + +MAKE_CONST_WXSTRING_NOSWIG(EmptyString); +MAKE_CONST_WXSTRING2(MediaCtrlNameStr, "mediaCtrl"); +MustHaveApp(wxMediaCtrl); + + +class wxMediaCtrl : public wxControl +{ +public: + %pythonAppend wxMediaCtrl "self._setOORInfo(self)" + %pythonAppend wxMediaCtrl() "" + + + wxMediaCtrl(wxWindow* parent, wxWindowID id=-1, + const wxString& fileName = wxPyEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& szBackend = wxPyEmptyString, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyMediaCtrlNameStr); + + %name(PreMediaCtrl) wxMediaCtrl(); + + %extend { + %name(MediaCtrlFromURI) + wxMediaCtrl(wxWindow* parent, wxWindowID id=-1, + const wxString& location=wxPyEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& szBackend = wxPyEmptyString, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyMediaCtrlNameStr) + { + return new wxMediaCtrl(parent, id, wxURI(location), + pos, size, style, szBackend, validator, name); + } + + bool CreateFromURI(wxWindow* parent, wxWindowID id=-1, + const wxString& location=wxPyEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& szBackend = wxPyEmptyString, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyMediaCtrlNameStr) + { + return self->Create(parent, id, wxURI(location), + pos, size, style, szBackend, validator, name); + } + } + + + bool Create(wxWindow* parent, wxWindowID id=-1, + const wxString& fileName = wxPyEmptyString, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, + const wxString& szBackend = wxPyEmptyString, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxPyMediaCtrlNameStr); + + + bool Play(); + bool Pause(); + bool Stop(); + + bool Load(const wxString& fileName); + %extend { + bool LoadFromURI(const wxString& location) { + return self->Load(wxURI(location)); + } + } + + void Loop(bool bLoop = true); + bool IsLooped(); + + wxMediaState GetState(); + + double GetPlaybackRate(); + bool SetPlaybackRate(double dRate); + + bool SetPosition(wxLongLong where); + wxLongLong GetPosition(); + wxLongLong GetDuration(); +}; + + + +%constant wxEventType wxEVT_MEDIA_FINISHED; +%constant wxEventType wxEVT_MEDIA_STOP; + +%pythoncode { +EVT_MEDIA_FINISHED = wx.PyEventBinder( wxEVT_MEDIA_FINISHED, 1) +EVT_MEDIA_STOP = wx.PyEventBinder( wxEVT_MEDIA_STOP, 1) +} + +//--------------------------------------------------------------------------- + +%init %{ +%} + +//--------------------------------------------------------------------------- + diff --git a/wxPython/wxPython/media.py b/wxPython/wxPython/media.py new file mode 100644 index 0000000000..3bcb9868ae --- /dev/null +++ b/wxPython/wxPython/media.py @@ -0,0 +1,39 @@ +## This file reverse renames symbols in the wx package to give +## them their wx prefix again, for backwards compatibility. +## +## Generated by BuildRenamers in config.py + +# This silly stuff here is so the wxPython.wx module doesn't conflict +# with the wx package. We need to import modules from the wx package +# here, then we'll put the wxPython.wx entry back in sys.modules. +import sys +_wx = None +if sys.modules.has_key('wxPython.wx'): + _wx = sys.modules['wxPython.wx'] + del sys.modules['wxPython.wx'] + +import wx.media + +sys.modules['wxPython.wx'] = _wx +del sys, _wx + + +# Now assign all the reverse-renamed names: +wxMEDIASTATE_STOPPED = wx.media.MEDIASTATE_STOPPED +wxMEDIASTATE_PAUSED = wx.media.MEDIASTATE_PAUSED +wxMEDIASTATE_PLAYING = wx.media.MEDIASTATE_PLAYING +wxMEDIATIMEFORMAT_TIME = wx.media.MEDIATIMEFORMAT_TIME +wxMEDIABACKEND_DIRECTSHOW = wx.media.MEDIABACKEND_DIRECTSHOW +wxMEDIABACKEND_MCI = wx.media.MEDIABACKEND_MCI +wxMEDIABACKEND_QUICKTIME = wx.media.MEDIABACKEND_QUICKTIME +wxMediaEvent = wx.media.MediaEvent +wxMediaEventPtr = wx.media.MediaEventPtr +wxMediaCtrlNameStr = wx.media.MediaCtrlNameStr +wxMediaCtrl = wx.media.MediaCtrl +wxMediaCtrlPtr = wx.media.MediaCtrlPtr +wxPreMediaCtrl = wx.media.PreMediaCtrl +wxMediaCtrlFromURI = wx.media.MediaCtrlFromURI +wxEVT_MEDIA_FINISHED = wx.media.wxEVT_MEDIA_FINISHED +wxEVT_MEDIA_STOP = wx.media.wxEVT_MEDIA_STOP + + -- 2.47.2