Adopt new WindowProperties(size=(x, y), ...) short-hand

This is intended as replacement for WindowProperties.size(x, y), which is deprecated since it conflicts with the `size` property.  See #444.
This commit is contained in:
rdb 2018-11-12 16:58:01 +01:00
parent 598664ab80
commit 074c5187b0
8 changed files with 142 additions and 11 deletions

View File

@ -960,8 +960,13 @@ setup_properties(const InterrogateFunction &ifunc, InterfaceMaker *interface_mak
} else if (!_has_this && _parameters.size() > 0 &&
(_cppfunc->_storage_class & CPPInstance::SC_explicit) == 0) {
// A non-explicit non-copy constructor might be eligible for coercion.
_flags |= F_coerce_constructor;
// A non-explicit non-copy constructor might be eligible for coercion,
// as long as it does not require explicit keyword args.
if ((_flags & F_explicit_args) == 0 ||
_args_type != InterfaceMaker::AT_keyword_args) {
_flags |= F_coerce_constructor;
}
}
// Constructors always take varargs, and possibly keyword args.

View File

@ -3875,9 +3875,7 @@ if (not RUNTIME):
IGATEFILES.remove("renderBuffer.h")
TargetAdd('libp3display.in', opts=OPTS, input=IGATEFILES)
TargetAdd('libp3display.in', opts=['IMOD:panda3d.core', 'ILIB:libp3display', 'SRCDIR:panda/src/display'])
PyTargetAdd('p3display_graphicsStateGuardian_ext.obj', opts=OPTS, input='graphicsStateGuardian_ext.cxx')
PyTargetAdd('p3display_graphicsWindow_ext.obj', opts=OPTS, input='graphicsWindow_ext.cxx')
PyTargetAdd('p3display_pythonGraphicsWindowProc.obj', opts=OPTS, input='pythonGraphicsWindowProc.cxx')
PyTargetAdd('p3display_ext_composite.obj', opts=OPTS, input='p3display_ext_composite.cxx')
if RTDIST and GetTarget() == 'darwin':
OPTS=['DIR:panda/src/display']
@ -4277,9 +4275,7 @@ if (not RUNTIME):
PyTargetAdd('core.pyd', input='p3event_pythonTask.obj')
PyTargetAdd('core.pyd', input='p3gobj_ext_composite.obj')
PyTargetAdd('core.pyd', input='p3pgraph_ext_composite.obj')
PyTargetAdd('core.pyd', input='p3display_graphicsStateGuardian_ext.obj')
PyTargetAdd('core.pyd', input='p3display_graphicsWindow_ext.obj')
PyTargetAdd('core.pyd', input='p3display_pythonGraphicsWindowProc.obj')
PyTargetAdd('core.pyd', input='p3display_ext_composite.obj')
PyTargetAdd('core.pyd', input='core_module.obj')
if not GetLinkAllStatic() and GetTarget() != 'emscripten':

View File

@ -0,0 +1,4 @@
#include "graphicsStateGuardian_ext.cxx"
#include "graphicsWindow_ext.cxx"
#include "pythonGraphicsWindowProc.cxx"
#include "windowProperties_ext.cxx"

View File

@ -135,6 +135,8 @@ clear_default() {
/**
* Returns a WindowProperties structure with only the size specified. The
* size is the only property that matters to buffers.
*
* @deprecated in the Python API, use WindowProperties(size=(x, y)) instead.
*/
WindowProperties WindowProperties::
size(const LVecBase2i &size) {

View File

@ -27,6 +27,10 @@
* properties for a window after it has been opened.
*/
class EXPCL_PANDA_DISPLAY WindowProperties {
public:
WindowProperties();
INLINE WindowProperties(const WindowProperties &copy);
PUBLISHED:
enum ZOrder {
Z_bottom,
@ -40,8 +44,9 @@ PUBLISHED:
M_confined,
};
WindowProperties();
INLINE WindowProperties(const WindowProperties &copy);
EXTENSION(WindowProperties(PyObject *self, PyObject *args, PyObject *kwds));
PUBLISHED:
void operator = (const WindowProperties &copy);
INLINE ~WindowProperties();

View File

@ -0,0 +1,82 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file windowProperties_ext.cxx
* @author rdb
* @date 2018-11-12
*/
#include "windowProperties_ext.h"
#ifdef HAVE_PYTHON
extern struct Dtool_PyTypedObject Dtool_WindowProperties;
/**
* Creates a new WindowProperties initialized with the given properties.
*/
void Extension<WindowProperties>::
__init__(PyObject *self, PyObject *args, PyObject *kwds) {
nassertv_always(_this != nullptr);
// We need to initialize the self object before we can use it.
DtoolInstance_INIT_PTR(self, _this);
// Support copy constructor by extracting the one positional argument.
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
if (nargs != 0) {
if (nargs != 1) {
PyErr_Format(PyExc_TypeError,
"WindowProperties() takes at most 1 positional argument (%d given)",
(int)nargs);
return;
}
PyObject *arg = PyTuple_GET_ITEM(args, 0);
const WindowProperties *copy_from;
if (DtoolInstance_GetPointer(arg, copy_from, Dtool_WindowProperties)) {
*_this = *copy_from;
} else {
Dtool_Raise_ArgTypeError(arg, 0, "WindowProperties", "WindowProperties");
return;
}
}
// Now iterate over the keyword arguments, which define the default values
// for the different properties.
if (kwds != nullptr) {
PyTypeObject *type = Py_TYPE(self);
PyObject *key, *value;
Py_ssize_t pos = 0;
while (PyDict_Next(kwds, &pos, &key, &value)) {
// Look for a writable property on the type by this name.
PyObject *descr = _PyType_Lookup(type, key);
if (descr != nullptr && Py_TYPE(descr)->tp_descr_set != nullptr) {
if (Py_TYPE(descr)->tp_descr_set(descr, self, value) < 0) {
return;
}
} else {
PyObject *key_repr = PyObject_Repr(key);
PyErr_Format(PyExc_TypeError,
"%.100s is an invalid keyword argument for WindowProperties()",
#if PY_MAJOR_VERSION >= 3
PyUnicode_AsUTF8(key_repr)
#else
PyString_AsString(key_repr)
#endif
);
Py_DECREF(key_repr);
return;
}
}
}
}
#endif // HAVE_PYTHON

View File

@ -0,0 +1,37 @@
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file windowProperties_ext.h
* @author rdb
* @date 2018-11-12
*/
#ifndef WINDOWPROPERTIES_EXT_H
#define WINDOWPROPERTIES_EXT_H
#include "dtoolbase.h"
#ifdef HAVE_PYTHON
#include "extension.h"
#include "windowProperties.h"
#include "py_panda.h"
/**
* This class defines the extension methods for WindowProperties, which are
* called instead of any C++ methods with the same prototype.
*/
template<>
class Extension<WindowProperties> : public ExtensionBase<WindowProperties> {
public:
void __init__(PyObject *self, PyObject *args, PyObject *kwds);
};
#endif // HAVE_PYTHON
#endif // WINDOWPROPERTIES_EXT_H

View File

@ -40,7 +40,7 @@ class World(DirectObject):
# creating the offscreen buffer.
winprops = WindowProperties.size(512, 512)
winprops = WindowProperties(size=(512, 512))
props = FrameBufferProperties()
props.setRgbColor(1)
props.setAlphaBits(1)