私の目的は、スケールのスライダーをスピンの値と同期させ、その逆にすることです。いくつかの代替手段を試しましたが、新しいスピン位置を設定できるようにスケールの値を取得する方法が見つかりません。
小さな演習には、両方のウィジェットを同期する小さなチェック ボタンがあります。トグル機能を使用してこの同期を実行しようとしていますが、現在行き詰まっています。
これまでのコードは次のとおりです。
uses
Gtk
class TestWindow:Window
_spin:Gtk.SpinButton
_scale:Gtk.Scale
construct ()
//General aspects of the window
title = "Spin and scale"
window_position = WindowPosition.CENTER
destroy.connect( Gtk.main_quit )
//create the spin button
spinAdjustment:Gtk.Adjustment = new Gtk.Adjustment(50, 0, 100, 1, 5, 0)
scaleAdjustment:Gtk.Adjustment = new Gtk.Adjustment(50, 0, 100, 1, 5, 0)
_spin:SpinButton = new Gtk.SpinButton(spinAdjustment, 1.0,1)
//create the horizontal scale
_scale:Scale = new Gtk.Scale(Gtk.Orientation.HORIZONTAL, scaleAdjustment);
//create the check button
var check = new Gtk.CheckButton.with_label ("Sync both scales!")
check.toggled.connect(toggled)
// organize it in a box
var box = new Box( Orientation.VERTICAL, 0 )
box.pack_start(_spin, true, true, 0 )
box.pack_start(_scale, true, true, 0)
box.pack_start(check, true, true, 0)
add( box )
def toggled ()
message(_spin.get_value().to_string())
//if _scale.get_value_pos() != _spin.get_value()
// _scale.set_value_pos(_spin.get_value())
init
Gtk.init( ref args )
var test = new TestWindow()
test.show_all()
Gtk.main()
これを解決する方法について、誰かが私に少しの指針を与えることができますか?