mirror of
https://github.com/wxWidgets/Phoenix.git
synced 2026-01-04 19:10:09 +01:00
Add wx.Command and wx.CommandProcessor
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@72124 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
1
TODO.txt
1
TODO.txt
@@ -119,7 +119,6 @@ other dev stuff
|
||||
|
||||
* PseudoDC (not actually an ETG script, probably a .sip)
|
||||
* access
|
||||
* cmdproc
|
||||
* dialup ??
|
||||
* docmdi ??
|
||||
* docview ??
|
||||
|
||||
@@ -209,6 +209,7 @@ INCLUDES = [ # base and core stuff
|
||||
'fontmap',
|
||||
'mousemanager',
|
||||
'filehistory',
|
||||
'cmdproc',
|
||||
]
|
||||
|
||||
|
||||
|
||||
61
etg/cmdproc.py
Normal file
61
etg/cmdproc.py
Normal file
@@ -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 <wx/cmdproc.h>')
|
||||
|
||||
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()
|
||||
|
||||
67
unittests/test_cmdproc.py
Normal file
67
unittests/test_cmdproc.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user