Added wxPyWindow and wxPyControl which are just like their wx

counterparts except they allow some of the more common C++ virtual
methods to be overridden in Python derived classes.

Changed wxGenButton to derive from wxPyControl.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15760 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2002-06-06 17:37:38 +00:00
parent f8305cafb5
commit b0e5c03934
8 changed files with 2129 additions and 103 deletions

View File

@ -94,6 +94,34 @@ the image data. (Patch #546009)
Added a sample that shows how to embed wxPython in a wxWindows C++
application.
Added wxPyWindow and wxPyControl which are just like their wx
counterparts except they allow some of the more common C++ virtual
methods to be overridden in Python derived classes. The methods
supported are:
DoMoveWindow
DoSetSize
DoSetClientSize
DoSetVirtualSize
DoGetSize
DoGetClientSize
DoGetPosition
DoGetVirtualSize
DoGetBestSize
InitDialog
TransferDataFromWindow
TransferDataToWindow
Validate
AcceptsFocus
AcceptsFocusFromKeyboard
GetMaxSize
If there are other methods that should be supported please let me
know.
Changed wxGenButton to derive from wxPyControl and overload
DoGetBestSize and AcceptsFocus.
2.3.2.1

View File

@ -11,35 +11,42 @@ class TestPanel(wxPanel):
wxPanel.__init__(self, parent, -1)
self.log = log
b = wxButton(self, -1, "A real button", (10,10))
sizer = wxFlexGridSizer(1, 3, 20, 20)
b = wxButton(self, -1, "A real button")
b.SetDefault()
EVT_BUTTON(self, b.GetId(), self.OnButton)
b = wxButton(self, -1, "non-default", (140, 10))
EVT_BUTTON(self, b.GetId(), self.OnButton)
#wxTextCtrl(self, -1, "", (10,40))
sizer.Add(b)
b = wxGenButton(self, -1, 'Hello', (10,65))
b = wxButton(self, -1, "non-default")
EVT_BUTTON(self, b.GetId(), self.OnButton)
b = wxGenButton(self, -1, 'disabled', (140,65))
sizer.Add(b)
sizer.Add(10,10)
b = wxGenButton(self, -1, 'Hello')
EVT_BUTTON(self, b.GetId(), self.OnButton)
sizer.Add(b)
b = wxGenButton(self, -1, 'disabled')
EVT_BUTTON(self, b.GetId(), self.OnButton)
b.Enable(false)
sizer.Add(b)
b = wxGenButton(self, -1, 'bigger', (250,50))
EVT_BUTTON(self, b.GetId(), self.OnButton)
b = wxGenButton(self, -1, 'bigger')
EVT_BUTTON(self, b.GetId(), self.OnBiggerButton)
b.SetFont(wxFont(20, wxSWISS, wxNORMAL, wxBOLD, false))
b.SetBezelWidth(5)
b.SetBestSize()
b.SetBackgroundColour(wxNamedColour("Navy"))
###b.SetBestSize()
b.SetBackgroundColour("Navy")
b.SetForegroundColour(wxWHITE)
#b.SetUseFocusIndicator(false)
b.SetToolTipString("This is a BIG button...")
sizer.Add(b, flag=wxADJUST_MINSIZE) # let the sizer set best size
bmp = images.getTest2Bitmap()
b = wxGenBitmapButton(self, -1, bmp, (10, 130))
b = wxGenBitmapButton(self, -1, bmp)
EVT_BUTTON(self, b.GetId(), self.OnButton)
sizer.Add(b)
b = wxGenBitmapButton(self, -1, None, (140, 130))
b = wxGenBitmapButton(self, -1, None)
EVT_BUTTON(self, b.GetId(), self.OnButton)
bmp = images.getBulb1Bitmap()
mask = wxMaskColour(bmp, wxBLUE)
@ -50,12 +57,14 @@ class TestPanel(wxPanel):
bmp.SetMask(mask)
b.SetBitmapSelected(bmp)
b.SetBestSize()
sizer.Add(b)
sizer.Add(10,10)
b = wxGenToggleButton(self, -1, "Toggle Button", (10, 230))
b = wxGenToggleButton(self, -1, "Toggle Button")
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
sizer.Add(b)
b = wxGenBitmapToggleButton(self, -1, None, (140, 230))
b = wxGenBitmapToggleButton(self, -1, None)
EVT_BUTTON(self, b.GetId(), self.OnToggleButton)
bmp = images.getBulb1Bitmap()
mask = wxMaskColour(bmp, wxBLUE)
@ -67,8 +76,9 @@ class TestPanel(wxPanel):
b.SetBitmapSelected(bmp)
b.SetToggle(true)
b.SetBestSize()
sizer.Add(b)
b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", (220, 230), size = (200, 45))
b = wxGenBitmapTextButton(self, -1, None, "Bitmapped Text", size = (200, 45))
EVT_BUTTON(self, b.GetId(), self.OnButton)
bmp = images.getBulb1Bitmap()
mask = wxMaskColour(bmp, wxBLUE)
@ -80,11 +90,25 @@ class TestPanel(wxPanel):
b.SetBitmapSelected(bmp)
b.SetUseFocusIndicator(false)
b.SetBestSize()
sizer.Add(b)
border = wxBoxSizer(wxVERTICAL)
border.Add(sizer, 0, wxALL, 25)
self.SetSizer(border)
def OnButton(self, event):
self.log.WriteText("Button Clicked: %d\n" % event.GetId())
def OnBiggerButton(self, event):
self.log.WriteText("Bigger Button Clicked: %d\n" % event.GetId())
b = event.GetEventObject()
txt = "big " + b.GetLabel()
b.SetLabel(txt)
self.GetSizer().Layout()
def OnToggleButton(self, event):
msg = (event.GetIsDown() and "on") or "off"
self.log.WriteText("Button %d Toggled: %s\n" % (event.GetId(), msg))

View File

@ -92,12 +92,12 @@ public:
//
wxControl(wxWindow *parent,
wxWindowID id,
const wxPoint& pos=wxDefaultPosition,
const wxSize& size=wxDefaultSize,
long style=0,
const wxValidator& validator=wxDefaultValidator,
const wxString& name=wxPyControlNameStr);
wxWindowID id,
const wxPoint& pos=wxDefaultPosition,
const wxSize& size=wxDefaultSize,
long style=0,
const wxValidator& validator=wxDefaultValidator,
const wxString& name=wxPyControlNameStr);
//
%name(wxPreControl)wxControl();

