Changed how the stock objects (wx.RED, wx.RED_PEN, wx.RED_BRUSH, etc.)
are initialized. They are now created as a wrapper object that initializes itself on first use (when an attribute of the object is requested.) This was needed because of similar 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 under the covers. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38802 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -17,50 +17,139 @@
|
||||
%newgroup
|
||||
|
||||
|
||||
// See also wxPy_ReinitStockObjects in helpers.cpp
|
||||
class wxStockGDI
|
||||
{
|
||||
public:
|
||||
enum Item {
|
||||
BRUSH_BLACK,
|
||||
BRUSH_BLUE,
|
||||
BRUSH_CYAN,
|
||||
BRUSH_GREEN,
|
||||
BRUSH_GREY,
|
||||
BRUSH_LIGHTGREY,
|
||||
BRUSH_MEDIUMGREY,
|
||||
BRUSH_RED,
|
||||
BRUSH_TRANSPARENT,
|
||||
BRUSH_WHITE,
|
||||
COLOUR_BLACK,
|
||||
COLOUR_BLUE,
|
||||
COLOUR_CYAN,
|
||||
COLOUR_GREEN,
|
||||
COLOUR_LIGHTGREY,
|
||||
COLOUR_RED,
|
||||
COLOUR_WHITE,
|
||||
CURSOR_CROSS,
|
||||
CURSOR_HOURGLASS,
|
||||
CURSOR_STANDARD,
|
||||
FONT_ITALIC,
|
||||
FONT_NORMAL,
|
||||
FONT_SMALL,
|
||||
FONT_SWISS,
|
||||
PEN_BLACK,
|
||||
PEN_BLACKDASHED,
|
||||
PEN_CYAN,
|
||||
PEN_GREEN,
|
||||
PEN_GREY,
|
||||
PEN_LIGHTGREY,
|
||||
PEN_MEDIUMGREY,
|
||||
PEN_RED,
|
||||
PEN_TRANSPARENT,
|
||||
PEN_WHITE,
|
||||
ITEMCOUNT
|
||||
};
|
||||
|
||||
wxStockGDI();
|
||||
virtual ~wxStockGDI();
|
||||
static void DeleteAll();
|
||||
|
||||
static wxStockGDI& instance();
|
||||
|
||||
static const wxBrush* GetBrush(Item item);
|
||||
static const wxColour* GetColour(Item item);
|
||||
static const wxCursor* GetCursor(Item item);
|
||||
static const wxPen* GetPen(Item item);
|
||||
|
||||
virtual const wxFont* GetFont(Item item);
|
||||
};
|
||||
|
||||
|
||||
%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
|
||||
|
||||
def _wxPyFontInit(id):
|
||||
return StockGDI.instance().GetFont(id)
|
||||
|
||||
_wxPyStockPen = _wxPyMakeDelayedInitWrapper(StockGDI.GetPen)
|
||||
_wxPyStockBrush = _wxPyMakeDelayedInitWrapper(StockGDI.GetBrush)
|
||||
_wxPyStockCursor = _wxPyMakeDelayedInitWrapper(StockGDI.GetCursor)
|
||||
_wxPyStockColour = _wxPyMakeDelayedInitWrapper(StockGDI.GetColour)
|
||||
_wxPyStockFont = _wxPyMakeDelayedInitWrapper(_wxPyFontInit)
|
||||
|
||||
|
||||
ITALIC_FONT = _wxPyStockCursor(StockGDI.FONT_ITALIC)
|
||||
NORMAL_FONT = _wxPyStockCursor(StockGDI.FONT_NORMAL)
|
||||
SMALL_FONT = _wxPyStockCursor(StockGDI.FONT_SMALL)
|
||||
SWISS_FONT = _wxPyStockCursor(StockGDI.FONT_SWISS)
|
||||
|
||||
BLACK_DASHED_PEN = _wxPyStockPen(StockGDI.PEN_BLACKDASHED)
|
||||
BLACK_PEN = _wxPyStockPen(StockGDI.PEN_BLACK)
|
||||
CYAN_PEN = _wxPyStockPen(StockGDI.PEN_CYAN)
|
||||
GREEN_PEN = _wxPyStockPen(StockGDI.PEN_GREEN)
|
||||
GREY_PEN = _wxPyStockPen(StockGDI.PEN_GREY)
|
||||
LIGHT_GREY_PEN = _wxPyStockPen(StockGDI.PEN_LIGHTGREY)
|
||||
MEDIUM_GREY_PEN = _wxPyStockPen(StockGDI.PEN_MEDIUMGREY)
|
||||
RED_PEN = _wxPyStockPen(StockGDI.PEN_RED)
|
||||
TRANSPARENT_PEN = _wxPyStockPen(StockGDI.PEN_TRANSPARENT)
|
||||
WHITE_PEN = _wxPyStockPen(StockGDI.PEN_WHITE)
|
||||
|
||||
BLACK_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_BLACK)
|
||||
BLUE_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_BLUE)
|
||||
CYAN_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_CYAN)
|
||||
GREEN_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_GREEN)
|
||||
GREY_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_GREY)
|
||||
LIGHT_GREY_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_LIGHTGREY)
|
||||
MEDIUM_GREY_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_MEDIUMGREY)
|
||||
RED_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_RED)
|
||||
TRANSPARENT_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_TRANSPARENT)
|
||||
WHITE_BRUSH = _wxPyStockBrush(StockGDI.BRUSH_WHITE)
|
||||
|
||||
BLACK = _wxPyStockColour(StockGDI.COLOUR_BLACK)
|
||||
BLUE = _wxPyStockColour(StockGDI.COLOUR_BLUE)
|
||||
CYAN = _wxPyStockColour(StockGDI.COLOUR_CYAN)
|
||||
GREEN = _wxPyStockColour(StockGDI.COLOUR_GREEN)
|
||||
LIGHT_GREY = _wxPyStockColour(StockGDI.COLOUR_LIGHTGREY)
|
||||
RED = _wxPyStockColour(StockGDI.COLOUR_RED)
|
||||
WHITE = _wxPyStockColour(StockGDI.COLOUR_WHITE)
|
||||
|
||||
CROSS_CURSOR = _wxPyStockCursor(StockGDI.CURSOR_CROSS)
|
||||
HOURGLASS_CURSOR = _wxPyStockCursor(StockGDI.CURSOR_HOURGLASS)
|
||||
STANDARD_CURSOR = _wxPyStockCursor(StockGDI.CURSOR_STANDARD)
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
%immutable;
|
||||
%threadWrapperOff;
|
||||
|
||||
wxFont* const wxNORMAL_FONT;
|
||||
wxFont* const wxSMALL_FONT;
|
||||
wxFont* const wxITALIC_FONT;
|
||||
wxFont* const wxSWISS_FONT;
|
||||
|
||||
wxPen* const wxRED_PEN;
|
||||
wxPen* const wxCYAN_PEN;
|
||||
wxPen* const wxGREEN_PEN;
|
||||
wxPen* const wxBLACK_PEN;
|
||||
wxPen* const wxWHITE_PEN;
|
||||
wxPen* const wxTRANSPARENT_PEN;
|
||||
wxPen* const wxBLACK_DASHED_PEN;
|
||||
wxPen* const wxGREY_PEN;
|
||||
wxPen* const wxMEDIUM_GREY_PEN;
|
||||
wxPen* const wxLIGHT_GREY_PEN;
|
||||
|
||||
wxBrush* const wxBLUE_BRUSH;
|
||||
wxBrush* const wxGREEN_BRUSH;
|
||||
wxBrush* const wxWHITE_BRUSH;
|
||||
wxBrush* const wxBLACK_BRUSH;
|
||||
wxBrush* const wxTRANSPARENT_BRUSH;
|
||||
wxBrush* const wxCYAN_BRUSH;
|
||||
wxBrush* const wxRED_BRUSH;
|
||||
wxBrush* const wxGREY_BRUSH;
|
||||
wxBrush* const wxMEDIUM_GREY_BRUSH;
|
||||
wxBrush* const wxLIGHT_GREY_BRUSH;
|
||||
|
||||
wxColour* const wxBLACK;
|
||||
wxColour* const wxWHITE;
|
||||
wxColour* const wxRED;
|
||||
wxColour* const wxBLUE;
|
||||
wxColour* const wxGREEN;
|
||||
wxColour* const wxCYAN;
|
||||
wxColour* const wxLIGHT_GREY;
|
||||
|
||||
wxCursor* const wxSTANDARD_CURSOR;
|
||||
wxCursor* const wxHOURGLASS_CURSOR;
|
||||
wxCursor* const wxCROSS_CURSOR;
|
||||
|
||||
|
||||
const wxBitmap wxNullBitmap;
|
||||
const wxIcon wxNullIcon;
|
||||
const wxCursor wxNullCursor;
|
||||
@@ -74,36 +163,92 @@ const wxColour wxNullColour;
|
||||
%mutable;
|
||||
|
||||
|
||||
// %inline {
|
||||
// const wxBitmap& _wxPyInitNullBitmap() { return wxNullBitmap; }
|
||||
// const wxIcon& _wxPyInitNullIcon() { return wxNullIcon; }
|
||||
// const wxCursor& _wxPyInitNullCursor() { return wxNullCursor; }
|
||||
// const wxPen& _wxPyInitNullPen() { return wxNullPen; }
|
||||
// const wxBrush& _wxPyInitNullBrush() { return wxNullBrush; }
|
||||
// const wxPalette& _wxPyInitNullPalette() { return wxNullPalette; }
|
||||
// const wxFont& _wxPyInitNullFont() { return wxNullFont; }
|
||||
// const wxColour& _wxPyInitNullColour() { return wxNullColour; }
|
||||
// }
|
||||
|
||||
// %pythoncode {
|
||||
// NullBitmap = _wxPyMakeDelayedInitWrapper(_wxPyInitNullBitmap)()
|
||||
// NullIcon = _wxPyMakeDelayedInitWrapper(_wxPyInitNullIcon)()
|
||||
// NullCursor = _wxPyMakeDelayedInitWrapper(_wxPyInitNullCursor)()
|
||||
// NullPen = _wxPyMakeDelayedInitWrapper(_wxPyInitNullPen)()
|
||||
// NullBrush = _wxPyMakeDelayedInitWrapper(_wxPyInitNullBrush)()
|
||||
// NullPalette = _wxPyMakeDelayedInitWrapper(_wxPyInitNullPalette)()
|
||||
// NullFont = _wxPyMakeDelayedInitWrapper(_wxPyInitNullFont)()
|
||||
// NullColour = _wxPyMakeDelayedInitWrapper(_wxPyInitNullColour)()
|
||||
// }
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class wxPenList : public wxObject {
|
||||
|
||||
class wxGDIObjListBase {
|
||||
public:
|
||||
|
||||
void AddPen(wxPen* pen);
|
||||
wxPen* FindOrCreatePen(const wxColour& colour, int width, int style);
|
||||
void RemovePen(wxPen* pen);
|
||||
|
||||
int GetCount();
|
||||
wxGDIObjListBase();
|
||||
~wxGDIObjListBase();
|
||||
};
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class wxBrushList : public wxObject {
|
||||
class wxPenList : public wxGDIObjListBase {
|
||||
public:
|
||||
|
||||
void AddBrush(wxBrush *brush);
|
||||
wxBrush * FindOrCreateBrush(const wxColour& colour, int style=wxSOLID);
|
||||
void RemoveBrush(wxBrush *brush);
|
||||
wxPen* FindOrCreatePen(const wxColour& colour, int width, int style);
|
||||
|
||||
int GetCount();
|
||||
void AddPen(wxPen* pen);
|
||||
void RemovePen(wxPen* pen);
|
||||
%pythoncode {
|
||||
AddPen = wx._deprecated(AddPen)
|
||||
RemovePen = wx._deprecated(RemovePen)
|
||||
}
|
||||
// int GetCount();
|
||||
};
|
||||
|
||||
|
||||
class wxBrushList : public wxGDIObjListBase {
|
||||
public:
|
||||
|
||||
wxBrush * FindOrCreateBrush(const wxColour& colour, int style=wxSOLID);
|
||||
|
||||
void AddBrush(wxBrush *brush);
|
||||
void RemoveBrush(wxBrush *brush);
|
||||
%pythoncode {
|
||||
AddBrush = wx._deprecated(AddBrush)
|
||||
RemoveBrush = wx._deprecated(RemoveBrush)
|
||||
}
|
||||
// int GetCount();
|
||||
};
|
||||
|
||||
|
||||
class wxFontList : public wxGDIObjListBase {
|
||||
public:
|
||||
|
||||
wxFont * FindOrCreateFont(int point_size, int family, int style, int weight,
|
||||
bool underline = false,
|
||||
const wxString& facename = wxPyEmptyString,
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||
|
||||
void AddFont(wxFont* font);
|
||||
void RemoveFont(wxFont *font);
|
||||
%pythoncode {
|
||||
AddFont = wx._deprecated(AddFont)
|
||||
RemoveFont = wx._deprecated(RemoveFont)
|
||||
}
|
||||
|
||||
// int GetCount();
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
MustHaveApp(wxColourDatabase);
|
||||
|
||||
class wxColourDatabase : public wxObject {
|
||||
class wxColourDatabase {
|
||||
public:
|
||||
wxColourDatabase();
|
||||
~wxColourDatabase();
|
||||
@@ -123,35 +268,23 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
class wxFontList : public wxObject {
|
||||
public:
|
||||
|
||||
void AddFont(wxFont* font);
|
||||
wxFont * FindOrCreateFont(int point_size, int family, int style, int weight,
|
||||
bool underline = false, const wxString& facename = wxPyEmptyString,
|
||||
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
|
||||
void RemoveFont(wxFont *font);
|
||||
|
||||
int GetCount();
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
%newgroup
|
||||
|
||||
%inline {
|
||||
wxFontList* _wxPyInitTheFontList() { return wxTheFontList; }
|
||||
wxPenList* _wxPyInitThePenList() { return wxThePenList; }
|
||||
wxBrushList* _wxPyInitTheBrushList() { return wxTheBrushList; }
|
||||
wxColourDatabase* _wxPyInitTheColourDatabase() { return wxTheColourDatabase; }
|
||||
}
|
||||
|
||||
|
||||
// See also wxPy_ReinitStockObjects in helpers.cpp
|
||||
%immutable;
|
||||
|
||||
wxFontList* const wxTheFontList;
|
||||
wxPenList* const wxThePenList;
|
||||
wxBrushList* const wxTheBrushList;
|
||||
wxColourDatabase* const wxTheColourDatabase;
|
||||
|
||||
%mutable;
|
||||
|
||||
%pythoncode {
|
||||
wxTheFontList = _wxPyMakeDelayedInitWrapper(_wxPyInitTheFontList)()
|
||||
wxThePenList = _wxPyMakeDelayedInitWrapper(_wxPyInitThePenList)()
|
||||
wxTheBrushList = _wxPyMakeDelayedInitWrapper(_wxPyInitTheBrushList)()
|
||||
wxTheColourDatabase = _wxPyMakeDelayedInitWrapper(_wxPyInitTheColourDatabase)()
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
Reference in New Issue
Block a user