-
Notifications
You must be signed in to change notification settings - Fork 81
add glib.Object.GetProperty and glib.Object.SetProperty #56
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -534,6 +534,55 @@ func (v *Object) Set(name string, value interface{}) error { | |
return nil | ||
} | ||
|
||
func (v *Object) GetPropertyType(name string) (Type, error) { | ||
cstr := C.CString(name) | ||
defer C.free(unsafe.Pointer(cstr)) | ||
|
||
paramSpec := C.g_object_class_find_property(C._g_object_get_class(v.native()), (*C.gchar)(cstr)) | ||
if paramSpec == nil { | ||
return TYPE_INVALID, errors.New("couldn't find Property") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this whitespace. |
||
} | ||
return Type(paramSpec.value_type), nil | ||
|
||
} | ||
|
||
// Wrapper around g_object_get_property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should be in the from "// FuncName ..." and end with a period. |
||
func (v *Object) GetProperty(name string) (interface{}, error) { | ||
cstr := C.CString(name) | ||
defer C.free(unsafe.Pointer(cstr)) | ||
|
||
t, err := v.GetPropertyType(name) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
p, err := ValueInit(t) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this whitespace. |
||
if err != nil { | ||
return nil, errors.New("Unable to allocate value") | ||
} | ||
C.g_object_get_property(v.GObject, (*C.gchar)(cstr), p.native()) | ||
return p.GoValue() | ||
} | ||
|
||
// Wrapper around g_object_set_property | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should be in the from "// FuncName ..." and end with a period. |
||
func (v *Object) SetProperty(name string, value interface{}) error { | ||
cstr := C.CString(name) | ||
defer C.free(unsafe.Pointer(cstr)) | ||
|
||
if _, ok := value.(Object); ok { | ||
value = value.(Object).GObject | ||
} | ||
|
||
p, err := GValue(value) | ||
if err != nil { | ||
return errors.New("Unable to perform type conversion") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do not capitalize error strings. |
||
} | ||
C.g_object_set_property(v.GObject, (*C.gchar)(cstr), p.native()) | ||
return nil | ||
} | ||
|
||
// pointerVal attempts to return an unsafe.Pointer for value. | ||
// Not all types are understood, in which case a nil Pointer | ||
// is returned. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment here for godoc.