summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2004-08-06 15:56:53 +0000
committerJohan Dahlin <johan@src.gnome.org>2004-08-06 15:56:53 +0000
commit43a98de47fdb525027cf4c154581d328bcb4957e (patch)
treec7da76d20970bbcfdf146411ce3b2bbc783ca1bf
parentffaae65bbb21f2aa4b1f4214104ca6f7fddaa3bd (diff)
downloadpygtk-43a98de47fdb525027cf4c154581d328bcb4957e.tar.gz
Don't comment out the fallback, it break the test. (Wow, the testsuite
* gobject/pygflags.c (pyg_flags_from_gtype): Don't comment out the fallback, it break the test. (Wow, the testsuite caught another bug!) * tests/enum.py: Additional tests. * gobject/pygenum.c (pyg_enum_repr): Don't use g_enum_get_value, use enum_class->values[n].value_name instead. Also check if the value is NULL or not. This makes gtk.icon_size_register work a little bit better.
-rw-r--r--ChangeLog10
-rw-r--r--gobject/pygenum.c20
-rw-r--r--gobject/pygflags.c7
-rw-r--r--tests/enum.py11
4 files changed, 33 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index e7e0f823..8ff3c224 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2004-08-06 Johan Dahlin <johan@gnome.org>
+ * gobject/pygflags.c (pyg_flags_from_gtype): Don't comment out the
+ fallback, it break the test. (Wow, the testsuite caught another bug!)
+
+ * tests/enum.py: Additional tests.
+
+ * gobject/pygenum.c (pyg_enum_repr): Don't use g_enum_get_value,
+ use enum_class->values[n].value_name instead. Also check if the
+ value is NULL or not. This makes gtk.icon_size_register work a
+ little bit better.
+
* codegen/codegen.py (Wrapper.write_methods): Use methflags
argument for defines instead of discarding it
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index 80d241a7..17888c8b 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -52,16 +52,17 @@ static PyObject *
pyg_enum_repr(PyGEnum *self)
{
GEnumClass *enum_class;
- GEnumValue *enum_value;
+ char *value;
static char tmp[256];
enum_class = g_type_class_ref(self->gtype);
g_assert(G_IS_ENUM_CLASS(enum_class));
-
- enum_value = g_enum_get_value(enum_class, self->parent.ob_ival);
- g_assert(enum_value != 0);
-
- sprintf(tmp, "<enum %s of type %s>", enum_value->value_name, g_type_name(self->gtype));
+
+ value = enum_class->values[self->parent.ob_ival].value_name;
+ if (value)
+ sprintf(tmp, "<enum %s of type %s>", value, g_type_name(self->gtype));
+ else
+ sprintf(tmp, "<enum %ld of type %s>", self->parent.ob_ival, g_type_name(self->gtype));
g_type_class_unref(enum_class);
@@ -142,7 +143,12 @@ pyg_enum_from_gtype (GType gtype, int value)
retval = PyDict_GetItem(values, PyInt_FromLong(value));
if (!retval) {
PyErr_Clear();
- return PyInt_FromLong(value);
+ retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0);
+ g_assert(retval != NULL);
+
+ ((PyIntObject*)retval)->ob_ival = value;
+ ((PyGFlags*)retval)->gtype = gtype;
+ //return PyInt_FromLong(value);
}
Py_INCREF(retval);
diff --git a/gobject/pygflags.c b/gobject/pygflags.c
index 526368ab..98e3a9eb 100644
--- a/gobject/pygflags.c
+++ b/gobject/pygflags.c
@@ -80,8 +80,7 @@ pyg_flags_repr(PyGFlags *self)
char *tmp, *retval;
PyObject *pyretval;
- tmp = generate_repr(self->gtype,
- self->parent.ob_ival);
+ tmp = generate_repr(self->gtype, self->parent.ob_ival);
retval = g_strdup_printf("<flags %s of type %s>", tmp,
g_type_name(self->gtype));
@@ -169,15 +168,11 @@ pyg_flags_from_gtype (GType gtype, int value)
if (!retval) {
PyErr_Clear();
- return PyInt_FromLong(value);
-#if 0
- /* This breaks repr */
retval = ((PyTypeObject *)pyclass)->tp_alloc((PyTypeObject *)pyclass, 0);
g_assert(retval != NULL);
((PyIntObject*)retval)->ob_ival = value;
((PyGFlags*)retval)->gtype = gtype;
-#endif
}
Py_INCREF(retval);
diff --git a/tests/enum.py b/tests/enum.py
index 2e2a2dc8..052a5e98 100644
--- a/tests/enum.py
+++ b/tests/enum.py
@@ -73,8 +73,12 @@ class EnumTest(unittest.TestCase):
assert len(klass.__enum_values__) >= 2
def testOutofBounds(self):
- assert gtk.icon_size_register('fake', 24, 24) == 7
-
+ val = gtk.icon_size_register('fake', 24, 24)
+ assert isinstance(val, gobject.GEnum)
+ assert int(val) == 7
+ assert '7' in repr(val)
+ assert 'GtkIconSize' in repr(val)
+
class FlagsTest(unittest.TestCase):
def testFlags(self):
assert issubclass(gobject.GFlags, int)
@@ -100,16 +104,19 @@ class FlagsTest(unittest.TestCase):
def testFlagOperations(self):
a = gdk.BUTTON_PRESS_MASK
+ assert isinstance(a, gobject.GFlags)
assert a.first_value_name == 'GDK_BUTTON_PRESS_MASK'
assert a.first_value_nick == 'button-press-mask'
assert a.value_names == ['GDK_BUTTON_PRESS_MASK'], a.value_names
assert a.value_nicks == ['button-press-mask'], a.value_names
b = gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK
+ assert isinstance(b, gobject.GFlags)
assert b.first_value_name == 'GDK_BUTTON_PRESS_MASK'
assert b.first_value_nick == 'button-press-mask'
assert b.value_names == ['GDK_BUTTON_PRESS_MASK', 'GDK_BUTTON_RELEASE_MASK']
assert b.value_nicks == ['button-press-mask', 'button-release-mask']
c = gdk.BUTTON_PRESS_MASK | gdk.BUTTON_RELEASE_MASK | gdk.ENTER_NOTIFY_MASK
+ assert isinstance(c, gobject.GFlags)
assert c.first_value_name == 'GDK_BUTTON_PRESS_MASK'
assert c.first_value_nick == 'button-press-mask'
assert c.value_names == ['GDK_BUTTON_PRESS_MASK', 'GDK_BUTTON_RELEASE_MASK',