From 99ecb498e16c47ac35917fa41d0f7947a1d20dd0 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Wed, 20 Jun 2012 17:11:21 +0000 Subject: [PATCH] Add wx.FontEnumerator git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@71816 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO.txt | 1 - etg/_core.py | 1 + etg/fontenum.py | 46 +++++++++++++++++++++++++++++++++++ unittests/test_fontenum.py | 50 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 etg/fontenum.py create mode 100644 unittests/test_fontenum.py diff --git a/TODO.txt b/TODO.txt index 446c5613..dd5bdced 100644 --- a/TODO.txt +++ b/TODO.txt @@ -124,7 +124,6 @@ other dev stuff * docmdi ?? * docview ?? * filehistory - * fontenum * fontmap * fswatcher * headerctrl diff --git a/etg/_core.py b/etg/_core.py index d113a9bf..7bebcc4b 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -201,6 +201,7 @@ INCLUDES = [ # base and core stuff 'mimetype', 'busyinfo', 'caret', + 'fontenum', ] diff --git a/etg/fontenum.py b/etg/fontenum.py new file mode 100644 index 00000000..640e5f1a --- /dev/null +++ b/etg/fontenum.py @@ -0,0 +1,46 @@ +#--------------------------------------------------------------------------- +# Name: etg/fontenum.py +# Author: Robin Dunn +# +# Created: 19-Jun-2012 +# Copyright: (c) 2012 by Total Control Software +# License: wxWindows License +#--------------------------------------------------------------------------- + +import etgtools +import etgtools.tweaker_tools as tools + +PACKAGE = "wx" +MODULE = "_core" +NAME = "fontenum" # 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 = [ "wxFontEnumerator", + ] + +#--------------------------------------------------------------------------- + +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. + + c = module.find('wxFontEnumerator') + assert isinstance(c, etgtools.ClassDef) + c.addPrivateCopyCtor() + + #----------------------------------------------------------------- + tools.doCommonTweaks(module) + tools.runGenerators(module) + + +#--------------------------------------------------------------------------- +if __name__ == '__main__': + run() + diff --git a/unittests/test_fontenum.py b/unittests/test_fontenum.py new file mode 100644 index 00000000..6e0fb754 --- /dev/null +++ b/unittests/test_fontenum.py @@ -0,0 +1,50 @@ +import imp_unittest, unittest +import wtc +import wx +import sys + +#--------------------------------------------------------------------------- + +class fontenum_Tests(wtc.WidgetTestCase): + + @unittest.skipIf(sys.platform == 'darwin', 'EnumerateEncodings not implemented on Mac') + def test_fontenum1(self): + enc = wx.FontEnumerator.GetEncodings() + self.assertTrue(isinstance(enc, list)) + self.assertTrue(len(enc) > 0) + + def test_fontenum2(self): + faces = wx.FontEnumerator.GetFacenames() + self.assertTrue(isinstance(faces, list)) + self.assertTrue(len(faces) > 0) + + fw_faces = wx.FontEnumerator.GetFacenames(fixedWidthOnly=True) + self.assertTrue(len(fw_faces) < len(faces)) + + + def test_fontenum3(self): + class MyFontEnumerator(wx.FontEnumerator): + def __init__(self): + wx.FontEnumerator.__init__(self) + self.my_faces = list() + self.my_enc = list() + + def OnFacename(self, name): + self.my_faces.append(name) + return len(self.my_faces) < 5 # quit when we've got 5 + def OnFontEncoding(self, facename, encoding): + self.my_enc.append( (facename, encoding) ) + return len(self.my_enc) < 5 # quit when we've got 5 + + mfe = MyFontEnumerator() + mfe.EnumerateFacenames() + self.assertTrue(len(mfe.my_faces) > 0 and len(mfe.my_faces) <= 5) + + if sys.platform != 'darwin': + mfe.EnumerateEncodings() + self.assertTrue(len(mfe.my_enc) > 0 and len(mfe.my_enc) <= 5) + +#--------------------------------------------------------------------------- + +if __name__ == '__main__': + unittest.main()