From 6130163855a4623a3349ab66eaad0a8202cbc51a Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 17 Jul 2012 01:06:14 +0000 Subject: [PATCH] Add wx.Command and wx.CommandProcessor git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- TODO.txt | 1 - etg/_core.py | 1 + etg/cmdproc.py | 61 +++++++++++++++++++++++++++++++++++ unittests/test_cmdproc.py | 67 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 etg/cmdproc.py create mode 100644 unittests/test_cmdproc.py diff --git a/TODO.txt b/TODO.txt index 84d137d2..e3450310 100644 --- a/TODO.txt +++ b/TODO.txt @@ -119,7 +119,6 @@ other dev stuff * PseudoDC (not actually an ETG script, probably a .sip) * access - * cmdproc * dialup ?? * docmdi ?? * docview ?? diff --git a/etg/_core.py b/etg/_core.py index 5a6b94cf..2d130630 100644 --- a/etg/_core.py +++ b/etg/_core.py @@ -209,6 +209,7 @@ INCLUDES = [ # base and core stuff 'fontmap', 'mousemanager', 'filehistory', + 'cmdproc', ] diff --git a/etg/cmdproc.py b/etg/cmdproc.py new file mode 100644 index 00000000..6943f034 --- /dev/null +++ b/etg/cmdproc.py @@ -0,0 +1,61 @@ +#--------------------------------------------------------------------------- +# Name: etg/cmdproc.py +# Author: Robin Dunn +# +# Created: 16-Jul-2012 +# Copyright: (c) 2012 by Total Control Software +# License: wxWindows License +#--------------------------------------------------------------------------- + +import etgtools +import etgtools.tweaker_tools as tools + +PACKAGE = "wx" +MODULE = "_core" +NAME = "cmdproc" # 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 = [ "wxCommand", + "wxCommandProcessor", + ] + +#--------------------------------------------------------------------------- + +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 ') + + c = module.find('wxCommand') + assert isinstance(c, etgtools.ClassDef) + c.addPrivateCopyCtor() + + + c = module.find('wxCommandProcessor') + c.addPrivateCopyCtor() + + c.find('Submit.command').transfer = True + c.find('Store.command').transfer = True + + module.addItem( + tools.wxListWrapperTemplate('wxList', 'wxCommand', module, + fakeListClassName='wxCommandList')) + c.find('GetCommands').type = 'wxCommandList&' + + #----------------------------------------------------------------- + tools.doCommonTweaks(module) + tools.runGenerators(module) + + +#--------------------------------------------------------------------------- +if __name__ == '__main__': + run() + diff --git a/unittests/test_cmdproc.py b/unittests/test_cmdproc.py new file mode 100644 index 00000000..67b5043e --- /dev/null +++ b/unittests/test_cmdproc.py @@ -0,0 +1,67 @@ +import imp_unittest, unittest +import wtc +import wx + +#--------------------------------------------------------------------------- + +class cmdproc_Tests(wtc.WidgetTestCase): + + def test_cmdproc1(self): + with self.assertRaises(TypeError): + cmd = wx.Command() + + def test_cmdproc2(self): + class MyCommand(wx.Command): + def Do(self): + return True + def Undo(self): + return True + + cmd = MyCommand(name='TestCommand') + + + def test_cmdproc3(self): + class MyCommand(wx.Command): + def __init__(self, *args, **kw): + wx.Command.__init__(self, *args, **kw) + self.value = False + def Do(self): + self.value = True + return True + def Undo(self): + self.value = False + return True + def CanUndo(self): + return True + + cmdproc = wx.CommandProcessor() + for name in 'one two three four five'.split(): + cmd = MyCommand(name=name) + cmdproc.Submit(cmd) + + cmds = cmdproc.GetCommands() + self.assertEqual(len(cmds), 5) + self.assertEqual([x.value for x in cmds], [True]*5) + + self.assertTrue(cmdproc.CanUndo()) + self.assertFalse(cmdproc.CanRedo()) + + cmdproc.Undo() + cmdproc.Undo() + self.assertEqual([x.value for x in cmds], [True]*3 + [False]*2) + + self.assertTrue(cmdproc.CanRedo()) + cmdproc.Redo() + cmdproc.Redo() + self.assertEqual([x.value for x in cmds], [True]*5) + + cmdproc.Undo() + cmdproc.Undo() + cmdproc.Submit(MyCommand(name='NewCmd')) + self.assertEqual(len(cmds), 4) + + +#--------------------------------------------------------------------------- + +if __name__ == '__main__': + unittest.main()