View File

@ -453,10 +453,10 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
#define IMP_PYCALLBACK_VOID_INTINT(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int a, int b) { \
bool found; \
wxPyBeginBlockThreads(); \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(ii)",a,b)); \
wxPyEndBlockThreads(); \
wxPyEndBlockThreads(); \
if (! found) \
PCLASS::CBNAME(a,b); \
} \
@ -466,6 +466,133 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_VOID_INT4(CBNAME) \
void CBNAME(int a, int b, int c, int d); \
void base_##CBNAME(int a, int b, int c, int d);
#define IMP_PYCALLBACK_VOID_INT4(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int a, int b, int c, int d) { \
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiii)",a,b,c,d)); \
wxPyEndBlockThreads(); \
if (! found) \
PCLASS::CBNAME(a,b,c,d); \
} \
void CLASS::base_##CBNAME(int a, int b, int c, int d) { \
PCLASS::CBNAME(a,b,c,d); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_VOID_INT5(CBNAME) \
void CBNAME(int a, int b, int c, int d, int e); \
void base_##CBNAME(int a, int b, int c, int d, int e);
#define IMP_PYCALLBACK_VOID_INT5(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int a, int b, int c, int d, int e) { \
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
wxPyCBH_callCallback(m_myInst, Py_BuildValue("(iiiii)",a,b,c,d,e)); \
wxPyEndBlockThreads(); \
if (! found) \
PCLASS::CBNAME(a,b,c,d,e); \
} \
void CLASS::base_##CBNAME(int a, int b, int c, int d, int e) { \
PCLASS::CBNAME(a,b,c,d,e); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_VOID_INTPINTP_const(CBNAME) \
void CBNAME(int* a, int* b) const; \
void base_##CBNAME(int* a, int* b) const;
#define IMP_PYCALLBACK_VOID_INTPINTP_const(CLASS, PCLASS, CBNAME) \
void CLASS::CBNAME(int* a, int* b) const { \
const char* errmsg = #CBNAME " should return a 2-tuple of integers."; \
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* ro; \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
if (ro) { \
if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
PyObject* o1 = PySequence_GetItem(ro, 0); \
PyObject* o2 = PySequence_GetItem(ro, 1); \
if (PyNumber_Check(o1) && PyNumber_Check(o2)) { \
*a = PyInt_AsLong(o1); *b = PyInt_AsLong(o2); \
} \
else \
PyErr_SetString(PyExc_TypeError, errmsg); \
Py_DECREF(o1); \
Py_DECREF(o2); \
} \
else { \
PyErr_SetString(PyExc_TypeError, errmsg); \
} \
Py_DECREF(ro); \
} \
} \
wxPyEndBlockThreads(); \
if (! found) \
PCLASS::CBNAME(a,b); \
} \
void CLASS::base_##CBNAME(int* a, int* b) const { \
PCLASS::CBNAME(a,b); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_SIZE_const(CBNAME) \
wxSize CBNAME() const; \
wxSize base_##CBNAME() const;
#define IMP_PYCALLBACK_SIZE_const(CLASS, PCLASS, CBNAME) \
wxSize CLASS::CBNAME() const { \
const char* errmsg = #CBNAME " should return a 2-tuple of integers."; \
bool found; wxSize rval(0,0); \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) { \
PyObject* ro; \
ro = wxPyCBH_callCallbackObj(m_myInst, Py_BuildValue("()")); \
if (ro) { \
if (PySequence_Check(ro) && PyObject_Length(ro) == 2) { \
PyObject* o1 = PySequence_GetItem(ro, 0); \
PyObject* o2 = PySequence_GetItem(ro, 1); \
if (PyNumber_Check(o1) && PyNumber_Check(o2)) { \
rval = wxSize(PyInt_AsLong(o1), PyInt_AsLong(o2)); \
} \
else \
PyErr_SetString(PyExc_TypeError, errmsg); \
Py_DECREF(o1); \
Py_DECREF(o2); \
} \
else { \
PyErr_SetString(PyExc_TypeError, errmsg); \
} \
Py_DECREF(ro); \
} \
} \
wxPyEndBlockThreads(); \
if (! found) \
return PCLASS::CBNAME(); \
else \
return rval; \
} \
wxSize CLASS::base_##CBNAME() const { \
return PCLASS::CBNAME(); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_BOOL_INT(CBNAME) \
bool CBNAME(int a); \
bool base_##CBNAME(int a);
@ -474,10 +601,10 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
#define IMP_PYCALLBACK_BOOL_INT(CLASS, PCLASS, CBNAME) \
bool CLASS::CBNAME(int a) { \
bool rval=FALSE, found; \
wxPyBeginBlockThreads(); \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("(i)",a));\
wxPyEndBlockThreads(); \
wxPyEndBlockThreads(); \
if (! found) \
rval = PCLASS::CBNAME(a); \
return rval; \
@ -1165,10 +1292,10 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
bool CLASS::CBNAME() { \
bool rval=FALSE; \
bool found; \
wxPyBeginBlockThreads(); \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
wxPyEndBlockThreads(); \
wxPyEndBlockThreads(); \
if (! found) \
rval = PCLASS::CBNAME(); \
return rval; \
@ -1179,6 +1306,29 @@ void wxPyCBH_delete(wxPyCallbackHelper* cbh);
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_BOOL_const(CBNAME) \
bool CBNAME() const; \
bool base_##CBNAME() const;
#define IMP_PYCALLBACK_BOOL_const(CLASS, PCLASS, CBNAME) \
bool CLASS::CBNAME() const { \
bool rval=FALSE; \
bool found; \
wxPyBeginBlockThreads(); \
if ((found = wxPyCBH_findCallback(m_myInst, #CBNAME))) \
rval = wxPyCBH_callCallback(m_myInst, Py_BuildValue("()")); \
wxPyEndBlockThreads(); \
if (! found) \
rval = PCLASS::CBNAME(); \
return rval; \
} \
bool CLASS::base_##CBNAME() const { \
return PCLASS::CBNAME(); \
}
//---------------------------------------------------------------------------
#define DEC_PYCALLBACK_DR_2WXCDR(CBNAME) \
wxDragResult CBNAME(wxCoord x, wxCoord y, wxDragResult def); \
wxDragResult base_##CBNAME(wxCoord x, wxCoord y, wxDragResult def);

File diff suppressed because it is too large Load Diff

View File

@ -284,6 +284,146 @@ class wxTaskBarIcon(wxTaskBarIconPtr):
class wxPyWindowPtr(wxWindowPtr):
def __init__(self,this):
self.this = this
self.thisown = 0
def _setCallbackInfo(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow__setCallbackInfo,(self,) + _args, _kwargs)
return val
def base_DoMoveWindow(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoMoveWindow,(self,) + _args, _kwargs)
return val
def base_DoSetSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoSetSize,(self,) + _args, _kwargs)
return val
def base_DoSetClientSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoSetClientSize,(self,) + _args, _kwargs)
return val
def base_DoSetVirtualSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoSetVirtualSize,(self,) + _args, _kwargs)
return val
def base_DoGetSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoGetSize,(self,) + _args, _kwargs)
return val
def base_DoGetClientSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoGetClientSize,(self,) + _args, _kwargs)
return val
def base_DoGetPosition(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoGetPosition,(self,) + _args, _kwargs)
return val
def base_DoGetVirtualSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoGetVirtualSize,(self,) + _args, _kwargs)
if val: val = wxSizePtr(val) ; val.thisown = 1
return val
def base_DoGetBestSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_DoGetBestSize,(self,) + _args, _kwargs)
if val: val = wxSizePtr(val) ; val.thisown = 1
return val
def base_InitDialog(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_InitDialog,(self,) + _args, _kwargs)
return val
def base_TransferDataToWindow(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_TransferDataToWindow,(self,) + _args, _kwargs)
return val
def base_TransferDataFromWindow(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_TransferDataFromWindow,(self,) + _args, _kwargs)
return val
def base_Validate(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_Validate,(self,) + _args, _kwargs)
return val
def base_AcceptsFocus(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_AcceptsFocus,(self,) + _args, _kwargs)
return val
def base_AcceptsFocusFromKeyboard(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_AcceptsFocusFromKeyboard,(self,) + _args, _kwargs)
return val
def base_GetMaxSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyWindow_base_GetMaxSize,(self,) + _args, _kwargs)
if val: val = wxSizePtr(val) ; val.thisown = 1
return val
def __repr__(self):
return "<C wxPyWindow instance at %s>" % (self.this,)
class wxPyWindow(wxPyWindowPtr):
def __init__(self,*_args,**_kwargs):
self.this = apply(windows2c.new_wxPyWindow,_args,_kwargs)
self.thisown = 1
self._setCallbackInfo(self, wxPyWindow)
self._setOORInfo(self)
class wxPyControlPtr(wxControlPtr):
def __init__(self,this):
self.this = this
self.thisown = 0
def _setCallbackInfo(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl__setCallbackInfo,(self,) + _args, _kwargs)
return val
def base_DoMoveWindow(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoMoveWindow,(self,) + _args, _kwargs)
return val
def base_DoSetSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoSetSize,(self,) + _args, _kwargs)
return val
def base_DoSetClientSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoSetClientSize,(self,) + _args, _kwargs)
return val
def base_DoSetVirtualSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoSetVirtualSize,(self,) + _args, _kwargs)
return val
def base_DoGetSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoGetSize,(self,) + _args, _kwargs)
return val
def base_DoGetClientSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoGetClientSize,(self,) + _args, _kwargs)
return val
def base_DoGetPosition(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoGetPosition,(self,) + _args, _kwargs)
return val
def base_DoGetVirtualSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoGetVirtualSize,(self,) + _args, _kwargs)
if val: val = wxSizePtr(val) ; val.thisown = 1
return val
def base_DoGetBestSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_DoGetBestSize,(self,) + _args, _kwargs)
if val: val = wxSizePtr(val) ; val.thisown = 1
return val
def base_InitDialog(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_InitDialog,(self,) + _args, _kwargs)
return val
def base_TransferDataToWindow(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_TransferDataToWindow,(self,) + _args, _kwargs)
return val
def base_TransferDataFromWindow(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_TransferDataFromWindow,(self,) + _args, _kwargs)
return val
def base_Validate(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_Validate,(self,) + _args, _kwargs)
return val
def base_AcceptsFocus(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_AcceptsFocus,(self,) + _args, _kwargs)
return val
def base_AcceptsFocusFromKeyboard(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_AcceptsFocusFromKeyboard,(self,) + _args, _kwargs)
return val
def base_GetMaxSize(self, *_args, **_kwargs):
val = apply(windows2c.wxPyControl_base_GetMaxSize,(self,) + _args, _kwargs)
if val: val = wxSizePtr(val) ; val.thisown = 1
return val
def __repr__(self):
return "<C wxPyControl instance at %s>" % (self.this,)
class wxPyControl(wxPyControlPtr):
def __init__(self,*_args,**_kwargs):
self.this = apply(windows2c.new_wxPyControl,_args,_kwargs)
self.thisown = 1
self._setCallbackInfo(self, wxPyControl)
self._setOORInfo(self)
#-------------- FUNCTION WRAPPERS ------------------

