I’m trying to learn Julia by converting some of my Python apps to it. I’m using gtk because Tk no longer builds in Julia 1.0. I’ve hit a brick wall trying to get the value of a GtkScale widget. Here’s an example:
Gtk scale widget test
win = GtkWindow()
s = GtkScale(false, 0:10)
if widget == s
id = signal_connect(scaleset, s, “value_changed”)
This correctly calls the callback function scaleset when the slider is dragged. I need to get the new value of the scale at that point, which is trivial in Python, Java, C#, …, but I can find no documentation that tells how to do it in Julia. I’ve read that the value is stored in the parent GtkRange but I don’t know how to access that. REPL help says “Binding GtkRange does not exist.”
Can anybody tell me how to get the value, or, even better, point me to valid documentation for this? Many thanks for any help.
looks to me like get_value is missing in Gtk.jl. I’d recommend to put an issue there.
a = Gtk.GAccessor.adjustment(s)
value = Gtk.get_gtk_property(a,“value”,Float64)
(edit: jonathans syntax below is recommended)
Here’s two ways to do it (using the new getproperty syntax):
println( Gtk.GAccessor.value(widget) )
adj = s.adjustment[GtkAdjustment]
println( adj.value[Float64] )
What I usually do is look in Gtk docs for properties that I can use. If there no properties then I look for a method and I just search that method name in the Gtk.jl repo. In that case I found this. All the methods there have been automatically wrapped with
Clang.jl, and they are in the submodule
Is far as I have understood one usually uses the
GtkAdjustment to communicate with a scale or a spin button. In that way you can exchange the visual representation.
I do my UI fully in glade and the create the GtkAdjustment + SpinButton from there and also connect them there. In julia I then just need to communicate with the Adjustment.
With GtkReactive it’s just
julia> using Gtk.ShortNames, GtkReactive
julia> win = Window("slider") |> (sl = slider(1:10)); Gtk.showall(win);
These are exactly what I needed. And they suggested the way to reset the Scale limits dynamically, which I also need to do, using Gtk.GAccessor.range(s,newmin,newmax). Thanks very much!
Thanks. I’d tried to use GtkReactive, but the package manager failed to add it, apparently because of an error building Tk.jl (!?) which I had tried initially. I’m off and running now with GAccessor.