Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Getting setproperty! on GtkTextTag for foreground_rgba to work #243

Closed
guidocalvano opened this issue Jul 2, 2016 · 5 comments · Fixed by #533
Closed

Getting setproperty! on GtkTextTag for foreground_rgba to work #243

guidocalvano opened this issue Jul 2, 2016 · 5 comments · Fixed by #533

Comments

@guidocalvano
Copy link

guidocalvano commented Jul 2, 2016

Hey,

I'm trying to get tags with color to work... But for some reason I can't.

When using setproperty! the code complained that my GdkRGBA class could not be converted to a GType. I could not figure out how the g type system works as I am fairly new to julia. I could also not create a new setproperty! method that specifically targets what I want to do. I suspect it is fairly easy to accomplish what I am trying to do with only a little bit of help from you.

So I have two questions:

  1. What is the correct approach to register my GdkRGBA type?
  2. If you think it is better to use a custom setproperty! method, how do I pass my GdkRGBA type to ccal to invoke gobject_set

My GdkRGBA type:


type GdkRGBA
  red::Cdouble
  green::Cdouble
  blue::Cdouble
  alpha::Cdouble
  GdkRGBA() = new(0,0,0,0)
  GdkRGBA(red, green, blue, alpha) = new(red, green, blue, alpha);
end
typealias GDKRGBA Union{Mutable{GdkRGBA},GdkRGBA}
zero(::Type{GdkRGBA}) = GdkRGBA()
copy(rgba::GdkRGBA) = rgba
copy(rgba::Mutable{GdkRGBA}) = mutable(rgba[])

My attempt at writing a setproperty! method:

function setproperty!(w::Gtk.GtkTextTag, name::AbstractStringLike, value)
    ccall((:g_object_set_property, libgobject), Void,
        (Ptr{GObject}, Ptr{UInt8}, Ptr{GdkRGBA}), w, GLib.bytestring(name), Ptr(value))
end

Thank you for your great work and the time to have a look at my issue.

ps. I've also gotten a place_cursor! function to work for the GtkTextBuffer. If you want it let, me know and I'll create a pull request.

@guidocalvano
Copy link
Author

At the bottom of this page was the solution to what I had to do:
https://github.com/JuliaGraphics/Gtk.jl/blob/master/doc/developer.md#adding-new-gvaluejulia-auto-conversions

I've got two pull requests if you want them:

  1. place_cursor now works on a textbuffer
  2. I can create text tags with color now.
    (and 3. I've replaced a number of deprecated calls to the bool function, with a call to the Bool function, so Gtk.jl does not break on julia v0.5).

Send me a message and I will send you the code.

@vtjnash
Copy link
Contributor

vtjnash commented Jul 4, 2016

sgtm if you want to make a PR. I have a RGBA type in displays.jl, but it lacks support for most operations, so if you have found some support methods that would make it more usable, put it in a PR

@guidocalvano
Copy link
Author

In order to prevent having two rgba types in the repo, I tried to set the color of a tag using the RGBA type you spoke about but I get errors.
Also; the constructor of the RGBA type in display misses an argument for the alpha value
and apparently get_type doesn’t work for that RGBA value, causing assignment to fail.

Is the RGBA object there used? and if so where? if not, shall I replace it with my RGBA?

I understand the basic principles of writing a binding now, so if you want I can spend half a day adding a few if you like. Just let me know the ones you are eager to have soon.

@vtjnash
Copy link
Contributor

vtjnash commented Jul 6, 2016

It's used, but not much. it's just provided as a way to describe the image buffer type. You should merge it with your complete definition. Agreed that the constructor is wrong.

@guidocalvano
Copy link
Author

Made the pull request. Check the comment there before merging.

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 a pull request may close this issue.

2 participants