View File

@ -31,6 +31,7 @@
// Put some wx default wxChar* values into wxStrings.
DECLARE_DEF_STRING(NOTEBOOK_NAME);
DECLARE_DEF_STRING(PanelNameStr);
DECLARE_DEF_STRING(ControlNameStr);
static const wxChar* wxSplitterNameStr = wxT("splitter");
DECLARE_DEF_STRING(SplitterNameStr);
@ -304,69 +305,241 @@ public:
// wxPyWindow derives from wxWindow and adds support for overriding many of
// the virtual methods in Python derived classes.
// Do wxPyControl too.
// %{
// class wxPyWindow : public wxWindow
// {
// DECLARE_DYNAMIC_CLASS(wxPyWindow)
// public:
// wxPyWindow(wxWindow* parent, const wxWindowID id,
// const wxPoint& pos = wxDefaultPosition,
// const wxSize& size = wxDefaultSize,
// long style = 0,
// const wxString& name = wxPyPanelNameStr)
// : wxWindow(parent, id, pos, size, style, name) {}
// // Which of these should be done???
// DoSetSize
// DoGetSize
// DoSetClientSize
// DoGetClientSize
// DoGetPosition
// DoSetVirtualSize
// DoGetVirtualSize
// GetClientAreaOrigin
// Fit
// SetSizeHints
// SetVirtualSizeHints
// GetMaxSize
// Show
// Enable
// SetFocus
// SetFocusFromKbd
// AcceptsFocus
// AcceptsFocusFromKeyboard
// GetDefaultItem
// SetDefaultItem
// IsTopLevel
// Which of these should be done???
// AddChild
// RemoveChild
// Validate
// TransferDataToWindow
// TransferDataFromWindow
// InitDialog
// SetBackgroundColour
// SetForegroundColour
// Destroy
// DoCaptureMouse
// DoClientToScreen
// DoHitTest
// DoMoveWindow
// DoPopupMenu
// DoReleaseMouse
// DoScreenToClient
// DoSetToolTip
// Enable
// Fit
// GetCharHeight
// GetCharWidth
// DoClientToScreen
// DoScreenToClient
// DoHitTest
// DoPopupMenu
// DoSetToolTip
// DoCaptureMouse
// DoReleaseMouse
// DoMoveWindow
// GetClientAreaOrigin
// GetDefaultItem
// IsTopLevel
// RemoveChild
// SetBackgroundColour
// SetDefaultItem
// SetFocus
// SetFocusFromKbd
// SetForegroundColour
// SetSizeHints
// SetVirtualSizeHints
// Show
// PYPRIVATE;
// };
%{ // C++ version of Python aware wxWindow
class wxPyWindow : public wxWindow
{
DECLARE_DYNAMIC_CLASS(wxPyWindow)
public:
wxPyWindow() : wxWindow() {}
wxPyWindow(wxWindow* parent, const wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxPyPanelNameStr)
: wxWindow(parent, id, pos, size, style, name) {}
// %}
DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
DEC_PYCALLBACK_VOID_INT5(DoSetSize);
DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
DEC_PYCALLBACK__(InitDialog);
DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
DEC_PYCALLBACK_BOOL_(Validate);
DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
DEC_PYCALLBACK_SIZE_const(GetMaxSize);
PYPRIVATE;
};
IMPLEMENT_DYNAMIC_CLASS(wxPyWindow, wxWindow);
IMP_PYCALLBACK_VOID_INT4(wxPyWindow, wxWindow, DoMoveWindow);
IMP_PYCALLBACK_VOID_INT5(wxPyWindow, wxWindow, DoSetSize);
IMP_PYCALLBACK_VOID_INTINT(wxPyWindow, wxWindow, DoSetClientSize);
IMP_PYCALLBACK_VOID_INTINT(wxPyWindow, wxWindow, DoSetVirtualSize);
IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWindow, wxWindow, DoGetSize);
IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWindow, wxWindow, DoGetClientSize);
IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyWindow, wxWindow, DoGetPosition);
IMP_PYCALLBACK_SIZE_const(wxPyWindow, wxWindow, DoGetVirtualSize);
IMP_PYCALLBACK_SIZE_const(wxPyWindow, wxWindow, DoGetBestSize);
IMP_PYCALLBACK__(wxPyWindow, wxWindow, InitDialog);
IMP_PYCALLBACK_BOOL_(wxPyWindow, wxWindow, TransferDataFromWindow);
IMP_PYCALLBACK_BOOL_(wxPyWindow, wxWindow, TransferDataToWindow);
IMP_PYCALLBACK_BOOL_(wxPyWindow, wxWindow, Validate);
IMP_PYCALLBACK_BOOL_const(wxPyWindow, wxWindow, AcceptsFocus);
IMP_PYCALLBACK_BOOL_const(wxPyWindow, wxWindow, AcceptsFocusFromKeyboard);
IMP_PYCALLBACK_SIZE_const(wxPyWindow, wxWindow, GetMaxSize);
%}
// And now the one for SWIG to see
class wxPyWindow : public wxWindow
{
public:
wxPyWindow(wxWindow* parent, const wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxString& name = wxPyPanelNameStr);
void _setCallbackInfo(PyObject* self, PyObject* _class);
%pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyWindow)"
%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
void base_DoMoveWindow(int x, int y, int width, int height);
void base_DoSetSize(int x, int y, int width, int height,
int sizeFlags = wxSIZE_AUTO);
void base_DoSetClientSize(int width, int height);
void base_DoSetVirtualSize( int x, int y );
void base_DoGetSize( int *OUTPUT, int *OUTPUT ) const;
void base_DoGetClientSize( int *OUTPUT, int *OUTPUT ) const;
void base_DoGetPosition( int *OUTPUT, int *OUTPUT ) const;
wxSize base_DoGetVirtualSize() const;
wxSize base_DoGetBestSize() const;
void base_InitDialog();
bool base_TransferDataToWindow();
bool base_TransferDataFromWindow();
bool base_Validate();
bool base_AcceptsFocus() const;
bool base_AcceptsFocusFromKeyboard() const;
wxSize base_GetMaxSize() const;
}
//---------------------------------------------------------------------------
// Do the same thing for wxControl
%{ // C++ version of Python aware wxControl
class wxPyControl : public wxControl
{
DECLARE_DYNAMIC_CLASS(wxPyControl)
public:
wxPyControl() : wxControl() {}
wxPyControl(wxWindow* parent, const wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator=wxDefaultValidator,
const wxString& name = wxPyControlNameStr)
: wxControl(parent, id, pos, size, style, validator, name) {}
DEC_PYCALLBACK_VOID_INT4(DoMoveWindow);
DEC_PYCALLBACK_VOID_INT5(DoSetSize);
DEC_PYCALLBACK_VOID_INTINT(DoSetClientSize);
DEC_PYCALLBACK_VOID_INTINT(DoSetVirtualSize);
DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetSize);
DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetClientSize);
DEC_PYCALLBACK_VOID_INTPINTP_const(DoGetPosition);
DEC_PYCALLBACK_SIZE_const(DoGetVirtualSize);
DEC_PYCALLBACK_SIZE_const(DoGetBestSize);
DEC_PYCALLBACK__(InitDialog);
DEC_PYCALLBACK_BOOL_(TransferDataFromWindow);
DEC_PYCALLBACK_BOOL_(TransferDataToWindow);
DEC_PYCALLBACK_BOOL_(Validate);
DEC_PYCALLBACK_BOOL_const(AcceptsFocus);
DEC_PYCALLBACK_BOOL_const(AcceptsFocusFromKeyboard);
DEC_PYCALLBACK_SIZE_const(GetMaxSize);
PYPRIVATE;
};
IMPLEMENT_DYNAMIC_CLASS(wxPyControl, wxControl);
IMP_PYCALLBACK_VOID_INT4(wxPyControl, wxControl, DoMoveWindow);
IMP_PYCALLBACK_VOID_INT5(wxPyControl, wxControl, DoSetSize);
IMP_PYCALLBACK_VOID_INTINT(wxPyControl, wxControl, DoSetClientSize);
IMP_PYCALLBACK_VOID_INTINT(wxPyControl, wxControl, DoSetVirtualSize);
IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyControl, wxControl, DoGetSize);
IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyControl, wxControl, DoGetClientSize);
IMP_PYCALLBACK_VOID_INTPINTP_const(wxPyControl, wxControl, DoGetPosition);
IMP_PYCALLBACK_SIZE_const(wxPyControl, wxControl, DoGetVirtualSize);
IMP_PYCALLBACK_SIZE_const(wxPyControl, wxControl, DoGetBestSize);
IMP_PYCALLBACK__(wxPyControl, wxControl, InitDialog);
IMP_PYCALLBACK_BOOL_(wxPyControl, wxControl, TransferDataFromWindow);
IMP_PYCALLBACK_BOOL_(wxPyControl, wxControl, TransferDataToWindow);
IMP_PYCALLBACK_BOOL_(wxPyControl, wxControl, Validate);
IMP_PYCALLBACK_BOOL_const(wxPyControl, wxControl, AcceptsFocus);
IMP_PYCALLBACK_BOOL_const(wxPyControl, wxControl, AcceptsFocusFromKeyboard);
IMP_PYCALLBACK_SIZE_const(wxPyControl, wxControl, GetMaxSize);
%}
// And now the one for SWIG to see
class wxPyControl : public wxControl
{
public:
wxPyControl(wxWindow* parent, const wxWindowID id,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = 0,
const wxValidator& validator=wxDefaultValidator,
const wxString& name = wxPyControlNameStr);
void _setCallbackInfo(PyObject* self, PyObject* _class);
%pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPyControl)"
%pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
void base_DoMoveWindow(int x, int y, int width, int height);
void base_DoSetSize(int x, int y, int width, int height,
int sizeFlags = wxSIZE_AUTO);
void base_DoSetClientSize(int width, int height);
void base_DoSetVirtualSize( int x, int y );
void base_DoGetSize( int *OUTPUT, int *OUTPUT ) const;
void base_DoGetClientSize( int *OUTPUT, int *OUTPUT ) const;
void base_DoGetPosition( int *OUTPUT, int *OUTPUT ) const;
wxSize base_DoGetVirtualSize() const;
wxSize base_DoGetBestSize() const;
void base_InitDialog();
bool base_TransferDataToWindow();
bool base_TransferDataFromWindow();
bool base_Validate();
bool base_AcceptsFocus() const;
bool base_AcceptsFocusFromKeyboard() const;
wxSize base_GetMaxSize() const;
}
//---------------------------------------------------------------------------

