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
This commit is contained in:
parent
06cf7c08f2
commit
d3bfec747d
25
wxPython/demo/template.py
Normal file
25
wxPython/demo/template.py
Normal file
@ -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 = """<html><body>
|
||||
<h2><center>Say something nice here</center></h2>
|
||||
|
||||
</body></html>
|
||||
"""
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
};
|
||||
|
||||
|
||||
|
@ -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 },
|
||||
|
@ -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 "<C wxBufferedDC instance at %s>" % (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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user