summaryrefslogtreecommitdiffstats
path: root/gobject
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2005-07-15 20:27:38 +0000
committerJohan Dahlin <johan@src.gnome.org>2005-07-15 20:27:38 +0000
commit233789c73ffcbbe18b8dffdcf91416875f99c3a4 (patch)
tree4ef38f9033e92b6944827c862e0c0cc0838d0051 /gobject
parentb06e98fe21c4748d79d9eb966ddb301dc7779c4b (diff)
downloadpygobject-233789c73ffcbbe18b8dffdcf91416875f99c3a4.tar.gz
pygobject-233789c73ffcbbe18b8dffdcf91416875f99c3a4.tar.xz
pygobject-233789c73ffcbbe18b8dffdcf91416875f99c3a4.zip
Allow enums to be specified in the constructor Return flags or enum object
* gobject/gobjectmodule.c: (create_property): Allow enums to be specified in the constructor * gobject/pygparamspec.c: (pyg_param_spec_getattr): Return flags or enum object for pspec.default_value * tests/test_enum.py: Remove usage of assert statement, add default_value test, both for flags and enum
Diffstat (limited to 'gobject')
-rw-r--r--gobject/gobjectmodule.c18
-rw-r--r--gobject/pygparamspec.c36
2 files changed, 39 insertions, 15 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index b6dba0d..e038bfa 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -701,9 +701,15 @@ create_property (const gchar *prop_name,
case G_TYPE_ENUM:
{
gint default_value;
-
- if (!PyArg_ParseTuple(args, "i", &default_value))
+ PyObject *pydefault;
+
+ if (!PyArg_ParseTuple(args, "O", &pydefault))
+ return NULL;
+
+ if (pyg_enum_get_value(prop_type, pydefault,
+ (gint *)&default_value))
return NULL;
+
pspec = g_param_spec_enum (prop_name, nick, blurb,
prop_type, default_value, flags);
}
@@ -711,9 +717,15 @@ create_property (const gchar *prop_name,
case G_TYPE_FLAGS:
{
guint default_value;
+ PyObject *pydefault;
- if (!PyArg_ParseTuple(args, "i", &default_value))
+ if (!PyArg_ParseTuple(args, "O", &pydefault))
+ return NULL;
+
+ if (pyg_flags_get_value(prop_type, pydefault,
+ (gint *)&default_value))
return NULL;
+
pspec = g_param_spec_flags (prop_name, nick, blurb,
prop_type, default_value, flags);
}
diff --git a/gobject/pygparamspec.c b/gobject/pygparamspec.c
index 13a526c..4bcc3f1 100644
--- a/gobject/pygparamspec.c
+++ b/gobject/pygparamspec.c
@@ -131,7 +131,8 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
"value_type", "minimum", "maximum",
"default_value");
} else if (!strcmp(attr, "default_value")) {
- return PyString_FromFormat("%c", G_PARAM_SPEC_CHAR(pspec)->default_value);
+ return PyString_FromFormat(
+ "%c", G_PARAM_SPEC_CHAR(pspec)->default_value);
} else if (!strcmp(attr, "minimum")) {
return PyInt_FromLong(G_PARAM_SPEC_CHAR(pspec)->minimum);
} else if (!strcmp(attr, "maximum")) {
@@ -145,7 +146,8 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
"value_type", "minimum", "maximum",
"default_value");
} else if (!strcmp(attr, "default_value")) {
- return PyString_FromFormat("%c", G_PARAM_SPEC_UCHAR(pspec)->default_value);
+ return PyString_FromFormat(
+ "%c", G_PARAM_SPEC_UCHAR(pspec)->default_value);
} else if (!strcmp(attr, "minimum")) {
return PyInt_FromLong(G_PARAM_SPEC_UCHAR(pspec)->minimum);
} else if (!strcmp(attr, "maximum")) {
@@ -251,7 +253,8 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
"flags", "name", "nick", "owner_type",
"value_type", "default_value");
} else if (!strcmp(attr, "default_value")) {
- return PyString_FromFormat("%c", G_PARAM_SPEC_UNICHAR(pspec)->default_value);
+ return PyString_FromFormat(
+ "%c", G_PARAM_SPEC_UNICHAR(pspec)->default_value);
}
} else if (G_IS_PARAM_SPEC_ENUM(pspec)) {
if (!strcmp(attr, "__members__")) {
@@ -260,7 +263,8 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
"flags", "name", "nick", "owner_type",
"value_type", "enum_class");
} else if (!strcmp(attr, "default_value")) {
- return PyInt_FromLong(G_PARAM_SPEC_ENUM(pspec)->default_value);
+ return pyg_enum_from_gtype(
+ pspec->value_type, G_PARAM_SPEC_ENUM(pspec)->default_value);
} else if (!strcmp(attr, "enum_class")) {
return pygenum_from_pspec(pspec);
}
@@ -271,7 +275,8 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
"flags", "name", "nick", "owner_type",
"value_type", "flags_class");
} else if (!strcmp(attr, "default_value")) {
- return PyInt_FromLong(G_PARAM_SPEC_FLAGS(pspec)->default_value);
+ return pyg_flags_from_gtype(
+ pspec->value_type, G_PARAM_SPEC_FLAGS(pspec)->default_value);
} else if (!strcmp(attr, "flags_class")) {
return pygflags_from_pspec(pspec);
}
@@ -299,7 +304,8 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
"minimum", "maximum",
"default_value", "epsilon");
} else if (!strcmp(attr, "default_value")) {
- return PyFloat_FromDouble(G_PARAM_SPEC_DOUBLE(pspec)->default_value);
+ return PyFloat_FromDouble(
+ G_PARAM_SPEC_DOUBLE(pspec)->default_value);
} else if (!strcmp(attr, "minimum")) {
return PyFloat_FromDouble(G_PARAM_SPEC_DOUBLE(pspec)->minimum);
} else if (!strcmp(attr, "maximum")) {
@@ -315,17 +321,23 @@ pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
"cset_nth", "substitutor",
"null_fold_if_empty", "ensure_non_null");
} else if (!strcmp(attr, "default_value")) {
- return Py_BuildValue("s", G_PARAM_SPEC_STRING(pspec)->default_value);
+ return Py_BuildValue(
+ "s", G_PARAM_SPEC_STRING(pspec)->default_value);
} else if (!strcmp(attr, "cset_first")) {
- return Py_BuildValue("s", G_PARAM_SPEC_STRING(pspec)->cset_first);
+ return Py_BuildValue(
+ "s", G_PARAM_SPEC_STRING(pspec)->cset_first);
} else if (!strcmp(attr, "cset_nth")) {
- return Py_BuildValue("s", G_PARAM_SPEC_STRING(pspec)->cset_nth);
+ return Py_BuildValue(
+ "s", G_PARAM_SPEC_STRING(pspec)->cset_nth);
} else if (!strcmp(attr, "substitutor")) {
- return Py_BuildValue("c", G_PARAM_SPEC_STRING(pspec)->substitutor);
+ return Py_BuildValue(
+ "c", G_PARAM_SPEC_STRING(pspec)->substitutor);
} else if (!strcmp(attr, "null_fold_if_empty")) {
- return PyBool_FromLong(G_PARAM_SPEC_STRING(pspec)->null_fold_if_empty);
+ return PyBool_FromLong(
+ G_PARAM_SPEC_STRING(pspec)->null_fold_if_empty);
} else if (!strcmp(attr, "ensure_non_null")) {
- return PyBool_FromLong(G_PARAM_SPEC_STRING(pspec)->ensure_non_null);
+ return PyBool_FromLong(
+ G_PARAM_SPEC_STRING(pspec)->ensure_non_null);
}
} else {
if (!strcmp(attr, "__members__")) {