A
andrea_gavana
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 wxFoldWindowItem
{
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
wxFoldWindowItem(wxWindow *wnd, int flags = wxFPB_ALIGN_WIDTH, int ySpacing
= wxFPB_DEFAULT_YSPACING,
int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, int rightSpacing
= wxFPB_DEFAULT_RIGHTSPACING)
: _wnd(wnd)
, _type(WINDOW)
, _flags(flags)
, _leftSpacing(leftSpacing)
, _rightSpacing(rightSpacing)
, _ySpacing(ySpacing)
, _lineWidth(0)
, _lineY(0)
{
};
// separator constructor. This initialises the class as a separator
type
wxFoldWindowItem(int y, const wxColour &lineColor = *wxBLACK, int ySpacing
= wxFPB_DEFAULT_YSPACING,
int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING,
int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING)
: _wnd(0)
, _type(SEPARATOR)
, _flags(wxFPB_ALIGN_WIDTH)
, _leftSpacing(leftSpacing)
, _rightSpacing(rightSpacing)
, _ySpacing(ySpacing)
, _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
"initializations".
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 "constructors" 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 wxFoldWindowItem
{
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
wxFoldWindowItem(wxWindow *wnd, int flags = wxFPB_ALIGN_WIDTH, int ySpacing
= wxFPB_DEFAULT_YSPACING,
int leftSpacing = wxFPB_DEFAULT_LEFTSPACING, int rightSpacing
= wxFPB_DEFAULT_RIGHTSPACING)
: _wnd(wnd)
, _type(WINDOW)
, _flags(flags)
, _leftSpacing(leftSpacing)
, _rightSpacing(rightSpacing)
, _ySpacing(ySpacing)
, _lineWidth(0)
, _lineY(0)
{
};
// separator constructor. This initialises the class as a separator
type
wxFoldWindowItem(int y, const wxColour &lineColor = *wxBLACK, int ySpacing
= wxFPB_DEFAULT_YSPACING,
int leftSpacing = wxFPB_DEFAULT_LEFTLINESPACING,
int rightSpacing = wxFPB_DEFAULT_RIGHTLINESPACING)
: _wnd(0)
, _type(SEPARATOR)
, _flags(wxFPB_ALIGN_WIDTH)
, _leftSpacing(leftSpacing)
, _rightSpacing(rightSpacing)
, _ySpacing(ySpacing)
, _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
"initializations".
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 "constructors" 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.