View File

@ -52,7 +52,7 @@ class wxGenButtonEvent(wxPyCommandEvent):
#----------------------------------------------------------------------
class wxGenButton(wxControl):
class wxGenButton(wxPyControl):
labelDelta = 1
def __init__(self, parent, ID, label,
@ -61,7 +61,7 @@ class wxGenButton(wxControl):
name = "genbutton"):
if style == 0:
style = wxNO_BORDER
wxControl.__init__(self, parent, ID, pos, size, style, validator, name)
wxPyControl.__init__(self, parent, ID, pos, size, style, validator, name)
self.up = true
self.bezelWidth = 2
@ -79,6 +79,7 @@ class wxGenButton(wxControl):
EVT_LEFT_DOWN(self, self.OnLeftDown)
EVT_LEFT_UP(self, self.OnLeftUp)
EVT_LEFT_DCLICK(self, self.OnLeftDown)
EVT_MOTION(self, self.OnMotion)
EVT_SET_FOCUS(self, self.OnGainFocus)
EVT_KILL_FOCUS(self, self.OnLoseFocus)
@ -97,27 +98,38 @@ class wxGenButton(wxControl):
size = wxSize(-1,-1)
if type(size) == type(()):
size = wxSize(size[0], size[1])
size = wxSize(size.width, size.height) # make a copy
# make a new size so we don't mess with the one passed in
size = wxSize(size.width, size.height)
w, h, useMin = self._GetLabelSize()
defSize = wxButton_GetDefaultSize()
best = self.GetBestSize()
if size.width == -1:
size.width = 12 + w
if useMin and size.width < defSize.width:
size.width = defSize.width
size.width = best.width
if size.height == -1:
size.height = 11 + h
if useMin and size.height < defSize.height:
size.height = defSize.height
size.width = size.width + self.bezelWidth - 1
size.height = size.height + self.bezelWidth - 1
size.height = best.height
self.SetSize(size)
def DoGetBestSize(self):
"""Overridden base class virtual. Determines the best size of the
button based on the label and bezel size."""
w, h, useMin = self._GetLabelSize()
defSize = wxButton_GetDefaultSize()
width = 12 + w
if useMin and width < defSize.width:
width = defSize.width
height = 11 + h
if useMin and height < defSize.height:
height = defSize.height
width = width + self.bezelWidth - 1
height = height + self.bezelWidth - 1
return (width, height)
def AcceptsFocus(self):
"""Overridden base class virtual."""
return self.IsShown() and self.IsEnabled()
def SetBezelWidth(self, width):
"""Set the width of the 3D effect"""
self.bezelWidth = width
@ -151,7 +163,8 @@ class wxGenButton(wxControl):
def SetBackgroundColour(self, colour):
wxControl.SetBackgroundColour(self, colour)
wxPyControl.SetBackgroundColour(self, colour)
colour = self.GetBackgroundColour()
# Calculate a new set of highlight and shadow colours based on
# the new background colour. Works okay if the colour is dark...
@ -174,6 +187,7 @@ class wxGenButton(wxControl):
evt = wxGenButtonEvent(wxEVT_COMMAND_BUTTON_CLICKED, self.GetId())
evt.SetIsDown(not self.up)
evt.SetButtonObj(self)
evt.SetEventObject(self)
self.GetEventHandler().ProcessEvent(evt)
@ -263,6 +277,7 @@ class wxGenButton(wxControl):
self.Refresh()
event.Skip()
def OnMotion(self, event):
if not self.IsEnabled():
return