From d3bfec747ddf7b27e6f41f0117cd5cd6755fe021 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Tue, 9 Apr 2002 01:25:47 +0000 Subject: [PATCH] Some little additions to how wxBufferedDC is wrapped. SHow how to use the wxBufferedDC in the demo. Other demo tweaks git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15049 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/demo/template.py | 25 +++++++++++++++ wxPython/demo/wxFileHistory.py | 5 +-- wxPython/demo/wxScrolledWindow.py | 52 ++++++++++++++++++++++++------- wxPython/src/gdi.i | 13 ++++++++ wxPython/src/msw/gdi.cpp | 29 +++++++++++++++++ wxPython/src/msw/gdi.py | 5 +++ 6 files changed, 115 insertions(+), 14 deletions(-) create mode 100644 wxPython/demo/template.py diff --git a/wxPython/demo/template.py b/wxPython/demo/template.py new file mode 100644 index 0000000000..4ccfcd4c4b --- /dev/null +++ b/wxPython/demo/template.py @@ -0,0 +1,25 @@ + +from wxPython.wx import * + +#---------------------------------------------------------------------- + +class TestPanel(wxPanel): + def __init__(self, parent, log): + self.log = log + wxPanel.__init__(self, parent, -1) + +#---------------------------------------------------------------------- + +def runTest(frame, nb, log): + win = TestPanel(nb, log) + return win + +#---------------------------------------------------------------------- + + + +overview = """ +

Say something nice here

