| | 592 | static PyObject * |
|---|
| | 593 | __get_attro(PyObject *self, PyObject *attr) |
|---|
| | 594 | { |
|---|
| | 595 | GObject *object = G_OBJECT(((PyGObject*)self)->obj); |
|---|
| | 596 | |
|---|
| | 597 | /* Now we do fallback to generic GetAttr */ |
|---|
| | 598 | if(!object) |
|---|
| | 599 | return PyObject_GenericGetAttr(self, attr); |
|---|
| | 600 | |
|---|
| | 601 | /* There's underlying GObject so we can run custom routines and get property*/ |
|---|
| | 602 | GObjectClass *klass = G_OBJECT_GET_CLASS(object); |
|---|
| | 603 | GParamSpec *pspec; |
|---|
| | 604 | const gchar *attr_name = PyString_AsString(attr); |
|---|
| | 605 | PyTypeObject *tp = self->ob_type; |
|---|
| | 606 | |
|---|
| | 607 | pspec = g_object_class_find_property(klass, attr_name); |
|---|
| | 608 | |
|---|
| | 609 | if(!pspec) { |
|---|
| | 610 | |
|---|
| | 611 | PyErr_Format(PyExc_AttributeError, |
|---|
| | 612 | "'%.50s' object has no attribute '%.400s'", |
|---|
| | 613 | tp->tp_name, attr_name); |
|---|
| | 614 | return NULL; |
|---|
| | 615 | } |
|---|
| | 616 | |
|---|
| | 617 | GValue pval = {0, }; |
|---|
| | 618 | g_value_init(&pval, pspec->value_type); |
|---|
| | 619 | g_object_get_property(object, attr_name, &pval); |
|---|
| | 620 | |
|---|
| | 621 | PyObject *pvalue = pyg_value_as_pyobject((const GValue *)&pval, FALSE); |
|---|
| | 622 | |
|---|
| | 623 | g_value_unset(&pval); |
|---|
| | 624 | |
|---|
| | 625 | return pvalue; |
|---|
| | 626 | } |
|---|
| | 627 | |
|---|
| | 628 | static int |
|---|
| | 629 | __set_attro(PyObject *self, PyObject *attr, PyObject *value) |
|---|
| | 630 | { |
|---|
| | 631 | GObject *object = G_OBJECT(((PyGObject*)self)->obj); |
|---|
| | 632 | |
|---|
| | 633 | /* Now we do fallback to generic SetAttr */ |
|---|
| | 634 | if(!object) |
|---|
| | 635 | return PyObject_GenericSetAttr(self, attr, value); |
|---|
| | 636 | |
|---|
| | 637 | /* There's underlying GObject so we can run custom routines and set property*/ |
|---|
| | 638 | GObjectClass *klass = G_OBJECT_GET_CLASS(object); |
|---|
| | 639 | GParamSpec *pspec; |
|---|
| | 640 | const gchar *attr_name = PyString_AsString(attr); |
|---|
| | 641 | PyTypeObject *tp = self->ob_type; |
|---|
| | 642 | |
|---|
| | 643 | pspec = g_object_class_find_property(klass, attr_name); |
|---|
| | 644 | |
|---|
| | 645 | if(!pspec) { |
|---|
| | 646 | |
|---|
| | 647 | PyErr_Format(PyExc_AttributeError, |
|---|
| | 648 | "'%.50s' object has no attribute '%.400s'", |
|---|
| | 649 | tp->tp_name, attr_name); |
|---|
| | 650 | return -1; |
|---|
| | 651 | } |
|---|
| | 652 | |
|---|
| | 653 | GValue pval = {0, }; |
|---|
| | 654 | g_value_init(&pval, pspec->value_type); |
|---|
| | 655 | pyg_value_from_pyobject(&pval, value); |
|---|
| | 656 | |
|---|
| | 657 | g_object_set_property(object, attr_name, &pval); |
|---|
| | 658 | |
|---|
| | 659 | g_value_unset(&pval); |
|---|
| | 660 | |
|---|
| | 661 | return 0; |
|---|
| | 662 | } |
|---|
| | 663 | |
|---|