diff --git a/etg/intl.py b/etg/intl.py index ded5598b..74dd00df 100644 --- a/etg/intl.py +++ b/etg/intl.py @@ -2,7 +2,7 @@ # Name: etg/intl.py # Author: Robin Dunn # -# Created: +# Created: 27-Nov-2010 # Copyright: (c) 2011 by Total Control Software # License: wxWindows License #--------------------------------------------------------------------------- @@ -38,7 +38,8 @@ def run(): assert isinstance(c, etgtools.ClassDef) c.addPrivateAssignOp() c.addPrivateCopyCtor() - tools.removeVirtuals(c) + + c.addCppMethod('int', '__nonzero__', '()', 'return self->IsOk();') c = module.find('wxLanguageInfo') @@ -49,6 +50,7 @@ def run(): #----------------------------------------------------------------- tools.doCommonTweaks(module) + tools.addAutoProperties(module) tools.runGenerators(module) diff --git a/etg/kbdstate.py b/etg/kbdstate.py index 606ba9a8..c5447149 100644 --- a/etg/kbdstate.py +++ b/etg/kbdstate.py @@ -32,13 +32,21 @@ def run(): c = module.find('wxKeyboardState') + assert isinstance(c, etgtools.ClassDef) c.addProperty("controlDown ControlDown SetControlDown") c.addProperty("shiftDown ShiftDown SetShiftDown") c.addProperty("altDown AltDown SetAltDown") c.addProperty("metaDown MetaDown SetMetaDown") c.addProperty("cmdDown CmdDown") - + + c.addPyCode("""\ + # For 2.8 compatibility + KeyboardState.m_controlDown = wx.deprecated(KeyboardState.controlDown) + KeyboardState.m_shiftDown = wx.deprecated(KeyboardState.shiftDown) + KeyboardState.m_altDown = wx.deprecated(KeyboardState.altDown) + KeyboardState.m_metaDown = wx.deprecated(KeyboardState.metaDown) + """) #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/listbox.py b/etg/listbox.py index 885480b3..366a3b68 100644 --- a/etg/listbox.py +++ b/etg/listbox.py @@ -1,6 +1,7 @@ #--------------------------------------------------------------------------- # Name: etg/listbox.py # Author: Kevin Ollivier +# Robin Dunn # # Created: 10-Sept-2011 # Copyright: (c) 2011 by Kevin Ollivier @@ -37,10 +38,21 @@ def run(): c.find('Create').findOverload('wxString choices').ignore() c.find('Create').findOverload('wxArrayString').find('choices').default = 'wxArrayString()' - # TODO: Take a closer look at this. + # Just use the Set() method inherited from wxControlWithItems, it has the + # overload defined that works best for us for set in c.findAll('Set'): set.ignore() + c.find('GetSelections').type = 'wxArrayInt*' + c.find('GetSelections.selections').ignore() + c.find('GetSelections').setCppCode("""\ + wxArrayInt* array = new wxArrayInt; + self->GetSelections(*array); + return array; + """) + + c.find('InsertItems').findOverload('wxString *items').ignore() + tools.fixWindowClass(c) #----------------------------------------------------------------- diff --git a/etg/log.py b/etg/log.py index 2f8dc976..ae9ebb5b 100644 --- a/etg/log.py +++ b/etg/log.py @@ -1,6 +1,7 @@ #--------------------------------------------------------------------------- # Name: etg/log.py # Author: Kevin Ollivier +# Robin Dunn # # Created: 08-Sept-2011 # Copyright: (c) 2011 by Wide Open Technologies @@ -22,6 +23,14 @@ ITEMS = [ 'wxLogGui', 'wxLogNull', 'wxLogRecordInfo', + 'wxLogWindow', + 'wxLogInterposerTemp', + 'wxLogChain', + #'wxLogStream', # needs std::ostream + 'wxLogStderr', + 'wxLogBuffer', + 'wxLogInterposer', + 'wxLogTextCtrl', ] @@ -32,19 +41,68 @@ def run(): 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. + # do not use the va_list forms of the functions for func in module.allItems(): if 'wxVLog' in func.name: func.ignore() module.find('wxLogTrace').ignore() # deprecated in 2.8, do we support? - + + # Switch the parameters to wxStrings to capitalize on the conversion code + # we already have for them. String formatting can be done in Python if + # needed. Drop the '...' too. + for name in ['wxLogMessage', 'wxLogVerbose', 'wxLogWarning', 'wxLogFatalError', + 'wxLogError', 'wxLogDebug', 'wxLogStatus', 'wxLogSysError']: + for f in module.find(name).all(): + p = f.find('formatString') + p.type = 'const wxString&' + p.name = 'message' + f.items = f.items[:-1] + + module.find('wxSysErrorMsg').type = 'wxString' + c = module.find('wxLogRecordInfo') c.find('threadId').ignore() - # deprecated, do we want to keep supporting these? - #----------------------------------------------------------------- - # Tweak the parsed meta objects in the module object as needed for - # customizing the generated code and docstrings. + + c = module.find('wxLog') + assert isinstance(c, etgtools.ClassDef) + + c.find('SetActiveTarget').transferBack = True + c.find('SetActiveTarget.logtarget').transfer = True + c.find('SetThreadActiveTarget').transferBack = True + c.find('SetThreadActiveTarget.logger').transfer = True + + # we need to un-ignore these protected methods as they need to be overridable + c.find('DoLogRecord').ignore(False) + c.find('DoLogTextAtLevel').ignore(False) + c.find('DoLogText').ignore(False) + + + c = module.find('wxLogStderr') + c.find('wxLogStderr.fp').ignore() + c.addPrivateCopyCtor() + c.addPrivateAssignOp() + + + c = module.find('wxLogBuffer') + c.addPrivateCopyCtor() + c.addPrivateAssignOp() + + c = module.find('wxLogChain') + c.addPrivateCopyCtor() + c.addPrivateAssignOp() + + c = module.find('wxLogGui') + c.addPrivateCopyCtor() + c.addPrivateAssignOp() + + c = module.find('wxLogTextCtrl') + c.addPrivateCopyCtor() + c.addPrivateAssignOp() #----------------------------------------------------------------- tools.doCommonTweaks(module) diff --git a/etg/nonownedwnd.py b/etg/nonownedwnd.py index e746f37f..9205ab81 100644 --- a/etg/nonownedwnd.py +++ b/etg/nonownedwnd.py @@ -23,7 +23,8 @@ ITEMS = [ 'wxNonOwnedWindow' ] def run(): # Parse the XML file(s) building a collection of Extractor objects - module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING) + module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING, + check4unittest=False) etgtools.parseDoxyXML(module, ITEMS) #----------------------------------------------------------------- diff --git a/etg/object.py b/etg/object.py index 6652d9eb..d3388664 100644 --- a/etg/object.py +++ b/etg/object.py @@ -27,7 +27,8 @@ ITEMS = [ def run(): # Parse the XML file(s) building a collection of Extractor objects - module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING) + module = etgtools.ModuleDef(PACKAGE, MODULE, NAME, DOCSTRING, + check4unittest=False) etgtools.parseDoxyXML(module, ITEMS) #----------------------------------------------------------------- @@ -59,14 +60,16 @@ def run(): # EXPERIMENTAL: By turning off the virtualness of the wxObject dtor, and # since there are no other virutals that we are exposing here, then all # classes that derive from wxObject that do not have any virtuals of - # their own can have simpler wrappers generated for them with no extra - # derived class whose only purpose is to reflect calls to the virtual - # methods to Python implementations. (And since the only virtual is the - # dtor then that is of no real benefit to Python code since we're not - # overriding the dtor anyhow.) In addition it appears that none of these + # their own (or have the virtual flags turned off by the tweaker code) + # can have simpler wrappers generated for them with no extra derived + # class whose only purpose is to reflect calls to the virtual methods to + # Python implementations. (And since the only virtual is the dtor then + # that is of no real benefit to Python code since we're not overriding + # the dtor anyhow.) In addition it appears so far that none of these # classes would ever need to have Python derived classes anyway. This # also makes it easier and less SIP-specific to add or replace ctors in - # those classes with custom C++ code. (See wxFont and wxAcceleratorTable.) + # those classes with custom C++ code. (See wxFont and wxAcceleratorTable + # for examples.) c.find('~wxObject').isVirtual = False c.addCppMethod('const wxChar*', 'GetClassName', '()', diff --git a/unittests/test_imaglist.py b/unittests/test_imaglist.py new file mode 100644 index 00000000..104af83d --- /dev/null +++ b/unittests/test_imaglist.py @@ -0,0 +1,33 @@ +import imp_unittest, unittest +import wtc +import wx +import os + +pngFile = os.path.join(os.path.dirname(__file__), 'pointy.png') + +#--------------------------------------------------------------------------- + +class image_Tests(wtc.WidgetTestCase): + + def test_imaglist(self): + bmp = wx.Bitmap(pngFile) + w, h = bmp.GetSize() + i = wx.ImageList(w, h) + i.Add(bmp) + + + def test_imaglistConstants(self): + wx.IMAGE_LIST_NORMAL + wx.IMAGE_LIST_SMALL + wx.IMAGE_LIST_STATE + wx.IMAGELIST_DRAW_NORMAL + wx.IMAGELIST_DRAW_TRANSPARENT + wx.IMAGELIST_DRAW_SELECTED + wx.IMAGELIST_DRAW_FOCUSED + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_intl.py b/unittests/test_intl.py new file mode 100644 index 00000000..5f97a575 --- /dev/null +++ b/unittests/test_intl.py @@ -0,0 +1,49 @@ +import imp_unittest, unittest +import wtc +import wx +import os + +pngFile = os.path.join(os.path.dirname(__file__), 'pointy.png') + +#--------------------------------------------------------------------------- + +class intl_Tests(wtc.WidgetTestCase): + + def test_intlLanguageInfo(self): + info = wx.Locale.GetLanguageInfo(wx.LANGUAGE_ENGLISH_US) + info.CanonicalName + info.Description + info.LocaleName + + + def test_intlLocale(self): + loc = wx.Locale(wx.LANGUAGE_ENGLISH_US) + self.assertTrue(loc.IsOk()) + loc.CanonicalName + loc.Language + loc.Locale + loc.Name + loc.SysName + del loc + + + def test_intlGetString(self): + # This tests if we're able to pull translations from the wx message catalogs + loc = wx.Locale(wx.LANGUAGE_SPANISH) + st = loc.GetString('Next') + #self.assertEqual(st, 'Siguiente') + + + def test_intlConstants(self): + # just a few of them to make sure the file is included properly + wx.LANGUAGE_AFRIKAANS + wx.LANGUAGE_ALBANIAN + wx.LANGUAGE_AMHARIC + + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_kbdstate.py b/unittests/test_kbdstate.py index c8c60b03..10bf90e7 100644 --- a/unittests/test_kbdstate.py +++ b/unittests/test_kbdstate.py @@ -1,4 +1,4 @@ -import unittest +import imp_unittest, unittest import wx @@ -19,4 +19,4 @@ class KeyboardState(unittest.TestCase): if __name__ == '__main__': - unittest2.main() + unittest.main() diff --git a/unittests/test_layout.py b/unittests/test_layout.py new file mode 100644 index 00000000..28f71eeb --- /dev/null +++ b/unittests/test_layout.py @@ -0,0 +1,29 @@ +import imp_unittest, unittest +import wtc +import wx +import os + + +#--------------------------------------------------------------------------- + +class layout_Tests(wtc.WidgetTestCase): + + def test_layout(self): + frame = self.frame + panel = wx.Panel(frame) + panel.BackgroundColour = 'blue' + + lc = wx.LayoutConstraints() + lc.top.SameAs(frame, wx.Top, 10) + lc.left.SameAs(frame, wx.Left, 10) + lc.bottom.SameAs(frame, wx.Bottom, 10) + lc.right.PercentOf(frame, wx.Right, 50) + + panel.SetConstraints(lc) + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_listbox.py b/unittests/test_listbox.py new file mode 100644 index 00000000..2a45df0e --- /dev/null +++ b/unittests/test_listbox.py @@ -0,0 +1,28 @@ +import imp_unittest, unittest +import wtc +import wx + +#--------------------------------------------------------------------------- + +class listbox_Tests(wtc.WidgetTestCase): + + def test_ComboBoxCtors(self): + c = wx.ListBox(self.frame, choices="one two three four".split()) + c = wx.ListBox(self.frame, -1, wx.Point(10,10), wx.Size(80,-1), + "one two three four".split(), 0) + c = wx.ListBox(self.frame, -1, (10,10), (80,-1), "one two three four".split(), 0) + + self.assertTrue(c.GetCount() == 4) + + + def test_ComboBoxDefaultCtor(self): + c = wx.ListBox() + c.Create(self.frame, choices="one two three four".split()) + + + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main() diff --git a/unittests/test_log.py b/unittests/test_log.py new file mode 100644 index 00000000..ed177c3f --- /dev/null +++ b/unittests/test_log.py @@ -0,0 +1,30 @@ +import imp_unittest, unittest +import wtc +import wx + +#--------------------------------------------------------------------------- + +class log_Tests(wtc.WidgetTestCase): + + def test_log(self): + + class MyLog(wx.Log): + def __init__(self): + wx.Log.__init__(self) + self.messageLogged = False + self.messages = list() + + def DoLogText(self, message): + self.messageLogged = True + self.messages.append(message) + + log = MyLog() + old = wx.Log.SetActiveTarget(log) + wx.LogMessage("This is a test") + self.assertTrue(log.messageLogged) + +#--------------------------------------------------------------------------- + + +if __name__ == '__main__': + unittest.main()