+ + +""" diff --git a/wxPython/demo/wxFileHistory.py b/wxPython/demo/wxFileHistory.py index bb90041bf7..9e0725705a 100644 --- a/wxPython/demo/wxFileHistory.py +++ b/wxPython/demo/wxFileHistory.py @@ -21,8 +21,9 @@ class TestPanel(wxPanel): box = wxBoxSizer(wxVERTICAL) # Make and layout the controls - bf = wxFont(14, wxSWISS, wxNORMAL, wxBOLD) - nf = wxFont(11, wxSWISS, wxNORMAL, wxNORMAL) + fs = self.GetFont().GetPointSize() + bf = wxFont(fs+4, wxSWISS, wxNORMAL, wxBOLD) + nf = wxFont(fs+2, wxSWISS, wxNORMAL, wxNORMAL) t = wxStaticText(self, -1, "wxFileHistory") t.SetFont(bf) diff --git a/wxPython/demo/wxScrolledWindow.py b/wxPython/demo/wxScrolledWindow.py index 76d83ee714..ad1fa7beca 100644 --- a/wxPython/demo/wxScrolledWindow.py +++ b/wxPython/demo/wxScrolledWindow.py @@ -3,6 +3,8 @@ from wxPython.wx import * import images +BUFFERED = 1 + #--------------------------------------------------------------------------- class MyCanvas(wxScrolledWindow): @@ -12,7 +14,9 @@ class MyCanvas(wxScrolledWindow): self.lines = [] self.maxWidth = 1000 self.maxHeight = 1000 - self.count = 0 + self.x = self.y = 0 + self.curLine = [] + self.drawing = false self.SetBackgroundColour("WHITE") EVT_LEFT_DOWN(self, self.OnLeftButtonEvent) @@ -28,6 +32,14 @@ class MyCanvas(wxScrolledWindow): self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20) + if BUFFERED: + # Initialize the buffer bitmap. No real DC is needed at this point. + self.buffer = wxEmptyBitmap(self.maxWidth, self.maxHeight) + dc = wxBufferedDC(None, self.buffer) + dc.SetBackground(wxBrush(self.GetBackgroundColour())) + dc.Clear() + self.DoDrawing(dc) + def getWidth(self): return self.maxWidth @@ -37,12 +49,18 @@ class MyCanvas(wxScrolledWindow): def OnPaint(self, event): - #self.count += 1 - #print self.count, "begin paint...", - dc = wxPaintDC(self) - self.PrepareDC(dc) - self.DoDrawing(dc) - #print "end paint" + if BUFFERED: + # Create a buffered paint DC. It will create the real + # wxPaintDC and then blit the bitmap to it when dc is + # deleted. Since we don't need to draw anything else + # here that's all there is to it. + dc = wxBufferedPaintDC(self, self.buffer) + else: + dc = wxPaintDC(self) + self.PrepareDC(dc) + # since we're not buffering in this case, we have to + # paint the whole window, potentially very time consuming. + self.DoDrawing(dc) def DoDrawing(self, dc): @@ -107,7 +125,6 @@ class MyCanvas(wxScrolledWindow): dc.SetPen(old_pen) dc.DrawRectangle(490, 90, 20, 20) - self.DrawSavedLines(dc) dc.EndDrawing() @@ -133,10 +150,19 @@ class MyCanvas(wxScrolledWindow): self.SetXY(event) self.curLine = [] self.CaptureMouse() + self.drawing = true + + elif event.Dragging() and self.drawing: + if BUFFERED: + # If doing buffered drawing, create the buffered DC, giving it + # it a real DC to blit to when done. + cdc = wxClientDC(self) + self.PrepareDC(cdc) + dc = wxBufferedDC(cdc, self.buffer) + else: + dc = wxClientDC(self) + self.PrepareDC(dc) - elif event.Dragging(): - dc = wxClientDC(self) - self.PrepareDC(dc) dc.BeginDrawing() dc.SetPen(wxPen('MEDIUM FOREST GREEN', 4)) coords = (self.x, self.y) + self.ConvertEventCoords(event) @@ -145,10 +171,12 @@ class MyCanvas(wxScrolledWindow): self.SetXY(event) dc.EndDrawing() - elif event.LeftUp(): + + elif event.LeftUp() and self.drawing: self.lines.append(self.curLine) self.curLine = [] self.ReleaseMouse() + self.drawing = false ## This is an example of what to do for the EVT_MOUSEWHEEL event, diff --git a/wxPython/src/gdi.i b/wxPython/src/gdi.i index f250e55540..349699d6d3 100644 --- a/wxPython/src/gdi.i +++ b/wxPython/src/gdi.i @@ -878,6 +878,19 @@ public: // (where area is usually something like the size of the window // being buffered) %name(wxBufferedDCInternalBuffer)wxBufferedDC( wxDC *dc, const wxSize &area ); + + // Blits the buffer to the dc, and detaches the dc from + // the buffer. Usually called in the dtor or by the dtor + // of derived classes if the BufferedDC must blit before + // the derived class (which may own the dc it's blitting + // to) is destroyed. + void UnMask(); + + + %pragma(python) addtomethod = + "__init__:self._dc = _args[0] # save a ref so the other dc won't be deleted before self" + %pragma(python) addtomethod = + "wxBufferedDCInternalBuffer:val._dc = _args[0] # save a ref so the other dc won't be deleted before self" }; diff --git a/wxPython/src/msw/gdi.cpp b/wxPython/src/msw/gdi.cpp index 2a76d24c15..ea26ff17ff 100644 --- a/wxPython/src/msw/gdi.cpp +++ b/wxPython/src/msw/gdi.cpp @@ -8633,6 +8633,34 @@ static PyObject *_wrap_new_wxBufferedDCInternalBuffer(PyObject *self, PyObject * return _resultobj; } +#define wxBufferedDC_UnMask(_swigobj) (_swigobj->UnMask()) +static PyObject *_wrap_wxBufferedDC_UnMask(PyObject *self, PyObject *args, PyObject *kwargs) { + PyObject * _resultobj; + wxBufferedDC * _arg0; + PyObject * _argo0 = 0; + char *_kwnames[] = { "self", NULL }; + + self = self; + if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O:wxBufferedDC_UnMask",_kwnames,&_argo0)) + return NULL; + if (_argo0) { + if (_argo0 == Py_None) { _arg0 = NULL; } + else if (SWIG_GetPtrObj(_argo0,(void **) &_arg0,"_wxBufferedDC_p")) { + PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxBufferedDC_UnMask. Expected _wxBufferedDC_p."); + return NULL; + } + } +{ + PyThreadState* __tstate = wxPyBeginAllowThreads(); + wxBufferedDC_UnMask(_arg0); + + wxPyEndAllowThreads(__tstate); + if (PyErr_Occurred()) return NULL; +} Py_INCREF(Py_None); + _resultobj = Py_None; + return _resultobj; +} + static void *SwigwxBufferedPaintDCTowxBufferedDC(void *ptr) { wxBufferedPaintDC *src; wxBufferedDC *dest; @@ -11180,6 +11208,7 @@ static PyMethodDef gdicMethods[] = { { "wxScreenDC_StartDrawingOnTopWin", (PyCFunction) _wrap_wxScreenDC_StartDrawingOnTopWin, METH_VARARGS | METH_KEYWORDS }, { "new_wxScreenDC", (PyCFunction) _wrap_new_wxScreenDC, METH_VARARGS | METH_KEYWORDS }, { "new_wxBufferedPaintDC", (PyCFunction) _wrap_new_wxBufferedPaintDC, METH_VARARGS | METH_KEYWORDS }, + { "wxBufferedDC_UnMask", (PyCFunction) _wrap_wxBufferedDC_UnMask, METH_VARARGS | METH_KEYWORDS }, { "new_wxBufferedDCInternalBuffer", (PyCFunction) _wrap_new_wxBufferedDCInternalBuffer, METH_VARARGS | METH_KEYWORDS }, { "new_wxBufferedDC", (PyCFunction) _wrap_new_wxBufferedDC, METH_VARARGS | METH_KEYWORDS }, { "wxMemoryDC_SelectObject", (PyCFunction) _wrap_wxMemoryDC_SelectObject, METH_VARARGS | METH_KEYWORDS }, diff --git a/wxPython/src/msw/gdi.py b/wxPython/src/msw/gdi.py index 58affdf548..eda13bc5ec 100644 --- a/wxPython/src/msw/gdi.py +++ b/wxPython/src/msw/gdi.py @@ -857,18 +857,23 @@ class wxBufferedDCPtr(wxMemoryDCPtr): def __init__(self,this): self.this = this self.thisown = 0 + def UnMask(self, *_args, **_kwargs): + val = apply(gdic.wxBufferedDC_UnMask,(self,) + _args, _kwargs) + return val def __repr__(self): return "" % (self.this,) class wxBufferedDC(wxBufferedDCPtr): def __init__(self,*_args,**_kwargs): self.this = apply(gdic.new_wxBufferedDC,_args,_kwargs) self.thisown = 1 + self._dc = _args[0] # save a ref so it won't be deleted before self def wxBufferedDCInternalBuffer(*_args,**_kwargs): val = wxBufferedDCPtr(apply(gdic.new_wxBufferedDCInternalBuffer,_args,_kwargs)) val.thisown = 1 + val._dc = _args[0] # save a ref so it won't be deleted before self return val -- 2.45.2