Hello NG,
I am trying to port a useful class from wxWidgets (C++) to a pure Python/wxPython
implementation. In the C++ source code, a unique class is initialized with
2 different methods (???). This is what it seems to me. I have this declarations:
class wxFoldWindowIte m
{
private:
wxWindow *_wnd;
int _type, _flags;
int _leftSpacing,
_rightSpacing,
_ySpacing;
int _lineWidth, _lineY;
wxColour _sepLineColour;
public:
enum
{
WINDOW = 0,
SEPARATOR
};
// wxWindow constructor. This initialises the class as a wxWindow type
wxFoldWindowIte m(wxWindow *wnd, int flags = wxFPB_ALIGN_WID TH, int ySpacing
= wxFPB_DEFAULT_Y SPACING,
int leftSpacing = wxFPB_DEFAULT_L EFTSPACING, int rightSpacing
= wxFPB_DEFAULT_R IGHTSPACING)
: _wnd(wnd)
, _type(WINDOW)
, _flags(flags)
, _leftSpacing(le ftSpacing)
, _rightSpacing(r ightSpacing)
, _ySpacing(ySpac ing)
, _lineWidth(0)
, _lineY(0)
{
};
// separator constructor. This initialises the class as a separator
type
wxFoldWindowIte m(int y, const wxColour &lineColor = *wxBLACK, int ySpacing
= wxFPB_DEFAULT_Y SPACING,
int leftSpacing = wxFPB_DEFAULT_L EFTLINESPACING,
int rightSpacing = wxFPB_DEFAULT_R IGHTLINESPACING )
: _wnd(0)
, _type(SEPARATOR )
, _flags(wxFPB_AL IGN_WIDTH)
, _leftSpacing(le ftSpacing)
, _rightSpacing(r ightSpacing)
, _ySpacing(ySpac ing)
, _lineWidth(0)
, _lineY(y)
, _sepLineColour( lineColor)
{
};
The 2 different initializations refers to completely different objects (the
first one is a wx.Window, the second one is an horizontal line). Next, there
are a lot of functions that, depending on the variable _type, return properties
of the wx.Window or of the line. I would like to keep the same names for
classes/methods, so it would be useful to have the same class with 2 different
"initialization s".
Does anyone know if is there a way to achieve the same thing in Python/wxPython?
Someone else has talked about overloaded constructors, but I don't have
any idea on how to implement this kind of "constructo rs" in Python. Does
anyone have a small example of overloaded constructors in Python?
I have no idea... Or am I missing something obvious?
Thanks to you all.
Andrea.
I am trying to port a useful class from wxWidgets (C++) to a pure Python/wxPython
implementation. In the C++ source code, a unique class is initialized with
2 different methods (???). This is what it seems to me. I have this declarations:
class wxFoldWindowIte m
{
private:
wxWindow *_wnd;
int _type, _flags;
int _leftSpacing,
_rightSpacing,
_ySpacing;
int _lineWidth, _lineY;
wxColour _sepLineColour;
public:
enum
{
WINDOW = 0,
SEPARATOR
};
// wxWindow constructor. This initialises the class as a wxWindow type
wxFoldWindowIte m(wxWindow *wnd, int flags = wxFPB_ALIGN_WID TH, int ySpacing
= wxFPB_DEFAULT_Y SPACING,
int leftSpacing = wxFPB_DEFAULT_L EFTSPACING, int rightSpacing
= wxFPB_DEFAULT_R IGHTSPACING)
: _wnd(wnd)
, _type(WINDOW)
, _flags(flags)
, _leftSpacing(le ftSpacing)
, _rightSpacing(r ightSpacing)
, _ySpacing(ySpac ing)
, _lineWidth(0)
, _lineY(0)
{
};
// separator constructor. This initialises the class as a separator
type
wxFoldWindowIte m(int y, const wxColour &lineColor = *wxBLACK, int ySpacing
= wxFPB_DEFAULT_Y SPACING,
int leftSpacing = wxFPB_DEFAULT_L EFTLINESPACING,
int rightSpacing = wxFPB_DEFAULT_R IGHTLINESPACING )
: _wnd(0)
, _type(SEPARATOR )
, _flags(wxFPB_AL IGN_WIDTH)
, _leftSpacing(le ftSpacing)
, _rightSpacing(r ightSpacing)
, _ySpacing(ySpac ing)
, _lineWidth(0)
, _lineY(y)
, _sepLineColour( lineColor)
{
};
The 2 different initializations refers to completely different objects (the
first one is a wx.Window, the second one is an horizontal line). Next, there
are a lot of functions that, depending on the variable _type, return properties
of the wx.Window or of the line. I would like to keep the same names for
classes/methods, so it would be useful to have the same class with 2 different
"initialization s".
Does anyone know if is there a way to achieve the same thing in Python/wxPython?
Someone else has talked about overloaded constructors, but I don't have
any idea on how to implement this kind of "constructo rs" in Python. Does
anyone have a small example of overloaded constructors in Python?
I have no idea... Or am I missing something obvious?
Thanks to you all.
Andrea.
Comment