From bd2903e1c321d5890bfe00266b7992803e24428d Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 26 May 2006 16:43:24 +0000 Subject: [PATCH] Another stab (hopefully the last) at how to handle the delayed initialization of the stock objects. Go ahead and create an uninitialized instance using __new__, and then just set the .this attribute when the app is initialized. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39350 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/docs/CHANGES.txt | 21 ++++-- wxPython/src/_stockobjs.i | 150 +++++++++++++++++++++++--------------- wxPython/wxPython/_gdi.py | 74 +++++++++---------- 3 files changed, 143 insertions(+), 102 deletions(-) diff --git a/wxPython/docs/CHANGES.txt b/wxPython/docs/CHANGES.txt index d4c8498470..2fd3c0ec95 100644 --- a/wxPython/docs/CHANGES.txt +++ b/wxPython/docs/CHANGES.txt @@ -120,13 +120,13 @@ source of the clipboard or DnD operation, and then you'll know which of the component data objects to use to access the data. Changed how the stock objects (wx.RED, wx.RED_PEN, wx.RED_BRUSH, etc.) -are initialized. They are now created after the wx.App has been -created, but before OnInit is called, so if you use any of these -objects before the wx.App is created you will need to adjust your -code. This was needed because of some delayed initialization -functionality that was implemented in wxWidgets, but the end result is -cleaner for wxPython as well, and allowed me to remove some ugly code -previously hidden under the covers. +are initialized. They are now created as uninitialized instances +using __new__. Then after the wx.App has been created, but before +OnInit is called, the .this attribute of each obhect is initialized. +This was needed because of some delayed initialization functionality +that was implemented in wxWidgets, but the end result is cleaner for +wxPython as well, and allowed me to remove some ugly code previously +hidden under the covers. Added wx.StandardPaths.GetDocumentsDir. @@ -146,6 +146,13 @@ Added wrappers for Julian's new wxRichTextCtrl class, visible in wxPython as wx.richtext.RichTextCtrl window. It still needs some more work, but it is a great start. +wx.lib.mixins.listctrl.TextEditMixin: Fixed the double END_LABEL_EDIT +event problem in TextEditMixin by checking if the editor was already +hidden before continuing with the CloseEditor method. Also added code +to OpenEditor to send the BEGIN_LABEL_EDIT event and to not allow the +opening of the editor to continue if the event handler doesn't allow +it. + diff --git a/wxPython/src/_stockobjs.i b/wxPython/src/_stockobjs.i index 6eb20892c3..8eb9289ffa 100644 --- a/wxPython/src/_stockobjs.i +++ b/wxPython/src/_stockobjs.i @@ -74,50 +74,99 @@ public: %pythoncode { def _initStockObjects(): import wx - wx.ITALIC_FONT = StockGDI.instance().GetFont(StockGDI.FONT_ITALIC) - wx.NORMAL_FONT = StockGDI.instance().GetFont(StockGDI.FONT_NORMAL) - wx.SMALL_FONT = StockGDI.instance().GetFont(StockGDI.FONT_SMALL) - wx.SWISS_FONT = StockGDI.instance().GetFont(StockGDI.FONT_SWISS) + wx.ITALIC_FONT.this = StockGDI.instance().GetFont(StockGDI.FONT_ITALIC).this + wx.NORMAL_FONT.this = StockGDI.instance().GetFont(StockGDI.FONT_NORMAL).this + wx.SMALL_FONT.this = StockGDI.instance().GetFont(StockGDI.FONT_SMALL).this + wx.SWISS_FONT.this = StockGDI.instance().GetFont(StockGDI.FONT_SWISS).this - wx.BLACK_DASHED_PEN = StockGDI.GetPen(StockGDI.PEN_BLACKDASHED) - wx.BLACK_PEN = StockGDI.GetPen(StockGDI.PEN_BLACK) - wx.CYAN_PEN = StockGDI.GetPen(StockGDI.PEN_CYAN) - wx.GREEN_PEN = StockGDI.GetPen(StockGDI.PEN_GREEN) - wx.GREY_PEN = StockGDI.GetPen(StockGDI.PEN_GREY) - wx.LIGHT_GREY_PEN = StockGDI.GetPen(StockGDI.PEN_LIGHTGREY) - wx.MEDIUM_GREY_PEN = StockGDI.GetPen(StockGDI.PEN_MEDIUMGREY) - wx.RED_PEN = StockGDI.GetPen(StockGDI.PEN_RED) - wx.TRANSPARENT_PEN = StockGDI.GetPen(StockGDI.PEN_TRANSPARENT) - wx.WHITE_PEN = StockGDI.GetPen(StockGDI.PEN_WHITE) - - wx.BLACK_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_BLACK) - wx.BLUE_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_BLUE) - wx.CYAN_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_CYAN) - wx.GREEN_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_GREEN) - wx.GREY_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_GREY) - wx.LIGHT_GREY_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_LIGHTGREY) - wx.MEDIUM_GREY_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_MEDIUMGREY) - wx.RED_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_RED) - wx.TRANSPARENT_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_TRANSPARENT) - wx.WHITE_BRUSH = StockGDI.GetBrush(StockGDI.BRUSH_WHITE) - - wx.BLACK = StockGDI.GetColour(StockGDI.COLOUR_BLACK) - wx.BLUE = StockGDI.GetColour(StockGDI.COLOUR_BLUE) - wx.CYAN = StockGDI.GetColour(StockGDI.COLOUR_CYAN) - wx.GREEN = StockGDI.GetColour(StockGDI.COLOUR_GREEN) - wx.LIGHT_GREY = StockGDI.GetColour(StockGDI.COLOUR_LIGHTGREY) - wx.RED = StockGDI.GetColour(StockGDI.COLOUR_RED) - wx.WHITE = StockGDI.GetColour(StockGDI.COLOUR_WHITE) + wx.BLACK_DASHED_PEN.this = StockGDI.GetPen(StockGDI.PEN_BLACKDASHED).this + wx.BLACK_PEN.this = StockGDI.GetPen(StockGDI.PEN_BLACK).this + wx.CYAN_PEN.this = StockGDI.GetPen(StockGDI.PEN_CYAN).this + wx.GREEN_PEN.this = StockGDI.GetPen(StockGDI.PEN_GREEN).this + wx.GREY_PEN.this = StockGDI.GetPen(StockGDI.PEN_GREY).this + wx.LIGHT_GREY_PEN.this = StockGDI.GetPen(StockGDI.PEN_LIGHTGREY).this + wx.MEDIUM_GREY_PEN.this = StockGDI.GetPen(StockGDI.PEN_MEDIUMGREY).this + wx.RED_PEN.this = StockGDI.GetPen(StockGDI.PEN_RED).this + wx.TRANSPARENT_PEN.this = StockGDI.GetPen(StockGDI.PEN_TRANSPARENT).this + wx.WHITE_PEN.this = StockGDI.GetPen(StockGDI.PEN_WHITE).this + + wx.BLACK_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_BLACK).this + wx.BLUE_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_BLUE).this + wx.CYAN_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_CYAN).this + wx.GREEN_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_GREEN).this + wx.GREY_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_GREY).this + wx.LIGHT_GREY_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_LIGHTGREY).this + wx.MEDIUM_GREY_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_MEDIUMGREY).this + wx.RED_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_RED).this + wx.TRANSPARENT_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_TRANSPARENT).this + wx.WHITE_BRUSH.this = StockGDI.GetBrush(StockGDI.BRUSH_WHITE).this + + wx.BLACK.this = StockGDI.GetColour(StockGDI.COLOUR_BLACK).this + wx.BLUE.this = StockGDI.GetColour(StockGDI.COLOUR_BLUE).this + wx.CYAN.this = StockGDI.GetColour(StockGDI.COLOUR_CYAN).this + wx.GREEN.this = StockGDI.GetColour(StockGDI.COLOUR_GREEN).this + wx.LIGHT_GREY.this = StockGDI.GetColour(StockGDI.COLOUR_LIGHTGREY).this + wx.RED.this = StockGDI.GetColour(StockGDI.COLOUR_RED).this + wx.WHITE.this = StockGDI.GetColour(StockGDI.COLOUR_WHITE).this - wx.CROSS_CURSOR = StockGDI.GetCursor(StockGDI.CURSOR_CROSS) - wx.HOURGLASS_CURSOR = StockGDI.GetCursor(StockGDI.CURSOR_HOURGLASS) - wx.STANDARD_CURSOR = StockGDI.GetCursor(StockGDI.CURSOR_STANDARD) + wx.CROSS_CURSOR.this = StockGDI.GetCursor(StockGDI.CURSOR_CROSS).this + wx.HOURGLASS_CURSOR.this = StockGDI.GetCursor(StockGDI.CURSOR_HOURGLASS).this + wx.STANDARD_CURSOR.this = StockGDI.GetCursor(StockGDI.CURSOR_STANDARD).this + + wx.TheFontList.this = _wxPyInitTheFontList().this + wx.ThePenList.this = _wxPyInitThePenList().this + wx.TheBrushList.this = _wxPyInitTheBrushList().this + wx.TheColourDatabase.this = _wxPyInitTheColourDatabase().this + _initStockObjects = staticmethod(_initStockObjects) } }; +%pythoncode { +%# Create an uninitialized instance for the stock objects, they will +%# be initialized later when the wx.App object is created. +ITALIC_FONT = Font.__new__(Font) +NORMAL_FONT = Font.__new__(Font) +SMALL_FONT = Font.__new__(Font) +SWISS_FONT = Font.__new__(Font) + +BLACK_DASHED_PEN = Pen.__new__(Pen) +BLACK_PEN = Pen.__new__(Pen) +CYAN_PEN = Pen.__new__(Pen) +GREEN_PEN = Pen.__new__(Pen) +GREY_PEN = Pen.__new__(Pen) +LIGHT_GREY_PEN = Pen.__new__(Pen) +MEDIUM_GREY_PEN = Pen.__new__(Pen) +RED_PEN = Pen.__new__(Pen) +TRANSPARENT_PEN = Pen.__new__(Pen) +WHITE_PEN = Pen.__new__(Pen) + +BLACK_BRUSH = Brush.__new__(Brush) +BLUE_BRUSH = Brush.__new__(Brush) +CYAN_BRUSH = Brush.__new__(Brush) +GREEN_BRUSH = Brush.__new__(Brush) +GREY_BRUSH = Brush.__new__(Brush) +LIGHT_GREY_BRUSH = Brush.__new__(Brush) +MEDIUM_GREY_BRUSH = Brush.__new__(Brush) +RED_BRUSH = Brush.__new__(Brush) +TRANSPARENT_BRUSH = Brush.__new__(Brush) +WHITE_BRUSH = Brush.__new__(Brush) + +BLACK = Colour.__new__(Colour) +BLUE = Colour.__new__(Colour) +CYAN = Colour.__new__(Colour) +GREEN = Colour.__new__(Colour) +LIGHT_GREY = Colour.__new__(Colour) +RED = Colour.__new__(Colour) +WHITE = Colour.__new__(Colour) + +CROSS_CURSOR = Cursor.__new__(Cursor) +HOURGLASS_CURSOR = Cursor.__new__(Cursor) +STANDARD_CURSOR = Cursor.__new__(Cursor) +} + %immutable; %threadWrapperOff; @@ -229,31 +278,16 @@ public: } %pythoncode { -%# This function makes a class used to do delayed initialization of some -%# stock wx objects. When they are used the first time then an init function -%# is called to make the real instance, which is then used to replace the -%# original instance and class seen by the programmer. -def _wxPyMakeDelayedInitWrapper(initFunc): - class _wxPyStockObjectWrapper(object): - def __init__(self, *args): - self._args = args - def __getattr__(self, name): - obj = initFunc(*self._args) - self.__class__ = obj.__class__ - self.__dict__ = obj.__dict__ - return getattr(self, name) - def __str__(self): - return self.__getattr__("__str__")() - def __repr__(self): - return self.__getattr__("__repr__")() - return _wxPyStockObjectWrapper -TheFontList = _wxPyMakeDelayedInitWrapper(_wxPyInitTheFontList)() -ThePenList = _wxPyMakeDelayedInitWrapper(_wxPyInitThePenList)() -TheBrushList = _wxPyMakeDelayedInitWrapper(_wxPyInitTheBrushList)() -TheColourDatabase = _wxPyMakeDelayedInitWrapper(_wxPyInitTheColourDatabase)() +%# Create an uninitialized instance for the stock objects, they will +%# be initialized later when the wx.App object is created. +TheFontList = FontList.__new__(FontList) +ThePenList = PenList.__new__(PenList) +TheBrushList = BrushList.__new__(BrushList) +TheColourDatabase = ColourDatabase.__new__(ColourDatabase) } + //--------------------------------------------------------------------------- %pythoncode { NullColor = NullColour } diff --git a/wxPython/wxPython/_gdi.py b/wxPython/wxPython/_gdi.py index 9f188ca5b0..ed33b59f5f 100644 --- a/wxPython/wxPython/_gdi.py +++ b/wxPython/wxPython/_gdi.py @@ -540,42 +540,42 @@ wxRendererNative_GetGeneric = wx._gdi.RendererNative_GetGeneric wxRendererNative_GetDefault = wx._gdi.RendererNative_GetDefault wxRendererNative_Set = wx._gdi.RendererNative_Set wxMaskColour = wx._gdi.MaskColour -## wxNORMAL_FONT = wx._gdi.NORMAL_FONT -## wxSMALL_FONT = wx._gdi.SMALL_FONT -## wxITALIC_FONT = wx._gdi.ITALIC_FONT -## wxSWISS_FONT = wx._gdi.SWISS_FONT -## wxRED_PEN = wx._gdi.RED_PEN -## wxCYAN_PEN = wx._gdi.CYAN_PEN -## wxGREEN_PEN = wx._gdi.GREEN_PEN -## wxBLACK_PEN = wx._gdi.BLACK_PEN -## wxWHITE_PEN = wx._gdi.WHITE_PEN -## wxTRANSPARENT_PEN = wx._gdi.TRANSPARENT_PEN -## wxBLACK_DASHED_PEN = wx._gdi.BLACK_DASHED_PEN -## wxGREY_PEN = wx._gdi.GREY_PEN -## wxMEDIUM_GREY_PEN = wx._gdi.MEDIUM_GREY_PEN -## wxLIGHT_GREY_PEN = wx._gdi.LIGHT_GREY_PEN -## wxBLUE_BRUSH = wx._gdi.BLUE_BRUSH -## wxGREEN_BRUSH = wx._gdi.GREEN_BRUSH -## wxWHITE_BRUSH = wx._gdi.WHITE_BRUSH -## wxBLACK_BRUSH = wx._gdi.BLACK_BRUSH -## wxTRANSPARENT_BRUSH = wx._gdi.TRANSPARENT_BRUSH -## wxCYAN_BRUSH = wx._gdi.CYAN_BRUSH -## wxRED_BRUSH = wx._gdi.RED_BRUSH -## wxGREY_BRUSH = wx._gdi.GREY_BRUSH -## wxMEDIUM_GREY_BRUSH = wx._gdi.MEDIUM_GREY_BRUSH -## wxLIGHT_GREY_BRUSH = wx._gdi.LIGHT_GREY_BRUSH -## wxBLACK = wx._gdi.BLACK -## wxWHITE = wx._gdi.WHITE -## wxRED = wx._gdi.RED -## wxBLUE = wx._gdi.BLUE -## wxGREEN = wx._gdi.GREEN -## wxCYAN = wx._gdi.CYAN -## wxLIGHT_GREY = wx._gdi.LIGHT_GREY -## wxSTANDARD_CURSOR = wx._gdi.STANDARD_CURSOR -## wxHOURGLASS_CURSOR = wx._gdi.HOURGLASS_CURSOR -## wxCROSS_CURSOR = wx._gdi.CROSS_CURSOR -## wxTheFontList = wx._gdi.wxTheFontList -## wxTheBrushList = wx._gdi.wxTheBrushList -## wxTheColourDatabase = wx._gdi.wxTheColourDatabase +wxNORMAL_FONT = wx._gdi.NORMAL_FONT +wxSMALL_FONT = wx._gdi.SMALL_FONT +wxITALIC_FONT = wx._gdi.ITALIC_FONT +wxSWISS_FONT = wx._gdi.SWISS_FONT +wxRED_PEN = wx._gdi.RED_PEN +wxCYAN_PEN = wx._gdi.CYAN_PEN +wxGREEN_PEN = wx._gdi.GREEN_PEN +wxBLACK_PEN = wx._gdi.BLACK_PEN +wxWHITE_PEN = wx._gdi.WHITE_PEN +wxTRANSPARENT_PEN = wx._gdi.TRANSPARENT_PEN +wxBLACK_DASHED_PEN = wx._gdi.BLACK_DASHED_PEN +wxGREY_PEN = wx._gdi.GREY_PEN +wxMEDIUM_GREY_PEN = wx._gdi.MEDIUM_GREY_PEN +wxLIGHT_GREY_PEN = wx._gdi.LIGHT_GREY_PEN +wxBLUE_BRUSH = wx._gdi.BLUE_BRUSH +wxGREEN_BRUSH = wx._gdi.GREEN_BRUSH +wxWHITE_BRUSH = wx._gdi.WHITE_BRUSH +wxBLACK_BRUSH = wx._gdi.BLACK_BRUSH +wxTRANSPARENT_BRUSH = wx._gdi.TRANSPARENT_BRUSH +wxCYAN_BRUSH = wx._gdi.CYAN_BRUSH +wxRED_BRUSH = wx._gdi.RED_BRUSH +wxGREY_BRUSH = wx._gdi.GREY_BRUSH +wxMEDIUM_GREY_BRUSH = wx._gdi.MEDIUM_GREY_BRUSH +wxLIGHT_GREY_BRUSH = wx._gdi.LIGHT_GREY_BRUSH +wxBLACK = wx._gdi.BLACK +wxWHITE = wx._gdi.WHITE +wxRED = wx._gdi.RED +wxBLUE = wx._gdi.BLUE +wxGREEN = wx._gdi.GREEN +wxCYAN = wx._gdi.CYAN +wxLIGHT_GREY = wx._gdi.LIGHT_GREY +wxSTANDARD_CURSOR = wx._gdi.STANDARD_CURSOR +wxHOURGLASS_CURSOR = wx._gdi.HOURGLASS_CURSOR +wxCROSS_CURSOR = wx._gdi.CROSS_CURSOR +wxTheFontList = wx._gdi.TheFontList +wxTheBrushList = wx._gdi.TheBrushList +wxTheColourDatabase = wx._gdi.TheColourDatabase -- 2.45.2