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 00000000..33dc6a74 Binary files /dev/null and b/unittests/sound.wav differ diff --git a/unittests/test_sound.py b/unittests/test_sound.py new file mode 100644 index 00000000..4ce8a3fc --- /dev/null +++ b/unittests/test_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()