この問題の解決に成功しなかったのは久しぶりです。チェックボタンをチェックしている間、スピンボタンとスケールを常に同期させる練習です。ただし、チェック ボタンがアクティブでない場合は、スケールとスピンの両方が自由に値を取得できます。
ここの前の質問では、bind_property メソッドを使用することが提案されました。これは、スピンとスケールの両方を常に同期させたい場合に実際にうまく機能します。ただし、チェックボタンのアクティビティ(またはその欠如)にリンクする必要がある場合、機能しません。2 回目にチェック ボタンをクリックすると、プログラムがハングします。
これが私が持っている距離です:
[indent=4]
uses
Gtk
class TestWindow:Window
_spin:SpinButton
_scale:Scale
_check:CheckButton
construct ()
//General aspects of the window
title = "Spin and scale"
window_position = WindowPosition.CENTER
destroy.connect( main_quit )
//create the spin button
spinAdjustment:Adjustment = new Adjustment( 50, 0, 100, 1, 5, 0 )
scaleAdjustment:Adjustment = new Adjustment( 50, 0, 100, 1, 5, 0 )
_spin = new SpinButton( spinAdjustment, 1.0, 1 )
//create the horizontal scale
_scale = new Scale( Orientation.HORIZONTAL, scaleAdjustment );
//create the check button
_check = new CheckButton.with_label ( "Sync both scales!" )
_check.set_active(true)
_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 ()
if (_check.active)
_spin.adjustment.bind_property( "value", _scale.adjustment, "value",BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL )
init
Gtk.init( ref args )
var test = new TestWindow()
test.show_all()
Gtk.main()
押されている間だけ同期するようにバインディングをチェックボタンにリンクする方法について誰か提案がありますか? 問題を解決するための他の戦略を見つけようとする必要がありますか?
ありがとう