From 340e631233b47db06dfe6a802cbd784eab2c384b Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 17 May 2012 02:54:28 +0000 Subject: [PATCH] Add wx.adv.Sound git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71463 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO.txt | 1 - etg/_adv.py | 2 +- etg/sound.py | 75 ++++++++++++++++++++++++++++++++++++++++ unittests/sound.wav | Bin 0 -> 5338 bytes unittests/test_sound.py | 38 ++++++++++++++++++++ 5 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 etg/sound.py create mode 100755 unittests/sound.wav create mode 100644 unittests/test_sound.py diff --git a/TODO.txt b/TODO.txt index 17b8ff98..a1af9845 100644 --- a/TODO.txt +++ b/TODO.txt @@ -127,7 +127,6 @@ other dev stuff * axbase (ActiveX. Need to figure out best ways to do MSW-only items...) * check that all items in _functions.i and _misc.i have been wrapped * joystick - * sound * mimetype * power * overlay diff --git a/etg/_adv.py b/etg/_adv.py index a2f3bbee..b873017a 100644 --- a/etg/_adv.py +++ b/etg/_adv.py @@ -34,6 +34,7 @@ INCLUDES = [ 'hyperlink', 'tipdlg', 'taskbar', + 'sound', # TODOs - @@ -49,7 +50,6 @@ INCLUDES = [ #'odcombo', #'richtooltip', #'sashwin', - #'sound', #'splash', #'timectrl', #'treelist', diff --git a/etg/sound.py b/etg/sound.py new file mode 100644 index 00000000..f06f775b --- /dev/null +++ b/etg/sound.py @@ -0,0 +1,75 @@ +#--------------------------------------------------------------------------- +# Name: etg/sound.py +# Author: Robin Dunn +# +# Created: 15-May-2012 +# Copyright: (c) 2012 by Total Control Software +# License: wxWindows License +#--------------------------------------------------------------------------- + +import etgtools +import etgtools.tweaker_tools as tools + +PACKAGE = "wx" +MODULE = "_adv" +NAME = "sound" # Base name of the file to generate to for this script +DOCSTRING = "" + +# The classes and/or the basename of the Doxygen XML files to be processed by +# this script. +ITEMS = [ "wxSound", + ] + +#--------------------------------------------------------------------------- + +def run(): + # Parse the XML file(s) building a collection of Extractor objects + module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING) + etgtools.parseDoxyXML(module, ITEMS) + + #----------------------------------------------------------------- + # Tweak the parsed meta objects in the module object as needed for + # customizing the generated code and docstrings. + + module.addHeaderCode('#include ') + module.addHeaderCode('#include "wxpybuffer.h"') + + c = module.find('wxSound') + assert isinstance(c, etgtools.ClassDef) + c.addPrivateCopyCtor() + c.addPublic() + + c.find('wxSound').findOverload('data').ignore() + #c.addCppCtor_sip('(wxPyBuffer* data)', + # useDerivedName=True, + # doc="Create a sound object from data in a memory buffer in WAV format.", + # body="""\ + # sipCpp = new sipwxSound(); + # sipCpp->Create((size_t)data->m_len, data->m_ptr); + # """) + + + c.find('Create').findOverload('data').ignore() + c.addCppMethod('bool', 'CreateFromData', '(wxPyBuffer* data)', + doc="Create a sound object from data in a memory buffer in WAV format.", + body="return self->Create((size_t)data->m_len, data->m_ptr);") + + + c.find('wxSound.isResource').ignore() + c.find('Create.isResource').ignore() + + c.addCppMethod('int', '__nonzero__', '()', """\ + return self->IsOk(); + """) + + c.find('Play').renameOverload('filename', 'PlaySound') + + #----------------------------------------------------------------- + tools.doCommonTweaks(module) + tools.runGenerators(module) + + +#--------------------------------------------------------------------------- +if __name__ == '__main__': + run() + diff --git a/unittests/sound.wav b/unittests/sound.wav new file mode 100755 index 0000000000000000000000000000000000000000..33dc6a7468c3cd29c413df02160a42d1633b33d5 GIT binary patch literal 5338 zcmeI0$+EN75y$0SDyyU_OE12CR>>P=5m&j&i&T=bmzD%*1PLKP%=09H2GA^oi*G}e}4VdS3mx#)%xyl-~PSFiJ$(^YPG(A&maHX zB0pcWe%GQqV&@+a)1|3VRF(IONzruAxt8VK8_;xDJKW1EnNTz(ZSLiLErQ1<;N>b! zQ>=d}%cDJ{>7liUQ*z;k`ycP+y(EXM=SHXF~YJvi+;mT5qs=R?Yi=US#|LW<|PHn^7Kf(NH9 z3j&E}S~iH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sound.py @@ -0,0 +1,38 @@ +import imp_unittest, unittest +import wtc +import wx +import wx.adv +import sys, os + +wavFile = os.path.join(os.path.dirname(__file__), 'sound.wav') + +#--------------------------------------------------------------------------- + +class sound_Tests(wtc.WidgetTestCase): + + def test_sound1(self): + wx.adv.SOUND_SYNC + wx.adv.SOUND_ASYNC + wx.adv.SOUND_LOOP + + def test_sound2(self): + sound = wx.adv.Sound(wavFile) + self.assertTrue(sound.IsOk()) + rv = sound.Play(wx.adv.SOUND_SYNC) + + @unittest.skipIf(sys.platform == 'darwin', 'CreateFromBuffer not implemented on Mac') + def test_sound3(self): + sound = wx.adv.Sound() + self.assertTrue(not sound.IsOk()) + data = open(wavFile, 'rb').read() + sound.CreateFromData(data) + self.assertTrue(sound.IsOk()) + rv = sound.Play(wx.adv.SOUND_SYNC) + + def test_sound4(self): + rv = wx.adv.Sound.PlaySound(wavFile, wx.adv.SOUND_SYNC) + +#--------------------------------------------------------------------------- + +if __name__ == '__main__': + unittest.main()