在Julia中,我想根据Gtk滑块中值的更改来更新绘图。我知道这与https://developer.gnome.org/gtk2/2.24/GtkRange.html#GtkRange-value-changed中的“更改值”信号有关。但是,作为一个初学者,我不知道如何实现代码
The “change-value” signal
gboolean
user_function (GtkRange *range,
GtkScrollType scroll,
gdouble value,
gpointer user_data)
实现我想要做的。有人可以举一个例子说明如何使用“变化值”信号吗?
我知道如何为滑块设置窗口
sl = slider(1:11)
win = Window("Testing") |> (bx = Box(:v))
push!(bx, sl)
Gtk.showall(win)
我也知道更新情节需要什么样的功能
function update(val)
int_val = int(val)
if Signal(sl) != int_val
x = range(0., 2*pi, step=0.01)
y = map(sin, x)
PyPlot.plot(x,Signal(sl)*y)
end
end
但是,我不知道如何或在何处触发“更新”功能以采取实际行动。
谢谢!
答案 0 :(得分:0)
谢谢,liberforce为您提供建议! 这是我的最小工作示例: '''
using Gtk
# Set up scale (slider) and window
sl = GtkScale(false, 0:10)
win = Gtk.Window("Gain Selection") |> (bx = Gtk.Box(:v))
push!(bx, sl)
Gtk.showall(win)
# Connect with value-changed signal
id = signal_connect(sl, "value-changed") do widget
# Get scale value
sub = Gtk.GAccessor.adjustment(widget)
val = Gtk.get_gtk_property(sub,"value",Int64)
# Perform function related to the scale value.
println("Gain is changed to ", val)
end
push!(bx, sl)
Gtk.showall(win);
'''
参考: 信号连接:http://juliagraphics.github.io/Gtk.jl/latest/manual/signals.html
GtkScale:https://lazka.github.io/pgi-docs/Gtk-3.0/classes/Scale.html
提取比例值:https://discourse.julialang.org/t/how-to-get-the-current-value-of-a-gtk-scale-widget/15680
朱莉娅(Julia)封锁:https://www.juliabloggers.com/julia-do-block-vs-python-with-statement/