Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

add glib.Object.GetProperty and glib.Object.SetProperty #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mstoykov
Copy link

I had problems using the Object.Set method so decided to implement the SetProperty and GetProperty (at which point my problem was resolved).

I might implement the property listing and wrap GParamSpec in the future

@jrick
Copy link
Member

jrick commented May 14, 2014

I think that Set should be fixed rather than just tacking on a workaround. Do you have an example that shows the failure?

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")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this whitespace.

@jrick
Copy link
Member

jrick commented May 14, 2014

In any case, I added a whole bunch of comments for some style mistakes. Please fix Set with the new implementation and fix these style issues and I'd be happy to merge the PR.

@mstoykov
Copy link
Author

First thank you for the comments.

My problem was with setting 'uri' on a playbin in the example in my gst binding fork - here (it currently needs additional changes in my development branch of gotk3).
WIth Set I get a decodebin error and I get some leftover symbols in the property (which should not happen) - with SetProperty it works correctly.
I'm not sure what the problem is but I think that given g_object_set_property and g_object_get_property exist we can use them.
I would actually prefer if Set gets to be a real binding to g_object_set (sometime in the future of course).

@mstoykov
Copy link
Author

Thinking about it - I would really prefer if GParamSpec gets a representation as a go type which would take GObjectClass representation too. That would make GetPropertyType unnecessary.
I would like to know what you think about it - and I would try to see how far I get in the mean time.

@jrick
Copy link
Member

jrick commented May 25, 2014

Sorry for the slow response. I think it may be a good idea if it can be done without substantial complexity, but I'm not totally familiar with the internals of and API for using GParamSpec (and the glib doco is rather light in this area). If my understanding is correct, this should allow creating/retrieving the properties for any Object, like:

paramSpec := obj.ParamSpec()
prop, err := paramSpec.GetPropery(propName)
// Assumming prop is an int
n, ok := prop.(int)
paramSpec.SetProperty(propName, n+1)

What other advantages would adding ParamSpec wrappers have? The above is basically how I expect Get and Set must work, but without the ParamSpec plumbing in the middle.

@mstoykov
Copy link
Author

No worries, and I'm sorry for my slow response, too :).

I more and more think that you are correct at least for the moment as the two things I can think of using GParamSpec implementation are :
Defining our own GObjectClass_ - we will need GParamSpec to implement new property on them. But currently I have no interest in even trying to implement this and then test it.
Inspecting object properties - in my development branch I have also implemented g_object_class_list_properties - which returns all properties defined for a particular class - by which you can then get all the values + type and restrictions (read, write, constructor only) for them and so do a nice dump of a particular object that you don't know anything about before hand.

Both are not bad features to have, but will take a lot more work to implement either of them. On the other hand redoing the above code to use a possible future implementation of both GParamSpec and GObjectClass does not actually take a lot of code changes.

I'm not all that familiar with glib, gtk or any of the other techonology/libraries that are being used. So all of the above was learned while reading the docs to bind what I need.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants